-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: karol-bisztyga <[email protected]> Copied from #1149 ## Description Previously, we were handling dispatched events like so: ```java @OverRide public void onEventDispatch(Event event) { if (UiThreadUtil.isOnUiThread()) { handleEvent(event); } else { mEventQueue.offer(event); startUpdatingOnAnimationFrame(); } } ``` Event handling in RN works by utilizing `EventDispatcher.dispatchEvent(event)` which 1. runs `onEventDispatch` callback on any registered listener 2. adds `event` to internal event queue 3. adds frame callback which dispatches and disposes events on JS thread This approach introduced timing issues - RN's `EventDispatcher` dispatches events on JS thread and Reanimated handles events on UI thread. There's a possibility that `EventDispatcher` will dispose event (possibly destroying it's state in `onDispose()`) before Reanimated would have chance to handle it. This was found after investigating [pretty popular crash in react-native-gesture-handler](software-mansion/react-native-gesture-handler#1171). # HOW The pull-request adds another method `isAnyHandlerWaitingForEvent` to NativeProxy API which lets us check if an event is important (there is workletHandler listening for the event) or not. The rest part of the pr is very similar to Jakub's pr. However, there are some differences. Instead of saving copied event Object, we save: tag, eventName, and payload in the new class `CopiedEvent`.
- Loading branch information
Szymon20000
authored
Oct 27, 2020
1 parent
7685287
commit c79d27c
Showing
9 changed files
with
101 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
android/src/main/java/com/swmansion/reanimated/CopiedEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.swmansion.reanimated; | ||
|
||
import com.facebook.react.bridge.WritableArray; | ||
import com.facebook.react.bridge.WritableMap; | ||
import com.facebook.react.uimanager.events.Event; | ||
import com.facebook.react.uimanager.events.RCTEventEmitter; | ||
|
||
import androidx.annotation.Nullable; | ||
|
||
public class CopiedEvent { | ||
private int targetTag; | ||
private String eventName; | ||
private WritableMap payload; | ||
|
||
CopiedEvent(Event event) { | ||
event.dispatch(new RCTEventEmitter() { | ||
@Override | ||
public void receiveEvent(int targetTag, String eventName, @Nullable WritableMap event) { | ||
CopiedEvent.this.targetTag = targetTag; | ||
CopiedEvent.this.eventName = eventName; | ||
CopiedEvent.this.payload = event.copy(); | ||
} | ||
|
||
@Override | ||
public void receiveTouches(String eventName, WritableArray touches, WritableArray changedIndices) { | ||
//noop | ||
} | ||
}); | ||
} | ||
|
||
public int getTargetTag() { | ||
return targetTag; | ||
} | ||
|
||
public String getEventName() { | ||
return eventName; | ||
} | ||
|
||
public WritableMap getPayload() { | ||
return payload; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters