-
-
Notifications
You must be signed in to change notification settings - Fork 983
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests, packages, memoize parts of swipeable
- Loading branch information
Showing
5 changed files
with
420 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,77 @@ | ||
import React from 'react'; | ||
import { StyleSheet, Text, View } from 'react-native'; | ||
import React, { useCallback } from 'react'; | ||
import { Text, StyleSheet, View, Alert } from 'react-native'; | ||
|
||
import { FlashList, ListRenderItem, useBenchmark } from '@shopify/flash-list'; | ||
import { useRef } from 'react'; | ||
import { Pressable } from 'react-native-gesture-handler'; | ||
import ReanimatedSwipeable from 'react-native-gesture-handler/ReanimatedSwipeable'; | ||
|
||
type Item = { | ||
id: string; | ||
title: string; | ||
}; | ||
|
||
const generateItems = (count: number): Item[] => { | ||
return Array.from({ length: count }, () => { | ||
const randomNumber = Math.random().toString(36).substring(2, 8); | ||
return { | ||
id: randomNumber, | ||
title: `Title ${randomNumber}`, | ||
}; | ||
}); | ||
}; | ||
|
||
const data = generateItems(200); | ||
|
||
export default function Example() { | ||
const renderSwipeable: ListRenderItem<Item> = useCallback( | ||
({ item }: { item: any }) => { | ||
return ( | ||
<ReanimatedSwipeable> | ||
<View style={styles.swipeable}> | ||
<Text>{item.title}</Text> | ||
</View> | ||
</ReanimatedSwipeable> | ||
); | ||
// eslint-disable-next-line no-unreachable | ||
return ( | ||
<Pressable> | ||
<View style={styles.swipeable}> | ||
<Text>{item.title}</Text> | ||
</View> | ||
</Pressable> | ||
); | ||
}, | ||
[] | ||
); | ||
|
||
const flashListRef = useRef<FlashList<Item> | null>(null); | ||
useBenchmark(flashListRef, (callback) => { | ||
Alert.alert('result', callback.formattedString); | ||
}); | ||
|
||
console.log('main rerender'); | ||
|
||
export default function EmptyExample() { | ||
return ( | ||
<View style={styles.container}> | ||
<Text style={{ fontSize: 64, opacity: 0.25 }}>😞</Text> | ||
<Text style={{ fontSize: 24, opacity: 0.25 }}>It's so empty here</Text> | ||
</View> | ||
<FlashList | ||
ref={flashListRef} | ||
data={data} | ||
renderItem={renderSwipeable} | ||
estimatedItemSize={50} | ||
keyExtractor={(item: any) => item.id} | ||
/> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
justifyContent: 'center', | ||
action: { width: 50, height: 50, backgroundColor: 'purple' }, | ||
separator: { | ||
width: '100%', | ||
borderTopWidth: 1, | ||
}, | ||
swipeable: { | ||
height: 50, | ||
backgroundColor: 'papayawhip', | ||
alignItems: 'center', | ||
}, | ||
}); |
Oops, something went wrong.