diff --git a/packages/rn-tester/js/examples/FlatList/FlatList-onMomentumScroll.js b/packages/rn-tester/js/examples/FlatList/FlatList-onMomentumScroll.js new file mode 100644 index 000000000000..7fb91a1de14f --- /dev/null +++ b/packages/rn-tester/js/examples/FlatList/FlatList-onMomentumScroll.js @@ -0,0 +1,110 @@ +/** + * 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. + * + * @flow strict-local + * @format + */ + +'use strict'; + +import type {RNTesterModuleExample} from '../../types/RNTesterTypes'; + +import * as React from 'react'; +import {useCallback, useRef, useState} from 'react'; +import {Button, FlatList, StyleSheet, Text, View} from 'react-native'; + +const DATA = [...Array(30)].map((_, i) => `Item ${i}`); + +component FlatList_onMomentumScroll() { + const ref = useRef>(null); + const [beginCount, setBeginCount] = useState(0); + const [endCount, setEndCount] = useState(0); + + const renderItem = useCallback( + ({item}: {item: string, ...}) => ( + + {item} + + ), + [], + ); + + const resetCounts = useCallback(() => { + setBeginCount(0); + setEndCount(0); + }, []); + + return ( + + begin:{beginCount} + end:{endCount} + index.toString()} + renderItem={renderItem} + getItemLayout={(_data: unknown, index: number) => ({ + length: 40, + offset: 40 * index, + index, + })} + style={styles.list} + testID="flatlist_momentum_list" + onMomentumScrollBegin={() => setBeginCount(count => count + 1)} + onMomentumScrollEnd={() => setEndCount(count => count + 1)} + /> +