-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
[ScrollView] contentInset bug if content height on initial mount is larger than the viewport #1878
Comments
Most likely related #1641 |
thanks for the report @orktes, cc @tadeuzagallo @nicklockwood |
👍 |
@orktes have you found a way to make this work yet? I'm still seeing this issue for ScrollView |
As a workaround I've just been scrolling to -topInset on mount. |
To clarify ide's comment, if you have a contentInset of
|
If you do it in the ref handler, define a separate autobound function so that the same function is passed into |
Hi there! This issue is being closed because it has been inactive for a while. But don't worry, it will live on with ProductPains! Check out its new home: https://productpains.com/post/react-native/scrollview-contentinset-bug-if-content-height-on-initial-mount-is-larger-than-the-viewport- ProductPains helps the community prioritize the most important issues thanks to its voting feature. Also, if this issue is a bug, please consider sending a PR with a fix. We rely on the community to provide |
Here my workaround to scroll up on initial render for a FlatList.
|
This is a legitimate bug, and as far as I can tell is still unresolved. Why are legit bugs being moved to some feature request app? @mkonicek this should be re-opened as far as I can tell. |
How can this bug be more than 2 years old and still not resolved |
I have a SectionList with sticky headers, and I need to use contentInset since I have native top and bottom nav bars. I managed to find a solution with both working sticky headers and insets. This is RN v0.55.4 class MyScreen extends Component<AllProps> {
listEl: SectionList<Item>;
componentDidMount() {
if (__IOS__) {
(this.listEl as any).setNativeProps({
style: {
paddingTop: getOffsets(this.props).topOffset,
},
});
}
}
render() {
const sections: { title: string; data: Item[] }[] = whateverData;
return (
<SectionList
style={{ flex: 1 }}
automaticallyAdjustContentInsets={false}
ref={view => (this.listEl = view as any)}
contentContainerStyle={{
paddingBottom: __IOS__ ? getOffsets(this.props).topOffset : 0,
}}
stickySectionHeadersEnabled
contentInset={__IOS__? { bottom: getOffsets(this.props).bottomOffset } : undefined}
sections={sections}
keyExtractor={(item: Item) => item.data.id}
renderSectionHeader={({ section: { title } }) => <MyHeader title={title} />}
renderItem={({ item }) => <MyItem item={item} />}
ItemSeparatorComponent={() => <Box borderBottom borderColor="transparent" />}
/>
);
}
} |
It seems that contentInset only works properly if the ScrollView is first mounted without content (or with less content than the viewport height). If content height overflows the scrollview viewport height the contentInset only takes effect after first scroll.
Example of the issue (using ListView)
https://rnplay.org/apps/SdfSNw
The text was updated successfully, but these errors were encountered: