diff --git a/React/Base/RCTRootView.m b/React/Base/RCTRootView.m index 63e0a410fd7247..66f7b1eaf472fe 100644 --- a/React/Base/RCTRootView.m +++ b/React/Base/RCTRootView.m @@ -33,10 +33,6 @@ #import "RCTDevMenu.h" #endif // ]TODO(OSS Candidate ISS#2710739) -#if TARGET_OS_OSX // [TODO(macOS GH#774) -#define RCT_LAYOUT_THROTTLE 0.25 -#endif // ]TODO(macOS GH#774) - NSString *const RCTContentDidAppearNotification = @"RCTContentDidAppearNotification"; @interface RCTUIManager (RCTRootView) @@ -51,11 +47,6 @@ @implementation RCTRootView { RCTRootContentView *_contentView; BOOL _passThroughTouches; CGSize _intrinsicContentSize; - -#if TARGET_OS_OSX // [TODO(macOS GH#774) - NSDate *_lastLayout; - BOOL _throttleLayout; -#endif // ]TODO(macOS GH#774) } - (instancetype)initWithFrame:(CGRect)frame @@ -85,10 +76,6 @@ - (instancetype)initWithFrame:(CGRect)frame _sizeFlexibility = RCTRootViewSizeFlexibilityNone; _minimumSize = CGSizeZero; -#if TARGET_OS_OSX // [TODO(macOS GH#774) - _lastLayout = [NSDate new]; -#endif // ]TODO(macOS GH#774) - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(bridgeDidReload) name:RCTJavaScriptWillStartLoadingNotification @@ -182,35 +169,6 @@ - (CGSize)sizeThatFits:(CGSize)size return fitSize; } -#if TARGET_OS_OSX // [TODO(macOS GH#774) -// TODO: https://github.com/microsoft/react-native-macos/issues/459 -// This is a workaround for window resizing events overloading the shadow queue: -// - https://github.com/microsoft/react-native-macos/issues/322 -// - https://github.com/microsoft/react-native-macos/issues/422 -// We should revisit this issue when we switch over to Fabric. -- (void)layout -{ - if (self.window != nil && !_throttleLayout) { - NSTimeInterval interval = [[NSDate date] timeIntervalSinceDate:_lastLayout]; - if (interval >= RCT_LAYOUT_THROTTLE) { - _lastLayout = [NSDate new]; - [self layoutSubviews]; - } else { - _throttleLayout = YES; - __weak typeof(self) weakSelf = self; - int64_t delta = (RCT_LAYOUT_THROTTLE - interval) * NSEC_PER_SEC; - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, delta), dispatch_get_main_queue(), ^{ - typeof(self) strongSelf = weakSelf; - if (strongSelf != nil) { - strongSelf->_throttleLayout = NO; - [strongSelf setNeedsLayout]; - } - }); - } - } -} -#endif // ]TODO(macOS GH#774) - - (void)layoutSubviews { [super layoutSubviews]; diff --git a/React/Modules/RCTUIManager.m b/React/Modules/RCTUIManager.m index 721047c4aaaba4..7b3057ed65c438 100644 --- a/React/Modules/RCTUIManager.m +++ b/React/Modules/RCTUIManager.m @@ -412,21 +412,34 @@ - (void)_executeBlockWithShadowView:(void (^)(RCTShadowView *shadowView))block f - (void)setAvailableSize:(CGSize)availableSize forRootView:(RCTUIView *)rootView // TODO(macOS ISS#3536887) { RCTAssertMainQueue(); - [self - _executeBlockWithShadowView:^(RCTShadowView *shadowView) { - RCTAssert( - [shadowView isKindOfClass:[RCTRootShadowView class]], @"Located shadow view is actually not root view."); - RCTRootShadowView *rootShadowView = (RCTRootShadowView *)shadowView; + void (^block)(RCTShadowView *) = ^(RCTShadowView *shadowView) { + RCTAssert( + [shadowView isKindOfClass:[RCTRootShadowView class]], @"Located shadow view is actually not root view."); - if (CGSizeEqualToSize(availableSize, rootShadowView.availableSize)) { - return; - } + RCTRootShadowView *rootShadowView = (RCTRootShadowView *)shadowView; - rootShadowView.availableSize = availableSize; - [self setNeedsLayout]; - } - forTag:rootView.reactTag]; + if (CGSizeEqualToSize(availableSize, rootShadowView.availableSize)) { + return; + } + + rootShadowView.availableSize = availableSize; + [self setNeedsLayout]; + }; + +#if TARGET_OS_OSX // [TODO(macOS GH#744) + if (rootView.inLiveResize) { + NSNumber* tag = rootView.reactTag; + // Synchronously relayout to prevent "tearing" when resizing windows. + // Still run block asynchronously below so it "wins" after any in-flight layout. + RCTUnsafeExecuteOnUIManagerQueueSync(^{ + RCTShadowView *shadowView = self->_shadowViewRegistry[tag]; + block(shadowView); + }); + } +#endif // ]TODO(macOS GH#744) + + [self _executeBlockWithShadowView:block forTag:rootView.reactTag]; } - (void)setLocalData:(NSObject *)localData forView:(RCTUIView *)view // TODO(macOS ISS#3536887)