forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRNTPressableRow.js
84 lines (80 loc) · 2.16 KB
/
RNTPressableRow.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* Copyright (c) Meta Platforms, Inc. and 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 strict-local
*/
import RNTesterComponentTitle from './RNTesterComponentTitle';
import {RNTesterThemeContext} from './RNTesterTheme';
import * as React from 'react';
import {Pressable, StyleSheet, Text, View} from 'react-native';
type ViewStyleProp = $ElementType<React.ElementConfig<typeof View>, 'style'>;
type Props = {
accessibilityLabel?: ?string,
testID?: ?string,
onPressIn?: ?() => mixed,
onPressOut?: ?() => mixed,
children?: ?React.Node,
title: string,
description?: ?string,
onPress: () => mixed,
style?: ViewStyleProp | ((pressed: boolean) => ViewStyleProp),
};
export default function RNTPressableRow({
onPressIn,
onPressOut,
title,
description,
onPress,
style,
accessibilityLabel,
}: Props): React.Node {
const theme = React.useContext(RNTesterThemeContext);
const label = accessibilityLabel ?? `${title} ${description ?? ''}`;
return (
<Pressable
testID={title}
onPressIn={onPressIn}
onPressOut={onPressOut}
accessibilityLabel={label}
style={({pressed}) => [
styles.row,
typeof style === 'function' ? style(pressed) : style,
pressed
? {backgroundColor: theme.SecondarySystemFillColor}
: {backgroundColor: theme.SecondaryGroupedBackgroundColor},
]}
onPress={onPress}>
<View style={styles.topRowStyle}>
<RNTesterComponentTitle>{title}</RNTesterComponentTitle>
</View>
<Text
style={[styles.descriptionText, {color: theme.SecondaryLabelColor}]}>
{description}
</Text>
</Pressable>
);
}
const styles = StyleSheet.create({
row: {
justifyContent: 'center',
paddingHorizontal: 16,
paddingVertical: 16,
marginVertical: 5,
marginHorizontal: 16,
boxShadow: '0 2px 4px -1px rgba(0, 0, 0, 0.25)',
borderRadius: 8,
},
descriptionText: {
marginTop: 6,
fontSize: 12,
},
topRowStyle: {
flexDirection: 'row',
justifyContent: 'space-between',
flex: 1,
},
});