PedroBern / react-native-collapsible-tab-view

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

Delay on open with react navigation #155

Closed picknamexd closed 3 years ago

picknamexd commented 3 years ago

I have a Tab.Navigator wrapping a Stack.Navigator that calls one Screen that shows a list of users, when I click on one of them, I call the Screen that contains collapsible-tab-view, and when it opens, it has a lot of lag, I have verified that if I put a single Tab, it works fine, but if I add 3 or 4, it starts to have lag, am I doing something wrong?

PedroBern commented 3 years ago

Does it happen if the content of your tabs are light components, something like an empty view or null? Did you try lazy mode?

picknamexd commented 3 years ago

Hello! @PedroBern Thanks for your answer, right now I'm only testing the example in the read.me, the tabs are practically empty. I just tried wrapping with Lazy mode and nothing changes, I put the code I am using.

In react navigation collapsibleScreen:

const Perfil: React.FC = () => {
  const renderItem: ListRenderItem<number> = React.useCallback(({index}) => {
    return (
      <View style={[styles.box, index % 2 === 0 ? styles.boxB : styles.boxA]} />
    );
  }, []);
  return (
    <Tabs.Container
      HeaderComponent={HeaderComponent}
      headerHeight={HEADER_HEIGHT}
      minHeaderHeight={MIN_HEADER_HEIGHT}
      TabBarComponent={(props) => (
        <MaterialTabBar
          {...props}
          activeColor="black"
          inactiveColor="black"
          inactiveOpacity={1}
          labelStyle={{fontSize: 14}}
        />
      )}>
      <Tabs.Tab name="Tab1" label="A">
        <Tabs.Lazy>
          <Tabs.Container />
        </Tabs.Lazy>
      </Tabs.Tab>
      <Tabs.Tab name="Tab2" label="B">
        <Tabs.Lazy>
          <Tabs.Container />
        </Tabs.Lazy>
      </Tabs.Tab>
      <Tabs.Tab name="Tab3" label="C">
        <Tabs.Lazy>
          <Tabs.Container />
        </Tabs.Lazy>
      </Tabs.Tab>
      <Tabs.Tab name="Tab4" label="D">
        <Tabs.Lazy>
          <Tabs.Container />
        </Tabs.Lazy>
      </Tabs.Tab>
    </Tabs.Container>
  );
};

In Navigation Component

return (
    <SafeAreaProvider>
        <NavigationContainer
          theme={this.scheme === 'dark' ? DarkTheme : DefaultTheme}>
          ...
            <Tab.Screen name="PerfilStack" component={PerfilStackScreen} />
          </Tab.Navigator>
        </NavigationContainer>
    </SafeAreaProvider>
);

In PerfilStackScreen:

return (
    <PerfilStack.Navigator>
      ...
       <PerfilStack.Screen name="Perfil" component={Perfil} />
    </PerfilStack.Navigator>
);

And Finally in Perfil component

return (
     ...
        <Ionicons.Button
          name={'settings'}
          size={25}
          color={'black'}
          onPress={() => navigation.navigate('collapsibleScreen')}
          backgroundColor="white"
        />
      </View>
    );
Jalson1982 commented 3 years ago

I have the same issue. I put 4 same scrollviews and the same problem. JS thread goes down to 20 and UI thread about 55 when I navigate to screen that contains collapsible-tab-view. I tried lazy too but it is the same.

andreialecu commented 3 years ago

@Jalson1982 and others, is this on Android or iOS?

I think there are some upstream issues with Reanimated because I'm running into: https://github.com/software-mansion/react-native-reanimated/issues/1932 which is somewhat related, but more serious.

Jalson1982 commented 3 years ago

@andreialecu I see it on IOS on Android I am scared to look . It is very very noticeable that there is some big lag.

andreialecu commented 3 years ago

Does the JS thread consistently stay down to 20fps, or is it just for the initial load?

If so, a repro would be good to see.

On the app I'm working on I have a collapsible tab view with 6 lazy loaded scrollable tabs, and on iOS the performance is perfect. (using reanimated 2.1.0)

Jalson1982 commented 3 years ago

Ok, repro is very hard to get with the current code but I can make something similar maybe. But basically, it is just scroll view with some text nothing heavy. I can make a video to see drops if you like. @andreialecu I was on reanimated 2.0.0 can it be issue? JS only on load goes down to 20.

andreialecu commented 3 years ago

@Jalson1982 try reproducing it on https://github.com/andreialecu/rnctv-react-native-bare-test

It has two tabs, but it doesn't seem to exhibit the problem by default.

simulator_screenshot_D91C15CA-20C0-4CD7-A71C-17EDAE5D6936

Open a PR with the reproduction on the repository above if you can achieve it.

andreialecu commented 3 years ago

I believe this may be fixed by #186

andreialecu commented 3 years ago

4.2.1 should have some pretty huge performance improvements, which I think should resolve this.

Closing, feel free to ping me to reopen if this is still an issue.

siddharth-kt commented 2 years ago

4.2.1 should have some pretty huge performance improvements, which I think should resolve this.

Closing, feel free to ping me to reopen if this is still an issue.

@andreialecu i am using version 2.0.2 with react-navigation + react-native-page-view and i am facing same issue kindly implement such update in react-navigation too.