question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FlatList is not scrollable inside TabView

See original GitHub issue

Explain what you did (Required) Using TabView and TabView.Item, containing a list inside the TabView.Item.

Expected behavior (Required) The list inside the TabView should continue to be scrollable.

Describe the bug (Required) When having a FlatList inside a TabView.Item, the scrolling of the list is broken - you can only scroll if you very quickly swipe the screen.

To Reproduce (Required) I created this Snack: https://snack.expo.io/2K8V8ALHy

You will notice that, in the browser, everything seems to work. If you actually use Expo GO and scan the app to run it on your device, you will be able to reproduce the bug - not being able to scroll the list in the first tab.

Screenshots (Required) image

Your Environment (Required):

software version
react-native-elements 3.4.2
react-native Expo 40

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:24 (5 by maintainers)

github_iconTop GitHub Comments

53reactions
ruiaraujo012commented, Jun 23, 2021

Now, it works on android but in ios, the scroll is buggy and not work as expected if you try the same code but on an ios device, it won’t work.

Edit: It can be “fixed” with the following code, but the swipe left/right to move between tabs stops working. I think I will use this approach for now, when this bug is fixed I will roll back my solutions.

<TabView.Item onMoveShouldSetResponder={(e) => e.stopPropagation()}>

5reactions
MarouaniALAcommented, Nov 8, 2021

I have same issue, I found a tempo solution by creating VirtualizedView component because 2 scroll in the same orientation will throw a warning and put the tabView inside it also used @ruiaraujo012 solution for better performance

export default function VirtualizedView({
                                            children,
                                            getRef, ...props
                                        }: { children?: any, getRef?: any } & FlatListProps) {
    const {data, renderItem, ...otherProps} = props
    const flatListRef = useRef();

    useEffect(() => {
        if (getRef && flatListRef.current)
            getRef(flatListRef.current)

    }, [flatListRef]);


    function header() {
        return <React.Fragment>{children}</React.Fragment>;
    }

    return (
        <FlatList
            ref={flatListRef}
            data={[]}
            ListEmptyComponent={null}
            renderItem={null}
            ListHeaderComponent={header()}
            {...otherProps}
        />
    );
}


export function TabsScreen() {
    const [index, setIndex] = useState(0);
    const [listRef, setlistRef] = useState<FlatList>();

    useEffect(() => {
        listRef?.scrollToOffset({ animated: true, offset: 0 })
    }, [index]);

    return (
        <View>
            <Tab
                indicatorStyle={{backgroundColor: Colors.primary}}
                value={index} onChange={setIndex}>
                <Tab.Item
                    containerStyle={styles.itemContainer}
                    titleStyle={[index === 0 ? styles.selectedItem : styles.unSelectedItem, styles.tabTitleTxt]}
                    title="Tab1"/>

                <Tab.Item
                    containerStyle={styles.itemContainer}
                    titleStyle={[index === 1 ? styles.selectedItem : styles.unSelectedItem, styles.tabTitleTxt]}
                    title="Tab2"/>
            </Tab>

            <VirtualizedView
                getRef={(ref) => {
                    setlistRef(ref);
                }}
                contentContainerStyle={GlobalStyle.bgTransparent}>

                    <TabView value={index} onChange={setIndex}>
                        <TabView.Item
                            onMoveShouldSetResponder={(e) => {
                                e.stopPropagation();
                                return e.isPropagationStopped();
                            }}
                            style={styles.tabView}>

                            <FlatList
                                keyExtractor={item => item?.id.toString()}
                                data={[{id: 1}, {id: 2}, {id: 3}, {id: 4}, {id: 5}, {id: 6},]}
                                renderItem={({item}) => <ExchangeBox/>}

                            />
                        </TabView.Item>

                        <TabView.Item style={styles.tabView}>
                            <StyledText>Recent</StyledText>
                        </TabView.Item>
                    </TabView>
            </VirtualizedView>
        </View>
    )
}

hope it helps

Read more comments on GitHub >

github_iconTop Results From Across the Web

Flat List Not Scrolling in TabView (React Native Elements)
Under the TabView, I have a FlatList , the list appears but it is not able to scroll, I have tried implementing flex:...
Read more >
ScrollView - React Native
This is where FlatList comes into play. FlatList renders items lazily, when they are about to appear, and removes items that scroll way...
Read more >
react-native-tab-view - npm
Smooth animations and gestures; Scrollable tabs ; Custom Tab Bar · Lazy Load ; index : a number representing the index of the...
Read more >
Common bugs in React Native ScrollView and how to fix them
Because FlatList only renders elements that are currently showing on the screen — not all the elements at once — it is capable...
Read more >
react-native-scrollable-tab-view - Bountysource
The items of FlatList are wrapped inside a TouchableWithoutFeedback with onPress property. Scrolling vertical (witch is FlatList responsible for) is OK and the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found