Skip to content

Commit fc062e3

Browse files
authored
Skip flushing layout animation requests when handling events on Android (#8459)
## Summary Fixes #8422. Co-authored-with: Bartłomiej Błoniarz <[email protected]> ## Test plan
1 parent a06017c commit fc062e3

File tree

7 files changed

+19
-17
lines changed

7 files changed

+19
-17
lines changed

packages/react-native-reanimated/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ bool ReanimatedModuleProxy::handleRawEvent(const RawEvent &rawEvent, double curr
500500
// (res == true), but for now handleEvent always returns false. Thankfully,
501501
// performOperations does not trigger a lot of code if there is nothing to
502502
// be done so this is fine for now.
503-
performOperations();
503+
performOperations(true);
504504
return res;
505505
}
506506

@@ -549,13 +549,15 @@ double ReanimatedModuleProxy::getCssTimestamp() {
549549
return currentCssTimestamp_;
550550
}
551551

552-
void ReanimatedModuleProxy::performOperations() {
552+
void ReanimatedModuleProxy::performOperations(const bool isTriggeredByEvent) {
553553
ReanimatedSystraceSection s("ReanimatedModuleProxy::performOperations");
554554

555-
auto flushRequestsCopy = std::move(layoutAnimationFlushRequests_);
556-
for (const auto surfaceId : flushRequestsCopy) {
557-
uiManager_->getShadowTreeRegistry().visit(
558-
surfaceId, [](const ShadowTree &shadowTree) { shadowTree.notifyDelegatesOfUpdates(); });
555+
if (!isTriggeredByEvent) {
556+
auto flushRequestsCopy = std::move(layoutAnimationFlushRequests_);
557+
for (const auto surfaceId : flushRequestsCopy) {
558+
uiManager_->getShadowTreeRegistry().visit(
559+
surfaceId, [](const ShadowTree &shadowTree) { shadowTree.notifyDelegatesOfUpdates(); });
560+
}
559561
}
560562

561563
jsi::Runtime &rt = workletsModuleProxy_->getUIWorkletRuntime()->getJSIRuntime();

packages/react-native-reanimated/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class ReanimatedModuleProxy : public ReanimatedModuleProxySpec,
9999
void maybeRunCSSLoop();
100100
double getCssTimestamp();
101101

102-
void performOperations();
102+
void performOperations(const bool isTriggeredByEvent);
103103

104104
void setViewStyle(jsi::Runtime &rt, const jsi::Value &viewTag, const jsi::Value &viewStyle) override;
105105

packages/react-native-reanimated/android/src/main/cpp/reanimated/android/NativeProxy.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ bool NativeProxy::isAnyHandlerWaitingForEvent(const std::string &eventName, cons
112112
return reanimatedModuleProxy_->isAnyHandlerWaitingForEvent(eventName, emitterReactTag);
113113
}
114114

115-
void NativeProxy::performOperations() {
116-
reanimatedModuleProxy_->performOperations();
115+
void NativeProxy::performOperations(const bool isTriggeredByEvent) {
116+
reanimatedModuleProxy_->performOperations(isTriggeredByEvent);
117117
}
118118

119119
bool NativeProxy::getIsReducedMotion() {

packages/react-native-reanimated/android/src/main/cpp/reanimated/android/NativeProxy.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class NativeProxy : public jni::HybridClass<NativeProxy>, std::enable_shared_fro
5555

5656
double getAnimationTimestamp();
5757
bool isAnyHandlerWaitingForEvent(const std::string &eventName, const int emitterReactTag);
58-
void performOperations();
58+
void performOperations(const bool isTriggeredByEvent);
5959
bool getIsReducedMotion();
6060
void requestRender(std::function<void(double)> onRender);
6161
void registerEventHandler();

packages/react-native-reanimated/android/src/main/java/com/swmansion/reanimated/NativeProxy.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ private native HybridData initHybrid(
110110

111111
public native boolean isAnyHandlerWaitingForEvent(String eventName, int emitterReactTag);
112112

113-
public native void performOperations();
113+
public native void performOperations(boolean isTriggeredByEvent);
114114

115115
protected native void installJSIBindings();
116116

@@ -503,7 +503,7 @@ public boolean getIsReducedMotion() {
503503
void maybeFlushUIUpdatesQueue() {
504504
UiThreadUtil.assertOnUiThread();
505505
if (!mNodesManager.isAnimationRunning()) {
506-
mNodesManager.performOperations();
506+
mNodesManager.performOperations(false);
507507
}
508508
}
509509
}

packages/react-native-reanimated/android/src/main/java/com/swmansion/reanimated/NodesManager.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ private void stopUpdatingOnAnimationFrame() {
115115
}
116116
}
117117

118-
public void performOperations() {
118+
public void performOperations(boolean isTriggeredByEvent) {
119119
UiThreadUtil.assertOnUiThread();
120120
if (mNativeProxy != null) {
121-
mNativeProxy.performOperations();
121+
mNativeProxy.performOperations(isTriggeredByEvent);
122122
}
123123
}
124124

@@ -155,7 +155,7 @@ private void onAnimationFrame(long frameTimeNanos) {
155155
}
156156
}
157157

158-
performOperations();
158+
performOperations(false);
159159
}
160160

161161
mCallbackPosted.set(false);
@@ -189,7 +189,7 @@ public void onEventDispatch(Event event) {
189189
// the UI thread.
190190
if (UiThreadUtil.isOnUiThread()) {
191191
handleEvent(event);
192-
performOperations();
192+
performOperations(true);
193193
} else {
194194
String eventName = mCustomEventNamesResolver.resolveCustomEventName(event.getEventName());
195195
int viewTag = event.getViewTag();

packages/react-native-reanimated/apple/reanimated/apple/native/NativeProxy.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ - (void *)runtime;
4646
std::weak_ptr<ReanimatedModuleProxy> weakReanimatedModuleProxy = reanimatedModuleProxy; // to avoid retain cycle
4747
[nodesManager registerPerformOperations:^() {
4848
if (auto reanimatedModuleProxy = weakReanimatedModuleProxy.lock()) {
49-
reanimatedModuleProxy->performOperations();
49+
reanimatedModuleProxy->performOperations(false);
5050
}
5151
}];
5252

0 commit comments

Comments
 (0)