Permalink
Browse files

don't clip if ui and react view hierarchies are different

Reviewed By: mmmulani

Differential Revision: D4088498

fbshipit-source-id: ec08e4e68d327fc770c944c274bb9f367daba6d2
  • Loading branch information...
majak authored and Facebook Github Bot committed Nov 11, 2016
1 parent 625c8cb commit d5e067f244c3be28416c5ecb183e8a2b872d4fb4
Showing with 13 additions and 6 deletions.
  1. +13 −6 React/Views/UIView+React.m
View
@@ -295,9 +295,7 @@ - (void)rct_reclip
if (!CGRectIntersectsRect(self.frame, clippingRectForSuperview)) {
// we are clipped
if (self.superview) {
[self removeFromSuperview];
}
clipView(self);
} else {
// we are not clipped
if (!self.superview) {
@@ -330,7 +328,6 @@ - (void)rct_clipSubviewsWithAncestralClipRect:(CGRect)clipRect
clipRect = CGRectIntersection(clipRect, self.bounds);
}
for (UIView *subview in self.sortedReactSubviews) {
// TODO inserting subviews based on react subviews is not safe if react hierarchy doesn't match view hierarchy
if (CGRectIntersectsRect(subview.frame, clipRect)) {
if (!subview.superview) {
if (lastSubview) {
@@ -342,7 +339,18 @@ - (void)rct_clipSubviewsWithAncestralClipRect:(CGRect)clipRect
lastSubview = subview;
[subview rct_clipSubviewsWithAncestralClipRect:[self convertRect:clipRect toView:subview]];
} else {
[subview removeFromSuperview];
clipView(subview);
}
}
}
static void clipView(UIView *view)
{
// we are clipped
if (view.superview) {
// We don't clip if react hierarchy doesn't match uiview hierarchy, since we could get into inconsistent state.
if (view.reactSuperview == view.superview) {
[view removeFromSuperview];
}
}
}
@@ -380,7 +388,6 @@ - (CGRect)rct_activeClippingRect
- (void)rct_updateSubviewsWithNextClippingView:(UIView *)clippingView
{
for (UIView *subview in self.sortedReactSubviews) {
// TODO inserting subviews based on react subviews is not safe if react hierarchy doesn't match view hierarchy
if (!clippingView) {
[self addSubview:subview];
}

1 comment on commit d5e067f

@majak

This comment has been minimized.

Show comment
Hide comment
@majak

majak Nov 11, 2016

Contributor

If would clip uiviews which react superview is different from their .superview we wouldn't be able to add them back under the right view when they get visible again.
So this diff makes sure we won't clip in such case.

Contributor

majak commented on d5e067f Nov 11, 2016

If would clip uiviews which react superview is different from their .superview we wouldn't be able to add them back under the right view when they get visible again.
So this diff makes sure we won't clip in such case.

Please sign in to comment.