1111
1212@implementation RNNReactView {
1313 BOOL _isMounted;
14+ BOOL _pendingWillAppear;
1415 BOOL _pendingDidAppear;
1516 BOOL _didAppear;
1617 BOOL _willAppear;
@@ -56,17 +57,18 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
5657- (instancetype )initWithHost:(RCTHost *)host
5758 moduleName:(NSString *)moduleName
5859 initialProperties:(NSDictionary *)initialProperties
59- eventEmitter:(RNNEventEmitter *)eventEmitter
60+ eventEmitter:(RNNTurboEventEmitter *)eventEmitter
6061 sizeMeasureMode:(RCTSurfaceSizeMeasureMode)sizeMeasureMode
6162 reactViewReadyBlock:(RNNReactViewReadyCompletionBlock)reactViewReadyBlock {
63+
6264 RCTFabricSurface *surface = [host createSurfaceWithModuleName: moduleName
6365 initialProperties: initialProperties];
64- [host.surfacePresenter addObserver: self ];
66+ [host.surfacePresenter addObserver: self ];
6567 self = [super initWithSurface: surface sizeMeasureMode: sizeMeasureMode];
66-
68+
6769 _reactViewReadyBlock = reactViewReadyBlock;
6870 _eventEmitter = eventEmitter;
69-
71+
7072 return self;
7173}
7274#endif
@@ -88,7 +90,7 @@ - (void)contentDidAppear:(NSNotification *)notification {
8890 }
8991}
9092#endif
91-
93+
9294- (void )reactViewReady {
9395 if (_reactViewReadyBlock) {
9496 _reactViewReadyBlock ();
@@ -99,12 +101,19 @@ - (void)reactViewReady {
99101#endif
100102}
101103
104+ #pragma mark - RNNComponentProtocol
102105- (void )componentWillAppear {
106+ if (!_isMounted) {
107+ _pendingWillAppear = YES ;
108+ return ;
109+ }
110+
111+ _pendingWillAppear = NO ;
112+
103113 if (!_willAppear) {
104114 [_eventEmitter sendComponentWillAppear: self .componentId
105115 componentName: self .moduleName
106116 componentType: self .componentType];
107-
108117 _willAppear = YES ;
109118 }
110119}
@@ -116,6 +125,7 @@ - (void)componentDidAppear {
116125 }
117126
118127 _pendingDidAppear = NO ;
128+
119129 if (!_didAppear) {
120130 [_eventEmitter sendComponentDidAppear: self .componentId
121131 componentName: self .moduleName
@@ -131,18 +141,43 @@ - (void)componentDidDisappear {
131141 _willAppear = NO ;
132142 _didAppear = NO ;
133143}
144+
145+ - (NSString *)componentId {
146+ return self.appProperties [@" componentId" ];
147+ }
134148
149+ - (NSString *)componentType {
150+ @throw [NSException exceptionWithName: @" componentType not implemented"
151+ reason: @" Should always subclass RNNReactView"
152+ userInfo: nil ];
153+ }
154+ #pragma mark -
155+
156+
135157#ifdef RCT_NEW_ARCH_ENABLED
158+
159+ #pragma mark - RCTSurfacePresenterObserver
160+ - (void )willMountComponentsWithRootTag:(NSInteger )rootTag {
161+ if (self.surface .rootTag == rootTag) {
162+ _isMounted = YES ;
163+
164+ if (_pendingWillAppear) {
165+ [self componentWillAppear ];
166+ }
167+ }
168+ }
136169
137170- (void )didMountComponentsWithRootTag:(NSInteger )rootTag {
138171 if (self.surface .rootTag == rootTag) {
139172 _isMounted = YES ;
173+
140174 if (_pendingDidAppear) {
141175 [self componentDidAppear ];
142176 }
143177 }
144178}
145-
179+ #pragma mark -
180+
146181- (NSDictionary *)appProperties {
147182 @synchronized (self) {
148183 return self.surface .properties ;
@@ -175,7 +210,7 @@ - (UIView *)view {
175210}
176211
177212- (UIView *)contentView {
178- return self;
213+ return self;
179214}
180215
181216- (RCTRootViewSizeFlexibility)sizeFlexibility {
@@ -185,17 +220,7 @@ - (RCTRootViewSizeFlexibility)sizeFlexibility {
185220- (void )setSizeFlexibility:(RCTRootViewSizeFlexibility)sizeFlexibility {
186221 super.sizeMeasureMode = convertToSurfaceSizeMeasureMode (sizeFlexibility);
187222}
188-
223+
189224#endif
190-
191- - (NSString *)componentId {
192- return self.appProperties [@" componentId" ];
193- }
194-
195- - (NSString *)componentType {
196- @throw [NSException exceptionWithName: @" componentType not implemented"
197- reason: @" Should always subclass RNNReactView"
198- userInfo: nil ];
199- }
200-
225+
201226@end
0 commit comments