Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit 1a0c18a

Browse files
authored
adding RNTester to react-native-improved (#15)
1 parent 65d1e33 commit 1a0c18a

File tree

267 files changed

+40975
-105
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

267 files changed

+40975
-105
lines changed

example/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { AppRegistry } from 'react-native';
2-
import App from './src/App';
32
import { name as appName } from './app.json';
3+
import RNTesterApp from './src/RNTesterAppShared';
44

5-
AppRegistry.registerComponent(appName, () => App);
5+
AppRegistry.registerComponent(appName, () => RNTesterApp);

example/src/App.tsx

Lines changed: 0 additions & 15 deletions
This file was deleted.

example/src/RNTesterApp.android.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @format
8+
* @flow
9+
*/
10+
11+
import {AppRegistry} from 'react-native';
12+
13+
import RNTesterApp from './RNTesterAppShared';
14+
15+
AppRegistry.registerComponent('RNTesterApp', () => RNTesterApp);
16+
17+
module.exports = RNTesterApp;

example/src/RNTesterApp.ios.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @format
8+
* @flow
9+
*/
10+
11+
import type {Node} from 'react';
12+
13+
import {AppRegistry} from 'react-native';
14+
import React from 'react';
15+
16+
import SnapshotViewIOS from './examples/Snapshot/SnapshotViewIOS.ios';
17+
import RNTesterModuleContainer from './components/RNTesterModuleContainer';
18+
import RNTesterList from './utils/RNTesterList';
19+
import RNTesterApp from './RNTesterAppShared';
20+
import type {RNTesterModuleInfo} from './types/RNTesterTypes';
21+
22+
AppRegistry.registerComponent('SetPropertiesExampleApp', () =>
23+
require('./examples/SetPropertiesExample/SetPropertiesExampleApp'),
24+
);
25+
AppRegistry.registerComponent('RootViewSizeFlexibilityExampleApp', () =>
26+
require('./examples/RootViewSizeFlexibilityExample/RootViewSizeFlexibilityExampleApp'),
27+
);
28+
AppRegistry.registerComponent('RNTesterApp', () => RNTesterApp);
29+
30+
// Register suitable examples for snapshot tests
31+
RNTesterList.Components.concat(RNTesterList.APIs).forEach(
32+
(Example: RNTesterModuleInfo) => {
33+
const ExampleModule = Example.module;
34+
if (ExampleModule.displayName) {
35+
class Snapshotter extends React.Component<{...}> {
36+
render(): Node {
37+
return (
38+
<SnapshotViewIOS>
39+
<RNTesterModuleContainer
40+
module={ExampleModule}
41+
onExampleCardPress={() => {}}
42+
/>
43+
</SnapshotViewIOS>
44+
);
45+
}
46+
}
47+
48+
AppRegistry.registerComponent(
49+
ExampleModule.displayName,
50+
() => Snapshotter,
51+
);
52+
}
53+
},
54+
);
55+
56+
module.exports = RNTesterApp;

example/src/RNTesterApp.js.flow

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @format
8+
* @flow
9+
*/
10+
11+
import typeof RNTesterApp from './RNTesterAppShared';
12+
13+
declare module.exports: RNTesterApp;

example/src/RNTesterAppShared.js

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @format
8+
* @flow
9+
*/
10+
11+
import {RNTesterEmptyBookmarksState} from './components/RNTesterEmptyBookmarksState';
12+
import RNTesterModuleContainer from './components/RNTesterModuleContainer';
13+
import RNTesterModuleList from './components/RNTesterModuleList';
14+
import RNTesterNavBar, {navBarHeight} from './components/RNTesterNavbar';
15+
import {RNTesterThemeContext, themes} from './components/RNTesterTheme';
16+
import RNTTitleBar from './components/RNTTitleBar';
17+
import RNTesterList from './utils/RNTesterList';
18+
import {
19+
RNTesterNavigationActionsType,
20+
RNTesterNavigationReducer,
21+
} from './utils/RNTesterNavigationReducer';
22+
import {
23+
Screens,
24+
getExamplesListWithBookmarksAndRecentlyUsed,
25+
initialNavigationState,
26+
} from './utils/testerStateUtils';
27+
import * as React from 'react';
28+
import {BackHandler, StyleSheet, View, useColorScheme} from 'react-native';
29+
30+
// RNTester App currently uses in memory storage for storing navigation state
31+
32+
const RNTesterApp = (): React.Node => {
33+
const [state, dispatch] = React.useReducer(
34+
RNTesterNavigationReducer,
35+
initialNavigationState,
36+
);
37+
const colorScheme = useColorScheme();
38+
39+
const {
40+
activeModuleKey,
41+
activeModuleTitle,
42+
activeModuleExampleKey,
43+
screen,
44+
bookmarks,
45+
recentlyUsed,
46+
} = state;
47+
48+
const examplesList = React.useMemo(
49+
() =>
50+
getExamplesListWithBookmarksAndRecentlyUsed({bookmarks, recentlyUsed}),
51+
[bookmarks, recentlyUsed],
52+
);
53+
54+
const handleBackPress = React.useCallback(() => {
55+
if (activeModuleKey != null) {
56+
dispatch({type: RNTesterNavigationActionsType.BACK_BUTTON_PRESS});
57+
}
58+
}, [dispatch, activeModuleKey]);
59+
60+
// Setup hardware back button press listener
61+
React.useEffect(() => {
62+
const handleHardwareBackPress = () => {
63+
if (activeModuleKey) {
64+
handleBackPress();
65+
return true;
66+
}
67+
return false;
68+
};
69+
70+
BackHandler.addEventListener('hardwareBackPress', handleHardwareBackPress);
71+
72+
return () => {
73+
BackHandler.removeEventListener(
74+
'hardwareBackPress',
75+
handleHardwareBackPress,
76+
);
77+
};
78+
}, [activeModuleKey, handleBackPress]);
79+
80+
const handleModuleCardPress = React.useCallback(
81+
({exampleType, key, title}: any) => {
82+
dispatch({
83+
type: RNTesterNavigationActionsType.MODULE_CARD_PRESS,
84+
data: {exampleType, key, title},
85+
});
86+
},
87+
[dispatch],
88+
);
89+
90+
const handleModuleExampleCardPress = React.useCallback(
91+
(exampleName: string) => {
92+
dispatch({
93+
type: RNTesterNavigationActionsType.EXAMPLE_CARD_PRESS,
94+
data: {key: exampleName},
95+
});
96+
},
97+
[dispatch],
98+
);
99+
100+
const toggleBookmark = React.useCallback(
101+
({exampleType, key}: any) => {
102+
dispatch({
103+
type: RNTesterNavigationActionsType.BOOKMARK_PRESS,
104+
data: {exampleType, key},
105+
});
106+
},
107+
[dispatch],
108+
);
109+
110+
const handleNavBarPress = React.useCallback(
111+
(args: {screen: string}) => {
112+
dispatch({
113+
type: RNTesterNavigationActionsType.NAVBAR_PRESS,
114+
data: {screen: args.screen},
115+
});
116+
},
117+
[dispatch],
118+
);
119+
120+
const theme = colorScheme === 'dark' ? themes.dark : themes.light;
121+
122+
if (examplesList === null) {
123+
return null;
124+
}
125+
126+
const activeModule =
127+
activeModuleKey != null ? RNTesterList.Modules[activeModuleKey] : null;
128+
const activeModuleExample =
129+
activeModuleExampleKey != null
130+
? activeModule?.examples.find(e => e.name === activeModuleExampleKey)
131+
: null;
132+
const title =
133+
activeModuleTitle != null
134+
? activeModuleTitle
135+
: screen === Screens.COMPONENTS
136+
? 'Components'
137+
: screen === Screens.APIS
138+
? 'APIs'
139+
: 'Bookmarks';
140+
141+
const activeExampleList =
142+
screen === Screens.COMPONENTS
143+
? examplesList.components
144+
: screen === Screens.APIS
145+
? examplesList.apis
146+
: examplesList.bookmarks;
147+
148+
return (
149+
<RNTesterThemeContext.Provider value={theme}>
150+
<RNTTitleBar
151+
title={title}
152+
theme={theme}
153+
onBack={activeModule ? handleBackPress : null}
154+
documentationURL={activeModule?.documentationURL}
155+
/>
156+
<View
157+
style={StyleSheet.compose(styles.container, {
158+
backgroundColor: theme.GroupedBackgroundColor,
159+
})}>
160+
{activeModule != null ? (
161+
<RNTesterModuleContainer
162+
module={activeModule}
163+
example={activeModuleExample}
164+
onExampleCardPress={handleModuleExampleCardPress}
165+
/>
166+
) : screen === Screens.BOOKMARKS &&
167+
examplesList.bookmarks.length === 0 ? (
168+
<RNTesterEmptyBookmarksState />
169+
) : (
170+
<RNTesterModuleList
171+
sections={activeExampleList}
172+
toggleBookmark={toggleBookmark}
173+
handleModuleCardPress={handleModuleCardPress}
174+
/>
175+
)}
176+
</View>
177+
<View style={styles.bottomNavbar}>
178+
<RNTesterNavBar
179+
screen={screen || Screens.COMPONENTS}
180+
isExamplePageOpen={!!activeModule}
181+
handleNavBarPress={handleNavBarPress}
182+
/>
183+
</View>
184+
</RNTesterThemeContext.Provider>
185+
);
186+
};
187+
188+
export default RNTesterApp;
189+
190+
const styles = StyleSheet.create({
191+
container: {
192+
flex: 1,
193+
},
194+
bottomNavbar: {
195+
height: navBarHeight,
196+
},
197+
hidden: {
198+
display: 'none',
199+
},
200+
});

example/src/TextInputScreen.js

Lines changed: 0 additions & 31 deletions
This file was deleted.

example/src/assets/bandaged.png

5.42 KB
Loading
217 Bytes
Loading
1.01 KB
Loading

0 commit comments

Comments
 (0)