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

chore(Android): migrate from deprecated RCTEventEmitter #1867

Merged
merged 6 commits into from
Aug 31, 2023

Conversation

kkafar
Copy link
Member

@kkafar kkafar commented Aug 9, 2023

Description

Fixes #1759

RCTEventEmitter was deprecated over 3 years ago in this commit

I don't know when it will be finally deleted, but:

  1. There is no reason to wait for this moment with migration
  2. According to the commit message there can be some minor performance improvements on Fabric
  3. People complain on wall of warnings during build process

I inspected ReactNative's source code and it seems that parent class impl of Event.dispatch method we used up to this point calls Event.getEventData internally and if anything is returned it dispatches the event using appropriate event emitter (see here).

Note: This PR breaks support for versions of react-native lower than 0.65.x.

Changes

In all event classes:

  1. Removed Event.dispatch override
  2. Overrided Event.getEventData
  3. Added surfaceId to event ctor

In all event construction places:

  1. Resolved appropriate (🤞🏻) surfaceId
  2. Updated event construction

Test code and steps to reproduce

My empirical impression: it works as earlier.
My methodical attempt to test it:

  1. Add console logs to event handlers in RouteView in src/native-stack/views/NativeStackView.tsx use e.g. Test1072 or different ones
  2. Play around with text example
  3. Notice that events are received in JS as expected.

Checklist

  • Included code example that can be used to test this change
  • Ensured that CI passes

@kkafar kkafar force-pushed the @kkafar/migrate-from-deprecated-rct-event-emitter branch from 1ddc6f6 to ca261ac Compare August 9, 2023 18:45
@kkafar kkafar requested review from WoLewicki and tboba August 10, 2023 11:37
Copy link
Member Author

@kkafar kkafar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just few remarks for reviewer.

@@ -192,11 +192,12 @@ open class ScreenFragment : Fragment {
if (fragment is ScreenStackFragment && fragment.canDispatchEvent(event)) {
fragment.screen.let {
fragment.setLastEventDispatched(event)
val surfaceId = UIManagerHelper.getSurfaceId(it)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe on Paper surfaceId gets resolved always to -1 -- it is Paper compatible.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you test it on the lowest version of RN we support?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UIManagerHelper.getSurfaceId exists since 0.65 -> that leaves 0.64 behind -> this PR might wait for a while before it is merged. But this situation nudges me towards thoughts that maybe we should reopen the discussion on what should be the minimal supported RN version, because it is 8 versions back right now.

Copy link
Member

@WoLewicki WoLewicki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of questions 🚀

@@ -192,11 +192,12 @@ open class ScreenFragment : Fragment {
if (fragment is ScreenStackFragment && fragment.canDispatchEvent(event)) {
fragment.screen.let {
fragment.setLastEventDispatched(event)
val surfaceId = UIManagerHelper.getSurfaceId(it)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you test it on the lowest version of RN we support?

val args = Arguments.createMap()
// on Android we always dismiss one screen at a time
args.putInt("dismissCount", 1)
rctEventEmitter.receiveEvent(viewTag, eventName, args)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure we can just remove this code? Is it done like this in other libs/core ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just take a look into default implementation of this method.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I've just found an example

Copy link
Member

@tboba tboba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a yes from me! But as @WoLewicki said, before merging it let's discuss when we should support RN <0.65 (<0.66?) 👍

@kkafar
Copy link
Member Author

kkafar commented Aug 31, 2023

As we've reached agreement on dropping RN versions and I've just released 3.25.0 with already merged changes I'm merging this one.

@kkafar kkafar merged commit 30ee316 into main Aug 31, 2023
4 checks passed
@kkafar kkafar deleted the @kkafar/migrate-from-deprecated-rct-event-emitter branch August 31, 2023 07:36
renovate bot added a commit to valora-inc/wallet that referenced this pull request Nov 2, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
|
[react-native-screens](https://togithub.com/software-mansion/react-native-screens)
| [`^3.25.0` ->
`^3.26.0`](https://renovatebot.com/diffs/npm/react-native-screens/3.25.0/3.26.0)
|
[![age](https://developer.mend.io/api/mc/badges/age/npm/react-native-screens/3.26.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/react-native-screens/3.26.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/react-native-screens/3.25.0/3.26.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/react-native-screens/3.25.0/3.26.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>software-mansion/react-native-screens
(react-native-screens)</summary>

###
[`v3.26.0`](https://togithub.com/software-mansion/react-native-screens/releases/tag/3.26.0)

[Compare
Source](https://togithub.com/software-mansion/react-native-screens/compare/3.25.0...3.26.0)

Minor release adding new useAnimatedHeaderHeight and
useReanimatedHeaderHeight hooks, providing fixes for search bar and
introducing internal changes. *Please note that new hooks introduced in
this release are fully functional on Paper, on Fabric there are few edge
cases we are still working on*.

#### What's Changed

#### 🐛 Bug fixes

- Change implementation of `headerConfig` prop on Android by
[@&#8203;tboba](https://togithub.com/tboba) in
[software-mansion/react-native-screens#1883
- Change elements visibility on search bar open by
[@&#8203;tboba](https://togithub.com/tboba) in
[software-mansion/react-native-screens#1903
- Fix positioning of large header and search bar by
[@&#8203;tboba](https://togithub.com/tboba) in
[software-mansion/react-native-screens#1895
- Change implementation of calculating status bar, refactor methods used
on header height change by [@&#8203;tboba](https://togithub.com/tboba)
in
[software-mansion/react-native-screens#1917
- Fix calculating header height when changing status/action bar
visibility by [@&#8203;tboba](https://togithub.com/tboba) in
[software-mansion/react-native-screens#1922
- Allow Reanimated Screen to check large header by
[@&#8203;tboba](https://togithub.com/tboba) in
[software-mansion/react-native-screens#1915
- Fix issue when emptying nav stack on Windows by
[@&#8203;chrisglein](https://togithub.com/chrisglein) in
[software-mansion/react-native-screens#1890
- Update podspec to use install_modules_dependencies by
[@&#8203;cipolleschi](https://togithub.com/cipolleschi) in
[software-mansion/react-native-screens#1920
- Remove MaxPerm args from JVM invocation by
[@&#8203;kkafar](https://togithub.com/kkafar) in
[software-mansion/react-native-screens#1888

#### 👍 Improvements

- Calculate values of useHeaderHeight natively by
[@&#8203;tboba](https://togithub.com/tboba) in
[software-mansion/react-native-screens#1802
- Allow for different fragment types inside ScreenContainer by
[@&#8203;kkafar](https://togithub.com/kkafar) in
[software-mansion/react-native-screens#1887
- Add focused states on page transitions by
[@&#8203;tboba](https://togithub.com/tboba) in
[software-mansion/react-native-screens#1894

#### 🔢 Miscellaneous

- **Create FUNDING.yml by
[@&#8203;aleqsio](https://togithub.com/aleqsio) in
[software-mansion/react-native-screens#1886
- Migrate from deprecated `RCTEventEmitter` by
[@&#8203;kkafar](https://togithub.com/kkafar) in
[software-mansion/react-native-screens#1867
- Use `require` syntax for resolution of all native components by
[@&#8203;kkafar](https://togithub.com/kkafar) in
[software-mansion/react-native-screens#1909
- Run Android e2e with JDK 17 by
[@&#8203;kkafar](https://togithub.com/kkafar) in
[software-mansion/react-native-screens#1892
- Put timelimit on execution of each workflow by
[@&#8203;kkafar](https://togithub.com/kkafar) in
[software-mansion/react-native-screens#1893
- Trigger e2e tests on JS-only changes by
[@&#8203;kkafar](https://togithub.com/kkafar) in
[software-mansion/react-native-screens#1910
- Update deprecated expo install instructions to `npx expo install` by
[@&#8203;GabrieldosSantosOliveira](https://togithub.com/GabrieldosSantosOliveira)
in
[software-mansion/react-native-screens#1899
- Bump activesupport from 6.1.7.3 to 7.0.7.2 in /TestsExample by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[software-mansion/react-native-screens#1877
- Update deps & RN in example apps after release by
[@&#8203;kkafar](https://togithub.com/kkafar) in
[software-mansion/react-native-screens#1878
- Migrate `Example` app & e2e tests to RN 0.72.4 by
[@&#8203;kkafar](https://togithub.com/kkafar) in
[software-mansion/react-native-screens#1880
- Bump library deps to recent versions (including RN) by
[@&#8203;kkafar](https://togithub.com/kkafar) in
[software-mansion/react-native-screens#1881
- Bump library native Android deps & config by
[@&#8203;kkafar](https://togithub.com/kkafar) in
[software-mansion/react-native-screens#1891

#### New Contributors

- [@&#8203;chrisglein](https://togithub.com/chrisglein) made their first
contribution in
[software-mansion/react-native-screens#1890
-
[@&#8203;GabrieldosSantosOliveira](https://togithub.com/GabrieldosSantosOliveira)
made their first contribution in
[software-mansion/react-native-screens#1899
- [@&#8203;cipolleschi](https://togithub.com/cipolleschi) made their
first contribution in
[software-mansion/react-native-screens#1920

**Full Changelog**:
software-mansion/react-native-screens@3.25.0...3.26.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "after 5pm,every weekend" in timezone
America/Los_Angeles, Automerge - "after 5pm,every weekend" in timezone
America/Los_Angeles.

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/valora-inc/wallet).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4xOS4yIiwidXBkYXRlZEluVmVyIjoiMzcuMTkuMiIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==-->

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: valora-bot <valorabot@valoraapp.com>
Co-authored-by: Silas Boyd-Wickizer <silasbw@gmail.com>
Co-authored-by: Silas Boyd-Wickizer <silas@valora.xyz>
m-bert added a commit to software-mansion/react-native-gesture-handler that referenced this pull request Mar 12, 2024
## Description

It turns out that our code uses some deprecated functions. Also there were few more warnings, such as shadowed name or unused variables.

Some of included changes require digging into `react-native` source code to find alternative approach.

Fixes #2460 

## `dispatch` method

Based on @kkafar research in [screens](software-mansion/react-native-screens#1867), I've replaced `dispatch` method with `getEventData`.

- [Here](https://github.com/facebook/react-native/blob/e2ef6b98a061508bdd70a4c2747fe061c49b5c39/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/Event.java#L154-L168) you can find how `dispatch` looks like in the source code. 
- [Here](facebook/react-native@72d0ddc#diff-afc6f25f459dcf1e24a012e16862c869aa04b0de5795171efe14b7a88be08e64) you can see example change in react-native

## Test plan

Tested that our example apps (paper and fabric) work as expected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants