Skip to content

Commit 47d7a4f

Browse files
committed
move tab button test to ButtonTab page
1 parent 9deb36f commit 47d7a4f

3 files changed

Lines changed: 26 additions & 40 deletions

File tree

playground/src/screens/FirstBottomTabScreen.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ import Screens from './Screens';
99
import { component } from '../commons/Layouts';
1010
import testIDs from '../testIDs';
1111
import bottomTabsStruct from './BottomTabsLayoutStructure';
12+
import { launchTabsTogetherTest, launchTabsOnSwitchTest } from './TabsTogetherTest';
1213

1314
export 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);
@@ -108,6 +109,8 @@ export default class FirstBottomTabScreen extends Component<NavigationProps, Nav
108109
<Button label="Add border and shadow" onPress={this.modifyBottomTabs} />
109110
<Button label="Stylize" testID={STYLIZE_TABS_BTN} onPress={this.stylizeBottomTabs} />
110111
<Button label="Set Styled Root" testID={SET_ROOT_BTN} onPress={this.setStylizedRoot} />
112+
<Button label="Tabs Together Test" onPress={launchTabsTogetherTest} />
113+
<Button label="Tabs OnSwitch Test" onPress={launchTabsOnSwitchTest} />
111114

112115
<Text testID={MOUNTED_SCREENS_TEXT}>
113116
Mounted screens: {this.state.mountedBottomTabScreens.join(', ')}

playground/src/screens/LayoutsScreen.tsx

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import Screens from './Screens';
1414
import Navigation from '../services/Navigation';
1515
import { stack } from '../commons/Layouts';
1616
import bottomTabsStruct from './BottomTabsLayoutStructure';
17-
import { launchTabsTogetherTest, launchTabsOnSwitchTest } from './TabsTogetherTest';
1817

1918
const {
2019
WELCOME_SCREEN_HEADER,
@@ -84,16 +83,6 @@ export default class LayoutsScreen extends NavigationComponent<NavigationProps,
8483
platform="ios"
8584
onPress={this.splitView}
8685
/>
87-
<Button
88-
label="Tabs Together Test"
89-
testID="TABS_TOGETHER_TEST_BTN"
90-
onPress={launchTabsTogetherTest}
91-
/>
92-
<Button
93-
label="Tabs OnSwitch Test"
94-
testID="TABS_ONSWITCH_TEST_BTN"
95-
onPress={launchTabsOnSwitchTest}
96-
/>
9786
<Text>{this.state.componentWillAppear && 'componentWillAppear'}</Text>
9887
<Text>{this.state.componentDidAppear && 'componentDidAppear'}</Text>
9988
</Root>

playground/src/screens/TabsTogetherTest.tsx

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import React, { useEffect, useState } from 'react';
2-
import { View, Text, StyleSheet } from 'react-native';
1+
import React, { useEffect } from 'react';
2+
import { StyleSheet } from 'react-native';
33
import { Navigation, NavigationFunctionComponent } from 'react-native-navigation';
44
import { WebView } from 'react-native-webview';
55
import testIDs from '../testIDs';
6+
import Screens from './Screens';
67

78
const loadOrder: number[] = [];
89
const listeners: Set<() => void> = new Set();
@@ -16,9 +17,7 @@ interface Props {
1617
url: string;
1718
}
1819

19-
const WebViewTab: NavigationFunctionComponent<Props> = ({ componentId, tabIndex, title, url }) => {
20-
const [isLoaded, setIsLoaded] = useState(false);
21-
const [progress, setProgress] = useState(0);
20+
const WebViewTab: NavigationFunctionComponent<Props> = ({ componentId, tabIndex, url }) => {
2221

2322
useEffect(() => {
2423
const update = () => {
@@ -50,25 +49,15 @@ const WebViewTab: NavigationFunctionComponent<Props> = ({ componentId, tabIndex,
5049
const onLoadEnd = () => {
5150
loadOrder.push(tabIndex);
5251
notifyListeners();
53-
setIsLoaded(true);
5452
};
5553

5654
return (
57-
<View style={styles.container}>
58-
<View style={styles.header}>
59-
<Text style={styles.headerText}>Tab {tabIndex}: {title}</Text>
60-
<View style={[styles.status, isLoaded ? styles.loaded : styles.loading]}>
61-
<Text style={styles.statusText}>{isLoaded ? '✓' : `${progress}%`}</Text>
62-
</View>
63-
</View>
64-
<WebView
65-
source={{ uri: url }}
66-
style={styles.webview}
67-
onLoadEnd={onLoadEnd}
68-
onLoadProgress={(e) => setProgress(Math.round(e.nativeEvent.progress * 100))}
69-
startInLoadingState
70-
/>
71-
</View>
55+
<WebView
56+
source={{ uri: url }}
57+
style={styles.webview}
58+
onLoadEnd={onLoadEnd}
59+
startInLoadingState
60+
/>
7261
);
7362
};
7463

@@ -94,6 +83,18 @@ const goBackToPlayground = () => {
9483
},
9584
},
9685
});
86+
// Show the BottomTabs modal after restoring root
87+
Navigation.showModal({
88+
bottomTabs: {
89+
children: [
90+
{ stack: { children: [{ component: { name: Screens.FirstBottomTabsScreen } }] } },
91+
{ stack: { id: 'SecondTab', children: [{ component: { name: Screens.SecondBottomTabsScreen } }] } },
92+
],
93+
options: {
94+
bottomTabs: { testID: testIDs.BOTTOM_TABS },
95+
},
96+
},
97+
});
9798
};
9899

99100
const TABS = [
@@ -125,13 +126,6 @@ export const launchTabsTogetherTest = () => launchTest('together');
125126
export const launchTabsOnSwitchTest = () => launchTest('onSwitchToTab');
126127

127128
const styles = StyleSheet.create({
128-
container: { flex: 1, backgroundColor: '#f5f6fa' },
129-
header: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', padding: 12, backgroundColor: '#2c3e50' },
130-
headerText: { color: '#fff', fontSize: 16, fontWeight: '700' },
131-
status: { paddingHorizontal: 12, paddingVertical: 6, borderRadius: 16, minWidth: 50, alignItems: 'center' },
132-
loading: { backgroundColor: '#e67e22' },
133-
loaded: { backgroundColor: '#27ae60' },
134-
statusText: { color: '#fff', fontSize: 12, fontWeight: '600' },
135129
webview: { flex: 1 },
136130
});
137131

0 commit comments

Comments
 (0)