Skip to content

Commit 97e6ea1

Browse files
ericlewisfacebook-github-bot
authored andcommitted
Fabric: working podspecs & works in RNTester (#23803)
Summary: This is the couple of hacks I used after I finished #23802 in order to get fabric working on RNTester. This is inspired from prior work by kmagiera. The goal of this PR is to show others what I’m struggling with, and to eventually merge it sans hacks. - Yarn Install - Uncomment the commented out pods in RNTester's pod file - Open RNTesterPods workspace - Run App - this is only for pods, the non-pod RNTester will no longer work until updated with fabric too. - `SurfaceHostingView` & `SurfaceHostingProxyRootView` both try to start the surface immediately, this leads to a race condition due to the javascript not having loaded yet, the hack here is: 1. Swizzle the `start` method on `RCTFabricSurface` to no-op when called. 2. Add observer for `RCTJavaScriptDidLoadNotification` 3. Call private method `_startAllSurfaces` on `_surfacePresenter` in AppDelegate when we receive `RCTJavaScriptDidLoadNotification`. [General] [Added] - Use Fabric in RNTester Pull Request resolved: #23803 Reviewed By: shergin, mdvacca Differential Revision: D14450726 Pulled By: fkgozali fbshipit-source-id: 8ae2d48634fecb60db539aaf0a2c89ba1f572c27
1 parent 845189c commit 97e6ea1

File tree

18 files changed

+672
-52
lines changed

18 files changed

+672
-52
lines changed

RNTester/ComponentRegistry.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#ifdef RN_FABRIC_ENABLED
9+
#include <react/uimanager/ComponentDescriptorFactory.h>
10+
#include <react/uimanager/ComponentDescriptorRegistry.h>
11+
#include <react/uimanager/ContextContainer.h>
12+
13+
#include <react/config/ReactNativeConfig.h>
14+
#include <react/components/image/ImageComponentDescriptor.h>
15+
#include <react/components/scrollview/ScrollViewComponentDescriptor.h>
16+
#include <react/components/rncore/ComponentDescriptors.h>
17+
#include <react/components/text/ParagraphComponentDescriptor.h>
18+
#include <react/components/text/RawTextComponentDescriptor.h>
19+
#include <react/components/text/TextComponentDescriptor.h>
20+
#include <react/components/view/ViewComponentDescriptor.h>
21+
#include <react/components/slider/SliderComponentDescriptor.h>
22+
23+
namespace facebook {
24+
namespace react {
25+
26+
/**
27+
* This is a sample implementation. Each app should provide its own.
28+
*/
29+
ComponentRegistryFactory getDefaultComponentRegistryFactory() {
30+
return [](const EventDispatcher::Shared &eventDispatcher,
31+
const SharedContextContainer &contextContainer) {
32+
auto registry = std::make_shared<ComponentDescriptorRegistry>();
33+
registry->registerComponentDescriptor(std::make_shared<ViewComponentDescriptor>(eventDispatcher));
34+
registry->registerComponentDescriptor(std::make_shared<ImageComponentDescriptor>(eventDispatcher, contextContainer));
35+
registry->registerComponentDescriptor(std::make_shared<ScrollViewComponentDescriptor>(eventDispatcher));
36+
registry->registerComponentDescriptor(std::make_shared<ParagraphComponentDescriptor>(eventDispatcher, contextContainer));
37+
registry->registerComponentDescriptor(std::make_shared<TextComponentDescriptor>(eventDispatcher));
38+
registry->registerComponentDescriptor(std::make_shared<RawTextComponentDescriptor>(eventDispatcher));
39+
registry->registerComponentDescriptor(std::make_shared<ActivityIndicatorViewComponentDescriptor>(eventDispatcher));
40+
registry->registerComponentDescriptor(std::make_shared<SwitchComponentDescriptor>(eventDispatcher));
41+
registry->registerComponentDescriptor(std::make_shared<SliderComponentDescriptor>(eventDispatcher, contextContainer));
42+
return registry;
43+
};
44+
}
45+
46+
} // namespace react
47+
} // namespace facebook
48+
#endif

RNTester/Podfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ target 'RNTester' do
2525
pod 'React-RCTVibration', :path => '../Libraries/Vibration'
2626
pod 'React-RCTWebSocket', :path => '../Libraries/WebSocket'
2727

28+
# Fabric Pods, uncomment these to enable in RNTester
29+
# pod 'React-Fabric', :path => '../ReactCommon'
30+
# pod 'React-graphics', :path => '../ReactCommon/fabric/graphics'
31+
# pod 'React-jsi/Fabric', :path => '../ReactCommon/jsi'
32+
# pod 'React-RCTFabric', :path => '../React'
33+
# pod 'Folly/Fabric', :podspec => '../third-party-podspecs/Folly.podspec'
34+
2835
pod 'React-cxxreact', :path => '../ReactCommon/cxxreact'
2936
pod 'React-jsi', :path => '../ReactCommon/jsi'
3037
pod 'React-jsiexecutor', :path => '../ReactCommon/jsiexecutor'

RNTester/Podfile.lock

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ PODS:
22
- boost-for-react-native (1.63.0)
33
- DoubleConversion (1.1.6)
44
- Folly (2018.10.22.00):
5+
- boost-for-react-native
6+
- DoubleConversion
7+
- Folly/Default (= 2018.10.22.00)
8+
- glog
9+
- Folly/Default (2018.10.22.00):
510
- boost-for-react-native
611
- DoubleConversion
712
- glog
@@ -42,6 +47,12 @@ PODS:
4247
- DoubleConversion
4348
- Folly (= 2018.10.22.00)
4449
- glog
50+
- React-jsi/Default (= 1000.0.0)
51+
- React-jsi/Default (1000.0.0):
52+
- boost-for-react-native (= 1.63.0)
53+
- DoubleConversion
54+
- Folly (= 2018.10.22.00)
55+
- glog
4556
- React-jsiexecutor (1000.0.0):
4657
- DoubleConversion
4758
- Folly (= 2018.10.22.00)
@@ -170,33 +181,33 @@ EXTERNAL SOURCES:
170181

171182
SPEC CHECKSUMS:
172183
boost-for-react-native: 39c7adb57c4e60d6c5479dd8623128eb5b3f0f2c
173-
DoubleConversion: 3eb87e5bfd9737e9a8cc698f74ee064d00c8dafc
174-
Folly: de497beb10f102453a1afa9edbf8cf8a251890de
175-
glog: aefd1eb5dda2ab95ba0938556f34b98e2da3a60d
176-
React: 4d01f91757abcfd2adccf80248285957ac1a2de2
177-
React-ART: f03123e0f0b9850db4733ad94ded11d29c719dc6
178-
React-Core: fcb8a6f34de5a43426efcb9dfda6a434c1b1275d
179-
React-cxxreact: 2a2acf4466abf5b794da53bf69e757a885259452
180-
React-DevSupport: 140c1ccfa9ccba495977225c117dc78c8858224f
181-
React-fishhook: aefe3414f44d4deaa880f0e39dc76644f1072bf7
182-
React-jsi: 425cd468e0be54cdc9009a2b4d2c1a4eada83805
183-
React-jsiexecutor: 520560a0b08226e4e758645940253e270b4d7d76
184-
React-jsinspector: c9020e3a37b7b27125d824b1d02b9be0d1c737ac
185-
React-RCTActionSheet: 78b940169b3c12d199dbbd382c5a3d22ec2197e2
186-
React-RCTAnimation: da0026d00ed99669b6175a941189539d8f9d52a4
187-
React-RCTBlob: c5a2104bd8b8e0462fc35eefa9133dc04ced56dd
188-
React-RCTCameraRoll: effa220c8e244af93b44011ab85cab814c469e08
189-
React-RCTGeolocation: 3517483e877750bae5a03d9f52e7b0e48c49651e
190-
React-RCTImage: ed045a58ebc9c97870a4fe5d066fdf04f247023b
191-
React-RCTLinking: e5f174d3f9e6ffe30087b9edc8c9860d62c1413c
192-
React-RCTNetwork: 9fbf72be6083a4b5fffe3dc1afad9fa2b70c4f19
193-
React-RCTPushNotification: 106e9846882a8dcce372fc90531be996ce0bb29b
194-
React-RCTSettings: afd7ae33bacd09b12c8a0d3151069d465344ce24
195-
React-RCTText: 03945b44521b34f89f9a728e1c265fa096af9f94
196-
React-RCTVibration: ef9e4e077360a599a1b59cee7d18398871d37759
197-
React-RCTWebSocket: 510a4eef2c064ef30508aba41628e6d69f4df4c5
198-
yoga: c63f2cb4fd93594d29e792c198a8050d5daf9fdf
184+
DoubleConversion: 5805e889d232975c086db112ece9ed034df7a0b2
185+
Folly: 30e7936e1c45c08d884aa59369ed951a8e68cf51
186+
glog: 1f3da668190260b06b429bb211bfbee5cd790c28
187+
React: 113a88ebe41487ae78bde6494495d0e25f9fe2ff
188+
React-ART: 28f8815acbbc4816cec14866b59911a83eb780ed
189+
React-Core: 9da7fd6dc9e1e773f578cae2a00621a7c4422816
190+
React-cxxreact: 7e670bad16eb78fa889573d931c12bb1003a3598
191+
React-DevSupport: f34768e3aad3e59ee9800c752a78bc6cb24d0f75
192+
React-fishhook: d2a67f0eaeef9fe0dca0526812ca8fcff4b6f17b
193+
React-jsi: 74e5e06d56f71aff1cd75c7ca56cf0f27940e792
194+
React-jsiexecutor: ee776181a1ba315dbae9500c4dba5cb94ea3c5d2
195+
React-jsinspector: ea0a218071a11c3687cef2480580180caa6a64c0
196+
React-RCTActionSheet: caf6532394bdbbe0fc0ec2363c84f26bcfcdd36a
197+
React-RCTAnimation: b324c6eb699637c735650c6180e13d003eeb0e56
198+
React-RCTBlob: 069290c8db758bb1d77523a06d117dd668b6cef3
199+
React-RCTCameraRoll: 353af870a0acd5ebb0bcf6a8187ed78d94c4c65e
200+
React-RCTGeolocation: 4bbdba9893dc3f22b22553904e54ae46dcedf48b
201+
React-RCTImage: 012d845d919177e2726743ad06052dda66592760
202+
React-RCTLinking: c6fe7b82bed97ce72203b2ce2f4aac87b1e2647f
203+
React-RCTNetwork: 2a2b22a17cd965de53ba21c5ca392d0da84ef322
204+
React-RCTPushNotification: 13729b4a2b63b191f42ba7230a69f462f3b5a7f9
205+
React-RCTSettings: e36d7f7d566b80d4363176c2f76cc5eccfdd0ae1
206+
React-RCTText: 469ec754592c92fc639825e558908c2f0e783e2c
207+
React-RCTVibration: ade3c169b54f3bc16c9a9918e17e48ef66aee6ba
208+
React-RCTWebSocket: 90b78ed51d53d17db417d3956decba3f7ace58e4
209+
yoga: 542cb34fe3bca476487e08eb516dd640ea996a65
199210

200-
PODFILE CHECKSUM: c144025e9b0ade3d8b536a343fee89da69391cdc
211+
PODFILE CHECKSUM: 74d947ec52f59c3db4f273853e36d504be6e9414
201212

202-
COCOAPODS: 1.6.0
213+
COCOAPODS: 1.6.1

RNTester/RNTester/AppDelegate.m

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,54 @@
1818
#import <React/RCTPushNotificationManager.h>
1919
#endif
2020

21-
@interface AppDelegate() <RCTBridgeDelegate>
21+
#ifdef RN_FABRIC_ENABLED
22+
#import <React/RCTSurfacePresenter.h>
23+
#import <React/RCTFabricSurfaceHostingProxyRootView.h>
24+
25+
@interface AppDelegate() <RCTBridgeDelegate>{
26+
RCTSurfacePresenter *_surfacePresenter;
27+
}
28+
@end
2229

30+
// FIXME: remove when resolved https://github.com/facebook/react-native/issues/23910
31+
@interface RCTSurfacePresenter ()
32+
-(void)_startAllSurfaces;
2333
@end
2434

35+
#else
36+
@interface AppDelegate() <RCTBridgeDelegate>
37+
@end
38+
#endif
39+
2540
@implementation AppDelegate
2641

2742
- (BOOL)application:(__unused UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
2843
{
2944
_bridge = [[RCTBridge alloc] initWithDelegate:self
3045
launchOptions:launchOptions];
31-
46+
3247
// Appetizer.io params check
33-
NSDictionary *initProps = nil;
48+
NSDictionary *initProps = @{};
3449
NSString *_routeUri = [[NSUserDefaults standardUserDefaults] stringForKey:@"route"];
3550
if (_routeUri) {
3651
initProps = @{@"exampleFromAppetizeParams": [NSString stringWithFormat:@"rntester://example/%@Example", _routeUri]};
3752
}
38-
39-
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:_bridge
40-
moduleName:@"RNTesterApp"
41-
initialProperties:initProps];
42-
53+
54+
#ifdef RN_FABRIC_ENABLED
55+
// FIXME: remove when resolved https://github.com/facebook/react-native/issues/23910
56+
[[NSNotificationCenter defaultCenter] addObserver:self
57+
selector:@selector(handleJavaScriptDidLoadNotification:)
58+
name:RCTJavaScriptDidLoadNotification
59+
object:_bridge];
60+
61+
_surfacePresenter = [[RCTSurfacePresenter alloc] initWithBridge:_bridge config:nil];
62+
_bridge.surfacePresenter = _surfacePresenter;
63+
64+
UIView *rootView = [[RCTFabricSurfaceHostingProxyRootView alloc] initWithBridge:_bridge moduleName:@"RNTesterApp" initialProperties:initProps];
65+
#else
66+
UIView *rootView = [[RCTRootView alloc] initWithBridge:_bridge moduleName:@"RNTesterApp" initialProperties:initProps];
67+
#endif
68+
4369
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
4470
UIViewController *rootViewController = [UIViewController new];
4571
rootViewController.view = rootView;
@@ -48,6 +74,15 @@ - (BOOL)application:(__unused UIApplication *)application didFinishLaunchingWith
4874
return YES;
4975
}
5076

77+
#ifdef RN_FABRIC_ENABLED
78+
// FIXME: remove when resolved https://github.com/facebook/react-native/issues/23910
79+
- (void)handleJavaScriptDidLoadNotification:(__unused NSNotification*)notification {
80+
dispatch_async(dispatch_get_main_queue(), ^{
81+
[self->_surfacePresenter _startAllSurfaces];
82+
});
83+
}
84+
#endif
85+
5186
- (NSURL *)sourceURLForBridge:(__unused RCTBridge *)bridge
5287
{
5388
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"RNTester/js/RNTesterApp.ios"

0 commit comments

Comments
 (0)