[英]React Native Paper ProgressBar Not visible
Hello i was following along a tutorial and it was going fine, until the tutor used react-native-paper ProgressBar in his project, I wrote exactly same but it was not visible, I found the documentation and plugged it, still not visible.您好,我正在关注一个教程,一切顺利,直到导师在他的项目中使用 react-native-paper ProgressBar,我写的完全一样,但它不可见,我找到了文档并插入它,仍然不可见。
What am i Doing wrong?我究竟做错了什么?
import {View, StyleSheet, Text} from 'react-native' ;
import { ProgressBar, Colors } from 'react-native-paper';
import CountDown from '../comps/CountDown.js' ;
const Timer = ({task}) => {
return (
<View style={styles.container}>
<CountDown />
<Text style={styles.text}> Focusing On:</Text>
<Text style={[styles.text, styles.textBold]}> {task} </Text>
<ProgressBar progress={0.4} color='#5E84E2' style={styles.progress}/>
</View>
) ;
}
const styles = StyleSheet.create({
container : {
flex: 1,
width: 100,
alignItems: 'center' ,
justifyContent: 'center',
paddingTop: 40,
},
text: {
// flex: 0.5,
color: 'white'
},
textBold: {
fontWeight: 'bold' ,
// borderColor: 'white',
// borderWidth: 1,
// borderStyle: 'solid' ,
},
progress: {
height: 10,
// borderColor: 'white',
// borderWidth: 1,
// borderStyle: 'solid' ,
}
}) ;
export default Timer ;
Also, If i were to Give border to the progressBar, it appears but keep on increasing in width even when width is more than the viewport width.另外,如果我要给进度条提供边框,它会出现,但即使宽度大于视口宽度,它也会继续增加宽度。 I dont know what is happening
我不知道发生了什么
The problem here is when you use alignItems the children components need to have a fixed width, your progress bar doesnet have a fixed width.这里的问题是,当您使用 alignItems 时,子组件需要具有固定宽度,而您的进度条确实具有固定宽度。
You will have to provide a with in the styles.您必须在 styles 中提供一个。
progress: {
height: 10,
width:50
}
Based on documentation default value for width is根据文档,宽度的默认值为
auto (default value) React Native calculates the width/height for the element based on its content, whether that is other children, text, or an image.
auto (默认值) React Native 根据其内容计算元素的宽度/高度,无论是其他子元素、文本还是图像。
Better have a value for width which will solve your issue.最好有一个宽度值,这将解决您的问题。
Currently ProgressBar
doesn't support the flex
styling system.目前
ProgressBar
不支持flex
样式系统。 If someone is also looking to make the width equal to 100% if it's parrent component, there is a good recommended solution provided here .如果有人还希望宽度等于 100%(如果它是父组件),那么这里提供了一个很好的推荐解决方案。
Just set the width to undefined :只需将宽度设置为undefined :
progress: {
height: 10,
width:undefined
}
eg例如
<View style={{ flex: 2, other flex styles }}>
<ProgressBar progress={0.5} color="white" style={{ height: 5, width: undefined }} />
</View>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.