Avoid dirtying layout when frame doesn't change

Reviewed By: nicklockwood

Differential Revision: D2939782

fb-gh-sync-id: e2346f053e9594e5d24d1e73d493a34446fb228c
shipit-source-id: e2346f053e9594e5d24d1e73d493a34446fb228c
This commit is contained in:
Pieter De Baets 2016-02-25 09:38:23 -08:00 committed by facebook-github-bot-1
parent b8e7fe4959
commit f51c16b270
1 changed files with 20 additions and 14 deletions

View File

@ -375,19 +375,27 @@ extern NSString *RCTBridgeModuleNameForClass(Class cls);
NSNumber *reactTag = view.reactTag;
dispatch_async(_shadowQueue, ^{
RCTShadowView *rootShadowView = _shadowViewRegistry[reactTag];
RCTAssert(rootShadowView != nil, @"Could not locate root view with tag #%@", reactTag);
RCTShadowView *shadowView = _shadowViewRegistry[reactTag];
RCTAssert(shadowView != nil, @"Could not locate shadow view with tag #%@", reactTag);
if (RCTIsReactRootView(reactTag)) {
rootShadowView.frame = frame;
rootShadowView.sizeFlexibility = sizeFlexibility;
} else {
rootShadowView.frame = frame;
BOOL dirtyLayout = NO;
if (!CGRectEqualToRect(frame, shadowView.frame)) {
shadowView.frame = frame;
dirtyLayout = YES;
}
[rootShadowView dirtyLayout];
// Trigger re-layout when size flexibility changes, as the root view might grow or
// shrink in the flexible dimensions.
if (RCTIsReactRootView(reactTag) && shadowView.sizeFlexibility != sizeFlexibility) {
shadowView.sizeFlexibility = sizeFlexibility;
dirtyLayout = YES;
}
[self batchDidComplete];
if (dirtyLayout) {
[shadowView dirtyLayout];
[self batchDidComplete];
}
});
}
@ -1045,18 +1053,16 @@ RCT_EXPORT_METHOD(measure:(nonnull NSNumber *)reactTag
callback(@[]);
return;
}
CGRect frame = view.frame;
// If in a <Modal>, rootView will be the root of the modal container.
UIView *rootView = view;
while (rootView && ![rootView isReactRootView]) {
while (rootView.superview && ![rootView isReactRootView]) {
rootView = rootView.superview;
}
// TODO: this doesn't work because sometimes view is inside a modal window
// RCTAssert([rootView isReactRootView], @"React view is not inside a React root view");
// By convention, all coordinates, whether they be touch coordinates, or
// measurement coordinates are with respect to the root view.
CGRect frame = view.frame;
CGPoint pagePoint = [view.superview convertPoint:frame.origin toView:rootView];
callback(@[