Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix contentInsetAdjustmentBehavior set to automatic on ScrollView in the new architecture #34217

Closed
wants to merge 9 commits into from

Conversation

grahammendick
Copy link
Contributor

Summary

Fixes #34165 and Large title fails on the new React Native architecture.

There are problems with setting contentInsetAdjustmentBehavior to automatic on the ScrollView component in the new React Native architecture. The automatic setting matters to navigation libraries (like my Navigation router) because it stops the ScrollView from overlapping the UINavigationBar. The setting also powers important native features like large titles and search bars on iOS.

The automatic setting works fine on the old architecture. It doesn’t work on the new architecture because React Native is recycling views. In #34165 and Large title fails there are videos comparing the setting in the old and the new architecture.

Changelog

[iOS] [Fixed] - Fix contentInsetAdjustmentBehavior set to automatic on ScrollView in the new architecture

Test Plan

I checked the fix in both the repros in #34165 and Large title fails. Here is a video of the fix running with large titles in the new architecture.

Screen.Recording.2022-07-18.at.21.31.11.mov

iOS doesn't like reusing the underlying UIScrollView. It won't reset the content insets because it think it's already done it. So recreated the scroll view when the component is recycled. Also had to trigger a contentSize update after recycling otherwise the scroll view started with no inset and wouldn't scroll.
The underlying UIScrollView is create new each time so don't want to use default props instead of current props for comparison. Backed out the reset of other scroll props because not needed now it's created new each time
Previous solution of recreating scroll view each time didn't work for the large-title-bug.  Go to large title, scroll to collapse, go back then go to large title and it would be collapsed - it would scroll slightly so could see the first line of content but it would be collapsed.
Stumbled across changing frame from 0 then back to old value and it fixes all the inset behavior auto bugs. Guess it resets everything - without resetting the frame it remembered some settings and made it go through a completely different path when remounting from when recycling
@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels Jul 18, 2022
@react-native-bot react-native-bot added Bug Platform: iOS iOS applications. labels Jul 18, 2022
@analysis-bot
Copy link

analysis-bot commented Jul 18, 2022

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 7,820,484 +0
android hermes armeabi-v7a 7,214,372 +0
android hermes x86 8,134,204 +0
android hermes x86_64 8,112,309 +0
android jsc arm64-v8a 9,698,003 +0
android jsc armeabi-v7a 8,454,127 +0
android jsc x86 9,649,800 +0
android jsc x86_64 10,248,023 +0

Base commit: e1d17c8
Branch: main

@analysis-bot
Copy link

analysis-bot commented Jul 18, 2022

Platform Engine Arch Size (bytes) Diff
ios - universal n/a --

Base commit: 3188727
Branch: main

@facebook-github-bot
Copy link
Contributor

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Copy link
Contributor

@cipolleschi cipolleschi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @grahammendick, thanks for the PR.
I left some suggestions that could simplify the code. Thanks to @sammy-SC for them.

If you could try the last change, it could make the code much easier.

As per review comments, there's no need to delay the reset. Can do it all in when recycling
Copy link
Contributor

@cipolleschi cipolleschi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to bother you again but, could you rebase using main, please?
The PR looks good, but there are some failures in CI that should go away after a Rebase

@facebook-github-bot
Copy link
Contributor

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

1 similar comment
@facebook-github-bot
Copy link
Contributor

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @grahammendick in 27fe6f1.

When will my fix make it into a release? | Upcoming Releases

@react-native-bot react-native-bot added the Merged This PR has been merged. label Jul 20, 2022
@sammy-SC
Copy link
Contributor

@grahammendick thank you for fixing this!

@grahammendick
Copy link
Contributor Author

@sammy-SC it's a crucial fix for my Navigation router so thanks for merging it so quickly 👍

christophpurrer pushed a commit to christophpurrer/react-native-macos that referenced this pull request Nov 11, 2022
…the new architecture (facebook#34217)

Summary:
Fixes facebook#34165 and [Large title fails](reactwg/react-native-new-architecture#43) on the new React Native architecture.

There are problems with setting `contentInsetAdjustmentBehavior` to `automatic` on the `ScrollView` component in the new React Native architecture. The `automatic` setting matters to navigation libraries (like [my Navigation router](https://github.com/grahammendick/navigation)) because it stops the `ScrollView` from overlapping the `UINavigationBar`. The setting also powers important native features like large titles and search bars on iOS.

The `automatic` setting works fine on the old architecture. It doesn’t work on the new architecture because React Native is recycling views. In facebook#34165 and [Large title fails](reactwg/react-native-new-architecture#43) there are videos comparing the setting in the old and the new architecture.

## Changelog

[iOS] [Fixed] - Fix `contentInsetAdjustmentBehavior` set to `automatic` on `ScrollView` in the new architecture

Pull Request resolved: facebook#34217

Test Plan:
I checked the fix in both the repros in facebook#34165 and [Large title fails](reactwg/react-native-new-architecture#43). Here is a video of the fix running with large titles in the new architecture.

https://user-images.githubusercontent.com/1761227/179612188-162b896b-82c5-45de-bb5a-ba80f452fbee.mov

Reviewed By: sammy-SC

Differential Revision: D37952506

Pulled By: cipolleschi

fbshipit-source-id: 6cff6c85aa33b579405fe34a9e36c8630f4c24bd
christophpurrer pushed a commit to christophpurrer/react-native-macos that referenced this pull request Nov 11, 2022
…the new architecture (facebook#34217)

Summary:
Fixes facebook#34165 and [Large title fails](reactwg/react-native-new-architecture#43) on the new React Native architecture.

There are problems with setting `contentInsetAdjustmentBehavior` to `automatic` on the `ScrollView` component in the new React Native architecture. The `automatic` setting matters to navigation libraries (like [my Navigation router](https://github.com/grahammendick/navigation)) because it stops the `ScrollView` from overlapping the `UINavigationBar`. The setting also powers important native features like large titles and search bars on iOS.

The `automatic` setting works fine on the old architecture. It doesn’t work on the new architecture because React Native is recycling views. In facebook#34165 and [Large title fails](reactwg/react-native-new-architecture#43) there are videos comparing the setting in the old and the new architecture.

## Changelog

[iOS] [Fixed] - Fix `contentInsetAdjustmentBehavior` set to `automatic` on `ScrollView` in the new architecture

Pull Request resolved: facebook#34217

Test Plan:
I checked the fix in both the repros in facebook#34165 and [Large title fails](reactwg/react-native-new-architecture#43). Here is a video of the fix running with large titles in the new architecture.

https://user-images.githubusercontent.com/1761227/179612188-162b896b-82c5-45de-bb5a-ba80f452fbee.mov

Reviewed By: sammy-SC

Differential Revision: D37952506

Pulled By: cipolleschi

fbshipit-source-id: 6cff6c85aa33b579405fe34a9e36c8630f4c24bd
Saadnajmi pushed a commit to microsoft/react-native-macos that referenced this pull request Nov 11, 2022
…the new architecture (facebook#34217) (#1484)

Summary:
Fixes facebook#34165 and [Large title fails](reactwg/react-native-new-architecture#43) on the new React Native architecture.

There are problems with setting `contentInsetAdjustmentBehavior` to `automatic` on the `ScrollView` component in the new React Native architecture. The `automatic` setting matters to navigation libraries (like [my Navigation router](https://github.com/grahammendick/navigation)) because it stops the `ScrollView` from overlapping the `UINavigationBar`. The setting also powers important native features like large titles and search bars on iOS.

The `automatic` setting works fine on the old architecture. It doesn’t work on the new architecture because React Native is recycling views. In facebook#34165 and [Large title fails](reactwg/react-native-new-architecture#43) there are videos comparing the setting in the old and the new architecture.

## Changelog

[iOS] [Fixed] - Fix `contentInsetAdjustmentBehavior` set to `automatic` on `ScrollView` in the new architecture

Pull Request resolved: facebook#34217

Test Plan:
I checked the fix in both the repros in facebook#34165 and [Large title fails](reactwg/react-native-new-architecture#43). Here is a video of the fix running with large titles in the new architecture.

https://user-images.githubusercontent.com/1761227/179612188-162b896b-82c5-45de-bb5a-ba80f452fbee.mov

Reviewed By: sammy-SC

Differential Revision: D37952506

Pulled By: cipolleschi

fbshipit-source-id: 6cff6c85aa33b579405fe34a9e36c8630f4c24bd

Co-authored-by: Graham Mendick <graham.mendick@gmail.com>
shwanton pushed a commit to shwanton/react-native-macos that referenced this pull request Feb 13, 2023
…the new architecture (facebook#34217) (microsoft#1484)

Summary:
Fixes facebook#34165 and [Large title fails](reactwg/react-native-new-architecture#43) on the new React Native architecture.

There are problems with setting `contentInsetAdjustmentBehavior` to `automatic` on the `ScrollView` component in the new React Native architecture. The `automatic` setting matters to navigation libraries (like [my Navigation router](https://github.com/grahammendick/navigation)) because it stops the `ScrollView` from overlapping the `UINavigationBar`. The setting also powers important native features like large titles and search bars on iOS.

The `automatic` setting works fine on the old architecture. It doesn’t work on the new architecture because React Native is recycling views. In facebook#34165 and [Large title fails](reactwg/react-native-new-architecture#43) there are videos comparing the setting in the old and the new architecture.

## Changelog

[iOS] [Fixed] - Fix `contentInsetAdjustmentBehavior` set to `automatic` on `ScrollView` in the new architecture

Pull Request resolved: facebook#34217

Test Plan:
I checked the fix in both the repros in facebook#34165 and [Large title fails](reactwg/react-native-new-architecture#43). Here is a video of the fix running with large titles in the new architecture.

https://user-images.githubusercontent.com/1761227/179612188-162b896b-82c5-45de-bb5a-ba80f452fbee.mov

Reviewed By: sammy-SC

Differential Revision: D37952506

Pulled By: cipolleschi

fbshipit-source-id: 6cff6c85aa33b579405fe34a9e36c8630f4c24bd

Co-authored-by: Graham Mendick <graham.mendick@gmail.com>
shwanton pushed a commit to shwanton/react-native-macos that referenced this pull request Mar 10, 2023
…the new architecture (facebook#34217) (microsoft#1484)

Summary:
Fixes facebook#34165 and [Large title fails](reactwg/react-native-new-architecture#43) on the new React Native architecture.

There are problems with setting `contentInsetAdjustmentBehavior` to `automatic` on the `ScrollView` component in the new React Native architecture. The `automatic` setting matters to navigation libraries (like [my Navigation router](https://github.com/grahammendick/navigation)) because it stops the `ScrollView` from overlapping the `UINavigationBar`. The setting also powers important native features like large titles and search bars on iOS.

The `automatic` setting works fine on the old architecture. It doesn’t work on the new architecture because React Native is recycling views. In facebook#34165 and [Large title fails](reactwg/react-native-new-architecture#43) there are videos comparing the setting in the old and the new architecture.

## Changelog

[iOS] [Fixed] - Fix `contentInsetAdjustmentBehavior` set to `automatic` on `ScrollView` in the new architecture

Pull Request resolved: facebook#34217

Test Plan:
I checked the fix in both the repros in facebook#34165 and [Large title fails](reactwg/react-native-new-architecture#43). Here is a video of the fix running with large titles in the new architecture.

https://user-images.githubusercontent.com/1761227/179612188-162b896b-82c5-45de-bb5a-ba80f452fbee.mov

Reviewed By: sammy-SC

Differential Revision: D37952506

Pulled By: cipolleschi

fbshipit-source-id: 6cff6c85aa33b579405fe34a9e36c8630f4c24bd

Co-authored-by: Graham Mendick <graham.mendick@gmail.com>
shwanton pushed a commit to shwanton/react-native-macos that referenced this pull request Mar 10, 2023
…the new architecture (facebook#34217) (microsoft#1484)

Summary:
Fixes facebook#34165 and [Large title fails](reactwg/react-native-new-architecture#43) on the new React Native architecture.

There are problems with setting `contentInsetAdjustmentBehavior` to `automatic` on the `ScrollView` component in the new React Native architecture. The `automatic` setting matters to navigation libraries (like [my Navigation router](https://github.com/grahammendick/navigation)) because it stops the `ScrollView` from overlapping the `UINavigationBar`. The setting also powers important native features like large titles and search bars on iOS.

The `automatic` setting works fine on the old architecture. It doesn’t work on the new architecture because React Native is recycling views. In facebook#34165 and [Large title fails](reactwg/react-native-new-architecture#43) there are videos comparing the setting in the old and the new architecture.

## Changelog

[iOS] [Fixed] - Fix `contentInsetAdjustmentBehavior` set to `automatic` on `ScrollView` in the new architecture

Pull Request resolved: facebook#34217

Test Plan:
I checked the fix in both the repros in facebook#34165 and [Large title fails](reactwg/react-native-new-architecture#43). Here is a video of the fix running with large titles in the new architecture.

https://user-images.githubusercontent.com/1761227/179612188-162b896b-82c5-45de-bb5a-ba80f452fbee.mov

Reviewed By: sammy-SC

Differential Revision: D37952506

Pulled By: cipolleschi

fbshipit-source-id: 6cff6c85aa33b579405fe34a9e36c8630f4c24bd

Co-authored-by: Graham Mendick <graham.mendick@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Platform: iOS iOS applications. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ScrollView doesn't reset inset when contentInsetAdjustmentBehavior is automatic
6 participants