【发布时间】:2021-09-08 13:13:54
【问题描述】:
您将如何使用组件来通知用户他们在哪一步?我有这样的设置:
import React from 'react';
import {View, Text, StyleSheet} from 'react-native';
import styled from 'styled-components/native';
const ProgressBar = () => {
return (
<View style={styles.wrapper}>
<View style={styles.stepWrapper}>
<Bar />
<Text style={styles.stepText}>1. Photo</Text>
</View>
<View style={styles.stepWrapper}>
<Bar />
<Text style={styles.stepText}>2. Details</Text>
</View>
<View style={styles.stepWrapper}>
<Bar />
<Text style={styles.stepText}>3. Price</Text>
</View>
<View style={styles.stepWrapper}>
<Bar />
<Text style={styles.stepText}>4. Finish</Text>
</View>
</View>
);
};
const Bar = styled.View`
border: 1px solid red;
`;
const styles = StyleSheet.create({
wrapper: {
flexDirection: 'row',
},
stepWrapper: {
textAlign: 'center',
justifyContent: 'center',
width: '25%',
},
stepText: {
textAlign: 'center',
padding: 10,
fontSize: 13,
},
});
export default ProgressBar;
这会输出这个:
但是这个页面应该是第三步(3.价格)。由于类名,一切都是红色的,但我很好奇如何设置它,以便我可以将此组件插入每个屏幕并传递步骤的数字道具或其他东西。
可能是这样的:
<ProgressBar step={3} />
也许在我的组件中,我可以将所有颜色更改为<Bar /> 的第三个元素,或者是否有更优雅的方式?
【问题讨论】: