Skip to content

Commit

Permalink
[iOS] Support Fabric (#5086)
Browse files Browse the repository at this point in the history
## Summary
This is part of #5080. It is the required changes to the iOS side of RNN to support the Fabric architecture. I am testing this in my own application.

Limitations:
1. Currently, it replaces the paper implementation. 
2. Currently only supports cocoapods, no plan for RN to support non-cocoapods version.
3. iOS enabled only.
  • Loading branch information
ericlewis authored Jul 14, 2020
1 parent 1d4d054 commit 6ecdb51
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 20 deletions.
22 changes: 18 additions & 4 deletions ReactNativeNavigation.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,24 @@ Pod::Spec.new do |s|
s.platform = :ios, "9.0"

s.module_name = 'ReactNativeNavigation'

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

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}"
s.exclude_files = "lib/ios/ReactNativeNavigationTests/**/*.*", "lib/ios/OCMock/**/*.*"
end

s.subspec 'Fabric' do |ss|
ss.compiler_flags = "-DRN_FABRIC_ENABLED -DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32"
ss.pod_target_xcconfig = {
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost-for-react-native\" \"$(PODS_ROOT)/Folly\"",
"CLANG_CXX_LANGUAGE_STANDARD" => "c++14"
}
ss.dependency 'React-RCTFabric'
ss.dependency 'React-Fabric'
ss.dependency 'Folly/Fabric'
end

s.dependency 'React'
s.dependency 'React-RCTImage'
Expand Down
2 changes: 1 addition & 1 deletion lib/ios/EnumParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

@interface EnumParser : NSObject

+ (Enum *)parse:(NSDictionary *)json key:(NSString *)key ofClass:(Class)class;
+ (Enum *)parse:(NSDictionary *)json key:(NSString *)key ofClass:(Class)clazz;

@end
4 changes: 2 additions & 2 deletions lib/ios/EnumParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

@implementation EnumParser

+ (Enum *)parse:(NSDictionary *)json key:(NSString *)key ofClass:(Class)class {
+ (Enum *)parse:(NSDictionary *)json key:(NSString *)key ofClass:(Class)clazz {
if (json[key]) {
return [json[key] isKindOfClass:[NSString class]] ? [[class alloc] initWithValue:json[key]] : [NullEnum new];
return [json[key] isKindOfClass:[NSString class]] ? [[clazz alloc] initWithValue:json[key]] : [NullEnum new];
}
return [NullEnum new];
}
Expand Down
15 changes: 14 additions & 1 deletion lib/ios/RNNBridgeManager.m → lib/ios/RNNBridgeManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@
#import <React/RCTBridge.h>
#import <React/RCTUIManager.h>

#ifdef RN_FABRIC_ENABLED
#import <React/RCTSurfacePresenter.h>
#endif

#import "RNNEventEmitter.h"
#import "RNNSplashScreen.h"
#import "RNNBridgeModule.h"
#import "RNNComponentViewCreator.h"
#import "RNNReactRootViewCreator.h"
#import "RNNReactComponentRegistry.h"

@interface RNNBridgeManager() <RCTBridgeDelegate>
@interface RNNBridgeManager() <RCTBridgeDelegate> {
#ifdef RN_FABRIC_ENABLED
RCTSurfacePresenter *_surfacePresenter;
#endif
}

@property (nonatomic, strong, readwrite) RCTBridge *bridge;
@property (nonatomic, strong, readwrite) RNNExternalComponentStore *store;
Expand Down Expand Up @@ -44,6 +52,11 @@ - (instancetype)initWithJsCodeLocation:(NSURL *)jsCodeLocation launchOptions:(NS
_store = [RNNExternalComponentStore new];
_bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:_launchOptions];

#ifdef RN_FABRIC_ENABLED
_surfacePresenter = [[RCTSurfacePresenter alloc] initWithBridge:_bridge config:nil];
_bridge.surfacePresenter = _surfacePresenter;
#endif

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(onJavaScriptLoaded)
name:RCTJavaScriptDidLoadNotification
Expand Down
31 changes: 23 additions & 8 deletions lib/ios/RNNReactView.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#ifdef RN_FABRIC_ENABLED
#import <React/RCTFabricSurfaceHostingProxyRootView.h>
#else
#import <React/RCTRootView.h>
#import <React/RCTRootViewDelegate.h>
#import "UIView+Utils.h"
#endif

#import "RNNEventEmitter.h"
#import "UIView+Utils.h"
#import <React/RCTRootViewDelegate.h>
#import <React/RCTUIManager.h>

#define ComponentTypeScreen @"Component"
Expand All @@ -11,12 +16,22 @@

typedef void (^RNNReactViewReadyCompletionBlock)(void);

@interface RNNReactView : RCTRootView

- (instancetype)initWithBridge:(RCTBridge *)bridge moduleName:(NSString *)moduleName initialProperties:(NSDictionary *)initialProperties eventEmitter:(RNNEventEmitter *)eventEmitter reactViewReadyBlock:(RNNReactViewReadyCompletionBlock)reactViewReadyBlock;

@property (nonatomic, copy) RNNReactViewReadyCompletionBlock reactViewReadyBlock;
@property (nonatomic, strong) RNNEventEmitter* eventEmitter;
#ifdef RN_FABRIC_ENABLED
@interface RNNReactView
: RCTFabricSurfaceHostingProxyRootView <RCTRootViewDelegate>
#else
@interface RNNReactView : RCTRootView <RCTRootViewDelegate>
#endif

- (instancetype)initWithBridge:(RCTBridge *)bridge
moduleName:(NSString *)moduleName
initialProperties:(NSDictionary *)initialProperties
eventEmitter:(RNNEventEmitter *)eventEmitter
reactViewReadyBlock:
(RNNReactViewReadyCompletionBlock)reactViewReadyBlock;

@property(nonatomic, copy) RNNReactViewReadyCompletionBlock reactViewReadyBlock;
@property(nonatomic, strong) RNNEventEmitter *eventEmitter;

- (NSString *)componentId;

Expand Down
8 changes: 4 additions & 4 deletions lib/ios/ReactNativeNavigation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
26916C981E4B9E7700D13680 /* RNNReactRootViewCreator.h in Headers */ = {isa = PBXBuildFile; fileRef = 26916C961E4B9E7700D13680 /* RNNReactRootViewCreator.h */; };
26916C991E4B9E7700D13680 /* RNNReactRootViewCreator.m in Sources */ = {isa = PBXBuildFile; fileRef = 26916C971E4B9E7700D13680 /* RNNReactRootViewCreator.m */; };
2DCD9195200014A900EDC75D /* RNNBridgeManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 2DCD9193200014A900EDC75D /* RNNBridgeManager.h */; };
2DCD9196200014A900EDC75D /* RNNBridgeManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 2DCD9194200014A900EDC75D /* RNNBridgeManager.m */; };
2DCD9196200014A900EDC75D /* RNNBridgeManager.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2DCD9194200014A900EDC75D /* RNNBridgeManager.mm */; };
3098702E6833E5CC16D91CE3 /* NoColor.h in Headers */ = {isa = PBXBuildFile; fileRef = 309874C5B132A51A03DAA3BF /* NoColor.h */; };
3098730BC3B4DE41104D9CC4 /* RNNDotIndicatorPresenter.h in Headers */ = {isa = PBXBuildFile; fileRef = 309878B02F15ECDD1A286722 /* RNNDotIndicatorPresenter.h */; };
309874B40D202C9718F15CBD /* UIView+Utils.h in Headers */ = {isa = PBXBuildFile; fileRef = 309877F25920CFE113FADEE0 /* UIView+Utils.h */; };
Expand Down Expand Up @@ -512,7 +512,7 @@
26916C961E4B9E7700D13680 /* RNNReactRootViewCreator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNNReactRootViewCreator.h; sourceTree = "<group>"; };
26916C971E4B9E7700D13680 /* RNNReactRootViewCreator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNNReactRootViewCreator.m; sourceTree = "<group>"; };
2DCD9193200014A900EDC75D /* RNNBridgeManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNBridgeManager.h; sourceTree = "<group>"; };
2DCD9194200014A900EDC75D /* RNNBridgeManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNBridgeManager.m; sourceTree = "<group>"; };
2DCD9194200014A900EDC75D /* RNNBridgeManager.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = RNNBridgeManager.mm; sourceTree = "<group>"; };
30987122507D8CBF16624F93 /* DotIndicatorOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DotIndicatorOptions.h; sourceTree = "<group>"; };
309871A6C468B5DC1D0CA495 /* RNNTestNoColor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNNTestNoColor.m; sourceTree = "<group>"; };
309871FBA64AD937CEF3E191 /* DotIndicatorParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DotIndicatorParser.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1581,7 +1581,7 @@
5030B62623D5B54D008F1642 /* LNInterpolable.h */,
5030B61E23D5B4CA008F1642 /* LNInterpolable.m */,
2DCD9193200014A900EDC75D /* RNNBridgeManager.h */,
2DCD9194200014A900EDC75D /* RNNBridgeManager.m */,
2DCD9194200014A900EDC75D /* RNNBridgeManager.mm */,
5047E4F22267568500908DD3 /* RNNExternalComponentStore.h */,
5047E4F32267568700908DD3 /* RNNExternalComponentStore.m */,
7B4928061E70415400555040 /* RNNCommandsHandler.h */,
Expand Down Expand Up @@ -2123,8 +2123,8 @@
507E7D58201DDD3000444E6C /* RNNSharedElementAnimationOptions.m in Sources */,
2145452A1F4DC85F006E8DA1 /* RCTHelpers.m in Sources */,
503A8A1223BC9C040094D1C4 /* ElementBaseTransition.m in Sources */,
2DCD9196200014A900EDC75D /* RNNBridgeManager.m in Sources */,
50D4656E23CE2553005A84B2 /* Transition.m in Sources */,
2DCD9196200014A900EDC75D /* RNNBridgeManager.mm in Sources */,
263905D71E4C94970023D7D3 /* RNNSideMenuController.m in Sources */,
50EB4ED82068EBE000D6ED34 /* RNNBackgroundOptions.m in Sources */,
5022EDCA24054C8A00852BA6 /* BottomTabsPresenterCreator.m in Sources */,
Expand Down

0 comments on commit 6ecdb51

Please sign in to comment.