Skip to content

Commit

Permalink
don't clip if ui and react view hierarchies are different
Browse files Browse the repository at this point in the history
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 d5e067f
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions React/Views/UIView+React.m
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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];
}
}
}
Expand Down Expand Up @@ -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];
}
Expand Down

1 comment on commit d5e067f

@majak
Copy link
Contributor Author

@majak majak commented on d5e067f Nov 11, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.