From bde0be26d9a16f902b5036e198b5427cdee183a6 Mon Sep 17 00:00:00 2001 From: Luna Wei Date: Fri, 10 Sep 2021 11:40:50 -0700 Subject: [PATCH] Move out FlatList-onEndReached Summary: Changelog: [Internal] Refactor FlatList examples, move onEndReached under FlatList index Reviewed By: charlesbdudley Differential Revision: D30816722 fbshipit-source-id: 4ee233c7674ed0f5707d9d98388b8c36af900641 --- ...ListExamples.js => BaseFlatListExample.js} | 103 +++++++----------- .../FlatList/FlatList-onEndReached.js | 51 ++++++--- .../FlatList-onViewableItemsChanged.js | 2 +- .../FlatList/FlatList-withSeparators.js | 2 +- .../examples/FlatList/FlatListExampleIndex.js | 3 +- .../js/utils/RNTesterList.android.js | 5 - .../rn-tester/js/utils/RNTesterList.ios.js | 5 - 7 files changed, 80 insertions(+), 91 deletions(-) rename packages/rn-tester/js/examples/FlatList/{FlatListExamples.js => BaseFlatListExample.js} (77%) diff --git a/packages/rn-tester/js/examples/FlatList/FlatListExamples.js b/packages/rn-tester/js/examples/FlatList/BaseFlatListExample.js similarity index 77% rename from packages/rn-tester/js/examples/FlatList/FlatListExamples.js rename to packages/rn-tester/js/examples/FlatList/BaseFlatListExample.js index dd7aff73022..92c97fd49f1 100644 --- a/packages/rn-tester/js/examples/FlatList/FlatListExamples.js +++ b/packages/rn-tester/js/examples/FlatList/BaseFlatListExample.js @@ -96,7 +96,7 @@ export function FlatList_inverted(): React.Node { }; return ( - Menu - ); } -export function FlatList_onEndReached(): React.Node { - const [output, setOutput] = React.useState(''); - const exampleProps = { - onEndReached: info => setOutput('onEndReached'), - onEndReachedThreshold: 0, - }; - const ref = React.useRef(null); - - const onTest = () => { - const scrollResponder = ref?.current?.getScrollResponder(); - if (scrollResponder != null) { - scrollResponder.scrollToEnd(); - } - }; - - return ( - - ); -} export function FlatList_withSeparators(): React.Node { const exampleProps = { @@ -179,9 +155,7 @@ export function FlatList_withSeparators(): React.Node { }; const ref = React.useRef(null); - return ( - - ); + return ; } export function FlatList_onViewableItemsChanged(props: { @@ -217,13 +191,13 @@ export function FlatList_onViewableItemsChanged(props: { : null; return ( - {offScreen === true ? : null} - + ); } @@ -235,38 +209,41 @@ type Props = { children?: ?React.Node, }; -const FlatListExampleWithForwardedRef = React.forwardRef( - (props: Props, ref) => { - return ( - - {props.testOutput != null ? ( - - - {props.testOutput} - - {props.onTest != null ? ( -