我有一個我想要放置在FlatList(即ScrollView)中的數據列表,並且每當我嘗試向下滾動以查看更多列表時,ScrollView都會跳回到列表的頂部,所以我永遠不會看到列表的底部。React Native ScrollView/FlatList不滾動
我正在使用世博會和奇怪的是,如果我只是創建一個新項目或複製/粘貼一些代碼到Snack中,那麼滾動工作就好了。只有在我目前的項目中,我無法滾動列表。我甚至進入了main.js
文件,並在那裏粘貼了我的示例代碼,問題仍然存在。
我的示例代碼位於:https://snack.expo.io/ryDPtO5-b 我已經將這個確切的代碼粘貼到我的項目中,並且它不按預期工作。
版本: RN 0.44/ 世博SDK 17.0.0/ 陣營:16.0.0-alpha.6
我的實際使用情況爲我的項目涉及在的底部,第三放置FlatList組件屏幕顯示作業列表。這是我發現錯誤的地方,以及何時開始嘗試和調試問題。在項目中,我有一個父View
與{flex: 1
與List
孩子包含FlatList
風格... List
來自react-native-elements
編輯
這裏是我真正想使用的代碼:
<View style={styles.container}>
<View style={containerStyles.headerContainerStyle}>
<Text style={[textStyles.h2, { textAlign: 'center' }]}>
Territory: {this.props.currentTerritory}
</Text>
</View>
<View style={styles.mapContainer}>
<MapView
provider="google"
onRegionChangeComplete={this.onRegionChangeComplete}
region={this.state.region}
style={{ flex: 1 }}
>
{this.renderMapMarkers()}
</MapView>
</View>
<Badge containerStyle={styles.badgeStyle}>
<Text>Orders Remaining: {this.props.jobsList.length}</Text>
</Badge>
<List containerStyle={{ flex: 1 }}>
<FlatList
data={this.props.jobsList}
keyExtractor={item => item.id}
renderItem={this.renderJobs}
removeClippedSubviews={false}
/>
</List>
</View>
我所有的風格
const styles = StyleSheet.create({
container: {
flex: 1,
},
mapContainer: {
height: 300,
},
badgeStyle: {
backgroundColor: 'green',
alignSelf: 'center',
marginTop: 15,
width: 300,
height: 35,
},
});
,最後,我renderItem功能:
renderJobs = ({ item }) => {
const { fullAddress, pickupTime } = item;
return (
<ListItem
containerStyle={item.status === 'active' && { backgroundColor: '#7fbf7f' }}
title={fullAddress}
titleStyle={{ fontSize: 14 }}
subtitle={pickupTime}
subtitleStyle={{ fontSize: 12, color: 'black' }}
onPress={() => this.props.navigation.navigate('jobActions', { job: item })}
/>
);
}
不要提供外部鏈接到您的代碼。創建一個MCVE代替:https://stackoverflow.com/help/mcve – CinCout