reactjs - React Native 中的任何东西都可以通过样式来实现吗?
问题描述
我想知道,因为我添加了一个名为“progressCircle”的组件并试图将其居中,但我应用的样式似乎没有影响它。
我注意到文档中有一个 outerCircleStyle 道具,这是否意味着我不能使用标准样式? https://github.com/MrToph/react-native-progress-circle
代码(ProgressCircle 是我想要居中的):
<View>
<StatusBarPlaceHolder style = {styles.bar}/>
<ProgressCircle style = {{flexDirection: 'row', alignItems: 'center'}}
percent={30}
radius={100}
borderWidth={12}
color="#3399FF"
shadowColor="#999"
bgColor="#fff"
>
<Text style={{ fontSize: 18, fontWeight: 'bold'}}>{'30%'}</Text>
</ProgressCircle>
<Card style = {styles.card}>
<Card.Content>
<Title style = {styles.cardTitle}>{test.macro}</Title>
<Text style= {styles.cardElements}>{test.title}</Text>
<Progress.Bar progress={0.7} width={200} height={10} />
</Card.Content>
<Card.Actions>
</Card.Actions>
</Card>
<Card style = {styles.card}>
<Card.Content>
<Title style = {styles.cardTitle}>{30}</Title>
<Text style= {styles.cardElements}>Carbs</Text>
<Progress.Bar progress={0.3} width={200} height={10} />
</Card.Content>
<Card.Actions>
</Card.Actions>
</Card>
</View>
样式表:
const styles = StyleSheet.create({
bar: {
justifyContent: 'flex-start',
},
card: {
justifyContent: 'center',
borderRadius: 30,
margin: 5
},
cardTitle: {
paddingTop: 20,
fontSize: 40,
fontWeight: 'bold',
},
cardElements:{
fontSize: 20,
paddingTop: 10,
fontWeight: 'bold',
flexDirection: 'row',
},
});
解决方案
我假设视图中存在某种冲突,因此我创建了一个单独的函数来包含进度条视图。在此函数中对其进行样式设置允许我对其应用样式。由于某种原因,在我的原始代码中呈现在卡片上方的任何内容都无法设置样式。
我的解决方案:
function MainProgress(){
return(
<View style = {styles.progressBar}>
<ProgressCircle style = {styles.progressBar}
percent={30}
radius={100}
borderWidth={12}
color="#3399FF"
shadowColor="#999"
bgColor="#fff"
>
<Text>{'30%'}</Text>
</ProgressCircle>
</View>
)
}
class HomeScreen extends React.Component {
render() {
return (
<View>
<StatusBarPlaceHolder/>
<MainProgress/>
推荐阅读
- android - 如何更改 Intent.ACTION_EDIT 的目标活动
- html - 使用蒙版在 div 上自定义底部边框
- python - SSH 上的 Selenium Chrome 浏览器
- sql - 当产品出现在临时表中时,根据临时所有类型的订单的记录更新语句主表
- python - kivy-按下 MDFloatingActionButtonSpeedDial 后如何添加功能
- python - Cloud Pub/Sub 订阅者 max_messages 不适用于消息排序
- r - R中的绘图点在错误的位置?
- python - 如何使用 python 请求和 BeautifulSoup 在网站上的 html 中查找隐藏值
- hl7-v2 - HL7 附加段
- amazon-web-services - 有没有办法导出 AWS RDS MySQL 数据库而不必将其导出到 S3?