Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions lib/ios/RNNEventEmitter.mm
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ - (void)addListener:(NSString *)eventName {
#pragma mark private

- (void)send:(NSString *)eventName body:(id)body {
if (self.bridge == nil) {
return;
}
[self sendEventWithName:eventName body:body];
}

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
7 changes: 7 additions & 0 deletions lib/ios/TurboModules/RNNTurboEventEmitter.mm
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,12 @@ - (void)setHost:(RCTHost *)host {
_host = host;
}

- (void)send:(NSString *)eventName body:(id)body {
if (_host == nil) {
return;
}
[self sendEventWithName:eventName body:body];
}

@end
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@
BlueprintName = "NavigationTests"
ReferencedContainer = "container:playground.xcodeproj">
</BuildableReference>
<SkippedTests>
<Test
Identifier = "RNNCommandsHandlerTest">
</Test>
<Test
Identifier = "RNNModalManagerEventHandlerTest">
</Test>
</SkippedTests>
</TestableReference>
</Testables>
</TestAction>
Expand Down
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