reactjs - 组件在另一个组件下呈现
问题描述
我的标签组件由渲染的文本和一个文本输入组件组成,在另一个组件下渲染,我的按钮并且表现得非常奇怪。
如果您查看 gif,您还可以看到,从第二行开始的标签也没有被我的容器样式包裹。
我做了一个gif,应该更容易看到:) http://www.giphy.com/gifs/JmD2VWAXU3S12LQ0Ya
const styles = StyleSheet.create({
textInput: {
flex: 1,
borderRadius: 8,
paddingLeft: 9,
paddingRight: 9,
height: 30,
marginRight: 15,
},
tagContainer: {
flexDirection: 'row',
flexWrap: 'wrap'
},
tags: {
backgroundColor: "#9AA5B1",
borderRadius: 8,
paddingLeft: 9,
paddingRight: 9,
paddingTop: 4,
paddingBottom: 4,
marginRight: 10,
marginBottom: 4,
flexDirection: "row",
},
text: {
color: "white",
},
container: {
backgroundColor: '#F5F7FA',
borderRadius: 8,
paddingLeft: 9,
paddingRight: 9,
height: 30,
marginRight: 15,
flexDirection: "row",
flexWrap: "wrap",
},
});
renderTags1 = (tag, index, deleteTag) => {
return (
<TouchableOpacity
onPress={index => deleteTag(index)}
style={styles.tags}
key={`${tag}-${index}`}
>
<Text style={styles.text}>{tag}</Text>
</TouchableOpacity>
);
};
const InputTags = ({ tags, value, onChangeText, deleteTag }) => {
return (
<View style={styles.container}>
<View style={styles.tagContainer}>
{tags.map((tag, index) => {
return this.renderTags1(tag, index, deleteTag);
})}
</View>
<TextInput
style={styles.textInput}
placeholder="Outdoor"
onChangeText={text => onChangeText({ text })}
value={value}
autoCorrect={false}
multiline={true}
/>
</View>
);
};
export { InputTags };
对于我的按钮:
import React from 'react';
import { Text, TouchableOpacity, StyleSheet } from 'react-native';
const styles = StyleSheet.create({
view: {
backgroundColor: '#E12D39',
width: 280,
height: 50,
justifyContent: 'center',
alignSelf: 'center',
borderRadius: 10,
marginTop: 40,
marginBottom: 40,
},
text: {
alignSelf: 'center',
fontFamily: 'OpenSans-Semibold',
fontSize: 22,
color: 'white',
},
});
const SearchButton = ({ onPress, text }) => {
return (
<TouchableOpacity style={styles.view} onPress={onPress}>
<Text style={styles.text}>{text}</Text>
</TouchableOpacity>
);
};
export { SearchButton };
预期的行为是按钮下降。试图删除每一个 flex 属性,但还不能完全弄清楚
解决方案
包装时似乎高度没有增加,可以通过将容器 bg 设置为不同颜色来确认
看起来您将高度硬编码为 30,这可能是导致错误的原因
推荐阅读
- typescript - ApolloClient Typescript 高阶组件问题(不可分配给类型)
- java - 如何序列化 JComboBox 选择?
- r - ggplotly 图形在 jupyterlab 中无法正确显示
- python - 尝试在 Python 的循环中使用 .csv 文件填充嵌套字典
- r - 如何连接 R 数据框的特定值
- node.js - 如何在expressjs回调中以阻塞模式调用猫鼬?
- reactjs - 为 React Context 实现 useSelector 等效项?
- groovy - 将 Cucumber 结果导入 Jira/Xray
- java - Spring Boot:Json 响应未映射到实体
- python - 在 Python 3.6.8 中使用原始转义字符将字符串写入文件