Skip to content

Instantly share code, notes, and snippets.

@moretti
Created August 9, 2019 21:53
Show Gist options
  • Save moretti/89c40ee23e54f8576ba3d87b937774c2 to your computer and use it in GitHub Desktop.
Save moretti/89c40ee23e54f8576ba3d87b937774c2 to your computer and use it in GitHub Desktop.
react-native-tab-view ScrollView bug
import React, { useState } from 'react';
import {
Dimensions,
FlatList,
SafeAreaView,
ScrollView,
Text,
View,
} from 'react-native';
import { TabView, SceneMap } from 'react-native-tab-view';
const flatListData = [...Array(100).keys()].map(n => ({
key: n.toString(),
name: `Item ${n}`,
}));
const FirstRoute = () => (
<FlatList
style={{ flex: 1, backgroundColor: '#ff4081' }}
data={flatListData}
renderItem={({ item }) => <Text>{item.name}</Text>}
onEndReachedThreshold={0.5}
onEndReached={() =>
alert('onEndReached: should not fire without scrolling down')
}
/>
);
const SecondRoute = () => (
<View style={{ flex: 1, backgroundColor: '#673ab7' }} />
);
const routes = [
{ key: 'first', title: 'First' },
{ key: 'second', title: 'Second' },
];
export default function App() {
const [activeTabIndex, setActiveTabIndex] = useState(0);
return (
<SafeAreaView style={{ flex: 1 }}>
<ScrollView>
<TabView
navigationState={{ index: activeTabIndex, routes }}
renderScene={SceneMap({
first: FirstRoute,
second: SecondRoute,
})}
onIndexChange={setActiveTabIndex}
initialLayout={{ width: Dimensions.get('window').width }}
/>
</ScrollView>
</SafeAreaView>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment