Skip to content

feat!: Turbomodule support for ios + android #622

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

Conversation

intergalacticspacehighway
Copy link

@intergalacticspacehighway intergalacticspacehighway commented Sep 11, 2022

Overview

Addresses - #608

TurboModules is the new way to create native modules in react native. It loads the module lazily which can improve the start-up time and uses JSI to communicate with the platform. This PR migrates the existing native module to use turbomodule with backward compatibility.

Test Plan

  • Create a new RN app
npx init react-native MyApp
  • Install netinfo from local folder
cd MyApp/
yarn add ../react-native-netinfo
  • Test in non fabric architecture. Actual device and simulator.
// iOS 
cd MyApp/ios
pod install
yarn ios

// Android
yarn android
  • Test in fabric architecture. Actual device and simulator.
// iOS 
cd MyApp/ios
USE_FABRIC=1 RCT_NEW_ARCH_ENABLED=1 pod install
yarn ios

// Android
- Go to gradle.properties. Set `newArchEnabled` to true
yarn android

Copy link
Contributor

@mikehardy mikehardy left a comment

Choose a reason for hiding this comment

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

Wow! Thanks a bunch for proposing this, really nice to see someone having an attempt at forward-porting this.

I sprinkled a few questions around but in general this looks pretty good, I'd love to get this merged as long as I'm sure we can handle the privacy concerns with android MAC API access,

@@ -37,7 +37,6 @@ public abstract class ConnectivityReceiver {
private final WifiManager mWifiManager;
private final TelephonyManager mTelephonyManager;
private final ReactApplicationContext mReactContext;
public boolean hasListener = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

This feature was added to address privacy-related store rejections, in #548
How do you plan to defer getting the MAC address until the user has consented, or is this no longer necessary specifically because of the turbomodule migration (and if so, how exactly - please be specific so we make sure not to blow up approval process for all Chinese apps that use this module)

Choose a reason for hiding this comment

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

wow. Thanks for pointing this out. Didn't know this. I thought it was for performance reasons.
I've started a discussion regarding some changes in NativeEventEmitter. The addListener and removeListeners methods doesn't seem to be triggering on Android with Turbomodule. I'll verify again.

Copy link
Contributor

Choose a reason for hiding this comment

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

Great - hopefully there is resolution on that one - much of the netinfo information may be considered an information leak so perhaps the restrictions won't stop at MAC address only, and this was the best way (we thought!) to do a "privacy related total information cutout" so it either must be handled or there must be some other way to defer calling any platform APIs until desired

Copy link
Author

@intergalacticspacehighway intergalacticspacehighway Sep 11, 2022

Choose a reason for hiding this comment

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

@mikehardy I just tried and those methods are working on fabric and non-fabric. I think I messed up something while testing! I have added them back, so should be fine now. Thanks again!

}


public void removeListeners(double count) {
// iOS only
numberOfListeners -= count;
if (numberOfListeners == 0) {

Choose a reason for hiding this comment

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

unrelated to this PR - removeListeners doesn't get called as we're initialising a single listener and managing emitters on JS. I think it'll be only called on tearDown. I don't think it's a big issue, just wanted to point it out.

@mikehardy mikehardy self-requested a review September 11, 2022 17:49
Copy link
Contributor

@mikehardy mikehardy left a comment

Choose a reason for hiding this comment

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

alright - thank you! - as status, I wanted to get an initial review on this immediately to make sure there were no deal-breakers, I/we have achieved that, I think this should be merge-able, as code.

Now status is: I'm in the middle of a big work crunch so this either goes on a slightly deep pile in my work queue (which means I can make no guarantees on timing). So I don't have time to validate this unfortunately or perform the project management / documentation stuff that goes along with a serious PR (which this is)

Steps to move this to merge despite me not having time to actually do anything but hit buttons and type comments:

  • we need to determine + document how backwards compatible this release will be. Will it work with react-native < 0.59 still? or just 0.64+ or something else? We need to issue this as a breaking change and indicate lower level of support. I think it will be 0.64 or 0.65 because of the 7.1.1 gradle plugin but I'm not sure where the cutoff is. Maybe just pick one (64 or 65 or ?, test it and declare the rest untested / upgrade at your own risk / report results and PR doc updates if support is broader)

  • assert that you have tested this in non-fabric mode to at least the level indicated, for android + ios

It needs a fabric support documentation update - a new section in README with a grid for where fabric is supported - with a green check for ios / mac / android and a red X for windows and a note PRs are happily accepted

If you make the decision about a react-native backwards-compatibility testing cutoff for support + test it + document it + document the fabric support status we can tag this as a breaking change feature release and merge it (at which point semantic release will auto package + release and it is out the door)

@mikehardy mikehardy changed the title Turbomodule migration feat!: Turbomodule support for ios + android Sep 11, 2022
@mikehardy
Copy link
Contributor

Looks like there is a CI failure as well, the example may need an update to work with these changes:

src/internal/NativeRNCNetInfo.ts:3:15 - error TS2305: Module '"react-native"' has no exported member 'TurboModule'.

3 import type { TurboModule } from 'react-native';
                ~~~~~~~~~~~

src/internal/NativeRNCNetInfo.ts:4:10 - error TS2[30](https://github.com/react-native-netinfo/react-native-netinfo/runs/8294240381?check_suite_focus=true#step:4:31)5: Module '"react-native"' has no exported member 'TurboModuleRegistry'.

4 import { TurboModuleRegistry } from 'react-native';
           ~~~~~~~~~~~~~~~~~~~

commit message for merge, pending interpolation of backwards support results:

BREAKING CHANGE: adding turbomodule support requires gradle vNNN, which drops support for react-native < 0.NN.NN - If you cannot update to that version of react-native or higher stay on previous version

@intergalacticspacehighway
Copy link
Author

@mikehardy thanks for reviewing! I'll report back with the required changes.

the example may need an update to work with these changes

👍

@adamsolomon1986
Copy link

any updates on this?

@zabojad
Copy link

zabojad commented Jun 1, 2023

@mikehardy I've never done that before but I could handle the finalisation of that PR as @intergalacticspacehighway doesn't seem to respond... Do I create a new PR for that ?

@anton-patrushev
Copy link

@matt-oakes can you take a look? 🙏

@intergalacticspacehighway
Copy link
Author

Closing this PR on favor of updated - #655. Thanks @j-piasecki.

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.

5 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy