Skip to content

Commit

Permalink
Fix broken layout for header subviews in iOS (Fixes software-mansion#528
Browse files Browse the repository at this point in the history
)

This addresses bugs like software-mansion#528 where header content gets incorrectly
positioned on initial load or after rotation. I was experiencing
these issues in my current app, and when I looked at the XCode
view debugger I could see that RNSScreenStackHeaderConfig.subviews
were having their .frame.origin.x property set to a non-zero
value that moved them out of place.

I'm fairly new to React Native and very new to this codebase, so
I haven't totally got to the bottom of what's happening here. My
guess/theory is that RN layout code is setting the position of
these views as if they're part of of the regular view hierarchy,
even though they're meant to be managed by a UINavigationBar. Rather
than trying to fix this at a deeper level and risk introducing side
effects, I've added this small workaround.
  • Loading branch information
abram committed Apr 30, 2021
1 parent 7ea56a4 commit c3d1ce3
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ios/RNSScreen.m
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,13 @@ - (void)viewDidLayoutSubviews
_lastViewFrame = self.view.frame;
[((RNSScreenView *)self.viewIfLoaded) updateBounds];
}

// Clear any coordinates that have been (inadvertently) set on RNSScreenStackHeaderConfig subviews.
// This allows the native UINavigationBar to control the position of header content.
RNSScreenStackHeaderConfig * configView = [self findScreenConfig];
for (UIView* subview in configView.reactSubviews) {
subview.frame = CGRectMake(0, 0, subview.frame.size.width, subview.frame.size.height);
}
}

- (id)findFirstResponder:(UIView*)parent
Expand Down

0 comments on commit c3d1ce3

Please sign in to comment.