Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify event handling on Paper and Fabric #4012

Merged
merged 9 commits into from Feb 3, 2023
Merged

Conversation

tomekzaw
Copy link
Member

@tomekzaw tomekzaw commented Feb 1, 2023

Summary

This PR unifies code responsible for handling events on Paper and Fabric on both platforms.

Changes

  • Remove #ifdef for registerEventHandler and make it renderer-agnostic
  • Use convertObjCObjectToJSIValue instead of convertIdToFollyDynamic, folly::toJson and jsi::Value::createFromJsonUtf8 on iOS
  • Move Obj-C/JSI conversion functions from NativeProxy.mm to REAJSIUtils.h
  • Still use JSON as intermediate format between ReadableMap and jsi::Value on Android (no known alternatives)
  • Pass JNI values to EventHandler function instead of std::string (like on iOS we pass id<RCTEvent>)
  • Use const jsi::Value & for event payload
  • Use const std::string & for event name

Test plan

Check if GestureHandlerExample.tsx and ScrollViewExample.tsx work on all configurations (Paper/Fabric, Android/iOS).

@tomekzaw tomekzaw marked this pull request as ready for review February 2, 2023 12:15
@tomekzaw tomekzaw merged commit e683300 into main Feb 3, 2023
@tomekzaw tomekzaw deleted the @tomekzaw/better-events branch February 3, 2023 10:12
fluiddot pushed a commit to wordpress-mobile/react-native-reanimated that referenced this pull request Jun 5, 2023
## Summary

This PR unifies code responsible for handling events on Paper and Fabric
on both platforms.

## Changes

* Remove `#ifdef` for `registerEventHandler` and make it
renderer-agnostic
* Use `convertObjCObjectToJSIValue` instead of
`convertIdToFollyDynamic`, `folly::toJson` and
`jsi::Value::createFromJsonUtf8` on iOS
* Move Obj-C/JSI conversion functions from `NativeProxy.mm` to
`REAJSIUtils.h`
* Still use JSON as intermediate format between `ReadableMap` and
`jsi::Value` on Android (no known alternatives)
* Pass JNI values to EventHandler function instead of `std::string`
(like on iOS we pass `id<RCTEvent>`)
* Use `const jsi::Value &` for event payload
* Use `const std::string &` for event name

<!--
Android:
* `event == nullptr`
* contains NaN/INF values
* `event->toString()` fail
* `{ NativeMap: null }`
* invalid JSON
* normal case

iOS:
* `event == nil`
* `[event arguments][2]` is not a `NSDictionary`
* contains NaN/INF values
* normal case
-->

## Test plan

Check if `GestureHandlerExample.tsx` and `ScrollViewExample.tsx` work on
all configurations (Paper/Fabric, Android/iOS).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants