From 8765b93bae14477777ce6ae6df29e2201d90f983 Mon Sep 17 00:00:00 2001 From: Luna Wei Date: Thu, 1 Jul 2021 14:33:45 -0700 Subject: [PATCH] Generalize RNTPressableRow Summary: Changelog: [Internal] - Extract ExampleModuleRow and use Pressable Reviewed By: kacieb Differential Revision: D29480756 fbshipit-source-id: d256513bec497feeb429e9484ffe367b52e5b2ad --- .../js/components/RNTPressableRow.js | 96 +++++++++++++++++++ .../js/components/RNTesterModuleList.js | 70 ++++++-------- 2 files changed, 125 insertions(+), 41 deletions(-) create mode 100644 packages/rn-tester/js/components/RNTPressableRow.js diff --git a/packages/rn-tester/js/components/RNTPressableRow.js b/packages/rn-tester/js/components/RNTPressableRow.js new file mode 100644 index 0000000000..a17369993f --- /dev/null +++ b/packages/rn-tester/js/components/RNTPressableRow.js @@ -0,0 +1,96 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + * @flow + */ + +import * as React from 'react'; +import {RNTesterThemeContext} from './RNTesterTheme'; +import RNTesterComponentTitle from './RNTesterComponentTitle'; + +import {Platform, StyleSheet, Pressable, Text, View} from 'react-native'; + +type ViewStyleProp = $ElementType, 'style'>; +type Props = { + accessibilityLabel?: ?string, + testID?: ?string, + onPressIn: () => mixed, + onPressOut: () => mixed, + rightAddOn?: ?React.Node, + bottomAddOn?: ?React.Node, + children?: ?React.Node, + title: string, + description?: ?string, + onPress: () => mixed, + style?: ViewStyleProp | ((pressed: boolean) => ViewStyleProp), +}; + +export default function RNTPressableRow({ + onPressIn, + onPressOut, + title, + description, + rightAddOn, + bottomAddOn, + onPress, + accessibilityLabel, + style, +}: Props): React.Node { + const theme = React.useContext(RNTesterThemeContext); + const label = accessibilityLabel ?? `${title} ${description ?? ''}`; + return ( + [ + styles.row, + typeof style === 'function' ? style(pressed) : style, + pressed + ? styles.pressed + : {backgroundColor: theme.SystemBackgroundColor}, + ]} + onPress={onPress}> + + {title} + {rightAddOn} + + + {description} + + {bottomAddOn} + + ); +} + +const styles = StyleSheet.create({ + row: { + justifyContent: 'center', + paddingHorizontal: 15, + paddingVertical: 12, + marginVertical: Platform.select({ios: 4, android: 8}), + marginHorizontal: 15, + overflow: 'hidden', + elevation: 5, + backgroundColor: Platform.select({ios: '#FFFFFF', android: '#F3F8FF'}), + }, + descriptionText: { + fontSize: 12, + lineHeight: 20, + marginBottom: 5, + }, + pressed: { + backgroundColor: 'rgb(242,242,242)', + }, + topRowStyle: { + flexDirection: 'row', + justifyContent: 'space-between', + flex: 1, + }, +}); diff --git a/packages/rn-tester/js/components/RNTesterModuleList.js b/packages/rn-tester/js/components/RNTesterModuleList.js index 8c4c3d9f5b..fe37027261 100644 --- a/packages/rn-tester/js/components/RNTesterModuleList.js +++ b/packages/rn-tester/js/components/RNTesterModuleList.js @@ -9,7 +9,7 @@ */ const RNTesterExampleFilter = require('./RNTesterExampleFilter'); -const RNTesterComponentTitle = require('./RNTesterComponentTitle'); +import RNTPressableRow from './RNTPressableRow'; const React = require('react'); const { @@ -35,43 +35,32 @@ const ExampleModuleRow = ({ const platform = item.module.platform; const onIos = !platform || platform === 'ios'; const onAndroid = !platform || platform === 'android'; - return ( + const rightAddOn = ( - handlePress({exampleType: item.exampleType, key: item.key}) + toggleBookmark({exampleType: item.exampleType, key: item.key}) }> - - - {item.module.title} - - toggleBookmark({exampleType: item.exampleType, key: item.key}) - }> - - - - - {item.module.description} - + + + ); + return ( + {item.module.category || 'Other'} @@ -93,8 +82,11 @@ const ExampleModuleRow = ({ - - + } + onPress={() => + handlePress({exampleType: item.exampleType, key: item.key}) + } + /> ); }; @@ -226,10 +218,6 @@ const styles = StyleSheet.create({ flexDirection: 'row', justifyContent: 'space-between', }, - rowDetailText: { - fontSize: 12, - lineHeight: 20, - }, imageViewStyle: { height: 30, width: 30,