Skip to content

Commit

Permalink
refactor: test scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
ArekChr committed Jul 18, 2023
1 parent d4571bb commit 0d443e7
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions packages/react-native-web-examples/pages/viewable-items/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import Example from '../../shared/example';

const ITEMS = [...Array(200)].map((_, i) => `Item ${i}`);

const viewabilityConfig = {
itemVisiblePercentThreshold: 95
};

function createItemRow({ item, index }) {
return (
<Pressable key={index} style={[styles.item]}>
Expand All @@ -23,34 +27,26 @@ function Divider() {
return <View style={styles.divider} />;
}

const viewabilityConfig = {
itemVisiblePercentThreshold: 95
};

function onViewableItemsChanged({ viewableItems, changed }) {
console.log('Visible items are', viewableItems);
console.log('Changed in this iteration', changed);
}

export default function ScrollViewPage() {
const scrollRef = React.useRef(null);
const [isInverted, setIsInverted] = React.useState(true);

return (
<Example title="ViewableItems Test">
<View style={styles.container}>
<Button
onPress={() => {
setIsInverted((val) => !val);
}}
onPress={() => setIsInverted((val) => !val)}
title={isInverted ? 'Inverted Enabled' : 'Inverted Disabled'}
/>
<FlatList
ItemSeparatorComponent={Divider}
data={ITEMS}
inverted={isInverted}
onViewableItemsChanged={onViewableItemsChanged}
ref={scrollRef}
renderItem={createItemRow}
style={styles.scrollView}
viewabilityConfig={viewabilityConfig}
Expand Down

0 comments on commit 0d443e7

Please sign in to comment.