From 81d8992ceb44d0aef8f7ee5b40245477f37ecdc2 Mon Sep 17 00:00:00 2001 From: Samuel Susla Date: Fri, 21 Apr 2023 10:43:17 -0700 Subject: [PATCH] Fix outdated viewport offset on Fabric surface (#37020) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/37020 changelog: [internal] if host view's position on screen changes, `RootShadowNode` has to be notified of this. Otherwise the state of UI is not correctly reflected in ShadowTree, leading to inconsistencies. For example, when trying to get views position in window, it won't be correct when hosting view isn't full screen. Overriding `setFrame` only works for cases where it is hosting view's parent changing its position. But there are other cases where the position may change on the screen, like when hosting view's parent is moved by movable navigation bar. This does not affect frame of hosting view but it does change its position on the screen. To know about this event, we need to override `layoutSubviews`. `layoutSubviews` is called by UIKit whenever its internal flag `_needsLayout` is set to YES. Reviewed By: javache Differential Revision: D45122502 fbshipit-source-id: b7b1b08a8b3accffce7e3c71f7d19887caf6462f --- .../Base/Surface/SurfaceHostingView/RCTSurfaceHostingView.mm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/react-native/React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingView.mm b/packages/react-native/React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingView.mm index 8fd40462a23..1056ff08dbb 100644 --- a/packages/react-native/React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingView.mm +++ b/packages/react-native/React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingView.mm @@ -74,9 +74,9 @@ RCT_NOT_IMPLEMENTED(-(nullable instancetype)initWithCoder : (NSCoder *)coder) [_surface stop]; } -- (void)setFrame:(CGRect)frame +- (void)layoutSubviews { - [super setFrame:frame]; + [super layoutSubviews]; CGSize minimumSize; CGSize maximumSize;