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
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -245,4 +245,6 @@ lib/Mock/*.d.ts
Mock.js
Mock.d.ts

Gemfile.lock
Gemfile.lock

.yarn/cache
Binary file added .yarn/install-state.gz
Binary file not shown.
16 changes: 16 additions & 0 deletions .yarn/patches/react-native-reanimated-npm-3.10.0-3e9c2abe21.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
diff --git a/Common/cpp/NativeModules/NativeReanimatedModule.cpp b/Common/cpp/NativeModules/NativeReanimatedModule.cpp
index a1ace04a3f6ceb721383d4ba59a64b4e9d1f4bf0..73e3b0dba4b8c96f71a18ef4de9c3b1b53c9ac1c 100644
--- a/Common/cpp/NativeModules/NativeReanimatedModule.cpp
+++ b/Common/cpp/NativeModules/NativeReanimatedModule.cpp
@@ -692,7 +692,10 @@ void NativeReanimatedModule::performOperations() {

for (const auto &[shadowNode, props] : copiedOperationsQueue) {
const ShadowNodeFamily &family = shadowNode->getFamily();
- react_native_assert(family.getSurfaceId() == surfaceId_);
+ //react_native_assert(family.getSurfaceId() == surfaceId_);
+ if(family.getSurfaceId() != surfaceId_) {
+ return nullptr;
+ }

#if REACT_NATIVE_MINOR_VERSION >= 73
// Fix for catching nullptr returned from commit hook was
874 changes: 874 additions & 0 deletions .yarn/releases/yarn-3.6.4.cjs

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-3.6.4.cjs
12 changes: 12 additions & 0 deletions RNNExternalViewCreator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// RNNExternalViewCreator.h
// Pods
//
// Created by MacMini on 1.05.24.
//

#ifndef RNNExternalViewCreator_h
#define RNNExternalViewCreator_h


#endif /* RNNExternalViewCreator_h */
23 changes: 12 additions & 11 deletions ReactNativeNavigation.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,19 @@ Pod::Spec.new do |s|

s.subspec 'Core' do |ss|
s.source = { :git => "https://github.com/wix/react-native-navigation.git", :tag => "#{s.version}" }
s.source_files = 'lib/ios/**/*.{h,m,mm,cpp}'
s.source_files = 'lib/ios/**/*.{h,m,mm,cpp}'
s.exclude_files = "lib/ios/ReactNativeNavigationTests/**/*.*", "lib/ios/OCMock/**/*.*"
end

if fabric_enabled
install_modules_dependencies(s)

folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
fabric_flags = fabric_enabled ? '-DRCT_NEW_ARCH_ENABLED' : ''

s.pod_target_xcconfig = {
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32 -DFOLLY_CFG_NO_COROUTINES=1'
s.pod_target_xcconfig = {
'HEADER_SEARCH_PATHS' => '"$(PODS_ROOT)/boost" "$(PODS_ROOT)/boost-for-react-native" "$(PODS_ROOT)/RCT-Folly" "$(PODS_ROOT)/Headers/Private/React-Core" "$(PODS_ROOT)/Headers/Private/Yoga"',
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17",
"CLANG_CXX_LANGUAGE_STANDARD" => "c++20",
"OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
}
}

if fabric_enabled
install_modules_dependencies(s)

s.compiler_flags = folly_compiler_flags + ' ' + '-DRCT_NEW_ARCH_ENABLED'
s.requires_arc = true
Expand All @@ -46,9 +44,12 @@ Pod::Spec.new do |s|
s.dependency "RCT-Folly"
s.dependency "RCTRequired"
s.dependency "RCTTypeSafety"
s.dependency "ReactCommon/turbomodule/core"
s.dependency "ReactCommon"
s.dependency "React-runtimeexecutor"
s.dependency "React-rncore"
s.dependency "React-RuntimeCore"
else
s.compiler_flags = folly_compiler_flags
end

