Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions lib/ios/RNNCommandsHandler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ - (void)showOverlay:(NSDictionary *)layout
RNNAssertMainQueue();

UIViewController *overlayVC = [_controllerFactory createLayout:layout];
overlayVC.waitForRender = [RNNUtils getDefaultWaitForRender];
Comment thread
gosha212 marked this conversation as resolved.
Outdated
[_layoutManager addPendingViewController:overlayVC];

__weak UIViewController *weakOverlayVC = overlayVC;
Expand Down
2 changes: 1 addition & 1 deletion lib/ios/RNNReactButtonView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ @implementation RNNReactButtonView
- (instancetype)initWithHost:(RCTHost *)host
moduleName:(NSString *)moduleName
initialProperties:(NSDictionary *)initialProperties
eventEmitter:(RNNEventEmitter *)eventEmitter
eventEmitter:(RNNTurboEventEmitter *)eventEmitter
sizeMeasureMode:(RCTSurfaceSizeMeasureMode)sizeMeasureMode
reactViewReadyBlock:(RNNReactViewReadyCompletionBlock)reactViewReadyBlock {
self = [super initWithHost:host moduleName:moduleName initialProperties:initialProperties eventEmitter:eventEmitter sizeMeasureMode:convertToSurfaceSizeMeasureMode(RCTRootViewSizeFlexibilityWidthAndHeight) reactViewReadyBlock:reactViewReadyBlock];
Expand Down
4 changes: 3 additions & 1 deletion lib/ios/RNNReactView.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#define ComponentTypeButton @"TopBarButton"
#define ComponentTypeBackground @"TopBarBackground"

#import "RNNTurboEventEmitter.h"

#ifdef RCT_NEW_ARCH_ENABLED
static RCTSurfaceSizeMeasureMode convertToSurfaceSizeMeasureMode(RCTRootViewSizeFlexibility sizeFlexibility)
{
Expand Down Expand Up @@ -92,7 +94,7 @@ typedef void (^RNNReactViewReadyCompletionBlock)(void);
- (instancetype)initWithHost:(RCTHost *)host
moduleName:(NSString *)moduleName
initialProperties:(NSDictionary *)initialProperties
eventEmitter:(RNNEventEmitter *)eventEmitter
eventEmitter:(RNNTurboEventEmitter *)eventEmitter
sizeMeasureMode:(RCTSurfaceSizeMeasureMode)sizeMeasureMode
reactViewReadyBlock:(RNNReactViewReadyCompletionBlock)reactViewReadyBlock;

Expand Down
65 changes: 45 additions & 20 deletions lib/ios/RNNReactView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

@implementation RNNReactView {
BOOL _isMounted;
BOOL _pendingWillAppear;
BOOL _pendingDidAppear;
BOOL _didAppear;
BOOL _willAppear;
Expand Down Expand Up @@ -56,17 +57,18 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
- (instancetype)initWithHost:(RCTHost *)host
moduleName:(NSString *)moduleName
initialProperties:(NSDictionary *)initialProperties
eventEmitter:(RNNEventEmitter *)eventEmitter
eventEmitter:(RNNTurboEventEmitter *)eventEmitter
sizeMeasureMode:(RCTSurfaceSizeMeasureMode)sizeMeasureMode
reactViewReadyBlock:(RNNReactViewReadyCompletionBlock)reactViewReadyBlock {

RCTFabricSurface *surface = [host createSurfaceWithModuleName:moduleName
initialProperties:initialProperties];
[host.surfacePresenter addObserver:self];
[host.surfacePresenter addObserver:self];
self = [super initWithSurface:surface sizeMeasureMode:sizeMeasureMode];

_reactViewReadyBlock = reactViewReadyBlock;
_eventEmitter = eventEmitter;

return self;
}
#endif
Expand All @@ -88,7 +90,7 @@ - (void)contentDidAppear:(NSNotification *)notification {
}
}
#endif

- (void)reactViewReady {
if (_reactViewReadyBlock) {
_reactViewReadyBlock();
Expand All @@ -99,12 +101,19 @@ - (void)reactViewReady {
#endif
}

#pragma mark - RNNComponentProtocol
- (void)componentWillAppear {
if (!_isMounted) {
_pendingWillAppear = YES;
return;
}

_pendingWillAppear = NO;

if (!_willAppear) {
[_eventEmitter sendComponentWillAppear:self.componentId
componentName:self.moduleName
componentType:self.componentType];

_willAppear = YES;
}
}
Expand All @@ -116,6 +125,7 @@ - (void)componentDidAppear {
}

_pendingDidAppear = NO;

if (!_didAppear) {
[_eventEmitter sendComponentDidAppear:self.componentId
componentName:self.moduleName
Expand All @@ -131,18 +141,43 @@ - (void)componentDidDisappear {
_willAppear = NO;
_didAppear = NO;
}

- (NSString *)componentId {
Comment thread
gosha212 marked this conversation as resolved.
return self.appProperties[@"componentId"];
}

- (NSString *)componentType {
@throw [NSException exceptionWithName:@"componentType not implemented"
reason:@"Should always subclass RNNReactView"
userInfo:nil];
}
#pragma mark -


#ifdef RCT_NEW_ARCH_ENABLED

#pragma mark - RCTSurfacePresenterObserver
- (void)willMountComponentsWithRootTag:(NSInteger)rootTag {
if (self.surface.rootTag == rootTag) {
_isMounted = YES;

if (_pendingWillAppear) {
[self componentWillAppear];
}
}
}

- (void)didMountComponentsWithRootTag:(NSInteger)rootTag {
if (self.surface.rootTag == rootTag) {
_isMounted = YES;

if (_pendingDidAppear) {
[self componentDidAppear];
}
}
}

#pragma mark -

- (NSDictionary *)appProperties {
@synchronized(self) {
return self.surface.properties;
Expand Down Expand Up @@ -175,7 +210,7 @@ - (UIView *)view {
}

- (UIView *)contentView {
return self;
return self;
}

- (RCTRootViewSizeFlexibility)sizeFlexibility {
Expand All @@ -185,17 +220,7 @@ - (RCTRootViewSizeFlexibility)sizeFlexibility {
- (void)setSizeFlexibility:(RCTRootViewSizeFlexibility)sizeFlexibility {
super.sizeMeasureMode = convertToSurfaceSizeMeasureMode(sizeFlexibility);
}

#endif

- (NSString *)componentId {
return self.appProperties[@"componentId"];
}

- (NSString *)componentType {
@throw [NSException exceptionWithName:@"componentType not implemented"
reason:@"Should always subclass RNNReactView"
userInfo:nil];
}


@end
6 changes: 5 additions & 1 deletion playground/src/screens/LayoutsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const {
} = testIDs;

interface State {
componentWillAppear: boolean;
componentDidAppear: boolean;
}

Expand All @@ -33,11 +34,13 @@ export default class LayoutsScreen extends NavigationComponent<NavigationProps,
super(props);
Navigation.events().bindComponent(this);
this.state = {
componentWillAppear: false,
componentDidAppear: false,
};
}
componentWillAppear() {
console.log('componentWillAppear:', this.props.componentId);
this.setState(previousState => ({ ...previousState, componentWillAppear: true }));
}

componentDidDisappear() {
Expand All @@ -46,7 +49,7 @@ export default class LayoutsScreen extends NavigationComponent<NavigationProps,

componentDidAppear() {
console.log('componentDidAppear:', this.props.componentId);
this.setState({ componentDidAppear: true });
this.setState(previousState => ({ ...previousState, componentDidAppear: true }));
}

static options(): Options {
Expand Down Expand Up @@ -79,6 +82,7 @@ export default class LayoutsScreen extends NavigationComponent<NavigationProps,
platform="ios"
onPress={this.splitView}
/>
<Text>{this.state.componentWillAppear && 'componentWillAppear'}</Text>
<Text>{this.state.componentDidAppear && 'componentDidAppear'}</Text>
</Root>
);
Expand Down