1
0
mirror of https://gitcode.com/gh_mirrors/re/react-native-pushy.git synced 2025-09-18 21:00:38 +08:00
Code Issues Packages Projects Releases Wiki Activity GitHub Gitee

Implement download progress

This commit is contained in:
sunnylqm
2020-09-16 13:01:14 +08:00
parent a4052091e0
commit a966655faf
6 changed files with 1686 additions and 978 deletions

View File

@@ -27,6 +27,10 @@ import _updateConfig from '../update.json';
const {appKey} = _updateConfig[Platform.OS];
export default class App extends Component {
state = {
received: 0,
total: 0,
};
componentDidMount() {
if (isRolledBack) {
Alert.alert('提示', '刚刚更新失败了,版本被回滚.');
@@ -51,9 +55,16 @@ export default class App extends Component {
);
}
}
doUpdate = async info => {
doUpdate = async (info) => {
try {
const hash = await downloadUpdate(info);
const hash = await downloadUpdate(info, {
onDownloadProgress: ({received, total}) => {
setState({
received,
total,
});
},
});
Alert.alert('提示', '下载完毕,是否重启应用?', [
{
text: '是',
@@ -126,6 +137,9 @@ export default class App extends Component {
当前热更新版本Hash: {currentVersion || '(空)'}
{'\n'}
</Text>
<Text>
下载进度{received} / {total}
</Text>
<TouchableOpacity onPress={this.checkUpdate}>
<Text style={styles.instructions}>点击这里检查更新</Text>
</TouchableOpacity>