import React, { Component } from 'react'; import { StyleSheet, Text, View, Modal, StyleProp, ViewStyle, Animated, Easing, TextStyle, } from 'react-native'; import appStyles, { Theme } from '../styles'; import { Button } from './buttons'; const globalPadding = px2dp(40); export interface ProgressBarProps { /** 当前进度 */ progress: number; /** 进度条颜色, 默认theme */ progressColor?: string; /** 进度条背景颜色, 默认fontColor_cc */ progressBgColor?: string; /** 进度变化动画时长, 默认100毫秒 */ progressAniDuration?: number; /** 进度条样式 */ progressStyle?: StyleProp; } class ProgressBar extends Component { _progressAni: any = new Animated.Value(0); totalWidth: number = 0; static defaultProps = { progress: 0, progressColor: Theme.theme, progressBgColor: Theme.fontColor_cc, progressAniDuration: 100, }; componentWillReceiveProps(nextProps) { if (nextProps.progress !== this.props.progress) { this._startAniProgress(); } } _startAniProgress() { const { progress, progressAniDuration } = this.props; // console.log(`动画进度: ${progress}`); if (progress >= 0 && this.totalWidth !== 0) { Animated.timing(this._progressAni, { toValue: progress * this.totalWidth, duration: progressAniDuration, easing: Easing.linear, }).start(); } } _onLayout = ({ nativeEvent: { layout: { width } } }) => { if (width > 0 && this.totalWidth !== width) { this.totalWidth = width; this._startAniProgress(); } } render() { const h = px2dp(20); const { progressStyle, progressBgColor, progressColor, } = this.props; return ( this._onLayout(e)} > ); } } export interface CodePushModalProps extends ProgressBarProps { /** 组件样式 */ style?: StyleProp; /** 弹窗样式 */ alertStyle?: StyleProp; /** 弹窗标题样式 */ alertTitleStyle?: StyleProp; /** 弹窗标题, 默认是 更新提示 */ alertTitle?: string; /** 弹窗内容样式 */ alertDesStyle?: StyleProp; /** 弹窗内容, 默认是 有重要内容需要立即更新! */ alertDes?: string; /** 弹窗下载中提示文字样式 */ downloadingDesStyle?: StyleProp; /** 弹窗下载中提示文字, 默认是 极速更新中,请稍等... */ downloadingDes?: string; /** 右边按钮样式 */ okBtnStyle?: StyleProp; /** 左边按钮样式 */ cancelBtnStyle?: StyleProp; /** 右边按钮文字样式 */ okBtnTextStyle?: StyleProp; /** 左边按钮文字样式 */ cancelBtnTextStyle?: StyleProp; /** 右边按钮文字, 默认 立即更新 */ okBtnText?: string; /** 左边按钮文字, 默认 下次再说 */ cancelBtnText?: string; /** 右边按钮点击回调 */ okBtnOnPress?: (e?: any) => void; /** 左边边按钮点击回调 */ cancelBtnOnPress?: (e?: any) => void; /** 是否强制更新, 默认false */ isMandatory: boolean; /** 弹窗是否显示, 默认false */ modalVisible: boolean; } interface CodePushModalState { immediateUpdate: boolean; } class CodePushModal extends Component { static defaultProps = { buttonColor: Theme.theme, buttonTextColor: Theme.white, alertTitle: '更新提示', alertDes: '', downloadingDes: '极速更新中,请稍等...', okBtnText: '立即更新', cancelBtnText: '下次再说', isMandatory: false, modalVisible: false, }; constructor(props) { super(props); this.state = { immediateUpdate: false, // 是否是更新中 }; } _renderButton = () => { const { cancelBtnStyle, cancelBtnTextStyle, cancelBtnText, okBtnStyle, okBtnTextStyle, okBtnText, isMandatory, okBtnOnPress, cancelBtnOnPress, // progress, } = this.props; // console.log(progress); return ( { isMandatory ? null :