mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-03-26 09:14:22 +08:00
Fix updating navigation bar for modal transitions. (#305)
This change fixes the problem when navigation bar would not get properly updated for modal transitions. The problem was due to the fact that for modal transitions the animateAlongsideTransition block was not getting trriggered. This was noticeable on iOS versions before 13, as starting with iOS 13 we can use NavigationItem to specify most of the nav bar customization. On older versions however it is required that for a lot of navbar settings we need to update them durion animation. This wasn't the case for navigators presented modally. In case we show a modal we can update nav bar without animation because it actually renders a completely new navigation bar which isn't shared. On top of that this PR fixes the problem with bridge not being set for header subviews.
This commit is contained in:
committed by
GitHub
parent
65bd436cbe
commit
f78c264419
@@ -26,9 +26,20 @@
|
||||
@property (nonatomic, weak) UIView *reactSuperview;
|
||||
@property (nonatomic) RNSScreenStackHeaderSubviewType type;
|
||||
|
||||
- (instancetype)initWithBridge:(RCTBridge*)bridge;
|
||||
|
||||
@end
|
||||
|
||||
@implementation RNSScreenStackHeaderSubview
|
||||
|
||||
- (instancetype)initWithBridge:(RCTBridge *)bridge
|
||||
{
|
||||
if (self = [super init]) {
|
||||
_bridge = bridge;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation RNSScreenStackHeaderConfig {
|
||||
@@ -390,10 +401,16 @@
|
||||
}
|
||||
}
|
||||
|
||||
if (vc.transitionCoordinator != nil && !wasHidden) {
|
||||
[vc.transitionCoordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
|
||||
|
||||
} completion:nil];
|
||||
if (vc.transitionCoordinator != nil
|
||||
&& vc.transitionCoordinator.presentationStyle == UIModalPresentationNone
|
||||
&& !wasHidden) {
|
||||
// when there is an ongoing transition we may need to update navbar setting in animation block
|
||||
// using animateAlongsideTransition. However, we only do that given the transition is not a modal
|
||||
// transition (presentationStyle == UIModalPresentationNone) and that the bar was not previously
|
||||
// hidden. This is because both for modal transitions and transitions from screen with hidden bar
|
||||
// the transition animation block does not get triggered. This is ok, because with both of those
|
||||
// types of transitions there is no "shared" navigation bar that needs to be updated in an animated
|
||||
// way.
|
||||
[vc.transitionCoordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
|
||||
[self setAnimatedConfig:vc withConfig:config];
|
||||
} completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
|
||||
@@ -465,7 +482,7 @@ RCT_EXPORT_VIEW_PROPERTY(type, RNSScreenStackHeaderSubviewType)
|
||||
|
||||
- (UIView *)view
|
||||
{
|
||||
return [RNSScreenStackHeaderSubview new];
|
||||
return [[RNSScreenStackHeaderSubview alloc] initWithBridge:self.bridge];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user