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

ScrollTo doesn't take paddingTop in account. #702

Closed
2 tasks done
arjendevos opened this issue Dec 9, 2022 · 7 comments
Closed
2 tasks done

ScrollTo doesn't take paddingTop in account. #702

arjendevos opened this issue Dec 9, 2022 · 7 comments
Labels
bug Something isn't working

Comments

@arjendevos
Copy link

arjendevos commented Dec 9, 2022

Current behavior

<FlashList
  contentContainerStyle={{ paddingBottom: insets.bottom, paddingTop: H_MAX_HEIGHT }}
  ref={ref}
  automaticallyAdjustContentInsets={true}
  keyboardDismissMode="on-drag"
  onScroll={onScroll}
  data={mappedProducts}
  estimatedItemSize={120}
  keyExtractor={(item) => {
    return `${item.id}`;
  }}
  renderItem={({ item }) => {
    return <ProductItem product={item} restaurant={restaurant} />;
  }}
/>

This is our flashlist. It contains a list of products.

onPress={(item) => {
  setSelectedCategory(item);
  ref.current?.scrollToItem({ item: item.name, animated: true });
}}

As you can see we have a paddingTop and paddingBottom. When we do not have those, the scrollTo works perfectly. But when we have padding, it completely forgets about those paddings and just ignores them while scrolling. So, when we scroll to an item, we end up with a different item.

ref.current?.scrollToOffset({ offset: 10, animated: true });

^ScrollToOffset seems to acknowledge the padding.

ref.current?.scrollToIndex({ index: 0, animated: true });

^ScrollToIndex & scrollToItem does not acknowledge the padding.

Expected behavior

ScrollTo should take in account for the padding.

Platform:

  • iOS
  • Android

Environment

"@shopify/flash-list": "1.1.0",

@arjendevos arjendevos added the bug Something isn't working label Dec 9, 2022
@naqvitalha
Copy link
Collaborator

Can you provide a repro on expo snack? I'll be able to quickly take a look. This was verified to work in our testing.

@arjendevos
Copy link
Author

@naqvitalha
Copy link
Collaborator

In your sample, the list is starting from the top of the screen. And padding is being considered during the scroll. I've moved the overlay to the bottom to make you realize what's going on. Item no. 6 is going to the top as expected: https://snack.expo.dev/@naqvitalha/nervous-macaroni-and-cheese---fixed
Close the issue if this helps!

@arjendevos
Copy link
Author

Yeah but we actually don't want it to go to the top. We want the item to go to the top - padding top

@naqvitalha
Copy link
Collaborator

You can pass your paddingTop value as viewOffset when you call scrollToIndex.
The current API behavior is what we expect.

@arjendevos
Copy link
Author

Ah oke! Thank you very much!

@trevorpfiz
Copy link

trevorpfiz commented Aug 8, 2024

You can pass your paddingTop value as viewOffset when you call scrollToIndex. The current API behavior is what we expect.

is #1311 the expected behavior as well? how would using viewOffset fix the issue there?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants