@@ -18,109 +18,140 @@ import Animated, {
18
18
import { PanGestureHandler } from 'react-native-gesture-handler' ;
19
19
20
20
const SimpleTest = ( ) => {
21
- // check if certain hooks work
22
- const sv = useSharedValue ( 50 )
21
+ // check if certain hooks work
22
+ const sv = useSharedValue ( 50 ) ;
23
23
24
- const mapper = useMapper ( ( ) => {
25
- 'worklet'
26
- console . log ( `sv has been updated to ${ sv . value } ` )
27
- } , [ sv ] )
28
-
29
- const event = useEvent ( ( event ) => {
30
- 'worklet'
31
- console . log ( `event triggered ${ event } ` )
32
- } , [ 'onGestureHandlerStateChange' , 'onGestureHandlerEvent' ] )
24
+ useMapper ( ( ) => {
25
+ 'worklet' ;
26
+ console . log ( `sv has been updated to ${ sv . value } ` ) ;
27
+ } , [ sv ] ) ;
33
28
29
+ useEvent (
30
+ ( event ) => {
31
+ 'worklet' ;
32
+ console . log ( `event triggered ${ event } ` ) ;
33
+ } ,
34
+ [ 'onGestureHandlerStateChange' , 'onGestureHandlerEvent' ]
35
+ ) ;
34
36
35
- const derived = useDerivedValue ( ( ) => {
36
- return sv . value * 2
37
- } )
37
+ useDerivedValue ( ( ) => {
38
+ return sv . value * 2 ;
39
+ } ) ;
38
40
39
- const uas = useAnimatedStyle ( ( ) => {
40
- return {
41
- width : sv . value * 2 ,
42
- height : sv . value ,
43
- }
44
- } )
41
+ const uas = useAnimatedStyle ( ( ) => {
42
+ return {
43
+ width : sv . value * 2 ,
44
+ height : sv . value ,
45
+ } ;
46
+ } ) ;
45
47
46
- const AnimatedTextInput = Animated . createAnimatedComponent ( TextInput ) ;
47
- const props = useAnimatedProps ( ( ) => {
48
- return {
49
- value : 'animated props works ' + sv . value ,
50
- }
51
- } )
48
+ const AnimatedTextInput = Animated . createAnimatedComponent ( TextInput ) ;
49
+ const props = useAnimatedProps ( ( ) => {
50
+ return {
51
+ value : 'animated props works ' + sv . value ,
52
+ } ;
53
+ } ) ;
52
54
53
- const gestureHandler = useAnimatedGestureHandler ( {
54
- onStart : ( event , context ) => {
55
- console . log ( 'event started' )
56
- } ,
57
- onActive : ( event , context ) => {
58
- console . log ( 'event active' )
59
- } ,
60
- onEnd : ( event , context ) => {
61
- console . log ( 'event end' )
62
- } ,
63
- onFail : ( event , context ) => {
64
- console . log ( 'event fail' )
65
- } ,
66
- onCancel : ( event , context ) => {
67
- console . log ( 'event cancel' )
68
- } ,
69
- onFinish : ( event , context , isFinished ) => {
70
- console . log ( 'event finish' )
71
- } ,
72
- } )
55
+ const gestureHandler = useAnimatedGestureHandler ( {
56
+ onStart : ( event , context ) => {
57
+ console . log ( 'event started' ) ;
58
+ } ,
59
+ onActive : ( event , context ) => {
60
+ console . log ( 'event active' ) ;
61
+ } ,
62
+ onEnd : ( event , context ) => {
63
+ console . log ( 'event end' ) ;
64
+ } ,
65
+ onFail : ( event , context ) => {
66
+ console . log ( 'event fail' ) ;
67
+ } ,
68
+ onCancel : ( event , context ) => {
69
+ console . log ( 'event cancel' ) ;
70
+ } ,
71
+ onFinish : ( event , context , isFinished ) => {
72
+ console . log ( 'event finish' ) ;
73
+ } ,
74
+ } ) ;
73
75
74
-
75
- const scrollHandler = useAnimatedScrollHandler ( {
76
- onScroll : ( event ) => {
77
- console . log ( 'scroll on scroll' )
78
- } ,
79
- onBeginDrag : ( e ) => {
80
- console . log ( 'scroll being drag' )
81
- } ,
82
- onEndDrag : ( e ) => {
83
- console . log ( 'scroll drag end' )
84
- } ,
85
- onMomentumBegin : ( e ) => {
86
- console . log ( 'scroll momentum begin' )
87
- } ,
88
- onMomentumEnd : ( e ) => {
89
- console . log ( 'scroll momentum end' )
90
- } ,
91
- } ) ;
76
+ const scrollHandler = useAnimatedScrollHandler ( {
77
+ onScroll : ( event ) => {
78
+ console . log ( 'scroll on scroll' ) ;
79
+ } ,
80
+ onBeginDrag : ( e ) => {
81
+ console . log ( 'scroll being drag' ) ;
82
+ } ,
83
+ onEndDrag : ( e ) => {
84
+ console . log ( 'scroll drag end' ) ;
85
+ } ,
86
+ onMomentumBegin : ( e ) => {
87
+ console . log ( 'scroll momentum begin' ) ;
88
+ } ,
89
+ onMomentumEnd : ( e ) => {
90
+ console . log ( 'scroll momentum end' ) ;
91
+ } ,
92
+ } ) ;
92
93
93
- const updateSV = ( ) => {
94
- return Math . floor ( Math . random ( ) * 100 + 50 ) ;
95
- }
94
+ const updateSV = ( ) => {
95
+ return Math . floor ( Math . random ( ) * 100 + 50 ) ;
96
+ } ;
96
97
97
- return (
98
- < Animated . View >
99
- < AnimatedTextInput animatedProps = { props } style = { { padding : 10 } } />
100
- < Button title = "change size(raw)" onPress = { ( ) => { sv . value = updateSV ( ) } } />
101
- < Button title = "change size(with timing)" onPress = { ( ) => { sv . value = withTiming ( updateSV ( ) ) } } />
102
- < Button title = "change size(with spring)" onPress = { ( ) => { sv . value = withSpring ( updateSV ( ) ) } } />
103
- < Button title = "change size(with decay)" onPress = { ( ) => { sv . value = withDecay ( {
104
- velocity : Math . floor ( Math . random ( ) * 100 - 50 ) ,
105
- } ) ; } } />
106
- < Button title = "change size(delay)" onPress = { ( ) => { sv . value = delay ( 1000 , withTiming ( updateSV ( ) , { duration : 0 } ) ) } } />
107
- < Button title = "change size(loop)" onPress = { ( ) => { sv . value = loop ( withTiming ( updateSV ( ) , { duration : 500 } ) ) } } />
108
- < PanGestureHandler onGestureEvent = { gestureHandler } >
109
- < Animated . View style = { [ { backgroundColor : 'green' , } , uas ] } />
110
- </ PanGestureHandler >
98
+ return (
99
+ < Animated . View >
100
+ < AnimatedTextInput animatedProps = { props } style = { { padding : 10 } } />
101
+ < Button
102
+ title = "change size(raw)"
103
+ onPress = { ( ) => {
104
+ sv . value = updateSV ( ) ;
105
+ } }
106
+ />
107
+ < Button
108
+ title = "change size(with timing)"
109
+ onPress = { ( ) => {
110
+ sv . value = withTiming ( updateSV ( ) ) ;
111
+ } }
112
+ />
113
+ < Button
114
+ title = "change size(with spring)"
115
+ onPress = { ( ) => {
116
+ sv . value = withSpring ( updateSV ( ) ) ;
117
+ } }
118
+ />
119
+ < Button
120
+ title = "change size(with decay)"
121
+ onPress = { ( ) => {
122
+ sv . value = withDecay ( {
123
+ velocity : Math . floor ( Math . random ( ) * 100 - 50 ) ,
124
+ } ) ;
125
+ } }
126
+ />
127
+ < Button
128
+ title = "change size(delay)"
129
+ onPress = { ( ) => {
130
+ sv . value = delay ( 1000 , withTiming ( updateSV ( ) , { duration : 0 } ) ) ;
131
+ } }
132
+ />
133
+ < Button
134
+ title = "change size(loop)"
135
+ onPress = { ( ) => {
136
+ sv . value = loop ( withTiming ( updateSV ( ) , { duration : 500 } ) ) ;
137
+ } }
138
+ />
139
+ < PanGestureHandler onGestureEvent = { gestureHandler } >
140
+ < Animated . View style = { [ { backgroundColor : 'green' } , uas ] } />
141
+ </ PanGestureHandler >
111
142
112
- < Animated . ScrollView
113
- style = { { backgroundColor : 'yellow' } }
114
- scrollEventThrottle = { 1 }
115
- onScroll = { scrollHandler } >
116
- < View style = { { width : 25 , height : 25 , backgroundColor : 'black' , } } />
117
- < View style = { { width : 25 , height : 25 , backgroundColor : 'black' , } } />
118
- < View style = { { width : 25 , height : 25 , backgroundColor : 'black' , } } />
119
- < View style = { { width : 25 , height : 25 , backgroundColor : 'black' , } } />
120
- < View style = { { width : 25 , height : 25 , backgroundColor : 'black' , } } />
121
- </ Animated . ScrollView >
122
- </ Animated . View >
123
- ) ;
124
- }
143
+ < Animated . ScrollView
144
+ style = { { backgroundColor : 'yellow' } }
145
+ scrollEventThrottle = { 1 }
146
+ onScroll = { scrollHandler } >
147
+ < View style = { { width : 25 , height : 25 , backgroundColor : 'black' } } />
148
+ < View style = { { width : 25 , height : 25 , backgroundColor : 'black' } } />
149
+ < View style = { { width : 25 , height : 25 , backgroundColor : 'black' } } />
150
+ < View style = { { width : 25 , height : 25 , backgroundColor : 'black' } } />
151
+ < View style = { { width : 25 , height : 25 , backgroundColor : 'black' } } />
152
+ </ Animated . ScrollView >
153
+ </ Animated . View >
154
+ ) ;
155
+ } ;
125
156
126
157
export default SimpleTest ;
0 commit comments