Skip to content

Commit

Permalink
Flush operations for events on iOS Fabric (software-mansion#4110)
Browse files Browse the repository at this point in the history
## Summary

This PR fixes issue with UI not updating when style changes are
connected to events on iOS Fabric. This problem has been introduced in
software-mansion#3970 where we migrated from using `rAF` and started using
`setImmediate` instead. As a result we had to manually flush
set-immediates queue in certain conditions. Specifically this was
already happening after animations frame was run (i.e. in
`requestAnimationFrame` callback) but should also be done directly after
handling events much like we already do on Android
[here](https://github.com/software-mansion/react-native-reanimated/blob/99b8b3ed56e36ca615cce7164ccaf04d154571b1/android/src/main/java/com/swmansion/reanimated/NodesManager.java#L283)
and on iOS-paper
[here](https://github.com/software-mansion/react-native-reanimated/blob/d9a55c556fc32fcb5db59acc92cbedd6452af9dc/ios/REANodesManager.mm#L334).

The reason this stopped working on iOS and not on Android was that
Android-fabric implementation still uses old architecture flow for
handling events while iOS uses new C++ based `react::EventListener` API
(that apparently wasn't working on Android last time we checked). This
PR adds flushing operations queue in that new C++ based flow.

Note that this problem didn't occur before Shareable Rewrite (software-mansion#3722)
because before all mapper updates would result in us scheduling new
animation frames. So the updates were happening eventually, were just
delayed by one frame.

## Test plan

Run Fabric example on iOS, test Article progress example.
  • Loading branch information
kmagiera authored and fluiddot committed Jun 5, 2023
1 parent 69b9121 commit de07666
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Common/cpp/NativeModules/NativeReanimatedModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,13 @@ bool NativeReanimatedModule::handleRawEvent(
jsi::Runtime &rt = *runtime.get();
jsi::Value payload = payloadFactory(rt);

return handleEvent(eventName, std::move(payload), currentTime);
auto res = handleEvent(eventName, std::move(payload), currentTime);
// TODO: we should call performOperations conditionally if event is handled
// (res == true), but for now handleEvent always returns false. Thankfully,
// performOperations does not trigger a lot of code if there is nothing to be
// done so this is fine for now.
performOperations();
return res;
}

void NativeReanimatedModule::updateProps(
Expand Down

0 comments on commit de07666

Please sign in to comment.