react-native 封装一个可以滑动的步骤条 Step

可以根据prop (step)滑动 到指定位置,可以左右滑动
在这里插入图片描述
在这里插入图片描述

import React, { Component } from "react";
import {
  Text,
  View,
  StyleSheet,
  ScrollView,
  TouchableOpacity
} from "react-native";
import { scaleSizeW, setSpText } from "../utils/util";

export default class ProcessBar extends Component {
  constructor(props) {
    super(props);
    this.state = {
      step: props.step,
      stateArr: [
        { id: 1, name: "开始" },
        { id: 2, name: "补全工商信息" },
        { id: 3, name: "录入工商结果" },
        { id: 4, name: "收件刻章" },
        { id: 5, name: "证件邮寄" },
        { id: 6, name: "代客户签收" }
      ]
    };
  }
  componentWillReceiveProps(nextProps) {
    this.setState({
      step: nextProps.step
    });
  }
  componentDidMount() {
    if (this.state.step > 3) {
      setTimeout(() => {
        this._scrollView.scrollTo({ x: 500, y: 0, animated: true });
      }, 0);
    }
  }
  // 用于二期跳转页面 (在stateArr添加页面的screen)
  goStepPage = item => {};
  render() {
    const { stateArr, step } = this.state;
    return (
      <ScrollView
        horizontal
        showsHorizontalScrollIndicator={false}
        ref={ref => (this._scrollView = ref)}
        style={styles.scrollView}
        contentContainerStyle={styles.scrollViewContent}
      >
        {stateArr.map((item, index) => (
          <TouchableOpacity
            style={[
              styles.stepItem
            ]}
            key={item.id}
            onPress={item => {
              this.goStepPage(item);
            }}
            activeOpacity={1}
          >
            <View style={[styles.stepNumBox,step >= item.id && styles.stepNumBoxActive]}>
              <Text style={[styles.stepNum,step >= item.id && styles.stepNumActive]}>{item.id}</Text>
            </View>
            <Text style={[styles.stepName,step >= item.id && styles.stepNameActive]}>{item.name}</Text>
            {index + 1 < stateArr.length && (
              <Text style={[styles.stepIcon,step >= item.id && styles.stepIconActive]}>{"\ue633"}</Text>
            )}
          </TouchableOpacity>
        ))}
      </ScrollView>
    );
  }
}

let styles = StyleSheet.create({
  scrollView: {
    width: "100%",
    height: scaleSizeW(106),
    backgroundColor: "white"
  },
  scrollViewContent: {
    height: "100%",
    flexDirection: "row",
    flexWrap: "nowrap",
    alignItems: "center"
  },
  stepItem: {
    height: "100%",
    flexDirection: "row",
    alignItems: "center",
    justifyContent: "space-around"
  },
  stepNumBox: {
    width: scaleSizeW(40),
    height: scaleSizeW(40),
    borderRadius: scaleSizeW(20),
    justifyContent: "center",
    alignItems: "center",
    backgroundColor: "#f5f9ff"
  },
  stepNumBoxActive: {
    backgroundColor: "#FF6737"
  },
  stepNum: {
    color: "#9DAAB8",
    fontSize: setSpText(28)
  },
  stepNumActive:{
    color:'white'
  },
  stepName: {
    fontSize: setSpText(20),
    color: "#6f7d8a",
    marginHorizontal:scaleSizeW(10)
  },
  stepNameActive:{
   color:"#FF6737"
  },
  stepIcon: {
    fontFamily: "iconfont",
    fontSize: setSpText(16),
    color:'#9DAAB8',
    marginRight:scaleSizeW(10)
  },
  stepIconActive:{
    color:'#FF6737'
  }
});

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值