gpt4 book ai didi

React-native 导航进度条

转载 作者:行者123 更新时间:2023-12-05 06:39:01 24 4
gpt4 key购买 nike

我是 React-native 的新手,任何人都可以告诉我如何创建带有进度条的标题菜单,就像附图一样。非常感谢任何建议...

我已经取得了进步,如何去除每一步之间的空格?

enter image description here

   <View style={styles.stepIndicatorBox}>
{stepsIds.map((step, idx) => {
const words = steps[step].split(' ');
const activeStepStyle = step === activeStep && styles.activeStep;
return (
<View key={`${step}${idx}`}>
<Svg height="25" width="100">
<Line
x1="10"
y1="10"
x2="100"
y2="10"
stroke={theme.colors.blue}
strokeWidth="2"
/>
<Circle
cx="50"
cy="10"
r="3"
stroke={theme.colors.blue}
strokeWidth="2.5"
fill={theme.colors.lightBlue}
/>
</Svg>
{words.map(w =>
<Text style={[styles.stepName, activeStepStyle]}>
{w}
</Text>
)}
</View>
);
})}
</View>

我的风格是:

const styles = StyleSheet.create({
sceneContainer: {
bottom: 0,
left: 0,
position: 'absolute',
right: 0,
top: 0,
},
stepIndicatorBox: {
height: theme.utils.em(4),
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
backgroundColor: theme.colors.lightBlue,
paddingHorizontal: theme.metrics.mainPadding,
},
activeStep: {
...theme.fontStyles.smallBold,
color: theme.colors.activeStepName,
fontWeight: 'bold',
},
stepName: {
...theme.fontStyles.small,
color: theme.colors.blue,
textAlign: 'center',
},
});

最佳答案

我使用了以下代码和react-native-svg:

_renderStepIndicator = () => {
const { navigation } = this.props; // {dispatch}
const { steps, getStep } = stepsOptions;

const route = navigation.state.routes[navigation.state.routes.length - 1];
const activeStep = getStep(route.routeName);
const stepsIds = Object.keys(steps);
const { height, width } = Dimensions.get('window');

const stepWidth = width / 5;

const RouteComponent = StepIndicatorRouter.getComponentForRouteName(
route.routeName
);

if (RouteComponent.navigatorType === STEP_INDICATOR) {
return null;
}

return (
<View style={styles.stepIndicatorBox}>
{stepsIds.map((step, idx) => {
const words = steps[step].split(' ');
const activeStepStyle = step === activeStep && styles.activeStep;

return (
<View key={`${step}${idx}`} style={styles.stepIndicatorStep}>
<Svg height="25" width={stepWidth}>
<Line
x1="0"
y1="15"
x2={stepWidth}
y2="15"
stroke={theme.colors.blue}
strokeWidth="2"
/>
<Circle
cx="40"
cy="15"
r="3"
stroke={theme.colors.blue}
strokeWidth="2"
fill={
step === activeStep
? theme.colors.blue
: theme.colors.lightBlue
}
/>
</Svg>
{words.map(w =>
<Text style={[styles.stepName, activeStepStyle]}>
{w}
</Text>
)}
</View>
);
})}
</View>
);
};

关于React-native 导航进度条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45234767/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com