From f4d006a785c6bbb753857c3f11118afdf338d1af Mon Sep 17 00:00:00 2001 From: Ruslan Shestopalyuk Date: Fri, 17 Nov 2023 13:10:39 -0800 Subject: [PATCH] Optional prop for RNTesterApp to provide custom test lists (#41537) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/41537 # Changelog: [Internal] - This allows to optionally provide a custom list of component/api test clauses into `RNTesterApp`. Reviewed By: christophpurrer Differential Revision: D51429407 fbshipit-source-id: 3ee35f13f6156fd055f6e0cbc788b7cf01c22b36 --- packages/rn-tester/js/RNTesterAppShared.js | 15 ++++++++++++--- packages/rn-tester/js/utils/testerStateUtils.js | 11 +++++++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/packages/rn-tester/js/RNTesterAppShared.js b/packages/rn-tester/js/RNTesterAppShared.js index 04c17f58f32596..3f93d9aa4801f3 100644 --- a/packages/rn-tester/js/RNTesterAppShared.js +++ b/packages/rn-tester/js/RNTesterAppShared.js @@ -8,6 +8,8 @@ * @flow */ +import type {RNTesterModuleInfo} from './types/RNTesterTypes'; + import RNTesterModuleContainer from './components/RNTesterModuleContainer'; import RNTesterModuleList from './components/RNTesterModuleList'; import RNTesterNavBar, {navBarHeight} from './components/RNTesterNavbar'; @@ -28,7 +30,14 @@ import {BackHandler, StyleSheet, View, useColorScheme} from 'react-native'; // RNTester App currently uses in memory storage for storing navigation state -const RNTesterApp = (): React.Node => { +const RNTesterApp = ({ + testList, +}: { + testList?: { + components?: Array, + apis?: Array, + }, +}): React.Node => { const [state, dispatch] = React.useReducer( RNTesterNavigationReducer, initialNavigationState, @@ -44,8 +53,8 @@ const RNTesterApp = (): React.Node => { } = state; const examplesList = React.useMemo( - () => getExamplesListWithRecentlyUsed({recentlyUsed}), - [recentlyUsed], + () => getExamplesListWithRecentlyUsed({recentlyUsed, testList}), + [recentlyUsed, testList], ); const handleBackPress = React.useCallback(() => { diff --git a/packages/rn-tester/js/utils/testerStateUtils.js b/packages/rn-tester/js/utils/testerStateUtils.js index c3239adeab9737..805cfe83349e8c 100644 --- a/packages/rn-tester/js/utils/testerStateUtils.js +++ b/packages/rn-tester/js/utils/testerStateUtils.js @@ -48,15 +48,21 @@ const filterEmptySections = (examplesList: ExamplesList): any => { export const getExamplesListWithRecentlyUsed = ({ recentlyUsed, + testList, }: { recentlyUsed: ComponentList, + testList?: { + components?: Array, + apis?: Array, + }, }): ExamplesList | null => { // Return early if state has not been initialized from storage if (!recentlyUsed) { return null; } - const components = RNTesterList.Components.map( + const componentList = testList?.components ?? RNTesterList.Components; + const components = componentList.map( (componentExample): RNTesterModuleInfo => ({ ...componentExample, exampleType: Screens.COMPONENTS, @@ -69,7 +75,8 @@ export const getExamplesListWithRecentlyUsed = ({ ) .filter(Boolean); - const apis = RNTesterList.APIs.map((apiExample): RNTesterModuleInfo => ({ + const apisList = testList?.apis ?? RNTesterList.APIs; + const apis = apisList.map((apiExample): RNTesterModuleInfo => ({ ...apiExample, exampleType: Screens.APIS, }));