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