Skip to content

fix(ios): reset contentInset after centerContent changed#51231

Closed
ouchuan wants to merge 1 commit into
react:mainfrom
ouchuan:fix_50839
Closed

fix(ios): reset contentInset after centerContent changed#51231
ouchuan wants to merge 1 commit into
react:mainfrom
ouchuan:fix_50839

Conversation

@ouchuan

@ouchuan ouchuan commented May 10, 2025

Copy link
Copy Markdown
Contributor

Reset contentInset after centerContent changed

Summary:

Pull Request resolved: #50839

Changelog:

[IOS] [CHANGED] - The content in ScrollView now can be centered/uncentered by changing centerContent property

Test Plan

Tested with the following code

const [centerContent, setCenterContent] = useState(false);
setTimeout(() => {
    setCenterContent(!centerContent);
}, 2000);
return (
  <ScrollView centerContent={centerContent}
    contentContainerStyle={{alignItems: 'center'}}>
      <View style={{width: 200, height: 200, backgroundColor: 'blue'}}>
      </View>
    </ScrollView>
);
  1. If the initial state is false, the blue rectangle in the ScrollView will be initially located at the top and move to the center after the timer is triggered.
  2. If the initial state is true, the blue rectangle in the ScrollView will be centered initially and move to the top after the timer is triggered.

@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 May 10, 2025
@ouchuan

ouchuan commented May 13, 2025

Copy link
Copy Markdown
Contributor Author

@sammy-SC hi, I'm trying to fix #50839, can you review this patch?

@ouchuan

ouchuan commented Jun 6, 2025

Copy link
Copy Markdown
Contributor Author

Hi @sammy-SC any feedback about this ?

@casperstr

Copy link
Copy Markdown

Also need this!
The combination of this issue and the fact that fabric recycles your views makes the prop impossible to use.
Once you use it in one view all scroll views might be centered.

@johankasperi

Copy link
Copy Markdown
Contributor

I tried setting _scrollView.contentInset = UIEdgeInsetsZero in prepareForRecycle so the consentInset would be reset before recycling the UIScrollView. Similar to what I did in this PR. But it didn't work, however I think it would be more suitable to reset the contentInset state in that method. Would you like to give it a try?

@react-native-bot

Copy link
Copy Markdown
Collaborator

This PR is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@react-native-bot react-native-bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label May 26, 2026
@react-native-bot

Copy link
Copy Markdown
Collaborator

This PR was closed because it has been stalled for 7 days with no activity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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. Stale There has been a lack of activity on this issue and it may be closed soon.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ScrollView with centerContent={true} is not working properly

5 participants