Reactjs 如何使用Flatlist react native创建全幅面卡
我不知道为什么我的卡不是全宽的 我现在: 我希望卡片是全宽的 这是我的密码Reactjs 如何使用Flatlist react native创建全幅面卡,reactjs,react-native,native-base,Reactjs,React Native,Native Base,我不知道为什么我的卡不是全宽的 我现在: 我希望卡片是全宽的 这是我的密码 return ( <View style={styles.container}> <View> <Text style={{fontWeight: 'bold', fontSize: 20}}>Cateogories:</Text> <FlatGrid itemDime
return (
<View style={styles.container}>
<View>
<Text style={{fontWeight: 'bold', fontSize: 20}}>Cateogories:</Text>
<FlatGrid
itemDimension={90}
items={items}
style={styles.gridView}
renderItem={({item, index}) => (
<TouchableOpacity>
<View
style={[styles.itemContainer, {backgroundColor: item.code}]}>
<Text style={styles.itemName}>{item.name}</Text>
<Image style={styles.iconSize} source={item.picture} />
</View>
</TouchableOpacity>
)}
/>
</View>
<FlatList
data={DATA}
showsHorizontalScrollIndicator={false}
horizontal={false}
keyExtractor={item => item.id}
renderItem={({item}) => {
return (
<List>
<ListItem noBorder style={{flex: 1}}>
<View style={{flex: 1}}>
<Card style={{flex: 1}}>
<CardItem style={{flex: 1}}>
<Left>
<Thumbnail
source={{
uri:
'https://www.foodbusinessafrica.com/wp-content/uploads/2019/04/milled-rice.jpg',
}}
/>
<Body>
<Text>NativeBase</Text>
<Text note>GeekyAnts</Text>
</Body>
</Left>
</CardItem>
<CardItem cardBody>
<Image
source={{
uri:
'https://www.foodbusinessafrica.com/wp-content/uploads/2019/04/milled-rice.jpg',
}}
style={{height: 200, width: null, flex: 1}}
/>
</CardItem>
<CardItem>
<Left>
<Button transparent>
<Icon active name="thumbs-up" />
<Text>12 Likes</Text>
</Button>
</Left>
<Body>
<Button transparent>
<Icon active name="chatbubbles" />
<Text>4 Comments</Text>
</Button>
</Body>
<Right>
<Text>11h ago</Text>
</Right>
</CardItem>
</Card>
</View>
</ListItem>
</List>
);
}}
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
title: {
alignSelf: 'flex-end',
color: '#638A37',
fontSize: 15,
},
rowItem: {
flexDirection: 'row',
},
itemContainer: {
borderRadius: 10,
padding: 10,
height: 128,
borderWidth: 1,
borderColor: '#ddd',
borderBottomWidth: 0,
shadowColor: '#000',
shadowOffset: {width: 0, height: 5},
shadowOpacity: 0.8,
shadowRadius: 2,
elevation: 10,
marginLeft: 5,
marginRight: 5,
marginTop: 10,
},
itemName: {
// color: '#5E782F',
fontSize: 22,
},
iconSize: {
alignSelf: 'flex-end',
marginTop: 27,
paddingLeft: 20,
width: 56,
height: 56,
},
});
尝试在标记中添加宽度:100
<Card style={{flex: 1, width: 100}}/>
尝试在标记中添加宽度:100
<Card style={{flex: 1, width: 100}}/>
全幅卡片视图:
import 'react-native-gesture-handler';
import React from 'react';
import {Dimensions} from 'react-native';
import {Card} from 'react-native-elements';
const FullWidthCard = ({
gap = {horizontal: 0},
borderRadius = {topLeft: 0, topRight: 0},
children,
}) => {
return (
<Card
containerStyle={{
width: Dimensions.get('window').width - gap.horizontal,
borderTopLeftRadius: borderRadius.topLeft,
borderTopRightRadius: borderRadius.topRight,
children,
}}>
{children}
</Card>
);
};
export {FullWidthCard};
从UI组件:
<FullWidthCard
gap={{horizontal: 0}}
borderRadius={{topLeft: 50, topRight: 50}}>
<ProfileContent navigation={navigation}></ProfileContent>
</FullWidthCard>
全幅卡片视图:
import 'react-native-gesture-handler';
import React from 'react';
import {Dimensions} from 'react-native';
import {Card} from 'react-native-elements';
const FullWidthCard = ({
gap = {horizontal: 0},
borderRadius = {topLeft: 0, topRight: 0},
children,
}) => {
return (
<Card
containerStyle={{
width: Dimensions.get('window').width - gap.horizontal,
borderTopLeftRadius: borderRadius.topLeft,
borderTopRightRadius: borderRadius.topRight,
children,
}}>
{children}
</Card>
);
};
export {FullWidthCard};
从UI组件:
<FullWidthCard
gap={{horizontal: 0}}
borderRadius={{topLeft: 50, topRight: 50}}>
<ProfileContent navigation={navigation}></ProfileContent>
</FullWidthCard>