Skip to content

Commit

Permalink
only trigger RCTContentDidAppearNotification when content appears (#4…
Browse files Browse the repository at this point in the history
…3823)

Summary:
Pull Request resolved: #43823

changelog: [internal]

Notification RCTContentDidAppearNotification was posted too early in RCTSurfaceHostingProxyRootView, which does not know when views are mounted.
It was also posted if no views were mounted, leading to inconsistent behaviour between Paper and Fabric.

The implementation is aligned with Paper: https://github.com/facebook/react-native/blob/main/packages/react-native/React/Base/RCTRootContentView.m#L45-L55

Reviewed By: cipolleschi

Differential Revision: D55640654

fbshipit-source-id: 2d7bc5afb6ba1c1e8db529ee11eac2bae2d936d6
  • Loading branch information
sammy-SC authored and cipolleschi committed May 1, 2024
1 parent a14df93 commit 0a4cf49
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,6 @@ - (void)surface:(RCTSurface *)surface didChangeStage:(RCTSurfaceStage)stage
[super surface:surface didChangeStage:stage];
if (RCTSurfaceStageIsRunning(stage)) {
[_bridge.performanceLogger markStopForTag:RCTPLTTI];
dispatch_async(dispatch_get_main_queue(), ^{
[[NSNotificationCenter defaultCenter] postNotificationName:RCTContentDidAppearNotification object:self];
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,46 @@

#import "RCTRootComponentView.h"

#import <React/RCTRootView.h>
#import <react/renderer/components/root/RootComponentDescriptor.h>
#import <react/renderer/components/root/RootProps.h>
#import "RCTConversions.h"

using namespace facebook::react;

@implementation RCTRootComponentView
@implementation RCTRootComponentView {
BOOL _contentHasAppeared;
}

- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
_props = RootShadowNode::defaultSharedProps();
_contentHasAppeared = NO;
}

return self;
}

#pragma mark - RCTComponentViewProtocol

- (void)prepareForRecycle
{
[super prepareForRecycle];
_contentHasAppeared = NO;
}

- (void)mountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index
{
[super mountChildComponentView:childComponentView index:index];
if (!self->_contentHasAppeared) {
self->_contentHasAppeared = YES;
dispatch_async(dispatch_get_main_queue(), ^{
[[NSNotificationCenter defaultCenter] postNotificationName:RCTContentDidAppearNotification object:self];
});
}
}

+ (ComponentDescriptorProvider)componentDescriptorProvider
{
return concreteComponentDescriptorProvider<RootComponentDescriptor>();
Expand Down

0 comments on commit 0a4cf49

Please sign in to comment.