@@ -295,9 +295,7 @@ - (void)rct_reclip
295295
296296 if (!CGRectIntersectsRect (self.frame , clippingRectForSuperview)) {
297297 // we are clipped
298- if (self.superview ) {
299- [self removeFromSuperview ];
300- }
298+ clipView (self);
301299 } else {
302300 // we are not clipped
303301 if (!self.superview ) {
@@ -330,7 +328,6 @@ - (void)rct_clipSubviewsWithAncestralClipRect:(CGRect)clipRect
330328 clipRect = CGRectIntersection (clipRect, self.bounds );
331329 }
332330 for (UIView *subview in self.sortedReactSubviews ) {
333- // TODO inserting subviews based on react subviews is not safe if react hierarchy doesn't match view hierarchy
334331 if (CGRectIntersectsRect (subview.frame , clipRect)) {
335332 if (!subview.superview ) {
336333 if (lastSubview) {
@@ -342,7 +339,18 @@ - (void)rct_clipSubviewsWithAncestralClipRect:(CGRect)clipRect
342339 lastSubview = subview;
343340 [subview rct_clipSubviewsWithAncestralClipRect: [self convertRect: clipRect toView: subview]];
344341 } else {
345- [subview removeFromSuperview ];
342+ clipView (subview);
343+ }
344+ }
345+ }
346+
347+ static void clipView (UIView *view)
348+ {
349+ // we are clipped
350+ if (view.superview ) {
351+ // We don't clip if react hierarchy doesn't match uiview hierarchy, since we could get into inconsistent state.
352+ if (view.reactSuperview == view.superview ) {
353+ [view removeFromSuperview ];
346354 }
347355 }
348356}
@@ -380,7 +388,6 @@ - (CGRect)rct_activeClippingRect
380388- (void )rct_updateSubviewsWithNextClippingView : (UIView *)clippingView
381389{
382390 for (UIView *subview in self.sortedReactSubviews ) {
383- // TODO inserting subviews based on react subviews is not safe if react hierarchy doesn't match view hierarchy
384391 if (!clippingView) {
385392 [self addSubview: subview];
386393 }
0 commit comments