javascript - SectionList 的内容从 Web 浏览器可见,但在 iOS 中不可见
问题描述
在构建 SectionList 并用信息填充它时,我在使用 React-Native 时遇到了麻烦。它似乎在网络浏览器 (Chrome) 上显示良好,如此处所示。
但是,在 iOS 模拟器/设备上查看内容时,情况似乎并非如此。部分标题会显示,但内容不会。这是直接来自我的设备的屏幕截图。
这是用于每张卡的代码:
const Card = (props) => {
return (
<View>
<Text style={styles.english}>{props.english}</Text>
<Text style={styles.other}>{props.other}</Text>
</View>
);
}
..这是SectionList的代码:
export default function App() {
return (
<View style={styles.container}>
<SectionList sections= {[{
title: "English", data:
[
<Card english="English0" other="Other0"/>,
<Card english="English1" other="Other1"/>,
<Card english="English2" other="Other2"/>,
]
}]}
renderItem={
({item}) => <Text style={styles.box}>{item}</Text>
}
renderSectionHeader={({section}) => <Text style={styles.sectionHeader}>{section.title}</Text>}
keyExtractor={(item, index) => index}
/>
</View>
);
}
此外,样式表:
const styles = StyleSheet.create({
container: {
flex: 1,
padding: 5,
backgroundColor:"#f1faee",
},
box: {
marginBottom: 10,
padding: 10,
height: 150,
width: "95%",
backgroundColor:"#1d3557",
borderColor:"#000000",
shadowOffset:{ width: 3, height: 3},
shadowColor: 'black',
shadowOpacity: 0.4,
borderRadius: 15,
justifyContent: "center",
},
english: {
color:"#f1faee",
fontSize: 30,
},
other: {
color:"#f1faee",
fontSize: 50,
},
sectionHeader: {
paddingTop: 2,
paddingLeft: 10,
paddingRight: 10,
paddingBottom: 2,
fontSize: 14,
fontWeight: 'bold',
backgroundColor: "#f1faee"
}
});
有谁知道为什么会这样,我是否遗漏了一些明显的东西?提前道歉,因为这是我第一天使用 web/react-native 开发。如果有人能把我引向正确的方向,那将不胜感激。谢谢!
解决方案
对于那个很抱歉。我找到了答案,我不需要将 View 包裹在 Card 周围。JSX <> </> 足够合适,并设法让它工作。
const Card = (props) => {
return (
<>
<Text style={styles.english}>{props.english}{"\n"}</Text>
<Text style={styles.other}>{props.other}</Text>
</>
);
}
推荐阅读
- jquery - 更改所选分组单选按钮的背景
- angular - Angular2+ 将所有组件 css/scss 捆绑到一个文件中
- jquery - IE11 window.scroll 出现问题...但又不是
- python - 如何将我的 python 代码转换为在 GPU 而不是 CPU 上运行?
- html - 将 tabindex 附加到标题
- apache-kafka - 同一个消费组的两个消费者,只有一个实际消费,一个空闲
- node.js - 如何在 Digital Ocean 上安装 nodejs 应用程序
- rxjs - 来自不同管道的 RxJs globalState
- javascript - Mapbox line-pattern 扭曲了图像
- excel - 如何填充在第 52 周后的第 1 周重新开始的周数数组?