Replies: 2 comments 3 replies
-
here you would simply need to make a component for this and use a
useDerivedValue where you would have your Selector
…On Fri, Feb 9, 2024 at 8:59 AM Alex Shumihin ***@***.***> wrote:
How can I use the values useSharedValue or useDerivedValue inside list
rendering if I need to consider the index in these values, and have the
ability to refer to the actual size of the canvas from "const canvasSize =
useSharedValue" during calculations? Previously, it was possible to use
"Selector", but how can such a result be achieved now? Using usePathValue
does not allow manipulating the shape color based on the index.
I'm making this progress component
2024-02-09.08.54.15.png (view on web)
<https://github.com/Shopify/react-native-skia/assets/53976385/4258e02b-596d-4f9e-be18-143f9600b1c3>
Here is a rough code example.
const ITEMS_COUNT = 5
const OFFSET = 10
const canvasSize = useSharedValue({
width: CANVAS_WIDTH,
height: HEIGHT,
})
----<Canvas onSize={canvasSize} style={s.container}>
{steps.map((el, index) => (
<Fragment key={index}>
{percentStep > index ? (
<Rect x={Selector(canvasSize,(c)=>(c.width / ITEMS_COUNT) * index + OFFSET )}
y={10}
width={Selector(canvasSize,(c)=>c.width + OFFSET )}
height={HEIGHT / 2}
>
<BlurMask blur={5} style={'normal'} />
</Rect>
) : null}
<RoundedRect
x={Selector(canvasSize,(c)=>(c.width / ITEMS_COUNT) * index + OFFSET )}
r={ITEM_RADIUS}
width={Selector(canvasSize,(c)=>c.width + OFFSET )}
y={0}
height={HEIGHT}
color={progress < el ? '#DDE4FA' : 'red'}
/>
</Fragment>
))}</Canvas>
—
Reply to this email directly, view it on GitHub
<#2211>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACKXVVAH7CXR3EHEYAK5GLYSXJNRAVCNFSM6AAAAABDBBHK3OVHI2DSMVQWIX3LMV43ERDJONRXK43TNFXW4OZWGE4TQNJTGE>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
1 reply
-
that‘s a good point. you can use „notigyChange(value)“ to let reanimated
now that something has changed
…On Fri 9 Feb 2024 at 09:57, Alex Shumihin ***@***.***> wrote:
@wcandillon <https://github.com/wcandillon>
if I have 10 elements, and the offset depends on the size of the canvas
and the index of this element, how do I calculate this using the index and
useDerivedValue ?
if I count everything in useDerivedValue
then for the component I will have to use
derivedArray.value[index] means that when the canvas size is updated,
these values will not be updated for the component
const offsetsArray = useDerivedValue(()=>{
const itemWidth = canvasSize.value.width / steps.length
return steps.map((s,index)=> (itemWidth + SOME_SPACE) * index))},[canvasSize])....steps.map((el,index)=>
...
<RoundedRect
x={offsetsArray.value[index]}
....
—
Reply to this email directly, view it on GitHub
<#2211 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACKXVSTQWAYXHOBMUGFZH3YSXQGDAVCNFSM6AAAAABDBBHK3OVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4DIMJWGQZDK>
.
You are receiving this because you were mentioned.Message ID:
***@***.***
com>
|
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
How can I use the values useSharedValue or useDerivedValue inside list rendering if I need to consider the index in these values, and have the ability to refer to the actual size of the canvas from "const canvasSize = useSharedValue" during calculations? Previously, it was possible to use "Selector", but how can such a result be achieved now? Using usePathValue does not allow manipulating the shape color based on the index.
I'm making this progress component

Here is a rough code example.
Beta Was this translation helpful? Give feedback.
All reactions