Replies: 2 comments 6 replies
-
I encountered a similar issue (with the new architecture). I have a collapsible header (shared) and tabs underneath it. Each tab has its own scrollable content (similar to Instagram). On the initial render, I use The styles of my tab bar are as follows: const [headerHeight, setHeaderHeight] = useState(0)
const [tabBarHeight, setTabBarHeight] = useState(0)
useLayoutEffect(() => {
headerRef.current?.measure((x, y, w, h) => setHeaderHeight(h))
tabBarRef.current?.measure((x, y, w, h) => setTabBarHeight(h))
}, [])
const tabBarContainerAniStyle = useAnimatedStyle(() => ({
transform: [
{
translateY: interpolate(
currScrollY.value,
[0, headerHeight],
[headerHeight, 0],
Extrapolation.CLAMP,
),
},
],
}))
<Animated.View
ref={headerRef}
style={[styles.headerContainer, headerContainerAniStyle]}
/>
<Animated.View
ref={tabBarRef}
style={[styles.tabBarContainer, tabBarContainerAniStyle]}
/> If I use <Animated.View
ref={tabBarRef}
style={[
styles.tabBarContainer,
[{ transform: [{ translateY: headerHeight }] }],
]}
> In that case, there is no intermediate frame with a value of 0 — the tab bar is positioned correctly right from the start. The problem is that in this case, I can't use the |
Beta Was this translation helpful? Give feedback.
-
Unfortunately, this is not possible in Reanimated on the New Architecture. All updates from Reanimated are batched and sent in the next animation frame, which happens after React render completes. There is no valid solution and not even a single working workaround. For now, you have to write animations in a way that doesn't require synchronization with React renders. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Please see the following example.
And this video is the capture of the
Example1
component's behavior.2023-01-10.3.08.31.mov
You can see that the green box doesn't appear at the exactly same time as the red box. There is a frame where the red box without containing the green box flashes. I think that this is happening only on android(tested in Galaxy S20 and Pixel 3 Emulation), and not on ios(iPhone 13).
I suppose that this is because the update of
t.value
inuseLayoutEffect
doesn't trigger the update in animated stylestyle
before the rerender due to the update in statex
processed. Can I force an update to animated styles right after I assigned the new value to the shared values? Or is there any other solution to this problem?I also wrote the same component with Animated instead of reanimated.
It worked as I desired. There was no flashing.
Beta Was this translation helpful? Give feedback.
All reactions