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
This commit is contained in:
Samuel Susla
2021-08-20 05:42:21 -07:00
committed by Facebook GitHub Bot
parent 1036c14888
commit c2b971d6d4
4 changed files with 30 additions and 0 deletions
+6
View File
@@ -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
*/
+15
View File
@@ -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
*/
+4
View File
@@ -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) {
+5
View File
@@ -10,6 +10,7 @@
#import <mutex>
#import <React/RCTAssert.h>
#import <React/RCTConstants.h>
#import <React/RCTConversions.h>
#import <React/RCTFollyConvert.h>
#import <React/RCTI18nUtil.h>
@@ -60,6 +61,10 @@ using namespace facebook::react;
[_surfacePresenter registerSurface:self];
if (RCTGetInitialMaxSizeEnabled()) {
[self setMinimumSize:CGSizeZero maximumSize:RCTViewportSize()];
}
[self _updateLayoutContext];
[[NSNotificationCenter defaultCenter] addObserver:self