react-native-collapsible-tab-view icon indicating copy to clipboard operation
react-native-collapsible-tab-view copied to clipboard

With the latest release (or better yet since 7.0.1), tabs are always Lazy Loaded not matter what

Open gregavola opened this issue 6 months ago • 2 comments

When setting up a Tab controller, in the old version below 6.2.2, you could let all the tabs loaded, if they were not mounted (on screen), so when you swiped, they would be visible. Now there is about a 5-10 second delay on when the tab content is viewable, and then whenever you swipe, it's lazy loaded and takes some time to load in, even though the data is already there. Downgrading to 6.2.2 makes this work again, but I needed to upgraded to 8.0.01 to fix the issue of Tabs.FlashList not showing up on Android (due to the height and width).

Is there a way to have the same behavior as 6.2.2, where all tabs are mounted even if they are not visible?

Any ideas?

gregavola avatar May 14 '25 17:05 gregavola

+1

pfcodes avatar May 21 '25 06:05 pfcodes

same here, when I downgraded to 6.2.2, lazy={false} worked

weizhe412 avatar May 23 '25 04:05 weizhe412

bump on this, still having problems with tabs being lazy loaded regardless of the prop

tinaszheng avatar Aug 28 '25 21:08 tinaszheng

same here :/ we rly dont want lazy ones (8.0.1)

kristian-nst avatar Sep 30 '25 06:09 kristian-nst

I tried to fix it in this pull request works great on my app, so I'm wrapping the scenes in Lazy component only if the lazy prop is true https://github.com/PedroBern/react-native-collapsible-tab-view/pull/485

hariszulfiqar054 avatar Oct 01 '25 11:10 hariszulfiqar054

I tried to fix it in this pull request works great on my app, so I'm wrapping the scenes in Lazy component only if the lazy prop is true #485

awesome! i will test it tmr :D

kristian-nst avatar Oct 01 '25 12:10 kristian-nst

It is working as expected now! Would be great to merge this!

But for some reason my imports changed from 'react-native-collapsible-tab-view' to 'react-native-collapsible-tab-view/src'. I assume cause I'm using the branch and not the published package :)

kristian-nst avatar Oct 03 '25 02:10 kristian-nst

what i'm doing until this is merged, for anyone who needs :)

patch file:

diff --git a/src/Container.tsx b/src/Container.tsx
index e782b903b0220ec0114c62e268e7efb635e4be43..c53ff1341961eadd9be1439f7e04aa267d5635f5 100644
--- a/src/Container.tsx
+++ b/src/Container.tsx
@@ -1,4 +1,4 @@
-import React from 'react'
+import React, { useCallback } from 'react'
 import { StyleSheet, useWindowDimensions, View } from 'react-native'
 import PagerView from 'react-native-pager-view'
 import Animated, {
@@ -71,11 +71,11 @@ export const Container = React.memo(
         headerContainerStyle,
         cancelTranslation,
         containerStyle,
-        lazy,
-        cancelLazyFadeIn,
         pagerProps,
         onIndexChange,
         onTabChange,
+        lazy,
+        cancelLazyFadeIn,
         width: customWidth,
         allowHeaderOverscroll,
       },
@@ -349,6 +349,27 @@ export const Container = React.memo(
         [onTabPress]
       )
 
+      const renderContent = useCallback(
+        (tabName: string, i: number) => {
+          if (lazy) {
+            return (
+              <Lazy
+                startMounted={lazy ? undefined : true}
+                cancelLazyFadeIn={!lazy ? true : !!cancelLazyFadeIn}
+                // ensure that we remount the tab if its name changes but the index doesn't
+                key={tabName}
+              >
+                {React.Children.toArray(children)[i] as React.ReactElement}
+              </Lazy>
+            )
+          }
+          return (
+            <>{React.Children.toArray(children)[i] as React.ReactElement}</>
+          )
+        },
+        [cancelLazyFadeIn, children, lazy]
+      )
+
       return (
         <Context.Provider
           value={{
@@ -438,18 +459,7 @@ export const Container = React.memo(
                 return (
                   <View key={i} style={styles.pageContainer}>
                     <TabNameContext.Provider value={tabName}>
-                      <Lazy
-                        startMounted={lazy ? undefined : true}
-                        cancelLazyFadeIn={!lazy ? true : !!cancelLazyFadeIn}
-                        // ensure that we remount the tab if its name changes but the index doesn't
-                        key={tabName}
-                      >
-                        {
-                          React.Children.toArray(children)[
-                            i
-                          ] as React.ReactElement
-                        }
-                      </Lazy>
+                      {renderContent(tabName, i)}
                     </TabNameContext.Provider>
                   </View>
                 )

then i ran

bun patch react-native-collapsible-tab-view
patch -p1 -d node_modules/react-native-collapsible-tab-view < my.patch
bun patch --commit 'node_modules/react-native-collapsible-tab-view'

im sure anyone who needs can make it work with npm/yarn and 'patch-package' too :)

kristian-nst avatar Oct 03 '25 04:10 kristian-nst