-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRNTesterModuleList.js
216 lines (206 loc) · 5.6 KB
/
RNTesterModuleList.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/**
* 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
*/
const RNTesterExampleFilter = require('./RNTesterExampleFilter');
import RNTPressableRow from './RNTPressableRow';
const React = require('react');
const {
Platform,
SectionList,
StyleSheet,
Text,
TouchableHighlight,
Image,
View,
} = require('react-native');
import {RNTesterThemeContext} from './RNTesterTheme';
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
const ExampleModuleRow = ({
onShowUnderlay,
onHideUnderlay,
item,
toggleBookmark,
handlePress,
}) => {
const theme = React.useContext(RNTesterThemeContext);
const platform = item.module.platform;
const onIos = !platform || platform === 'ios';
const onAndroid = !platform || platform === 'android';
const rightAddOn = (
<TouchableHighlight
style={styles.imageViewStyle}
onPress={() =>
toggleBookmark({
exampleType: item.exampleType,
key: item.key,
})
}>
<Image
style={styles.imageStyle}
source={
item.isBookmarked
? require('../assets/bookmark-outline-blue.png')
: require('../assets/bookmark-outline-gray.png')
}
/>
</TouchableHighlight>
);
return (
<RNTPressableRow
title={item.module.title}
description={item.module.description}
testID={item.module.title}
onPressIn={onShowUnderlay}
onPressOut={onHideUnderlay}
accessibilityLabel={item.module.title + ' ' + item.module.description}
rightAddOn={rightAddOn}
bottomAddOn={
<View style={styles.bottomRowStyle}>
<Text style={{color: theme.SecondaryLabelColor, width: 65}}>
{item.module.category || 'Other'}
</Text>
<View style={styles.platformLabelStyle}>
<Text
style={{
color: onIos ? '#787878' : theme.SeparatorColor,
fontWeight: onIos ? '500' : '300',
}}>
iOS
</Text>
<Text
style={{
color: onAndroid ? '#787878' : theme.SeparatorColor,
fontWeight: onAndroid ? '500' : '300',
}}>
Android
</Text>
</View>
</View>
}
onPress={() =>
handlePress({
exampleType: item.exampleType,
key: item.key,
title: item.module.title,
})
}
/>
);
};
const renderSectionHeader = ({section}: {section: any, ...}) => (
<RNTesterThemeContext.Consumer>
{theme => {
return (
<Text
style={[
styles.sectionHeader,
{
color: theme.SecondaryLabelColor,
backgroundColor: theme.GroupedBackgroundColor,
},
]}>
{section.title}
</Text>
);
}}
</RNTesterThemeContext.Consumer>
);
const RNTesterModuleList: React$AbstractComponent<any, void> = React.memo(
({sections, toggleBookmark, handleModuleCardPress}) => {
const filter = ({example, filterRegex, category}: any) =>
filterRegex.test(example.module.title) &&
(!category || example.category === category);
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by
* Flow's LTI update could not be added via codemod */
const renderListItem = ({item, section, separators}) => {
return (
<ExampleModuleRow
item={item}
section={section}
onShowUnderlay={separators.highlight}
onHideUnderlay={separators.unhighlight}
toggleBookmark={toggleBookmark}
handlePress={handleModuleCardPress}
/>
);
};
return (
<View style={styles.listContainer}>
<RNTesterExampleFilter
testID="explorer_search"
page="components_page"
sections={sections}
filter={filter}
hideFilterPills={true}
render={({filteredSections}) => (
<SectionList
sections={filteredSections}
extraData={filteredSections}
renderItem={renderListItem}
keyboardShouldPersistTaps="handled"
automaticallyAdjustContentInsets={false}
keyboardDismissMode="on-drag"
renderSectionHeader={renderSectionHeader}
// eslint-disable-next-line react/no-unstable-nested-components
ListFooterComponent={() => <View style={{height: 80}} />}
/>
)}
/>
</View>
);
},
);
const styles = StyleSheet.create({
listContainer: {
flex: 1,
},
sectionHeader: {
padding: 5,
fontWeight: '500',
fontSize: 11,
},
row: {
justifyContent: 'center',
paddingHorizontal: 15,
paddingVertical: 12,
marginVertical: Platform.select({ios: 4, android: 8}),
marginHorizontal: 15,
overflow: 'hidden',
elevation: 5,
},
topRowStyle: {
flexDirection: 'row',
justifyContent: 'space-between',
flex: 1,
},
bottomRowStyle: {
flexDirection: 'row',
justifyContent: 'space-between',
},
imageViewStyle: {
height: 30,
width: 30,
borderRadius: 15,
justifyContent: 'center',
alignItems: 'center',
position: 'relative',
bottom: 5,
},
imageStyle: {
height: 25,
width: 25,
},
platformLabelStyle: {
flexDirection: 'row',
width: 100,
justifyContent: 'space-between',
},
});
module.exports = RNTesterModuleList;