Skip to content
Closed
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions packages/react-native/Libraries/AppDelegate/RCTAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
* LICENSE file in the root directory of this source tree.
*/

#import <React/RCTBridge.h>
#import <React/RCTBridgeDelegate.h>
#import <UIKit/UIKit.h>

@class RCTBridge;
@protocol RCTBridgeDelegate;
@protocol RCTComponentViewProtocol;
@class RCTSurfacePresenterBridgeAdapter;

Expand Down Expand Up @@ -132,6 +132,14 @@
/// @return: `true` if the Fabric Renderer is enabled. Otherwise, it returns `false`.
- (BOOL)fabricEnabled;

/// This method controls whether React Native's new initialization layer is enabled.
///
/// @return: `true` if the new initialization layer is enabled. Otherwise returns `false`.
- (BOOL)bridgelessEnabled;

/// Return the bundle URL for the main bundle.
- (NSURL *)getBundleURL;

#endif

@end
105 changes: 91 additions & 14 deletions packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,41 @@
#import "RCTAppDelegate.h"
#import <React/RCTRootView.h>
#import "RCTAppSetupUtils.h"
#import "RCTLegacyInteropComponents.h"

#if RCT_NEW_ARCH_ENABLED
#import <React/CoreModulesPlugins.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTComponentViewFactory.h>
#import <React/RCTComponentViewProtocol.h>
#import <React/RCTCxxBridgeDelegate.h>
#import <React/RCTFabricSurface.h>
#import <React/RCTFabricSurfaceHostingProxyRootView.h>
#import <React/RCTLegacyViewManagerInteropComponentView.h>
#import <React/RCTSurfaceHostingProxyRootView.h>
#import <React/RCTSurfacePresenter.h>
#import <React/RCTSurfacePresenterBridgeAdapter.h>
#import <ReactCommon/RCTContextContainerHandling.h>
#if USE_HERMES
#import <ReactCommon/RCTHermesInstance.h>
#else
#import <ReactCommon/RCTJscInstance.h>
#endif
#import <ReactCommon/RCTHost+Internal.h>
#import <ReactCommon/RCTHost.h>
#import <ReactCommon/RCTTurboModuleManager.h>
#import <react/bridgeless/JSEngineInstance.h>
#import <react/config/ReactNativeConfig.h>
#import <react/renderer/runtimescheduler/RuntimeScheduler.h>
#import <react/renderer/runtimescheduler/RuntimeSchedulerCallInvoker.h>
#import "RCTLegacyInteropComponents.h"

static NSString *const kRNConcurrentRoot = @"concurrentRoot";

@interface RCTAppDelegate () <
RCTTurboModuleManagerDelegate,
RCTCxxBridgeDelegate,
RCTComponentViewFactoryComponentProvider> {
RCTComponentViewFactoryComponentProvider,
RCTContextContainerHandling> {
std::shared_ptr<const facebook::react::ReactNativeConfig> _reactNativeConfig;
facebook::react::ContextContainer::Shared _contextContainer;
std::shared_ptr<facebook::react::RuntimeScheduler> _runtimeScheduler;
Expand All @@ -38,7 +51,11 @@ @interface RCTAppDelegate () <

#endif

@implementation RCTAppDelegate
@implementation RCTAppDelegate {
#if RCT_NEW_ARCH_ENABLED
RCTHost *_reactHost;
#endif
}

#if RCT_NEW_ARCH_ENABLED
- (instancetype)init
Expand All @@ -55,26 +72,44 @@ - (instancetype)init
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
BOOL enableTM = NO;
BOOL enableBridgeless = NO;
#if RCT_NEW_ARCH_ENABLED
enableTM = self.turboModuleEnabled;
enableBridgeless = self.bridgelessEnabled;
#endif

RCTAppSetupPrepareApp(application, enableTM);

if (!self.bridge) {
self.bridge = [self createBridgeWithDelegate:self launchOptions:launchOptions];
}
UIView *rootView;

if (enableBridgeless) {
#if RCT_NEW_ARCH_ENABLED
self.bridgeAdapter = [[RCTSurfacePresenterBridgeAdapter alloc] initWithBridge:self.bridge
contextContainer:_contextContainer];
self.bridge.surfacePresenter = self.bridgeAdapter.surfacePresenter;
[self createReactHost];
RCTFabricSurface *surface = [_reactHost createSurfaceWithModuleName:self.moduleName
initialProperties:launchOptions];

[self unstable_registerLegacyComponents];
[RCTComponentViewFactory currentComponentViewFactory].thirdPartyFabricComponentsProvider = self;
#endif
RCTSurfaceHostingProxyRootView *surfaceHostingProxyRootView = [[RCTSurfaceHostingProxyRootView alloc]
initWithSurface:surface
sizeMeasureMode:RCTSurfaceSizeMeasureModeWidthExact | RCTSurfaceSizeMeasureModeHeightExact
moduleRegistry:[_reactHost getModuleRegistry]];

NSDictionary *initProps = [self prepareInitialProps];
UIView *rootView = [self createRootViewWithBridge:self.bridge moduleName:self.moduleName initProps:initProps];
rootView = (RCTRootView *)surfaceHostingProxyRootView;
#endif
} else {
if (!self.bridge) {
self.bridge = [self createBridgeWithDelegate:self launchOptions:launchOptions];
}
#if RCT_NEW_ARCH_ENABLED
self.bridgeAdapter = [[RCTSurfacePresenterBridgeAdapter alloc] initWithBridge:self.bridge
contextContainer:_contextContainer];
self.bridge.surfacePresenter = self.bridgeAdapter.surfacePresenter;

[self unstable_registerLegacyComponents];
[RCTComponentViewFactory currentComponentViewFactory].thirdPartyFabricComponentsProvider = self;
#endif
NSDictionary *initProps = [self prepareInitialProps];
rootView = [self createRootViewWithBridge:self.bridge moduleName:self.moduleName initProps:initProps];
}
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIViewController *rootViewController = [self createRootViewController];
[self setRootView:rootView toRootViewController:rootViewController];
Expand Down Expand Up @@ -198,6 +233,11 @@ - (BOOL)fabricEnabled
return YES;
}

- (BOOL)bridgelessEnabled
{
return YES;
}

#pragma mark - New Arch Utilities

- (void)unstable_registerLegacyComponents
Expand All @@ -207,6 +247,43 @@ - (void)unstable_registerLegacyComponents
}
}

- (void)createReactHost
{
__weak __typeof(self) weakSelf = self;
_reactHost = [[RCTHost alloc] initWithBundleURL:[self getBundleURL]
hostDelegate:nil
turboModuleManagerDelegate:self
jsEngineProvider:^std::shared_ptr<facebook::react::JSEngineInstance>() {
return [weakSelf createJSEngineInstance];
}];
[_reactHost setBundleURLProvider:^NSURL *() {
return [weakSelf getBundleURL];
}];
[_reactHost setContextContainerHandler:self];
[_reactHost start];
}

- (std::shared_ptr<facebook::react::JSEngineInstance>)createJSEngineInstance
{
#if USE_HERMES
return std::make_shared<facebook::react::RCTHermesInstance>(_reactNativeConfig, nullptr);
#else
return std::make_shared<facebook::react::RCTJscInstance>();
#endif
}

- (void)didCreateContextContainer:(std::shared_ptr<facebook::react::ContextContainer>)contextContainer
{
contextContainer->insert("ReactNativeConfig", _reactNativeConfig);
}

- (NSURL *)getBundleURL
{
[NSException raise:@"RCTAppDelegate::getBundleURL not implemented"
format:@"Subclasses must implement a valid getBundleURL method"];
return nullptr;
}

#endif

@end
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@ folly_flags = ' -DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1'
folly_compiler_flags = folly_flags + ' ' + '-Wno-comma -Wno-shorten-64-to-32'

is_new_arch_enabled = ENV["RCT_NEW_ARCH_ENABLED"] == "1"
use_hermes = ENV['USE_HERMES'] == nil || ENV['USE_HERMES'] == '1'
use_frameworks = ENV['USE_FRAMEWORKS'] != nil

new_arch_enabled_flag = (is_new_arch_enabled ? " -DRCT_NEW_ARCH_ENABLED" : "")
is_fabric_enabled = is_new_arch_enabled || ENV["RCT_FABRIC_ENABLED"]
fabric_flag = (is_fabric_enabled ? " -DRN_FABRIC_ENABLED" : "")
other_cflags = "$(inherited)" + folly_flags + new_arch_enabled_flag + fabric_flag

use_hermes = ENV['USE_HERMES'] == '1'
use_frameworks = ENV['USE_FRAMEWORKS'] != nil
hermes_flag = (use_hermes ? " -DUSE_HERMES" : "")
other_cflags = "$(inherited)" + folly_flags + new_arch_enabled_flag + fabric_flag + hermes_flag

header_search_paths = [
"$(PODS_TARGET_SRCROOT)/ReactCommon",
"$(PODS_TARGET_SRCROOT)/../../ReactCommon",
"$(PODS_ROOT)/Headers/Private/React-Core",
"$(PODS_ROOT)/boost",
"$(PODS_ROOT)/DoubleConversion",
Expand All @@ -47,6 +48,8 @@ header_search_paths = [
"$(PODS_CONFIGURATION_BUILD_DIR)/React-graphics/React_graphics.framework/Headers/react/renderer/graphics/platform/ios",
"$(PODS_CONFIGURATION_BUILD_DIR)/ReactCommon/ReactCommon.framework/Headers/react/nativemodule/core",
"$(PODS_CONFIGURATION_BUILD_DIR)/React-NativeModulesApple/React_NativeModulesApple.framework/Headers",
"$(PODS_CONFIGURATION_BUILD_DIR)/React-BridgelessApple/React_BridgelessApple.framework/Headers",
"$(PODS_CONFIGURATION_BUILD_DIR)/React-BridgelessCore/React_BridgelessCore.framework/Headers",
"$(PODS_CONFIGURATION_BUILD_DIR)/React-RCTFabric/RCTFabric.framework/Headers/",
"$(PODS_CONFIGURATION_BUILD_DIR)/React-utils/React_utils.framework/Headers/",
"$(PODS_CONFIGURATION_BUILD_DIR)/React-debug/React_debug.framework/Headers/",
Expand Down Expand Up @@ -75,6 +78,8 @@ Pod::Spec.new do |s|
}
s.user_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/Headers/Private/React-Core\""}

use_hermes = ENV['USE_HERMES'] == nil || ENV['USE_HERMES'] == "1"

s.dependency "React-Core"
s.dependency "RCT-Folly"
s.dependency "RCTRequired"
Expand All @@ -84,8 +89,17 @@ Pod::Spec.new do |s|
s.dependency "React-RCTImage"
s.dependency "React-NativeModulesApple"
s.dependency "React-CoreModules"
s.dependency "React-nativeconfig"

if is_new_arch_enabled
s.dependency "React-BridgelessCore"
s.dependency "React-BridgelessApple"
if use_hermes
s.dependency "React-BridgelessHermes"
end
end

if ENV['USE_HERMES'] == nil || ENV['USE_HERMES'] == "1"
if use_hermes
s.dependency "React-hermes"
else
s.dependency "React-jsc"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ BOOL RCTUpscalingRequired(

// Calculate aspect ratios if needed (don't bother if resizeMode == stretch)
CGFloat aspect = 0.0, targetAspect = 0.0;
if (resizeMode != UIViewContentModeScaleToFill) {
if (resizeMode != RCTResizeModeStretch) {
aspect = sourceSize.width / sourceSize.height;
targetAspect = destSize.width / destSize.height;
if (aspect == targetAspect) {
Expand Down Expand Up @@ -267,8 +267,8 @@ BOOL RCTUpscalingRequired(
CFRelease(sourceRef);
return nil;
}
NSNumber *width = CFDictionaryGetValue(imageProperties, kCGImagePropertyPixelWidth);
NSNumber *height = CFDictionaryGetValue(imageProperties, kCGImagePropertyPixelHeight);
NSNumber *width = (NSNumber *)CFDictionaryGetValue(imageProperties, kCGImagePropertyPixelWidth);
NSNumber *height = (NSNumber *)CFDictionaryGetValue(imageProperties, kCGImagePropertyPixelHeight);
CGSize sourceSize = {width.doubleValue, height.doubleValue};
CFRelease(imageProperties);

Expand All @@ -281,7 +281,7 @@ BOOL RCTUpscalingRequired(
destScale = RCTScreenScale();
}

if (resizeMode == UIViewContentModeScaleToFill) {
if (resizeMode == RCTResizeModeStretch) {
// Decoder cannot change aspect ratio, so RCTResizeModeStretch is equivalent
// to RCTResizeModeCover for our purposes
resizeMode = RCTResizeModeCover;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Pod::Spec.new do |s|
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17",
"HEADER_SEARCH_PATHS" => header_search_paths.join(' ')
}
s.framework = ["Accelerate", "UIKit"]

s.dependency "RCT-Folly", folly_version
s.dependency "React-Codegen", version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ NS_ASSUME_NONNULL_BEGIN
RCT_EXTERN NSString *RCTInterpolateString(
NSString *pattern,
CGFloat inputValue,
NSArray *inputRange,
NSArray<NSNumber *> *inputRange,
NSArray<NSArray<NSNumber *> *> *outputRange,
NSString *extrapolateLeft,
NSString *extrapolateRight);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

#import <React/RCTInterpolationAnimatedNode.h>
#import "RCTInterpolationAnimatedNode.h"

#import <React/RCTAnimationUtils.h>
#import <React/RCTConvert.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ uint32_t RCTColorFromComponents(CGFloat red, CGFloat green, CGFloat blue, CGFloa

#if TARGET_IPHONE_SIMULATOR
// Based on https://stackoverflow.com/a/13307674
float UIAnimationDragCoefficient(void);
UIKIT_EXTERN float UIAnimationDragCoefficient(void);
#endif

CGFloat RCTAnimationDragCoefficient(void)
Expand Down
4 changes: 3 additions & 1 deletion packages/react-native/Libraries/Text/React-RCTText.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ Pod::Spec.new do |s|
s.author = "Meta Platforms, Inc. and its affiliates"
s.platforms = { :ios => min_ios_version_supported }
s.source = source
s.source_files = "**/*.{h,m}"
s.source_files = "**/*.{h,m,mm}"
s.preserve_paths = "package.json", "LICENSE", "LICENSE-docs"
s.header_dir = "RCTText"
s.framework = ["MobileCoreServices"]

s.dependency "Yoga"
s.dependency "React-Core/RCTTextHeaders", version
end
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ @implementation RCTInputAccessoryShadowView
- (void)insertReactSubview:(RCTShadowView *)subview atIndex:(NSInteger)atIndex
{
[super insertReactSubview:subview atIndex:atIndex];
subview.width = (YGValue){RCTScreenSize().width, YGUnitPoint};
subview.width = (YGValue){static_cast<float>(RCTScreenSize().width), YGUnitPoint};
}

@end
4 changes: 2 additions & 2 deletions packages/react-native/React-Core.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ Pod::Spec.new do |s|
"React/Fabric/**/*",
"React/FBReactNativeSpec/**/*",
"React/Tests/**/*",
"React/Inspector/**/*"
"React/Inspector/**/*",
]
# If we are using Hermes (the default is use hermes, so USE_HERMES can be nil), we don't have jsc installed
# So we have to exclude the JSCExecutorFactory
if ENV['USE_HERMES'] == nil || ENV['USE_HERMES'] == "1"
exclude_files = exclude_files.append("React/CxxBridge/JSCExecutorFactory.{h,mm}")
end
ss.exclude_files = exclude_files
ss.private_header_files = "React/Cxx*/*.h"
ss.private_header_files = "React/CxxLogUtils/*.h"
end

s.subspec "DevSupport" do |ss|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ - (UIWindow *)alertWindow

- (void)show:(BOOL)animated completion:(void (^)(void))completion
{
UIUserInterfaceStyle style =
RCTSharedApplication().delegate.window.overrideUserInterfaceStyle ?: UIUserInterfaceStyleUnspecified;
UIUserInterfaceStyle style = RCTSharedApplication().delegate.window.overrideUserInterfaceStyle
? RCTSharedApplication().delegate.window.overrideUserInterfaceStyle
: UIUserInterfaceStyleUnspecified;
self.overrideUserInterfaceStyle = style;

[self.alertWindow makeKeyAndVisible];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ - (instancetype)initWithFrame:(CGRect)frame color:(UIColor *)color
_length = (NSUInteger)floor(frame.size.width);
_height = (NSUInteger)floor(frame.size.height);
_scale = 60.0 / (CGFloat)_height;
_frames = calloc(sizeof(CGFloat), _length);
_frames = (CGFloat *)calloc(sizeof(CGFloat), _length);
_color = color;

[self.layer addSublayer:self.graph];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Pod::Spec.new do |s|
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17",
"HEADER_SEARCH_PATHS" => header_search_paths.join(" ")
}

s.framework = "UIKit"
s.dependency "React-Codegen", version
s.dependency "RCT-Folly", folly_version
s.dependency "RCTTypeSafety", version
Expand Down
Loading