|
5 | 5 | * LICENSE file in the root directory of this source tree.
|
6 | 6 | *
|
7 | 7 | * @format
|
8 |
| - * @flow |
| 8 | + * @flow strict-local |
9 | 9 | */
|
10 | 10 |
|
11 | 11 | 'use strict';
|
12 |
| -import {FlatList_withSeparators} from './BaseFlatListExample'; |
13 |
| -const React = require('react'); |
| 12 | +import type {RNTesterModuleExample} from '../../types/RNTesterTypes'; |
| 13 | +import BaseFlatListExample from './BaseFlatListExample'; |
| 14 | +import {StyleSheet, View, Text} from 'react-native'; |
| 15 | +import * as React from 'react'; |
14 | 16 |
|
15 |
| -exports.title = 'FlatList with Separators'; |
16 |
| -exports.testTitle = 'Test custom separator components'; |
17 |
| -exports.category = 'ListView'; |
18 |
| -exports.documentationURL = 'https://reactnative.dev/docs/sectionlist'; |
19 |
| -exports.description = 'Tap to see pressed states for separator components.'; |
20 |
| -exports.examples = [ |
21 |
| - { |
22 |
| - title: 'FlatList with Separators', |
23 |
| - render: function(): React.Element<typeof FlatList_withSeparators> { |
24 |
| - return <FlatList_withSeparators />; |
25 |
| - }, |
| 17 | +const Separator = (defaultColor, highlightColor) => ({ |
| 18 | + leadingItem, |
| 19 | + trailingItem, |
| 20 | + highlighted, |
| 21 | + hasBeenHighlighted, |
| 22 | +}) => { |
| 23 | + const text = `Separator for leading ${leadingItem} and trailing ${trailingItem} has ${ |
| 24 | + !hasBeenHighlighted ? 'not ' : '' |
| 25 | + }been pressed`; |
| 26 | + |
| 27 | + return ( |
| 28 | + <View |
| 29 | + style={[ |
| 30 | + styles.separator, |
| 31 | + {backgroundColor: highlighted ? highlightColor : defaultColor}, |
| 32 | + ]}> |
| 33 | + <Text style={styles.separtorText}>{text}</Text> |
| 34 | + </View> |
| 35 | + ); |
| 36 | +}; |
| 37 | + |
| 38 | +export function FlatList_withSeparators(): React.Node { |
| 39 | + const exampleProps = { |
| 40 | + ItemSeparatorComponent: Separator('lightgreen', 'green'), |
| 41 | + }; |
| 42 | + const ref = React.useRef(null); |
| 43 | + |
| 44 | + return <BaseFlatListExample ref={ref} exampleProps={exampleProps} />; |
| 45 | +} |
| 46 | + |
| 47 | +const styles = StyleSheet.create({ |
| 48 | + separator: { |
| 49 | + height: 12, |
| 50 | + }, |
| 51 | + separtorText: { |
| 52 | + fontSize: 10, |
26 | 53 | },
|
27 |
| -]; |
| 54 | +}); |
| 55 | + |
| 56 | +export default ({ |
| 57 | + title: 'FlatList with Separators', |
| 58 | + name: 'separators', |
| 59 | + description: 'Tap to see pressed states for separator components.', |
| 60 | + render: () => <FlatList_withSeparators />, |
| 61 | +}: RNTesterModuleExample); |
0 commit comments