[Bug]: Support react-native-reanimated 4.4.0
Description
Hi,
After upgrading react-native-reanimated and worklets, it seems there is a bug where sometimes the Sortable.Grid does not render the items until I scroll.
Video attached for reference. I am following almost exactly this example https://react-native-sortables-docs.vercel.app/grid/examples/auto-scroll
https://github.com/user-attachments/assets/c81b60ce-81a1-41dd-8eff-78e3b002b063
Steps to reproduce
- Upgrade react-native-reanimated 4.4.0 and Gesture handler to 3.0.0
Code snippet, Snack or GitHub repository link
https://videoattached.com
React Native Sortables version
1.9.4
Reanimated version
4.4.0
React Native Gesture Handler version
3.0.0
React Native version
0.85.3
Platforms
iOS
Architecture
Fabric (New Architecture)
Workflow
React Native Bare Workflow
Device
Real device
Acknowledgements
Yes
@faljabi as a tmp workaround, you can use this patch package. I created it for myself when I had the same problem.
I'm experiencing the same bug, but unlike the original report it only affects Android — iOS renders fine for me. Same symptom: Sortable.Grid items don't appear until the first scroll, then they show up.
Worth noting we reproduce it with a different react-native-gesture-handler version, so the issue likely isn't tied to gesture-handler 3.0.0.
Stack:
- react-native-sortables: 1.9.4
- react-native-reanimated: 4.4.0
- react-native-worklets: 0.9.x
- react-native-gesture-handler: 2.31.2
- react-native: 0.83.x (Expo SDK 55)
- Architecture: Fabric
- Platform affected: Android only (iOS works fine)
Workaround: rolling back deps to a known-good combo unblocks Android:
"react-native-reanimated": "~4.3.1",
"react-native-worklets": "~0.8.3"
Will switch back once a fix lands on the 4.4.x line. Thanks for the tracking.
+1
This fixed it for me:
diff --git a/dist/module/providers/shared/hooks/useItemLayout.js b/dist/module/providers/shared/hooks/useItemLayout.js
index 97aa96492a5546857a31266fbec731050e202d51..dd09b39065d78be8a762ae4f5d65aafc52b3088b 100644
--- a/dist/module/providers/shared/hooks/useItemLayout.js
+++ b/dist/module/providers/shared/hooks/useItemLayout.js
@@ -35,7 +35,12 @@ function useItemLayoutPaper(position, zIndex) {
return RELATIVE_STYLE;
}
if (!position.value) {
- return HIDDEN_STYLE;
+ // Reanimated 4 can flip `usesAbsoluteLayout` before item positions have
+ // been populated. Teleporting the item offscreen (HIDDEN_STYLE) in that
+ // window makes the whole grid vanish until a scroll forces a relayout
+ // (see react-native-sortables#552). Keep the item in normal flow until
+ // its absolute position is ready instead.
+ return RELATIVE_STYLE;
}
return {
left: position.value.x,
@@ -92,7 +97,12 @@ function useItemLayoutFabric(position, zIndex) {
return RELATIVE_STYLE;
}
if (!position.value) {
- return HIDDEN_STYLE;
+ // Reanimated 4 can flip `usesAbsoluteLayout` before item positions have
+ // been populated. Teleporting the item offscreen (HIDDEN_STYLE) in that
+ // window makes the whole grid vanish until a scroll forces a relayout
+ // (see react-native-sortables#552). Keep the item in normal flow until
+ // its absolute position is ready instead.
+ return RELATIVE_STYLE;
}
const startPosition = transformStartPosition.value;
return {
@MatiPl01 the PR solves the issue 🙏🏻. But there is one minor issue happening on Android where when we change the orientation, the widget does not resize until scrolling again.
I know I can pass a different key like current orientation and it will rerender, but previously it was working without any hacks.
Well, I think the problem is a bit more complex and the proposed fix just makes it work in this single place, but the problem itself is much more serious and is caused by a regression introduced in Reanimated in this PR: https://github.com/software-mansion/react-native-reanimated/pull/9270
We have a fix in Reanimated https://github.com/software-mansion/react-native-reanimated/pull/9644 that should land in the new version 4.5.0 and in a patch for 4.4.x (in 4.4.2). Both releases will be likely published in the next week, so please wait for the fix to come or patch reanimated to include the change from the linked fix PR.
Follow-up to my previous comment.
Upgrading to [email protected] and [email protected] appears to resolve the Android rendering issue I originally reported (items remained invisible until the first scroll). However, the same upgrade introduces a regression: drag and drop no longer works on either platform, and the following exception is thrown:
[Worklets] Cannot copy value of type `SyntheticEvent`.
at createSerializable (serializable.native.ts:212)
at value.map$argument_0 (serializable.native.ts:387)
at cloneArray (serializable.native.ts:386)
at createSerializable (serializable.native.ts:139)
at scheduleOnUI (threads.native.ts:103)
at executeDispatch (ReactFabric-dev.js:734)
Environment:
- react-native-sortables: 1.9.4
- react-native-reanimated: 4.5.0
- react-native-worklets: 0.10.0
- react-native-gesture-handler: 3.0.2
- react-native: 0.85.3 (Expo SDK 56)
- Affected platforms: iOS and Android
The workaround from my previous comment still applies:
"react-native-reanimated": "~4.3.1",
"react-native-worklets": "~0.8.3"
:tada: This issue has been resolved in version 1.10.0 :tada:
The release is available on:
Your semantic-release bot :package::rocket: