Giter Site home page Giter Site logo

Allow a hook like `react-navigation`'s hook `useScrollToTop` to scroll all tabs to the top about react-native-collapsible-tab-view HOT 6 OPEN

pedrobern avatar pedrobern commented on May 2, 2024 1
Allow a hook like `react-navigation`'s hook `useScrollToTop` to scroll all tabs to the top

from react-native-collapsible-tab-view.

Comments (6)

PedroBern avatar PedroBern commented on May 2, 2024

Related: #2

from react-native-collapsible-tab-view.

alexpchin avatar alexpchin commented on May 2, 2024

@PedroBern I was going to reference that issue actually! Also thanks for the good first issue 👍 Lol

from react-native-collapsible-tab-view.

PedroBern avatar PedroBern commented on May 2, 2024

@alexpchin this is a must-have feature, I was thinking about it since the beginning, you can see the related issue is number 2, the second opened issue ever. But I didn't have the time to work on it yet.

I think your suggestion to implement a hook simply to scroll to top is a lot easier to implement than #2.

from react-native-collapsible-tab-view.

PedroBern avatar PedroBern commented on May 2, 2024

This is easy to implement in v3.

from react-native-collapsible-tab-view.

alexpchin avatar alexpchin commented on May 2, 2024

@PedroBern Now with v3, this will scroll all tabs to the top FYI. We can DRY this implementation but just adding a note here for the moment.

// Setup some tab refs 
const containerRef = useAnimatedRef();
const uploadsRef = useAnimatedRef();
const aboutRef = useAnimatedRef();
const likesRef = useAnimatedRef();
const travelsRef = useAnimatedRef();

.
.
.

// Function to scroll all tabs to the top when the user clicks on the bottom tab
// - https://reactnavigation.org/docs/use-scroll-to-top/  
useScrollToTop(containerRef);
useScrollToTop(uploadsRef);
useScrollToTop(aboutRef);
useScrollToTop(likesRef);
useScrollToTop(travelsRef);

from react-native-collapsible-tab-view.

alexpchin avatar alexpchin commented on May 2, 2024

In the latest v4 version, if you use https://reactnavigation.org/docs/use-scroll-to-top/

const pageRef = useRef();
useScrollToTop(pageRef);

.
.
.
<Tabs.FlatList
      .
      .
      ref={pageRef}
      .
      .
    />

Then the page will scroll up so that the Tab is at the top of the screen rather than scrolling Down to reset the page so that the header is at the top of the screen.

E.g: From

To:

As per https://reactnavigation.org/docs/use-scroll-to-top/#providing-scroll-offset, you can add an offset. However, it's still a bit buggy... I'm trying to work out why.

useScrollToTop(
    useRef({
      scrollToTop: () =>
        pageRef.current?.scrollToOffset({
          // Doesn't work
          // offset: -(headerHeight + tabBarHeight),
          // Does work
          offset: -999,
        }),
    }),
  );

from react-native-collapsible-tab-view.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.