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

[core][updates] Add bridgeless support for ReactNativeHostHandler #27629

Merged
merged 6 commits into from
Mar 15, 2024

Conversation

Kudo
Copy link
Contributor

@Kudo Kudo commented Mar 13, 2024

Why

add bridgeless support for our react delegate on android
close ENG-11646

How

  • we cannot use getDefaultReactHost() because we will fit the You can call getDefaultReactHost only with instances of DefaultReactNativeHost exception. since our reactNativeHost is actually a ReactNativeHostWrapper. this pr tries to add a ExpoReactHostFactory to handle that.
  • refactor ReactNativeHostHandler a little bit to be ReactHost/ReactInstanceManager independent
  • drop react-native < 0.74.0 support

Test Plan

  • ci passed
  • test on fabric-tester
      diff --git a/packages/expo-modules-core/android/src/main/java/expo/modules/adapters/react/NativeModulesProxy.java b/packages/expo-modules-core/android/src/main/java/expo/modules/adapters/react/NativeModulesProxy.java
      index 0448aad361..4d52e3d062 100644
      --- a/packages/expo-modules-core/android/src/main/java/expo/modules/adapters/react/NativeModulesProxy.java
      +++ b/packages/expo-modules-core/android/src/main/java/expo/modules/adapters/react/NativeModulesProxy.java
      @@ -118,7 +118,7 @@ public class NativeModulesProxy extends ReactContextBaseJavaModule {
          * or `NativeModulesProxy.callMethod("NativeDictionary", 2, ["key", 42])`, where the second argument
          * is a method's constant key.
          */
      -  @ReactMethod
      +//  @ReactMethod
         public void callMethod(String moduleName, Dynamic methodKeyOrName, ReadableArray arguments, final Promise promise) {
           String methodName;
           if (methodKeyOrName.getType() == ReadableType.String) {
      diff --git a/packages/expo-modules-core/android/src/main/java/expo/modules/kotlin/ReactExtensions.kt b/packages/expo-modules-core/android/src/main/java/expo/modules/kotlin/ReactExtensions.kt
      index 6a79b5c101..1584f615d2 100644
      --- a/packages/expo-modules-core/android/src/main/java/expo/modules/kotlin/ReactExtensions.kt
      +++ b/packages/expo-modules-core/android/src/main/java/expo/modules/kotlin/ReactExtensions.kt
      @@ -1,6 +1,7 @@
       package expo.modules.kotlin
      
       import com.facebook.react.bridge.ReactContext
      +import com.facebook.react.uimanager.ThemedReactContext
       import expo.modules.adapters.react.NativeModulesProxy
      
       internal fun ReactContext.getUnimoduleProxy(): NativeModulesProxy? {
      @@ -8,6 +9,6 @@ internal fun ReactContext.getUnimoduleProxy(): NativeModulesProxy? {
         return if (!isBridgeless) {
           catalystInstance?.getNativeModule("NativeUnimoduleProxy") as? NativeModulesProxy
         } else {
      -    nativeModules?.find { it is NativeModulesProxy } as? NativeModulesProxy
      +    (this as? ThemedReactContext)?.reactApplicationContext?.nativeModules?.find { it is NativeModulesProxy } as? NativeModulesProxy
         }
       }
    • linked expo-updates and do some test (i believe that's not fully work, should follow up later)

Checklist

@expo-bot expo-bot added the bot: suggestions ExpoBot has some suggestions label Mar 13, 2024
@expo-bot
Copy link
Collaborator

expo-bot commented Mar 13, 2024

The Pull Request introduced fingerprint changes against the base commit: a632983

Fingerprint diff
[
  {
    "type": "dir",
    "filePath": "../../packages/expo-modules-core/android",
    "reasons": [
      "expoAutolinkingAndroid"
    ],
    "hash": "d3a235998c859b3ef094cb3ca6d0425a89486e54"
  },
  {
    "type": "dir",
    "filePath": "../../packages/expo-updates/android",
    "reasons": [
      "expoAutolinkingAndroid"
    ],
    "hash": "f08f526f2fc78d040db90bc8224970aa371cc550"
  },
  {
    "type": "dir",
    "filePath": "../../packages/expo/android",
    "reasons": [
      "expoAutolinkingAndroid"
    ],
    "hash": "b177add7cb93afab1d9a93b0f6ce56eeb4092a0a"
  },
  {
    "type": "dir",
    "filePath": "android",
    "reasons": [
      "bareNativeDir"
    ],
    "hash": "8025ef08d2bc6a33113825c1859d908da350bb01"
  }
]

Generated by PR labeler 🤖

@expo-bot expo-bot added bot: passed checks ExpoBot has nothing to complain about and removed bot: suggestions ExpoBot has some suggestions labels Mar 13, 2024
@Kudo
Copy link
Contributor Author

Kudo commented Mar 13, 2024

updates e2e failed because it's running on 0.73. will have a pr to migrate all our repo and template to 0.74

@Kudo Kudo marked this pull request as ready for review March 13, 2024 16:25
Copy link

linear bot commented Mar 13, 2024

Kudo added a commit that referenced this pull request Mar 14, 2024
# Why

previously we use yarn resolutions for 0.74 version pinning, that would
help us to test canary on 0.73. since #27573 drop react-native < 0.74
support. we could remove resolutions and that would help #27601 and
#27629 for updates-e2e testing. (updates-e2e testing still on 0.73
because we don't change react-native version on
expo-template-bare-minimum.

# How

- update versions and remove yarn resolutions
- update yarn.lock
- update templates based on [upgrade helper](https://react-native-community.github.io/upgrade-helper/?from=0.73.6&to=0.74.0-rc.3)
- for gradle wrapper, running `./gradlew wrapper --gradle-version 8.6 --distribution-type all` to update
@Kudo Kudo force-pushed the @kudo/bridgeless-delegate-android branch 2 times, most recently from 037284b to fb3a099 Compare March 14, 2024 09:40
@Kudo Kudo requested a review from wschurman March 14, 2024 11:05
Copy link
Member

@wschurman wschurman left a comment

Choose a reason for hiding this comment

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

expo-updates changes look good. will defer to other reviewers for the other parts.

packages/expo/CHANGELOG.md Outdated Show resolved Hide resolved
Copy link
Contributor

@lukmccall lukmccall left a comment

Choose a reason for hiding this comment

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

LGTM

Kudo and others added 2 commits March 15, 2024 21:19
Co-authored-by: Tomasz Sapeta <tomasz.sapeta@swmansion.com>
@Kudo Kudo force-pushed the @kudo/bridgeless-delegate-android branch from 73a7f23 to 1f6a6c1 Compare March 15, 2024 13:20
@Kudo Kudo merged commit d5079bb into main Mar 15, 2024
17 checks passed
@Kudo Kudo deleted the @kudo/bridgeless-delegate-android branch March 15, 2024 14:42
marklawlor pushed a commit that referenced this pull request Mar 18, 2024
…7629)

# Why

add bridgeless support for our react delegate on android
close ENG-11646

# How

- we cannot use `getDefaultReactHost()` because we will fit the `You can
call getDefaultReactHost only with instances of DefaultReactNativeHost`
exception. since our reactNativeHost is actually a
ReactNativeHostWrapper. this pr tries to add a `ExpoReactHostFactory` to
handle that.
- refactor `ReactNativeHostHandler` a little bit to be
ReactHost/ReactInstanceManager independent
- drop react-native < 0.74.0 support

---------

Co-authored-by: Tomasz Sapeta <tomasz.sapeta@swmansion.com>
Kudo added a commit that referenced this pull request Apr 13, 2024
# Why

the error recovery of updates was broken since
https://github.com/expo/expo/pull/27629/files#diff-b034a3a37c87b036bb0d9c0549d6701774c79fedb4892dd44807d8947d75d4fbL27-R37.
apparently when ReactContext is available, it's too late for error
recovery because bundle is loaded and may throw exceptions already.

# How

- i feel #27629's change is correct for `onDidCreateReactInstance`. for
error recovery we sound like need to call point between
onWillCreateReactInstance and DevSupportManager available (error
recovery requires DevSupportManager to detect exceptions). this pr
introduces a new `onDidCreateDevSupportManager` for this purpose.
- also fix incorrect onWillCreateReactInstance timing on bridgeless mode
- seen a detox failed from proguard that i have to add an additional
proguard rule to fix that.
@brentvatne brentvatne added the published Changes from the PR have been published to npm label Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot: fingerprint changed bot: passed checks ExpoBot has nothing to complain about published Changes from the PR have been published to npm
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants