css - React Native Flex 不会填充宽度相等
问题描述
我创建了一个自定义组件,它只是一个计数器,但有一个小样式错误。我尝试了很多东西,但我找不到任何解决方案。你能告诉我有什么问题和解决方法吗?
我添加了 3 可触摸的不透明度。他们有弹性: 1. 当我给它的父级提供背景颜色时,它会改变所有需要填充的区域。我需要做的是所有对象背景必须相等。
import React, { Component } from "react";
import { StyleSheet, View, Text, ViewPropTypes} from "react-native";
import { TouchableOpacity } from "react-native-gesture-handler";
import PropTypes from "prop-types";
class Counter extends Component{
constructor(props){
super(props);
this.style = StyleSheet.create({
topContainer:{
flex:1,
width:"100%",
flexDirection:"column",
alignItems:"center",
justifyContent:"center"
},
topPanel:{
flex:1,
flexDirection:"row",
alignItems:"center",
justifyContent:"center",
width:"100%",
},
bottomPane:{
flex:1,
flexDirection:"row",
width:"100%",
alignItems:"center",
justifyContent:"center",
},
buttonStyle:{
flex:1,
alignItems:"center",
justifyContent:"center",
},
});
}
static propTypes = {
backgroundStyle : ViewPropTypes.style,
textStyle: Text.propTypes.style,
buttonBackground: ViewPropTypes.style,
returnFunc: PropTypes.func,
};
/*
this.props =
{"buttonBackground":{"backgroundColor":"#cc99ff","borderRadius":20,"margin":4},
"backgroundStyle":{"backgroundColor":"#cc99ff","borderRadius":20,"margin":4},
"textStyle":{"fontSize":25.919999999999995,"textAlign":"center","color":"#ffffff"}}
*/
render(){
console.log("Counter:56 " , JSON.stringify(this.props));
return(
<View style = {this.style.topContainer}>
<View style={[this.style.topPanel,this.props.backgroundStyle]}>
<Text style={this.props.textStyle}>2</Text>
</View>
<View style={this.style.bottomPane}>
<TouchableOpacity style={[this.style.buttonStyle,this.props.buttonBackground]}>
<Text style={this.props.textStyle}>Increment</Text>
</TouchableOpacity>
<TouchableOpacity style={[this.style.buttonStyle,this.props.buttonBackground]}>
<Text style={this.props.textStyle}>Decrement</Text>
</TouchableOpacity>
<TouchableOpacity style={[this.style.buttonStyle,this.props.buttonBackground]}>
<Text style={this.props.textStyle}>Save</Text>
</TouchableOpacity>
</View>
</View>
);
}
}
export default Counter;
这是该组件的所有代码。所有样式都有弹性。我不知道它为什么这样做。
感谢所有帮助。
解决方案
似乎问题出在TouchableOpacity
from react-native-gesture-handler
。
尝试TouchableOpacity
从react-native
import { StyleSheet, View, Text, ViewPropTypes, TouchableOpacity } from "react-native";
推荐阅读
- julia - 我们如何在 Julia 中运行脚本
- r - 如何在 r 中将单个点绘制到 ggplot 图上?
- spring-boot - Issue loading external properties(which is added to classpath) in springboot
- arrays - 如何移植使用“${@:2}”?
- arrays - 按 asc 顺序排序 Fileinfo 列表
- c# - 通过代码从 Nhibernate 映射中的单个类 Map 生成多个物理表
- android - com.android.shell was not granted this permission: android.permission.WRITE_SETTINGS
- javascript - 如何根据目录中的视频制作自动填充的视频库?
- html - HTML form- check boxes programmatically
- spring-data-mongodb - Excluding bad data models during query