React 本机 ScrollView 不滚动
React native ScrollView is not scrolling
我试过使用 Flatlist 也没有用。在 FlatList 上它不会显示图像,所以我无法测试它。在 ScrollView 上它正在显示,但它不滚动。这是我的代码,请帮忙:
import { ScrollView, StyleSheet, View, Image } from "react-native";
import React from "react";
const StylistFeatures = ({ businessFeatures }) => {
const { wifi, walkIn, appointments, toHome, celebrityStylist, covidMask } =
businessFeatures;
return (
<View
style={{
alignSelf: "center",
flexDirection: "row",
width: "100%",
height: "14%",
}}
>
<ScrollView
horizontal
scrollEnabled
showsHorizontalScrollIndicator={false}
contentContainerStyle={styles.contentContainerFlatListStyle}
style={{ flexGrow: 1, padding: 10 }}
>
<View style={styles.imageContainerStyle}>
{wifi ? (
<Image
source={require("../assets/images/design-icon/wifi.png")}
style={styles.imageStyle}
/>
) : null}
</View>
<View style={styles.imageContainerStyle}>
{walkIn ? (
<Image
source={require("../assets/images/design-icon/walk.png")}
style={styles.imageStyle}
/>
) : null}
</View>
<View style={styles.imageContainerStyle}>
{appointments ? (
<Image
source={require("../assets/images/design-icon/calendar.png")}
style={styles.imageStyle}
/>
) : null}
</View>
<View style={styles.imageContainerStyle}>
{toHome ? (
<Image
source={require("../assets/images/design-icon/car.png")}
style={styles.imageStyle}
/>
) : null}
</View>
<View style={styles.imageContainerStyle}>
{celebrityStylist ? (
<Image
source={require("../assets/images/design-icon/celebrity.png")}
style={styles.imageStyle}
/>
) : null}
</View>
<View style={styles.imageContainerStyle}>
{covidMask ? (
<Image
source={require("../assets/images/design-icon/safety-mask.png")}
style={styles.imageStyle}
/>
) : (
<Image
source={require("../assets/images/design-icon/no-mask.png")}
style={styles.imageStyle}
/>
)}
</View>
</ScrollView>
</View>
);
};
export default StylistFeatures;
const styles = StyleSheet.create({
contentContainerFlatListStyle: {
width: "100%",
alignItems: "center",
height: "100%",
},
imageStyle: {
width: 40,
height: 40,
margin: 5,
},
imageContainerStyle: {
marginRight: 12,
borderColor: "black",
borderWidth: 1,
borderRadius: 10,
},
});
请帮帮我,有什么原因吗?创建无滚动是不是有什么不好的地方?
截图如下:
尝试删除“contentContainerFlatListStyle”width 属性,然后重试。如下图。它应该工作。让我知道进展如何。
contentContainerFlatListStyle: {
alignItems: "center",
height: "100%",
},
我试过使用 Flatlist 也没有用。在 FlatList 上它不会显示图像,所以我无法测试它。在 ScrollView 上它正在显示,但它不滚动。这是我的代码,请帮忙:
import { ScrollView, StyleSheet, View, Image } from "react-native";
import React from "react";
const StylistFeatures = ({ businessFeatures }) => {
const { wifi, walkIn, appointments, toHome, celebrityStylist, covidMask } =
businessFeatures;
return (
<View
style={{
alignSelf: "center",
flexDirection: "row",
width: "100%",
height: "14%",
}}
>
<ScrollView
horizontal
scrollEnabled
showsHorizontalScrollIndicator={false}
contentContainerStyle={styles.contentContainerFlatListStyle}
style={{ flexGrow: 1, padding: 10 }}
>
<View style={styles.imageContainerStyle}>
{wifi ? (
<Image
source={require("../assets/images/design-icon/wifi.png")}
style={styles.imageStyle}
/>
) : null}
</View>
<View style={styles.imageContainerStyle}>
{walkIn ? (
<Image
source={require("../assets/images/design-icon/walk.png")}
style={styles.imageStyle}
/>
) : null}
</View>
<View style={styles.imageContainerStyle}>
{appointments ? (
<Image
source={require("../assets/images/design-icon/calendar.png")}
style={styles.imageStyle}
/>
) : null}
</View>
<View style={styles.imageContainerStyle}>
{toHome ? (
<Image
source={require("../assets/images/design-icon/car.png")}
style={styles.imageStyle}
/>
) : null}
</View>
<View style={styles.imageContainerStyle}>
{celebrityStylist ? (
<Image
source={require("../assets/images/design-icon/celebrity.png")}
style={styles.imageStyle}
/>
) : null}
</View>
<View style={styles.imageContainerStyle}>
{covidMask ? (
<Image
source={require("../assets/images/design-icon/safety-mask.png")}
style={styles.imageStyle}
/>
) : (
<Image
source={require("../assets/images/design-icon/no-mask.png")}
style={styles.imageStyle}
/>
)}
</View>
</ScrollView>
</View>
);
};
export default StylistFeatures;
const styles = StyleSheet.create({
contentContainerFlatListStyle: {
width: "100%",
alignItems: "center",
height: "100%",
},
imageStyle: {
width: 40,
height: 40,
margin: 5,
},
imageContainerStyle: {
marginRight: 12,
borderColor: "black",
borderWidth: 1,
borderRadius: 10,
},
});
请帮帮我,有什么原因吗?创建无滚动是不是有什么不好的地方?
截图如下:
尝试删除“contentContainerFlatListStyle”width 属性,然后重试。如下图。它应该工作。让我知道进展如何。
contentContainerFlatListStyle: {
alignItems: "center",
height: "100%",
},