mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-02-11 09:20:54 +08:00
Trigger moveToWindow:nil call when screen animation starts to mimick UINavController behavior (#47)
With this change in the screens that are being transitioned get detach+attach events similarily to how it is done in UINavigationController. This allows views underneath to get notified that the transition is started and react to it when necessary (e.g. hide keyboard)
This commit is contained in:
committed by
GitHub
parent
5cd96cdd1b
commit
5dadab9aa6
@@ -86,34 +86,46 @@
|
||||
- (void)updateContainer
|
||||
{
|
||||
_needUpdate = NO;
|
||||
BOOL activeScreenChanged = NO;
|
||||
BOOL activeScreenRemoved = NO;
|
||||
// remove screens that are no longer active
|
||||
NSMutableSet *orphaned = [NSMutableSet setWithSet:_activeScreens];
|
||||
for (RNSScreenView *screen in _reactSubviews) {
|
||||
if (!screen.active && [_activeScreens containsObject:screen]) {
|
||||
activeScreenChanged = YES;
|
||||
activeScreenRemoved = YES;
|
||||
[self detachScreen:screen];
|
||||
}
|
||||
[orphaned removeObject:screen];
|
||||
}
|
||||
for (RNSScreenView *screen in orphaned) {
|
||||
activeScreenChanged = YES;
|
||||
activeScreenRemoved = YES;
|
||||
[self detachScreen:screen];
|
||||
}
|
||||
|
||||
// detect if new screen is going to be activated
|
||||
BOOL activeScreenAdded = NO;
|
||||
for (RNSScreenView *screen in _reactSubviews) {
|
||||
if (screen.active && ![_activeScreens containsObject:screen]) {
|
||||
activeScreenAdded = YES;
|
||||
}
|
||||
}
|
||||
|
||||
// add new screens in order they are placed in subviews array
|
||||
for (RNSScreenView *screen in _reactSubviews) {
|
||||
if (screen.active && ![_activeScreens containsObject:screen]) {
|
||||
activeScreenChanged = YES;
|
||||
[_activeScreens addObject:screen];
|
||||
[self attachScreen:screen];
|
||||
} else if (screen.active) {
|
||||
// if the view was already there we move it to "front" so that it is in the right
|
||||
// order accoring to the subviews array
|
||||
[_controller.view bringSubviewToFront:screen.controller.view];
|
||||
} else if (screen.active && activeScreenAdded) {
|
||||
// if we are adding new active screen, we perform remounting of all already marked as active
|
||||
// this is done to mimick the effect UINavigationController has when willMoveToWindow:nil is
|
||||
// triggered before the animation starts
|
||||
if (activeScreenAdded) {
|
||||
[self detachScreen:screen];
|
||||
[self attachScreen:screen];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (activeScreenChanged && _controller.presentedViewController == nil) {
|
||||
if ((activeScreenRemoved || activeScreenAdded) && _controller.presentedViewController == nil) {
|
||||
// if user has reachability enabled (one hand use) and the window is slided down the below
|
||||
// method will force it to slide back up as it is expected to happen with UINavController when
|
||||
// we push or pop views.
|
||||
|
||||
Reference in New Issue
Block a user