Skip to content

Revert "Alleviate excessive layout jittering when resizing window (#439)" #1318

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 0 additions & 42 deletions React/Base/RCTRootView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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];
Expand Down
37 changes: 25 additions & 12 deletions React/Modules/RCTUIManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down