@@ -16,13 +16,10 @@ import { GestureDetector } from 'react-native-gesture-handler'
1616
1717import {
1818 Canvas ,
19- runSpring ,
2019 SkPath ,
2120 LinearGradient ,
2221 Path ,
2322 Skia ,
24- useValue ,
25- useComputedValue ,
2623 vec ,
2724 Group ,
2825 PathCommand ,
@@ -78,7 +75,7 @@ export function AnimatedLineGraph({
7875} : AnimatedLineGraphProps ) : React . ReactElement {
7976 const [ width , setWidth ] = useState ( 0 )
8077 const [ height , setHeight ] = useState ( 0 )
81- const interpolateProgress = useValue ( 0 )
78+ const interpolateProgress = useSharedValue ( 0 )
8279
8380 const { gesture, isActive, x } = usePanGesture ( {
8481 enabled : enablePanGesture ,
@@ -139,8 +136,8 @@ export function AnimatedLineGraph({
139136 return path
140137 } , [ height , width ] )
141138
142- const paths = useValue < { from ?: SkPath ; to ?: SkPath } > ( { } )
143- const gradientPaths = useValue < { from ?: SkPath ; to ?: SkPath } > ( { } )
139+ const paths = useSharedValue < { from ?: SkPath ; to ?: SkPath } > ( { } )
140+ const gradientPaths = useSharedValue < { from ?: SkPath ; to ?: SkPath } > ( { } )
144141 const commands = useSharedValue < PathCommand [ ] > ( [ ] )
145142 const [ commandsChanged , setCommandsChanged ] = useState ( 0 )
146143 const pointSelectedIndex = useRef < number > ( )
@@ -214,55 +211,50 @@ export function AnimatedLineGraph({
214211 commands . value = path . toCmds ( )
215212
216213 if ( gradientPath != null ) {
217- const previous = gradientPaths . current
214+ const previous = gradientPaths . value
218215 let from : SkPath = previous . to ?? straightLine
219- if ( previous . from != null && interpolateProgress . current < 1 )
216+ if ( previous . from != null && interpolateProgress . value < 1 )
220217 from =
221- from . interpolate ( previous . from , interpolateProgress . current ) ?? from
218+ from . interpolate ( previous . from , interpolateProgress . value ) ?? from
222219
223220 if ( gradientPath . isInterpolatable ( from ) ) {
224- gradientPaths . current = {
221+ gradientPaths . value = {
225222 from,
226223 to : gradientPath ,
227224 }
228225 } else {
229- gradientPaths . current = {
226+ gradientPaths . value = {
230227 from : gradientPath ,
231228 to : gradientPath ,
232229 }
233230 }
234231 }
235232
236- const previous = paths . current
233+ const previous = paths . value
237234 let from : SkPath = previous . to ?? straightLine
238- if ( previous . from != null && interpolateProgress . current < 1 )
239- from =
240- from . interpolate ( previous . from , interpolateProgress . current ) ?? from
235+ if ( previous . from != null && interpolateProgress . value < 1 )
236+ from = from . interpolate ( previous . from , interpolateProgress . value ) ?? from
241237
242238 if ( path . isInterpolatable ( from ) ) {
243- paths . current = {
239+ paths . value = {
244240 from,
245241 to : path ,
246242 }
247243 } else {
248- paths . current = {
244+ paths . value = {
249245 from : path ,
250246 to : path ,
251247 }
252248 }
253249
254250 setCommandsChanged ( commandsChanged + 1 )
255251
256- runSpring (
257- interpolateProgress ,
258- { from : 0 , to : 1 } ,
259- {
260- mass : 1 ,
261- stiffness : 500 ,
262- damping : 400 ,
263- velocity : 0 ,
264- }
265- )
252+ interpolateProgress . value = withSpring ( 1 , {
253+ mass : 1 ,
254+ stiffness : 500 ,
255+ damping : 400 ,
256+ velocity : 0 ,
257+ } )
266258 // eslint-disable-next-line react-hooks/exhaustive-deps
267259 } , [
268260 height ,
@@ -298,23 +290,23 @@ export function AnimatedLineGraph({
298290 ]
299291 } , [ color , enableFadeInMask ] )
300292
301- const path = useComputedValue (
293+ const path = useDerivedValue (
302294 ( ) => {
303- const from = paths . current . from ?? straightLine
304- const to = paths . current . to ?? straightLine
295+ const from = paths . value . from ?? straightLine
296+ const to = paths . value . to ?? straightLine
305297
306- return to . interpolate ( from , interpolateProgress . current )
298+ return to . interpolate ( from , interpolateProgress . value )
307299 } ,
308300 // RN Skia deals with deps differently. They are actually the required SkiaValues that the derived value listens to, not react values.
309301 [ interpolateProgress ]
310302 )
311303
312- const gradientPath = useComputedValue (
304+ const gradientPath = useDerivedValue (
313305 ( ) => {
314- const from = gradientPaths . current . from ?? straightLine
315- const to = gradientPaths . current . to ?? straightLine
306+ const from = gradientPaths . value . from ?? straightLine
307+ const to = gradientPaths . value . to ?? straightLine
316308
317- return to . interpolate ( from , interpolateProgress . current )
309+ return to . interpolate ( from , interpolateProgress . value )
318310 } ,
319311 // RN Skia deals with deps differently. They are actually the required SkiaValues that the derived value listens to, not react values.
320312 [ interpolateProgress ]
0 commit comments