Skip to content

Commit

Permalink
Fix updating navigation bar for modal transitions. (#305)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kmagiera committed Feb 4, 2020
1 parent 65bd436 commit f78c264
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions ios/RNSScreenStackHeaderConfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,20 @@ @interface RNSScreenStackHeaderSubview : UIView
@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 {
Expand Down Expand Up @@ -390,10 +401,16 @@ + (void)updateViewController:(UIViewController *)vc withConfig:(RNSScreenStackHe
}
}

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) {
Expand Down Expand Up @@ -465,7 +482,7 @@ @implementation RNSScreenStackHeaderSubviewManager

- (UIView *)view
{
return [RNSScreenStackHeaderSubview new];
return [[RNSScreenStackHeaderSubview alloc] initWithBridge:self.bridge];
}

@end

0 comments on commit f78c264

Please sign in to comment.