11import React , { Component } from 'react' ;
2- import { Text } from 'react-native' ;
2+ import { EmitterSubscription , Platform , Text } from 'react-native' ;
33import { NavigationProps , Options } from 'react-native-navigation' ;
44
55import Root from '../components/Root' ;
66import Button from '../components/Button' ;
77import Navigation from './../services/Navigation' ;
88import Screens from './Screens' ;
9- import { component } from '../commons/Layouts' ;
9+ import { stack , component } from '../commons/Layouts' ;
1010import testIDs from '../testIDs' ;
1111import bottomTabsStruct from './BottomTabsLayoutStructure' ;
12+ import { resetWebViewLoadedOrder , TAB_SCREENS } from './TabbedWebViewScreen' ;
1213
1314export class MountedBottomTabScreensState {
1415 static mountedBottomTabScreens : string [ ] = [ ] ;
15- static callback : ( mountedBottomTabScreens : string [ ] ) => void = ( ) => { } ;
16+ static callback : ( mountedBottomTabScreens : string [ ] ) => void = ( ) => { } ;
1617
1718 static addScreen ( screen : string ) {
1819 this . mountedBottomTabScreens . push ( screen ) ;
@@ -34,6 +35,7 @@ const {
3435 SCREEN_ROOT ,
3536 SET_ROOT_BTN ,
3637 BOTTOM_TABS ,
38+ TABS_TOGETHER_BTN ,
3739} = testIDs ;
3840
3941interface NavigationState {
@@ -74,9 +76,19 @@ export default class FirstBottomTabScreen extends Component<NavigationProps, Nav
7476 }
7577
7678 badgeVisible = true ;
77- bottomTabPressedListener = Navigation . events ( ) . registerBottomTabPressedListener ( ( event ) => {
78- if ( event . tabIndex == 2 ) {
79- alert ( 'BottomTabPressed' ) ;
79+
80+ registerBottomTabListener = ( ) => {
81+ return Navigation . events ( ) . registerBottomTabPressedListener ( ( event ) => {
82+ if ( event . tabIndex == 2 ) {
83+ alert ( 'BottomTabPressed' ) ;
84+ }
85+ } ) ;
86+ } ;
87+
88+ bottomTabPressedListener : EmitterSubscription | null = this . registerBottomTabListener ( ) ;
89+ modalDismissedListener = Navigation . events ( ) . registerModalDismissedListener ( ( event ) => {
90+ if ( event . componentId === 'TogetherFlagTabTest' && ! this . bottomTabPressedListener ) {
91+ this . bottomTabPressedListener = this . registerBottomTabListener ( ) ;
8092 }
8193 } ) ;
8294
@@ -93,6 +105,13 @@ export default class FirstBottomTabScreen extends Component<NavigationProps, Nav
93105 testID = { SWITCH_TAB_BY_COMPONENT_ID_BTN }
94106 onPress = { this . switchTabByComponentId }
95107 />
108+ { Platform . OS === 'ios' && (
109+ < Button
110+ label = "Tabs loading with 'together' flag"
111+ testID = { TABS_TOGETHER_BTN }
112+ onPress = { this . launchTabbedWebViewScreen }
113+ />
114+ ) }
96115 < Button label = "Set Badge" testID = { SET_BADGE_BTN } onPress = { ( ) => this . setBadge ( 'NEW' ) } />
97116 < Button label = "Clear Badge" testID = { CLEAR_BADGE_BTN } onPress = { ( ) => this . setBadge ( '' ) } />
98117 < Button label = "Show Notification Dot" onPress = { ( ) => this . setNotificationDot ( true ) } />
@@ -117,7 +136,8 @@ export default class FirstBottomTabScreen extends Component<NavigationProps, Nav
117136 }
118137
119138 componentWillUnmount ( ) {
120- this . bottomTabPressedListener . remove ( ) ;
139+ this . bottomTabPressedListener ?. remove ( ) ;
140+ this . modalDismissedListener . remove ( ) ;
121141 }
122142
123143 modifyBottomTabs = ( ) => {
@@ -214,4 +234,19 @@ export default class FirstBottomTabScreen extends Component<NavigationProps, Nav
214234 ) ;
215235
216236 push = ( ) => Navigation . push ( this , Screens . Pushed ) ;
237+
238+ launchTabbedWebViewScreen = ( ) => {
239+ resetWebViewLoadedOrder ( ) ;
240+ this . bottomTabPressedListener ?. remove ( ) ;
241+ this . bottomTabPressedListener = null ;
242+ Navigation . showModal ( {
243+ bottomTabs : {
244+ id : 'TogetherFlagTabTest' ,
245+ options : { bottomTabs : { tabsAttachMode : 'together' , titleDisplayMode : 'alwaysShow' } } ,
246+ children : TAB_SCREENS . map ( ( tab ) =>
247+ stack ( component ( tab . name , undefined , { tabIndex : tab . tabIndex } ) )
248+ ) ,
249+ } ,
250+ } ) ;
251+ } ;
217252}
0 commit comments