import { Constructor } from '@ulangi/extended-types' ; import { Navigation } from '@ulangi/react-native-navigation' ; import { LightBoxState , ScreenState , Theme } from '@ulangi/ulangi-common/enums' ; import SplashScreen from 'react-native-splash-screen' ; import { Container } from '../Container' ; export function extendContainer < T extends Constructor < Container > > ( constructor ) { return class extends constructor { public constructor ( ... args ) { super ( ... args ) ; const containerOptions = this . getContainerOptions ( ) ; if ( containerOptions . autoBindNavigationEvent === true ) { Navigation . events ( ) . bindComponent ( this ) ; } if ( containerOptions . autoUpdateObservableScreen === true ) { if ( typeof this . observableScreen !== 'undefined' ) { this . props . observableScreenRegistry . screenList . push ( this . observableScreen ) ; } } if ( containerOptions . autoUpdateObservableLightBox === true ) { if ( typeof this . observableLightBox !== 'undefined' ) { this . observableLightBox . componentId = this . props . componentId ; } } } public componentDidMount ( ) { if ( typeof super . componentDidMount !== 'undefined' ) { super . componentDidMount ( ) ; } const containerOptions = this . getContainerOptions ( ) ; if ( containerOptions . autoUpdateObservableScreen === true ) { if ( typeof this . observableScreen !== 'undefined' ) { this . observableScreen . screenState = ScreenState . MOUNTED ; } } if ( containerOptions . autoUpdateObservableLightBox === true ) { if ( typeof this . observableLightBox !== 'undefined' ) { this . observableLightBox . state = LightBoxState . MOUNTED ; } } if ( containerOptions . autoCloseSplashScreen === true ) { SplashScreen . hide ( ) ; } this . observer . reaction ( ( ) : Theme => this . props . rootStore . themeStore . theme , ( theme ) : void => { this . onThemeChanged ( theme ) ; } ) ; } public componentWillUnmount ( ) { if ( typeof super . componentWillUnmount !== 'undefined' ) { super . componentWillUnmount ( ) ; } const containerOptions = this . getContainerOptions ( ) ; if ( containerOptions . autoUpdateObservableScreen === true ) { if ( typeof this . observableScreen !== 'undefined' ) { this . observableScreen . screenState = ScreenState . UNMOUNTED ; this . props . observableScreenRegistry . removeByComponentId ( this . observableScreen . componentId ) ; } } if ( containerOptions . autoUpdateObservableLightBox === true ) { if ( typeof this . observableLightBox !== 'undefined' ) { this . observableLightBox . componentId = null ; this . observableLightBox . state = LightBoxState . UNMOUNTED ; } } if ( containerOptions . autoUnsubscribeEventBus === true ) { this . eventBus . unsubscribeAll ( ) ; } if ( containerOptions . autoUnsubscribeObserver === true ) { this . observer . unsubscribeAll ( ) ; } } } ; }