File tree Expand file tree Collapse file tree 2 files changed +68
-0
lines changed
apps/common-app/src/apps/reanimated/examples Expand file tree Collapse file tree 2 files changed +68
-0
lines changed Original file line number Diff line number Diff line change 1+ import { useEffect } from 'react' ;
2+ import { ScrollView , StyleSheet , View } from 'react-native' ;
3+ import Animated , {
4+ useAnimatedStyle ,
5+ useSharedValue ,
6+ withRepeat ,
7+ withTiming ,
8+ } from 'react-native-reanimated' ;
9+
10+ export default function ScrollPerformanceExample ( ) {
11+ return (
12+ < ScrollView contentContainerStyle = { styles . container } >
13+ { Array . from ( { length : 500 } ) . map ( ( _ , index ) => (
14+ < Item key = { index } />
15+ ) ) }
16+ </ ScrollView >
17+ ) ;
18+ }
19+
20+ function Item ( ) {
21+ const sv = useSharedValue ( 0 ) ;
22+
23+ const animatedStyle = useAnimatedStyle ( ( ) => {
24+ return { opacity : sv . value } ;
25+ } ) ;
26+
27+ useEffect ( ( ) => {
28+ sv . value = withRepeat (
29+ withTiming ( 1 , { duration : Math . random ( ) * 1000 } ) ,
30+ - 1 ,
31+ true
32+ ) ;
33+ } , [ sv ] ) ;
34+
35+ return (
36+ < View style = { styles . item } >
37+ < Animated . View
38+ style = { [
39+ animatedStyle ,
40+ styles . box ,
41+ { backgroundColor : Math . random ( ) > 0.5 ? 'red' : 'blue' } ,
42+ ] }
43+ />
44+ </ View >
45+ ) ;
46+ }
47+
48+ const styles = StyleSheet . create ( {
49+ container : {
50+ gap : 10 ,
51+ } ,
52+ item : {
53+ flexDirection : 'row' ,
54+ width : '100%' ,
55+ justifyContent : 'center' ,
56+ alignItems : 'center' ,
57+ } ,
58+ box : {
59+ width : 100 ,
60+ height : 100 ,
61+ } ,
62+ } ) ;
Original file line number Diff line number Diff line change @@ -109,6 +109,7 @@ import ScreenStackHeaderConfigBackgroundColorExample from './ScreenStackHeaderCo
109109import ScreenTransitionExample from './ScreenTransitionExample' ;
110110import ScrollableViewExample from './ScrollableViewExample' ;
111111import ScrollEventExample from './ScrollEventExample' ;
112+ import ScrollPerformanceExample from './ScrollPerformanceExample' ;
112113import ScrollToExample from './ScrollToExample' ;
113114import ScrollViewExample from './ScrollViewExample' ;
114115import ScrollViewOffsetExample from './ScrollViewOffsetExample' ;
@@ -154,6 +155,11 @@ export const EXAMPLES: Record<string, Example> = {
154155 title : 'FPS' ,
155156 screen : FpsExample ,
156157 } ,
158+ ScrollPerformanceExample : {
159+ icon : '🚁' ,
160+ title : 'Scroll performance' ,
161+ screen : ScrollPerformanceExample ,
162+ } ,
157163 ThirdPartyComponentsExample : {
158164 icon : '3️⃣' ,
159165 title : 'Third party components' ,
You can’t perform that action at this time.
0 commit comments