Skip to content

Commit

Permalink
Add a hack to fix the Modal component interacting with LayoutAnimation
Browse files Browse the repository at this point in the history
Summary: As per the comment, <Modal> uses entering/leaving the view hierarchy as a cue to show/hide the modal. By re-adding it, we are causing a bunch of confusion.

Reviewed By: shergin

Differential Revision: D5893607

fbshipit-source-id: ecd05799751a9bba843998ae93f24fe35edca8b4
  • Loading branch information
Mehdi Mulani authored and facebook-github-bot committed Sep 25, 2017
1 parent d005c8c commit e220878
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 1 addition & 2 deletions React/Modules/RCTUIManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -784,11 +784,10 @@ - (void)_removeChildren:(NSArray<UIView *> *)children
UIView *originalSuperview = removedChild.superview;
NSUInteger originalIndex = [originalSuperview.subviews indexOfObjectIdenticalTo:removedChild];
[container removeReactSubview:removedChild];
[originalSuperview insertSubview:removedChild atIndex:originalIndex];

// Disable user interaction while the view is animating
// since the view is (conseptually) deleted and not supposed to be interactive.
removedChild.userInteractionEnabled = NO;
[originalSuperview insertSubview:removedChild atIndex:originalIndex];

NSString *property = deletingLayoutAnimation.property;
[deletingLayoutAnimation performAnimations:^{
Expand Down
6 changes: 6 additions & 0 deletions React/Views/RCTModalHostView.m
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ - (void)didMoveToWindow
{
[super didMoveToWindow];

// In the case where there is a LayoutAnimation, we will be reinserted into the view hierarchy but only for aesthetic purposes.
// In such a case, we should NOT represent the <Modal>.
if (!self.userInteractionEnabled && ![self.superview.reactSubviews containsObject:self]) {
return;
}

if (!_isPresented && self.window) {
RCTAssert(self.reactViewController, @"Can't present modal view controller without a presenting view controller");

Expand Down

0 comments on commit e220878

Please sign in to comment.