s.dependency 'React-Core'
Expand Down
Empty file modified autolink/postlink/run.js
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = function (api) {
api && api.cache(false);
return {
presets: ['module:metro-react-native-babel-preset'],
presets: ['module:@react-native/babel-preset'],
plugins: [
'@babel/plugin-proposal-export-namespace-from',
'@babel/plugin-proposal-export-default-from',
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ - (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionCo
[self animateElement:self.screenTransition.topBar
view:toViewController.navigationController.navigationBar
elementName:@"topBar"];
[self animateElement:self.screenTransition.content
[self animateElement:(ElementTransitionOptions *)self.screenTransition.content
view:toViewController.view
elementName:@"content"];
[self animateElement:self.screenTransition.bottomTabs
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,18 @@
#import <React/RCTUIManagerObserverCoordinator.h>
#import <React/RCTUIManagerUtils.h>

#ifdef RCT_NEW_ARCH_ENABLED
#import <React-RuntimeApple/ReactCommon/RCTHost.h>
#import <React/RCTSurfacePresenterStub.h>
#endif


@interface ScreenAnimationController
: NSObject <UIViewControllerTransitioningDelegate, UIViewControllerAnimatedTransitioning,
RCTUIManagerObserver>
#ifdef RCT_NEW_ARCH_ENABLED
RCTSurfacePresenterObserver,
#endif
RCTUIManagerObserver>

- (instancetype)initWithContentTransition:(RNNEnterExitAnimation *)contentTransition
elementTransitions:(NSArray<ElementTransitionOptions *> *)elementTransitions
Expand All @@ -15,6 +24,15 @@
duration:(CGFloat)duration
bridge:(RCTBridge *)bridge;

#ifdef RCT_NEW_ARCH_ENABLED
- (instancetype)initWithContentTransition:(RNNEnterExitAnimation *)contentTransition
elementTransitions:(NSArray<ElementTransitionOptions *> *)elementTransitions
sharedElementTransitions:
(NSArray<SharedElementTransitionOptions *> *)sharedElementTransitions
duration:(CGFloat)duration
host:(RCTHost *)host;
#endif

- (NSArray *)createTransitionsFromVC:(UIViewController *)fromVC
toVC:(UIViewController *)toVC
containerView:(UIView *)containerView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@
#import "SharedElementAnimator.h"
#import "UIViewController+LayoutProtocol.h"

#ifdef RCT_NEW_ARCH_ENABLED
#include <React/RCTSurfacePresenter.h>
#include <React/RCTMountingManager.h>
#endif

@implementation ScreenAnimationController {
RCTBridge *_bridge;
#ifdef RCT_NEW_ARCH_ENABLED
RCTHost *_host;
#endif
id<UIViewControllerContextTransitioning> _transitionContext;
SharedElementAnimator *_sharedElementAnimator;
BOOL _animate;
Expand All @@ -27,8 +35,34 @@ - (instancetype)initWithContentTransition:(RNNEnterExitAnimation *)contentTransi
return self;
}

#ifdef RCT_NEW_ARCH_ENABLED
- (instancetype)initWithContentTransition:(RNNEnterExitAnimation *)contentTransition
elementTransitions:(NSArray<ElementTransitionOptions *> *)elementTransitions
sharedElementTransitions:
(NSArray<SharedElementTransitionOptions *> *)sharedElementTransitions
duration:(CGFloat)duration
host:(RCTHost *)host {
self = [super init];
_host = host;
_content = contentTransition;
_elementTransitions = elementTransitions;
_sharedElementTransitions = sharedElementTransitions;
_duration = duration;
return self;
}
#endif

- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext {
#ifdef RCT_NEW_ARCH_ENABLED
if (_host != nil) {
[_host.surfacePresenter addObserver:self];
} else {
[_bridge.uiManager.observerCoordinator addObserver:self];
}
#else
[_bridge.uiManager.observerCoordinator addObserver:self];
#endif

_animate = YES;
_transitionContext = transitionContext;
[self prepareTransitionContext:transitionContext];
Expand Down Expand Up @@ -109,6 +143,13 @@ - (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)t
return _duration;
}

// TODO: TEST THIS
#ifdef RCT_NEW_ARCH_ENABLED
- (void)didMountComponentsWithRootTag:(NSInteger)rootTag {
[self performAnimationOnce];
}
#endif

- (void)uiManagerDidPerformMounting:(RCTUIManager *)manager {
[self performAnimationOnce];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#import "RNNElementFinder.h"
#import "SharedElementTransition.h"
#import "UIViewController+LayoutProtocol.h"
#import <React/RCTImageComponentView.h>

@implementation SharedElementAnimator {
NSArray<SharedElementTransitionOptions *> *_sharedElementTransitions;
Expand Down Expand Up @@ -35,13 +36,27 @@ - (instancetype)initWithTransitions:
UIView *fromView =
[RNNElementFinder findElementForId:transitionOptions.fromId
inView:_fromVC.presentedComponentViewController.reactView];

UIView *toView =
[RNNElementFinder findElementForId:transitionOptions.toId
inView:_toVC.presentedComponentViewController.reactView];

if (fromView == nil || toView == nil) {
continue;
}

#ifdef RCT_NEW_ARCH_ENABLED
auto castedFromView = (RCTViewComponentView *)fromView;
auto castedToView = (RCTViewComponentView *)toView;

if ([castedToView respondsToSelector:@selector(props)] && [castedFromView respondsToSelector:@selector(props)]) {
castedToView.reactZIndex = ((facebook::react::ViewProps *)castedToView.props.get())->zIndex.value_or(0);
castedFromView.reactZIndex = ((facebook::react::ViewProps *)castedFromView.props.get())->zIndex.value_or(0);

printf("%d %d\n", castedFromView.reactZIndex, castedToView.reactZIndex);
}
#endif

SharedElementTransition *sharedElementAnimator =
[[SharedElementTransition alloc] initWithTransitionOptions:transitionOptions
fromView:fromView
Expand Down
13 changes: 13 additions & 0 deletions lib/ios/AppDelegate/RNNAppDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#import <Foundation/Foundation.h>
#import <React/CoreModulesPlugins.h>

#if __has_include(<React-RCTAppDelegate/RCTAppDelegate.h>)
#import <React-RCTAppDelegate/RCTAppDelegate.h>
#elif __has_include(<React_RCTAppDelegate/RCTAppDelegate.h>)
// for importing the header from framework, the dash will be transformed to underscore
#import <React_RCTAppDelegate/RCTAppDelegate.h>
#endif

@interface RNNAppDelegate : RCTAppDelegate

@end
130 changes: 130 additions & 0 deletions lib/ios/AppDelegate/RNNAppDelegate.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#import "RNNAppDelegate.h"
#import <ReactNativeNavigation/ReactNativeNavigation.h>

#ifdef RCT_NEW_ARCH_ENABLED
#import "RCTAppSetupUtils.h"
#import <React/CoreModulesPlugins.h>
#import <React/RCTCxxBridgeDelegate.h>
#import <React/RCTLegacyViewManagerInteropComponentView.h>
#import <React/RCTSurfacePresenter.h>
#import <React/RCTSurfacePresenterStub.h>
#import <React/RCTSurfacePresenterBridgeAdapter.h>
#import <ReactCommon/RCTTurboModuleManager.h>
#import <react/config/ReactNativeConfig.h>
#import <react/renderer/runtimescheduler/RuntimeScheduler.h>
#import <react/renderer/runtimescheduler/RuntimeSchedulerCallInvoker.h>
#import <React/RCTSurfacePresenter.h>
#import <React/RCTBridge+Private.h>
#import <React/RCTImageLoader.h>
#import <React/RCTBridgeProxy.h>
#import <React/RCTSurfacePresenter.h>
#import <react/utils/ManagedObjectWrapper.h>

static NSString *const kRNConcurrentRoot = @"concurrentRoot";

@interface RNNAppDelegate () <RCTTurboModuleManagerDelegate, RCTCxxBridgeDelegate> {}
@end

#endif

@implementation RNNAppDelegate

- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

// Copied from RCTAppDelegate, it private inside it
self.rootViewFactory = [self createRCTRootViewFactory];

#ifdef RCT_NEW_ARCH_ENABLED
RCTAppSetupPrepareApp(application, self.turboModuleEnabled);
RCTSetNewArchEnabled(TRUE);

if (self.bridgelessEnabled) {
// Creating host instead of bridge
self.rootViewFactory.reactHost = [self.rootViewFactory createReactHost:launchOptions];

[ReactNativeNavigation bootstrapWithHost:self.rootViewFactory.reactHost];

return YES;
}
#endif
// Force RN to init all necessary modules instead of copy-pasting code (ex. bridge)
[self.rootViewFactory viewWithModuleName:@""];

[ReactNativeNavigation bootstrapWithBridge:self.bridge];

return YES;
}

- (RCTRootViewFactory *)createRCTRootViewFactory
{
__weak __typeof(self) weakSelf = self;
RCTBundleURLBlock bundleUrlBlock = ^{
RCTAppDelegate *strongSelf = weakSelf;
return strongSelf.bundleURL;
};

RCTRootViewFactoryConfiguration *configuration =
[[RCTRootViewFactoryConfiguration alloc] initWithBundleURLBlock:bundleUrlBlock
newArchEnabled:self.fabricEnabled
turboModuleEnabled:self.turboModuleEnabled
bridgelessEnabled:self.bridgelessEnabled];

if (!self.bridgelessEnabled) {
configuration.extraModulesForBridge = ^NSArray<id<RCTBridgeModule>> * _Nonnull(RCTBridge * _Nonnull bridge) {
return [ReactNativeNavigation extraModulesForBridge:bridge];
};
}

configuration.createRootViewWithBridge = ^UIView *(RCTBridge *bridge, NSString *moduleName, NSDictionary *initProps)
{
// Ignoring creation of default view, will initialize our custom UIViewController later
return nil;
};

configuration.createBridgeWithDelegate = ^RCTBridge *(id<RCTBridgeDelegate> delegate, NSDictionary *launchOptions)
{
return [weakSelf createBridgeWithDelegate:delegate launchOptions:launchOptions];
};

#ifndef RCT_NEW_ARCH_ENABLED
return [[RCTRootViewFactory alloc] initWithConfiguration:configuration];
}
#else
return [[RCTRootViewFactory alloc] initWithConfiguration:configuration andTurboModuleManagerDelegate:self];
}

#pragma mark RCTTurboModuleManagerDelegate

- (Class)getModuleClassFromName:(const char *)name {
return RCTCoreModulesClassProvider(name);
}

- (std::shared_ptr<facebook::react::TurboModule>)
getTurboModule:(const std::string &)name
jsInvoker:(std::shared_ptr<facebook::react::CallInvoker>)jsInvoker {
return nullptr;
}

- (std::shared_ptr<facebook::react::TurboModule>)
getTurboModule:(const std::string &)name
initParams:(const facebook::react::ObjCTurboModule::InitParams &)params {
return nullptr;
}

- (id<RCTTurboModule>)getModuleInstanceFromClass:(Class)moduleClass {
return RCTAppSetupDefaultModuleFromClass(moduleClass);
}
#endif

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge {
[NSException raise:@"RCTBridgeDelegate::sourceURLForBridge not implemented"
format:@"Subclasses must implement a valid sourceURLForBridge method"];
return nil;
}

- (BOOL)concurrentRootEnabled {
return true;
}

@end
4 changes: 4 additions & 0 deletions lib/ios/Bridge/RNNBridgeEventEmitter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#import "RNNEventEmitter.h"

@interface RNNBridgeEventEmitter : RNNEventEmitter
@end
Loading
Loading