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

RN 0.74 Bridgeless support #7875

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

TheLonelyAstronaut
Copy link
Contributor

@TheLonelyAstronaut TheLonelyAstronaut commented Apr 30, 2024

Description

This PR adds support of new stable Bridgeless mode and partial migration from deprecated components. Still need some additional work to make iOS work, but all major issues was resolved with two first commits. To get this work properly, we need to wait this changes in next RN release, that's why RNN bridgeless will only work with RN 0.74.2 and higher (This changes are from Expo team cause they also need such functionality).

What was done

Common:

  • Migrated to Yarn3 (following RN)
  • Added codegen for TurboModules API
  • Turbomodules for RNNEventEmitter and RNNCommandsModule
  • JS CommandsModule architecture-independent implementation (transforms sync to async Turbomodule call if using legacy methods, this should help to update library in production app without any JS changes)

iOS:

  • waitForRender is YES by default for new architecture
  • File structure now separates files by purpose (this helps separate RN-dependent components from independent abstractions)
  • Migration to C++20
  • Migration to ObjectiveC++
  • RNNEventEmitter is a base class now. RNNBridgeEventEmitter and RNNTurboEventEmitter are children of this class
  • RNNReactView was migrated to RCTSurfaceHostingView (in new architecture mode)
  • RNNAppDelegate now extends RCTAppDelegate
  • RNNAppDelegate now uses RCTRootViewFactory and RCTHost instead of RCTBridge (In new architecture mode with bridgeless support)
  • Added RNNTurboCommandsHandler as proxy for RNNCommandsHandler
  • Added ReactNativeNavigation:bootstrapWithHost: for bridgeless mode
  • Added conditional RCTHost (bridgeless) support for almost all core classes (need some work for SurfaceAnimationController), guarded by preprocessors:
#ifdef RCT_NEW_ARCH_ENABLED // new architecture branch
    if (_host != nil) {
        [_host callSomething]; // bridgeless mode
    } else {
        [_bridge callSomething]; // bridge support
    }
#else // old architecture branch
    [_bridge callSomething]; 
#endif

TODO

Common:

  • Add detailed description
  • Prettify code
  • [Playground] Remove libs that does not support Bridgeless
  • [Playground] Migrate to Reanimated v3 to support Bridgeless

iOS:

  • Bridgeless mode with bridge support for both old and new architectures
  • LeakChecker warnings in some flows
  • [New Architecture] find element by ID for shared element transition without UIManager
  • [New Architecture] setRoot failure cause of recursive invalidate call in RCTSurfaceHostingView instance
  • [Bridgeless] use RCTHost -> DidReceiveReloadCommand in RNNTurboModuleManager instead of bridge events
  • [Bridgeless] Test SurfaceAnimationController -> observer with RCTHost instead of _bridge.uiManager

Android:

  • Bridgeless mode with bridge support for both old and new architectures

Vadzim Filipovich added 2 commits April 25, 2024 20:08
…idgeless mode. TODO: add full native implementation of turbomodule spec
@TheLonelyAstronaut
Copy link
Contributor Author

🚀

image

@Arkkeeper
Copy link

Thanks for a great PR!
But could you please check one more thing: what happens if Navigation.setRoot is called once again? (for example, when any button on the root screen calls this method)

@TheLonelyAstronaut
Copy link
Contributor Author

TheLonelyAstronaut commented May 5, 2024

@Arkkeeper sure, I'll check this, but it could be a bit buggy (PR is still a draft/PoC, im planning to finish with iOS next week and start android), hope to resolve all the issues

@TheLonelyAstronaut
Copy link
Contributor Author

TheLonelyAstronaut commented May 6, 2024

There is an interesting moment regarding new architecture: RCTEventEmitter fires 'didApper' event before component actually was created (event JS component class constructor was not been called yet).

Native call is triggered by viewDidApper lifecycle iOS event when native navigator is ready, but react view is still not, that's why after loading of react view we are getting correct view, but no event about appear status.

I think it's because of synchronous nature of new architecture, cause with old architecture we sending events from native before first render, but they emitted in JS only after render. Workaround - waitForRender: true by default with Fabric/New Architecture, but it could be reverted by setting navigation options.

@TheLonelyAstronaut TheLonelyAstronaut marked this pull request as draft May 8, 2024 09:05
@TheLonelyAstronaut TheLonelyAstronaut changed the title [DRAFT] RN 0.74 Bridgeless support RN 0.74 Bridgeless support May 8, 2024
@TheLonelyAstronaut
Copy link
Contributor Author

TheLonelyAstronaut commented May 8, 2024

iOS example app now works fine for both old and new archs (with and without bridge) 🎉

Working on ToDo list right now

@TheLonelyAstronaut
Copy link
Contributor Author

TheLonelyAstronaut commented May 10, 2024

After porting SharedElementTransition example to Reanimated 3 (to support bridgeless), i found that new Reaniamted does not support multiple surfaces yet (one native screen - one surface)

image

To fix this locally, we actually need to change assertion to if branch and return nullptr as result of commit lambda

image

…Transition on new architcture with SurfaceHostingView
@enahum
Copy link

enahum commented May 25, 2024

Looking forward to this one 🎉🎉

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

3 participants