Skip to content

Commit 4cd0ca9

Browse files
author
Marek Fořt
committed
Fabric iOS support
1 parent 449fb43 commit 4cd0ca9

32 files changed

Lines changed: 984 additions & 314 deletions

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ module.exports = {
3939
"require-atomic-updates": "off",
4040
"@typescript-eslint/member-ordering": "off",
4141
"@typescript-eslint/consistent-indexed-object-style": "off",
42+
"@typescript-eslint/ban-ts-comment": "off",
4243
"jsx-a11y/no-autofocus": "off",
4344
},
4445
overrides: [

RNFlashList.podspec

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ require 'json'
22

33
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
44

5+
fabric_enabled = ENV['RCT_NEW_ARCH_ENABLED']
6+
57
Pod::Spec.new do |s|
68
s.name = 'RNFlashList'
79
s.version = package['version']
@@ -15,8 +17,31 @@ Pod::Spec.new do |s|
1517
s.requires_arc = true
1618
s.swift_version = '5.0'
1719

18-
# Dependencies
19-
s.dependency 'React-Core'
20+
if fabric_enabled
21+
# folly_version must match the version used in React Native
22+
# See folly_version in react-native/React/FBReactNativeSpec/FBReactNativeSpec.podspec
23+
folly_version = '2021.06.28.00-v2'
24+
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DRN_FABRIC_ENABLED -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
25+
26+
s.pod_target_xcconfig = {
27+
'HEADER_SEARCH_PATHS' => '"$(PODS_ROOT)/boost" "$(PODS_ROOT)/boost-for-react-native" "$(PODS_ROOT)/RCT-Folly"',
28+
'CLANG_CXX_LANGUAGE_STANDARD' => 'c++17',
29+
}
30+
s.platforms = { ios: '11.0', tvos: '11.0' }
31+
s.compiler_flags = folly_compiler_flags
32+
33+
s.dependency "React"
34+
s.dependency "React-RCTFabric" # This is for fabric component
35+
s.dependency "React-Codegen"
36+
s.dependency "RCT-Folly", folly_version
37+
s.dependency "RCTRequired"
38+
s.dependency "RCTTypeSafety"
39+
s.dependency "ReactCommon/turbomodule/core"
40+
else
41+
s.platforms = { :ios => "9.0", :tvos => "9.0" }
42+
43+
s.dependency "React-Core"
44+
end
2045

2146
# Tests spec
2247
s.test_spec 'Tests' do |test_spec|

fixture/babel.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = {
22
presets: ["module:metro-react-native-babel-preset"],
33
plugins: [
4-
"react-native-reanimated/plugin",
4+
// "react-native-reanimated/plugin",
55
[
66
"module-resolver",
77
{

fixture/ios/FlatListPro.xcodeproj/project.pbxproj

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,16 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10-
13B07FBC1A68108700A75B9A /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB01A68108700A75B9A /* AppDelegate.m */; };
1110
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; };
1211
13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
1312
4C28D4195347110DD7EFF250 /* libPods-FlatListPro.a in Frameworks */ = {isa = PBXBuildFile; fileRef = B5C2CC4776DE30CFFD3D9728 /* libPods-FlatListPro.a */; };
1413
81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */; };
14+
F8080E0328117D5C00721D6B /* AppDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = F8080E0228117D5C00721D6B /* AppDelegate.mm */; };
1515
/* End PBXBuildFile section */
1616

1717
/* Begin PBXFileReference section */
1818
13B07F961A680F5B00A75B9A /* FlatListPro.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = FlatListPro.app; sourceTree = BUILT_PRODUCTS_DIR; };
1919
13B07FAF1A68108700A75B9A /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; name = AppDelegate.h; path = FlatListPro/AppDelegate.h; sourceTree = "<group>"; tabWidth = 4; };
20-
13B07FB01A68108700A75B9A /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; name = AppDelegate.m; path = FlatListPro/AppDelegate.m; sourceTree = "<group>"; tabWidth = 4; };
2120
13B07FB51A68108700A75B9A /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Images.xcassets; path = FlatListPro/Images.xcassets; sourceTree = "<group>"; };
2221
13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = FlatListPro/Info.plist; sourceTree = "<group>"; };
2322
13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = FlatListPro/main.m; sourceTree = "<group>"; tabWidth = 4; };
@@ -26,6 +25,7 @@
2625
906B19594009D131502608CA /* Pods-FlatListPro.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FlatListPro.release.xcconfig"; path = "Target Support Files/Pods-FlatListPro/Pods-FlatListPro.release.xcconfig"; sourceTree = "<group>"; };
2726
B5C2CC4776DE30CFFD3D9728 /* libPods-FlatListPro.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-FlatListPro.a"; sourceTree = BUILT_PRODUCTS_DIR; };
2827
ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
28+
F8080E0228117D5C00721D6B /* AppDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = AppDelegate.mm; path = FlatListPro/AppDelegate.mm; sourceTree = "<group>"; };
2929
/* End PBXFileReference section */
3030

3131
/* Begin PBXFrameworksBuildPhase section */
@@ -43,8 +43,8 @@
4343
13B07FAE1A68108700A75B9A /* FlatListPro */ = {
4444
isa = PBXGroup;
4545
children = (
46+
F8080E0228117D5C00721D6B /* AppDelegate.mm */,
4647
13B07FAF1A68108700A75B9A /* AppDelegate.h */,
47-
13B07FB01A68108700A75B9A /* AppDelegate.m */,
4848
13B07FB51A68108700A75B9A /* Images.xcassets */,
4949
13B07FB61A68108700A75B9A /* Info.plist */,
5050
81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */,
@@ -265,7 +265,7 @@
265265
isa = PBXSourcesBuildPhase;
266266
buildActionMask = 2147483647;
267267
files = (
268-
13B07FBC1A68108700A75B9A /* AppDelegate.m in Sources */,
268+
F8080E0328117D5C00721D6B /* AppDelegate.mm in Sources */,
269269
13B07FC11A68108700A75B9A /* main.m in Sources */,
270270
);
271271
runOnlyForDeploymentPostprocessing = 0;
@@ -278,6 +278,7 @@
278278
baseConfigurationReference = 5715F3B3165A79E0A40F6237 /* Pods-FlatListPro.debug.xcconfig */;
279279
buildSettings = {
280280
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
281+
CLANG_CXX_LANGUAGE_STANDARD = "c++17";
281282
CLANG_ENABLE_MODULES = YES;
282283
CURRENT_PROJECT_VERSION = 1;
283284
ENABLE_BITCODE = NO;
@@ -305,6 +306,7 @@
305306
baseConfigurationReference = 906B19594009D131502608CA /* Pods-FlatListPro.release.xcconfig */;
306307
buildSettings = {
307308
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
309+
CLANG_CXX_LANGUAGE_STANDARD = "c++17";
308310
CLANG_ENABLE_MODULES = YES;
309311
CURRENT_PROJECT_VERSION = 1;
310312
INFOPLIST_FILE = FlatListPro/Info.plist;
@@ -330,7 +332,7 @@
330332
buildSettings = {
331333
ALWAYS_SEARCH_USER_PATHS = NO;
332334
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
333-
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
335+
CLANG_CXX_LANGUAGE_STANDARD = "c++17";
334336
CLANG_CXX_LIBRARY = "libc++";
335337
CLANG_ENABLE_MODULES = YES;
336338
CLANG_ENABLE_OBJC_ARC = YES;
@@ -358,7 +360,7 @@
358360
COPY_PHASE_STRIP = NO;
359361
ENABLE_STRICT_OBJC_MSGSEND = YES;
360362
ENABLE_TESTABILITY = YES;
361-
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "";
363+
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = i386;
362364
GCC_C_LANGUAGE_STANDARD = gnu99;
363365
GCC_DYNAMIC_NO_PIC = NO;
364366
GCC_NO_COMMON_BLOCKS = YES;
@@ -386,6 +388,12 @@
386388
);
387389
MTL_ENABLE_DEBUG_INFO = YES;
388390
ONLY_ACTIVE_ARCH = YES;
391+
OTHER_CPLUSPLUSFLAGS = (
392+
"$(OTHER_CFLAGS)",
393+
"-DFOLLY_NO_CONFIG",
394+
"-DFOLLY_MOBILE=1",
395+
"-DFOLLY_USE_LIBCPP=1",
396+
);
389397
SDKROOT = iphoneos;
390398
};
391399
name = Debug;
@@ -395,7 +403,7 @@
395403
buildSettings = {
396404
ALWAYS_SEARCH_USER_PATHS = NO;
397405
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
398-
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
406+
CLANG_CXX_LANGUAGE_STANDARD = "c++17";
399407
CLANG_CXX_LIBRARY = "libc++";
400408
CLANG_ENABLE_MODULES = YES;
401409
CLANG_ENABLE_OBJC_ARC = YES;
@@ -423,7 +431,7 @@
423431
COPY_PHASE_STRIP = YES;
424432
ENABLE_NS_ASSERTIONS = NO;
425433
ENABLE_STRICT_OBJC_MSGSEND = YES;
426-
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "";
434+
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = i386;
427435
GCC_C_LANGUAGE_STANDARD = gnu99;
428436
GCC_NO_COMMON_BLOCKS = YES;
429437
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
@@ -443,6 +451,12 @@
443451
"\"$(inherited)\"",
444452
);
445453
MTL_ENABLE_DEBUG_INFO = NO;
454+
OTHER_CPLUSPLUSFLAGS = (
455+
"$(OTHER_CFLAGS)",
456+
"-DFOLLY_NO_CONFIG",
457+
"-DFOLLY_MOBILE=1",
458+
"-DFOLLY_USE_LIBCPP=1",
459+
);
446460
SDKROOT = iphoneos;
447461
VALIDATE_PRODUCT = YES;
448462
};

fixture/ios/FlatListPro/AppDelegate.m

Lines changed: 0 additions & 62 deletions
This file was deleted.
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#import "AppDelegate.h"
2+
3+
#import <React/RCTBridge.h>
4+
#import <React/RCTBundleURLProvider.h>
5+
#import <React/RCTRootView.h>
6+
7+
#import <React/RCTAppSetupUtils.h>
8+
9+
#if RCT_NEW_ARCH_ENABLED
10+
#import <React/CoreModulesPlugins.h>
11+
#import <React/RCTCxxBridgeDelegate.h>
12+
#import <React/RCTFabricSurfaceHostingProxyRootView.h>
13+
#import <React/RCTSurfacePresenter.h>
14+
#import <React/RCTSurfacePresenterBridgeAdapter.h>
15+
#import <ReactCommon/RCTTurboModuleManager.h>
16+
#import <react/config/ReactNativeConfig.h>
17+
@interface AppDelegate () <RCTCxxBridgeDelegate, RCTTurboModuleManagerDelegate> {
18+
RCTTurboModuleManager *_turboModuleManager;
19+
RCTSurfacePresenterBridgeAdapter *_bridgeAdapter;
20+
std::shared_ptr<const facebook::react::ReactNativeConfig> _reactNativeConfig;
21+
facebook::react::ContextContainer::Shared _contextContainer;
22+
}
23+
@end
24+
#endif
25+
26+
@implementation AppDelegate
27+
28+
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
29+
{
30+
RCTAppSetupPrepareApp(application);
31+
RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
32+
33+
#if RCT_NEW_ARCH_ENABLED
34+
_contextContainer = std::make_shared<facebook::react::ContextContainer const>();
35+
_reactNativeConfig = std::make_shared<facebook::react::EmptyReactNativeConfig const>();
36+
_contextContainer->insert("ReactNativeConfig", _reactNativeConfig);
37+
_bridgeAdapter = [[RCTSurfacePresenterBridgeAdapter alloc] initWithBridge:bridge contextContainer:_contextContainer];
38+
bridge.surfacePresenter = _bridgeAdapter.surfacePresenter;
39+
#endif
40+
41+
UIView *rootView = RCTAppSetupDefaultRootView(bridge, @"FlatListPro", nil);
42+
43+
if (@available(iOS 13.0, *)) {
44+
rootView.backgroundColor = [UIColor systemBackgroundColor];
45+
} else {
46+
rootView.backgroundColor = [UIColor whiteColor];
47+
}
48+
49+
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
50+
UIViewController *rootViewController = [UIViewController new];
51+
rootViewController.view = rootView;
52+
self.window.rootViewController = rootViewController;
53+
[self.window makeKeyAndVisible];
54+
return YES;
55+
}
56+
57+
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
58+
{
59+
#if DEBUG
60+
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
61+
#else
62+
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
63+
#endif
64+
}
65+
66+
#if RCT_NEW_ARCH_ENABLED
67+
#pragma mark - RCTCxxBridgeDelegate
68+
- (std::unique_ptr<facebook::react::JSExecutorFactory>)jsExecutorFactoryForBridge:(RCTBridge *)bridge
69+
{
70+
_turboModuleManager = [[RCTTurboModuleManager alloc] initWithBridge:bridge
71+
delegate:self
72+
jsInvoker:bridge.jsCallInvoker];
73+
return RCTAppSetupDefaultJsExecutorFactory(bridge, _turboModuleManager);
74+
}
75+
#pragma mark RCTTurboModuleManagerDelegate
76+
- (Class)getModuleClassFromName:(const char *)name
77+
{
78+
return RCTCoreModulesClassProvider(name);
79+
}
80+
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const std::string &)name
81+
jsInvoker:(std::shared_ptr<facebook::react::CallInvoker>)jsInvoker
82+
{
83+
return nullptr;
84+
}
85+
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const std::string &)name
86+
initParams:
87+
(const facebook::react::ObjCTurboModule::InitParams &)params
88+
{
89+
return nullptr;
90+
}
91+
- (id<RCTTurboModule>)getModuleInstanceFromClass:(Class)moduleClass
92+
{
93+
return RCTAppSetupDefaultModuleFromClass(moduleClass);
94+
}
95+
#endif
96+
97+
@end

0 commit comments

Comments
 (0)