- Create Components folder under src folder
- Add ProgressBarEXP.js file and add below Code
import React, { Component } from "react";
import {
Platform,
StyleSheet,
View,
Text,
TouchableOpacity,
ProgressBarAndroid,
ProgressViewIOS
} from "react-native";
export default class ProgressBarEXP extends Component {
constructor() {
super();
this.state = {
Progress_Value: 0.0
};
}
Start_Progress = () => {
this.value = setInterval(() => {
if (this.state.Progress_Value <= 1) {
this.setState({ Progress_Value: this.state.Progress_Value + 0.01 });
}
}, 100);
};
Stop_Progress = () => {
clearInterval(this.value);
};
Clear_Progress = () => {
this.setState({ Progress_Value: 0.0 });
};
render() {
return (
<View style={styles.MainContainer}>
<Text style={{ fontSize: 20, color: "#000" }}>
{" "}
Progress Value:{" "}
{parseFloat((this.state.Progress_Value * 100).toFixed(3))} %
</Text>
{Platform.OS === "android" ? (
<ProgressBarAndroid
styleAttr="Horizontal"
progress={this.state.Progress_Value}
indeterminate={false}
/>
) : (
<ProgressViewIOS progress={this.state.Progress_Value} />
)}
<TouchableOpacity
activeOpacity={0.7}
style={styles.button}
onPress={this.Start_Progress}
>
<Text style={styles.TextStyle}> Start Progress </Text>
</TouchableOpacity>
<TouchableOpacity
activeOpacity={0.7}
style={styles.button}
onPress={this.Stop_Progress}
>
<Text style={styles.TextStyle}> Stop Progress </Text>
</TouchableOpacity>
<TouchableOpacity
activeOpacity={0.7}
style={styles.button}
onPress={this.Clear_Progress}
>
<Text style={styles.TextStyle}> Reset Progress </Text>
</TouchableOpacity>
</View>
);
}
}
const styles = StyleSheet.create({
MainContainer: {
flex: 1,
justifyContent: "center",
paddingTop: Platform.OS === "ios" ? 20 : 0,
margin: 20
},
button: {
width: "100%",
backgroundColor: "#00BCD4",
borderRadius: 5,
padding: 10,
marginTop: 10
},
TextStyle: {
color: "#fff",
textAlign: "center"
}
});
- Open App.js file and update code as below
import React from 'react';
import { View,StyleSheet } from 'react-native';
import ProgressBarEXP from './src/Component/ProgressBarEXP'
const App=()=> {
return (
<View style={styles.container}>
<ProgressBarEXP/>
</View>
);
}
export default App;
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
paddingTop:80
},
});
No comments:
Post a Comment