fix(iOS) - Prevent SwiftUI based filter from insetting content by the safe area - #58349
Open
intergalacticspacehighway wants to merge 1 commit into
Open
Conversation
UIHostingController insets its root view by the safe area, so a filtered view had its content moved down and shrunk whenever the view overlapped a safe area edge. A filter must not affect layout. Set `safeAreaRegions = []` on the hosting controller to opt out, and gate the SwiftUI filter container at iOS 16.4, the first version where that property exists. Below 16.4 the filters that need the container stay no-ops, which matches the behavior before `enableSwiftUIBasedFilters` existed. `safeAreaRegions` is declared `@available(iOS 16.4, tvOS 16.4, *)`, so both checks name tvOS. Without the tvOS clause the Swift file fails to build for tvOS.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
When a
filterstyle is passed to aView, it can shift theViewby safe area insets if it overlaps a safe area edge. Filter style should not affect layout. Also fixes - #57642Unset safeAreaRegions on the hosting controller to opt out of implicit safe area insets. Below iOS 16.4
safeAreaRegionsdoes not exist so it requires Obj-C swizzling hack as noted here - #57643. Hence, proper fix requires gating the filter feature to iOS 16.4. We can mention it in the documentation on release.Changelog:
[IOS] [FIXED] - Fix views with a filter having their content offset by the safe area insets
Test Plan:
releaseLevelto canary.<View style={{width: 100, height: 100, backgroundColor:"red", filter:[{blur: 10}]}} />in RNTester, make sure it renders on top of the screen.finalizeUpdatesbefore callingmountChildComponentView, so on first mount the hosting view has no window and its safe area insets are zero.cc - @jorge-cab