Closed lucksp closed 4 months ago
I am trying to update an array of values, so that I can smooth out a Skia frame processor drawing, so useSharedValue came up.
Skia
useSharedValue
I noticed in the remarks section of the docs, it says:
When storing large arrays or complex objects in a shared value, you can use .modify method to alter the existing value instead of creating a new one.
.modify
However, when I try to implement this method, the TypeDef does not show any modify as available as part of the ISharedValue
modify
ISharedValue
export interface ISharedValue<T> { get value(): T; set value(v: T); addListener(listener: () => void): () => void; }
I have also tried logging sv.modify but it is undefined.
sv.modify
undefined
react-native-reanimated@~3.6.2: version "3.6.3" resolved "https://registry.yarnpkg.com/react-native-reanimated/-/react-native-reanimated-3.6.3.tgz#859cf2320e37c80e3a21e19db24f82c34d6d3ded" integrity sha512-2KkkPozoIvDbJcHuf8qeyoLROXQxizSi+2CTCkuNVkVZOxxY4B0Omvgq61aOQhSZUh/649x1YHoAaTyGMGDJUw== dependencies: "@babel/plugin-transform-object-assign" "^7.16.7" "@babel/preset-typescript" "^7.16.7" convert-source-map "^2.0.0" invariant "^2.2.4"
"expo": "^50.0.17",
Please advise: Are the docs accurate and it's a version issue or something else?
In the meantime, I am falling back to copy array sv.value = [...sv.value, 1000]; // works, but creates a new copy ⚠️
sv.value = [...sv.value, 1000]; // works, but creates a new copy ⚠️
Copy the docs example into your project:
const sv = useSharedValue([1, 2, 3]); sv.value.push(1000); // Reanimated loses reactivity 🚨 sv.value = [...sv.value, 1000]; // works, but creates a new copy ⚠️ sv.modify((value) => { 'worklet'; value.push(1000); // ✅ return value; });
n/a
3.6.2
0.73.6
Android, iOS
Hermes
Expo Dev Client
Paper (Old Architecture)
Debug app & dev bundle
None
iPhone 13 pro
Yes
Hey! 👋
The issue doesn't seem to contain a minimal reproduction.
Could you provide a snack or a link to a GitHub repository under your username that reproduces the problem?
Description
I am trying to update an array of values, so that I can smooth out a
Skia
frame processor drawing, souseSharedValue
came up.I noticed in the remarks section of the docs, it says:
However, when I try to implement this method, the TypeDef does not show any
modify
as available as part of theISharedValue
I have also tried logging
sv.modify
but it isundefined
."expo": "^50.0.17",
with dev-clientPlease advise: Are the docs accurate and it's a version issue or something else?
In the meantime, I am falling back to copy array
sv.value = [...sv.value, 1000]; // works, but creates a new copy ⚠️
Steps to reproduce
Copy the docs example into your project:
modify
does not existSnack or a link to a repository
n/a
Reanimated version
3.6.2
React Native version
0.73.6
Platforms
Android, iOS
JavaScript runtime
Hermes
Workflow
Expo Dev Client
Architecture
Paper (Old Architecture)
Build type
Debug app & dev bundle
Device
None
Device model
iPhone 13 pro
Acknowledgements
Yes