From c3d1ce35d0335d82566a43c9bf149405a7fc711e Mon Sep 17 00:00:00 2001 From: Abe Fettig Date: Fri, 30 Apr 2021 13:09:52 -0400 Subject: [PATCH] Fix broken layout for header subviews in iOS (Fixes #528) This addresses bugs like #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. --- ios/RNSScreen.m | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ios/RNSScreen.m b/ios/RNSScreen.m index 3836d22d12..921b8c7b02 100644 --- a/ios/RNSScreen.m +++ b/ios/RNSScreen.m @@ -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