PedroBern / react-native-collapsible-tab-view

A cross-platform Collapsible Tab View component for React Native
MIT License
875 stars 171 forks source link

When setting state in `onTabChange` the indicator isn't smooth #130

Closed alexpchin closed 3 years ago

alexpchin commented 3 years ago

When you change tabs and have some code that sets some state in onTabChange the Indicator movement isn't smooth. Please see video.

simulator8.mov.zip

This can be avoided by memoizing the tabs, e.g

const MemoizedTabs = useMemo(
    () => (
      <Tabs.Container
        lazy
        onTabChange={onTabChange}
        ref={pageRef}
        TabBarComponent={_renderTabBar}
      >
        .
        .
        .
      </Tabs.Container>
    ),
    [],
  );

And rendering just.

{MemoizedTabs}

It may be a good idea to make a note of this in the Readme somewhere?

andreialecu commented 3 years ago

This should be fixed by #131, but please confirm.

alexpchin commented 3 years ago

I'm still seeing that the indicator isn't as smooth unless you use useMemo?

andreialecu commented 3 years ago

When I tested it on my simulator (M1 Mac Mini) I wasn't really able to notice the jumping. It was still extremely smooth. That's likely because the emulator and the CPU architecture are both arm64 so there are no bottlenecks. It basically all runs native.

I mainly had to confirm this issue via some logging I added.

Did you verify if this occurs on a real device?

andreialecu commented 3 years ago

I added memoization just in case, released as rc9