簡體   English   中英

平面列表不滾動反應本機

[英]Flatlist not scrolling react native

出於某種原因,我的平面列表沒有滾動,我不確定為什么。 希望得到任何提示:這是平面列表的代碼:

return (
      <Layout>
        <View style={styles.header}>
          <Text size="h1">Explore</Text>
        </View>
            <FlatList contentContainerStyle={styles.cards} data={events} renderItem={({item}) =>
                <EventCard event={item} keyExtractor={event => event.id} click={() => {
                navigation.navigate("FullCard", {
                  event: item
                });
                }}/>
            } />
      </Layout>
    );
}

const styles = StyleSheet.create({
  header: {
    padding: 10,
    display: "flex",
    marginBottom: 10
  },

  cards: {
      alignItems: "center",
      height: Dimensions.get('window').height/1.2
  },
});

這是導入平面列表的主頁:

export default function ({ navigation }) {
    return (
            <NavigationContainer independent={true}>
                <Stack.Navigator initialRouteName="Explore">
                    <Stack.Screen name="Explore" options={{headerShown: false}}>
                        {props => <Explore {...props}/>}
                    </Stack.Screen>
                    <Stack.Screen name="FullCard" options={{headerShown: false}}>
                        {props => <FullCard {...props}/>}
                    </Stack.Screen>
                </Stack.Navigator>
            </NavigationContainer>
        );
}

太感謝了!

直接在Stack.Screen中給你組件, props會自動訪問你的屏幕。

export default function ({ navigation }) {
    return (
            <NavigationContainer independent={true}>
                <Stack.Navigator initialRouteName="Explore">
                    <Stack.Screen name="Explore" options={{headerShown: false}} component={Explore}/>
                    <Stack.Screen name="FullCard" options={{headerShown: false}} component={FullCard}/>
                </Stack.Navigator>
            </NavigationContainer>
        );
}

FlatList contentContainerStyle樣式應如下所示

const styles = StyleSheet.create({
  header: {
    padding: 10,
    display: "flex",
    marginBottom: 10
  },
  cards: {
      flex:1,
      alignItems: "center",
  },
});

   

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM