import React, {
PureComponent
} from 'react';
import {
StyleSheet,
View,
Animated,
Easing,
} from 'react-native';
class Bar extends PureComponent {
constructor(props) {
super(props);
this.progress = new Animated.Value(this.props.initialProgress || 0);
}
static defaultProps = {
style: styles,
easing: Easing.inOut(Easing.ease)
}
componentWillReceiveProps(nextProps) {
if (this.props.progress >= 0 && this.props.progress !== nextProps.progress) {
this.update(nextProps.progress);
}
}
shouldComponentUpdate() {
return false;
}
update(progress) {
Animated.spring(this.progress, {
toValue: progress
}).start();
}
render() {
return (
<View style={[styles.background, this.props.backgroundStyle, this.props.style]}>
<Animated.View style={[styles.fill, this.props.fillStyle, { width: this.progress.interpolate({
inputRange: [0, 100],
outputRange: [0 * this.props.style.width, 1 * this.props.style.width],
})} ]}
/>
</View>
);
}
}
var styles = StyleSheet.create({
background: {
backgroundColor: '#bbbbbb',
height: 5,
overflow: 'hidden'
},
fill: {
backgroundColor: 'rgba(0, 122, 255, 1)',
height: 5
}
});
export default Bar;
import React, {
PropTypes,
PureComponent
} from 'react';
import {
View,
StyleSheet,
Modal,
Text,
Dimensions,
TouchableOpacity
} from 'react-native';
import Bar from './Bar';
const {
width
} = Dimensions.get('window');
class ProgressBarDialog extends PureComponent {
constructor(props) {
super(props);
}
static propTypes = {
...Modal.propTypes,
title: PropTypes.string,
canclePress: PropTypes.func,
cancleText: PropTypes.string,
needCancle: PropTypes.bool
};
static defaultProps = {
animationType: 'none',
transparent: true,
progressModalVisible: false,
onShow: () => {},
onRequestClose: () => {},
onOutSidePress: () => {},
title: '上传文件',
cancleText: '取消是',
canclePress: () => {},
needCancle: true
}
render() {
const {
animationType,
transparent,
onRequestClose,
progress,
title,
canclePress,
cancleText,
needCancle,
progressModalVisible
} = this.props;
return (
<Modal
animationType={animationType}
transparent={transparent}
visible={progressModalVisible}
onRequestClose={onRequestClose}>
<View style={styles.progressBarView}>
<View style={styles.subView}>
<Text style={styles.title}>
{title}
</Text>
<Bar
ref={this.refBar}
style={{marginLeft: 10,marginRight: 10,width:width - 80}}
progress={progress}
backgroundStyle={styles.barBackgroundStyle}
/>
<View style={styles.progressContainer}>
<Text style={styles.progressLeftText}>
{`${progress}`}%
</Text>
<Text style={styles.progressRightText}>
{`${progress}`}/100
</Text>
</View>
{needCancle &&
<View style={styles.cancleContainer}>
<TouchableOpacity style={styles.cancleButton} onPress={canclePress}>
<Text style={styles.cancleText}>
{cancleText}
</Text>
</TouchableOpacity>
</View>
}
</View>
</View>
</Modal>
);
}
}
const styles = StyleSheet.create({
progressBarView: {
flex:1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'rgba(0,0,0,0.2)'
},
barStyle: {
marginLeft: 10,
marginRight: 10,
width:width - 80
},
progressLeftText: {
fontSize: 14
},
cancleContainer: {
justifyContent: 'center',
alignItems: 'flex-end'
},
progressRightText: {
fontSize: 14,
color: '#666666'
},
barBackgroundStyle: {
backgroundColor: '#cccccc'
},
progressContainer: {
flexDirection: 'row',
padding: 10,
justifyContent: 'space-between'
},
subView: {
marginLeft: 30,
marginRight: 30,
backgroundColor: '#fff',
alignSelf: 'stretch',
justifyContent: 'center'
},
progressView: {
flexDirection: 'row',
padding: 10,
paddingBottom: 5,
justifyContent: 'space-between'
},
title: {
textAlign: 'left',
padding:10,
fontSize: 16
},
cancleButton: {
padding:10
},
cancleText: {
textAlign: 'right',
paddingTop: 0,
fontSize: 16,
color: 'rgba(0, 122, 255, 1)'
}
});
export default ProgressBarDialog;
import React , {
PureComponent
} from 'react';
import {
View
} from 'react-native';
import ProgressBarDialog from './ProgressBarDialog';
class Upload extends PureComponent {
constructor(props) {
this.state = {
progress: 0,
progressModalVisible: false
};
}
refProgressBar = (view) => {
this.progressBar = view;
}
showProgressBar = () => {
this.setState({
progressModalVisible: true
});
}
dismissProgressBar = () => {
this.setState({
progress: 0,
progressModalVisible: false
});
}
setProgressValue = (progress) => {
this.setState({
progress
});
}
onProgressRequestClose = () => {
this.dismissProgressBar();
}
canclePress = () => {
this.dismissProgressBar();
}
render() {
return (
<View>
<ProgressBarDialog
ref={this.refProgressBar}
progress={this.state.progress}
progressModalVisible={this.state.progressModalVisible}
onRequestClose={this.onProgressRequestClose}
canclePress={this.canclePress}
needCancle={true}
/>
</View>
)
}
}
export default Upload;
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有