From c2b971d6d48fc5dbc60d2f19c8f46641b32ff534 Mon Sep 17 00:00:00 2001 From: Samuel Susla Date: Fri, 20 Aug 2021 05:41:17 -0700 Subject: [PATCH] Set initial maximum surface size to viewport size Summary: Changelog: [internal] There is a possibility of race between JavaScript sending "completeRoot" and maximum size set on surface. To prevent this race, we set the initial maximum size to be equal to the viewport size. Alternative solution is to set maximumSize to {0, 0} initially instead of infinity. This is what old architecture does, even though not explicitly. Reviewed By: fkgozali Differential Revision: D30402207 fbshipit-source-id: 44427404eaf060a81de257797823edf971ffc1bb --- React/Base/RCTConstants.h | 6 ++++++ React/Base/RCTConstants.m | 15 +++++++++++++++ React/Fabric/RCTSurfacePresenter.mm | 4 ++++ React/Fabric/Surface/RCTFabricSurface.mm | 5 +++++ 4 files changed, 30 insertions(+) diff --git a/React/Base/RCTConstants.h b/React/Base/RCTConstants.h index c92fc1041c9..06fbc7597ca 100644 --- a/React/Base/RCTConstants.h +++ b/React/Base/RCTConstants.h @@ -16,6 +16,12 @@ RCT_EXTERN NSString *const RCTUserInterfaceStyleDidChangeNotificationTraitCollec RCT_EXTERN BOOL RCTExperimentGetPreemptiveViewAllocationDisabled(void); RCT_EXTERN void RCTExperimentSetPreemptiveViewAllocationDisabled(BOOL value); +/* + * Initial maximum surface size + */ +RCT_EXTERN BOOL RCTGetInitialMaxSizeEnabled(void); +RCT_EXTERN void RCTSetInitialMaxSizeEnabled(BOOL value); + /* * Remove clipped subviews */ diff --git a/React/Base/RCTConstants.m b/React/Base/RCTConstants.m index 38947bb170f..f734a3384a6 100644 --- a/React/Base/RCTConstants.m +++ b/React/Base/RCTConstants.m @@ -25,6 +25,21 @@ void RCTExperimentSetPreemptiveViewAllocationDisabled(BOOL value) RCTExperimentPreemptiveViewAllocationDisabled = value; } +/* + * Initial maximum surface size + */ +static BOOL RCTInitialMaxSizeEnabled = NO; + +BOOL RCTGetInitialMaxSizeEnabled() +{ + return RCTInitialMaxSizeEnabled; +} + +void RCTSetInitialMaxSizeEnabled(BOOL value) +{ + RCTInitialMaxSizeEnabled = value; +} + /* * Remove clipped subviews */ diff --git a/React/Fabric/RCTSurfacePresenter.mm b/React/Fabric/RCTSurfacePresenter.mm index 57b6889bc20..0c3d987ba1b 100644 --- a/React/Fabric/RCTSurfacePresenter.mm +++ b/React/Fabric/RCTSurfacePresenter.mm @@ -259,6 +259,10 @@ static BackgroundExecutor RCTGetBackgroundExecutor() RCTSetRemoveClippedSubviewsEnabled(YES); } + if (reactNativeConfig && reactNativeConfig->getBool("react_fabric:enable_initial_max_size_ios")) { + RCTSetInitialMaxSizeEnabled(YES); + } + auto componentRegistryFactory = [factory = wrapManagedObject(_mountingManager.componentViewRegistry.componentViewFactory)]( EventDispatcher::Weak const &eventDispatcher, ContextContainer::Shared const &contextContainer) { diff --git a/React/Fabric/Surface/RCTFabricSurface.mm b/React/Fabric/Surface/RCTFabricSurface.mm index f806c801aff..e18ee5a5f2b 100644 --- a/React/Fabric/Surface/RCTFabricSurface.mm +++ b/React/Fabric/Surface/RCTFabricSurface.mm @@ -10,6 +10,7 @@ #import #import +#import #import #import #import @@ -60,6 +61,10 @@ using namespace facebook::react; [_surfacePresenter registerSurface:self]; + if (RCTGetInitialMaxSizeEnabled()) { + [self setMinimumSize:CGSizeZero maximumSize:RCTViewportSize()]; + } + [self _updateLayoutContext]; [[NSNotificationCenter defaultCenter] addObserver:self