Skip to content

Commit 3063047

Browse files
Luna Weifacebook-github-bot
Luna Wei
authored andcommitted
Move FlatList separators example under FlatList index
Summary: Changelog: [Internal] Refactor FlatList examples, move separators example under FlatList index Reviewed By: charlesbdudley Differential Revision: D30816723 fbshipit-source-id: 741e4d97b18458fcedd9175309ff68c987d211b1
1 parent 5fd1983 commit 3063047

File tree

5 files changed

+51
-55
lines changed

5 files changed

+51
-55
lines changed

packages/rn-tester/js/examples/FlatList/BaseFlatListExample.js

-30
Original file line numberDiff line numberDiff line change
@@ -58,36 +58,6 @@ const Item = ({item, separators}) => {
5858
);
5959
};
6060

61-
const Separator = (defaultColor, highlightColor) => ({
62-
leadingItem,
63-
trailingItem,
64-
highlighted,
65-
hasBeenHighlighted,
66-
}) => {
67-
const text = `Separator for leading ${leadingItem} and trailing ${trailingItem} has ${
68-
!hasBeenHighlighted ? 'not ' : ''
69-
}been pressed`;
70-
71-
return (
72-
<View
73-
style={[
74-
styles.separator,
75-
{backgroundColor: highlighted ? highlightColor : defaultColor},
76-
]}>
77-
<Text style={styles.separtorText}>{text}</Text>
78-
</View>
79-
);
80-
};
81-
82-
export function FlatList_withSeparators(): React.Node {
83-
const exampleProps = {
84-
ItemSeparatorComponent: Separator('lightgreen', 'green'),
85-
};
86-
const ref = React.useRef(null);
87-
88-
return <BaseFlatListExample ref={ref} exampleProps={exampleProps} />;
89-
}
90-
9161
type Props = {
9262
exampleProps: $Shape<React.ElementConfig<typeof FlatList>>,
9363
onTest?: ?() => void,

packages/rn-tester/js/examples/FlatList/FlatList-withSeparators.js

+49-15
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,57 @@
55
* LICENSE file in the root directory of this source tree.
66
*
77
* @format
8-
* @flow
8+
* @flow strict-local
99
*/
1010

1111
'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';
1416

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,
2653
},
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);

packages/rn-tester/js/examples/FlatList/FlatListExampleIndex.js

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import OnEndReachedExample from './FlatList-onEndReached';
1414
import ContentInsetExample from './FlatList-contentInset';
1515
import InvertedExample from './FlatList-inverted';
1616
import onViewableItemsChangedExample from './FlatList-onViewableItemsChanged';
17+
import WithSeparatorsExample from './FlatList-withSeparators';
1718

1819
export default ({
1920
framework: 'React',
@@ -28,5 +29,6 @@ export default ({
2829
ContentInsetExample,
2930
InvertedExample,
3031
onViewableItemsChangedExample,
32+
WithSeparatorsExample,
3133
],
3234
}: RNTesterModule);

packages/rn-tester/js/utils/RNTesterList.android.js

-5
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ const Components: Array<RNTesterModuleInfo> = [
2929
category: 'ListView',
3030
supportsTVOS: true,
3131
},
32-
{
33-
key: 'FlatList-withSeparators',
34-
module: require('../examples/FlatList/FlatList-withSeparators'),
35-
category: 'ListView',
36-
},
3732
{
3833
key: 'ImageExample',
3934
category: 'Basic',

packages/rn-tester/js/utils/RNTesterList.ios.js

-5
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ const Components: Array<RNTesterModuleInfo> = [
3131
category: 'ListView',
3232
supportsTVOS: true,
3333
},
34-
{
35-
key: 'FlatList-withSeparators',
36-
module: require('../examples/FlatList/FlatList-withSeparators'),
37-
category: 'ListView',
38-
},
3934
{
4035
key: 'ImageExample',
4136
module: require('../examples/Image/ImageExample'),

0 commit comments

Comments
 (0)