1.0.7 • Published 4 years ago

react-native-qiji-updater v1.0.7

Weekly downloads
-
License
-
Repository
-
Last release
4 years ago

react-native-qiji-updater

npm version

React native应用更新的逻辑及UI的封装

TOC

Installation

Using npm:

npm install --save react-native-qiji-updater

or using yarn:

yarn add react-native-qiji-updater

Usage

import * as Updater from 'react-native-qiji-updater';

API

MethodReturn TypeDescription
init(config:Object)void初始化
checkUpdate()Promise<>版本检测(兼容android,ios)
checkAndroidUpdate()Promise<>android版本检测
checkIosUpdate()Promise<>ios版本检测

init(config:Object)

初始化更新参数

Examples

Updater.init({
    checkUrl:'http://127.0.0.1',
    checkSuccess:  (res) => {...},
    checkError: (err) => {...},
    downloadProgress: (res) => {...},
    downloadSuccess: (res) =>{...},
    downloadError: (err) => {...},
    installSuccess: (res) => {...},
    installError: (err) => {...},
    progressModal: this.progressModal.current
});

参数说明

nameTypeDescription
checkUrlString更新检测服务端地址
checkSuccessFunction检测成功回调
checkErrorFunction检测失败回调
downloadProgressFunction检测成功回调
downloadSuccessFunction检测成功回调
downloadErrorFunction检测失败回调
installSuccessFunction安装成功回调
installErrorFunction安装失败回调
progressModalUI Component下载进度框

checkSuccess

Android
//有更新内容
{"data": {"app_id": "com.demo", "app_name": "更新DEMO", "app_url": "http://xxxxxx/xxx.apk", "description": "v1.0.1:新增支付模块", "is_force": false, "title": "更新安装包", "ver": "1.0.1"}, "success": true}
//无更新内容
{"data":false, "success": true}
NameTypeDescription
app_idString应用ID
app_nameString应用名称
app_urlString安装包下载地址
descriptionString更新描述
is_forceboolean是否强制更新
titleString更新提示标题
verString版本

checkError

Android
{'success' => false, 'msg' => xxxxx];

checkUpdate()

更新检测

Examples

Updater.checkUpdate();

checkAndroidUpdate()

Android更新检测

Examples

Updater.checkAndroidUpdate();

checkIosUpdate()

IOS更新检测

Examples

Updater.checkIosUpdate();

UI组件


ProgressModal

进度提示框

Examples

<Updater.ProgressModal ref={this.refProgressModal} titleBgColor="#f7977a" title="下载安装包"></Updater.ProgressModal>

Props

NameDefaultTypeDescription
title文件下载中String标题
titleBgColor#0080ffString标题背景色
barBgColor#e0e0e0String进度条背景色
barColor#0080ffString进度条颜色色
visiblefalseboolean是否显示
onCloseFunction窗口关闭时的回调
total1Number总数
progress0Number当前进度

示例

import React, { Component } from 'react';
import { StyleSheet, Button, View, SafeAreaView, Text} from 'react-native';
import * as Updater from 'react-native-qiji-updater';

const Separator = () => {
  return <View style={styles.separator} />;
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    marginHorizontal: 16,
  },
  title: {
    textAlign: 'center',
    marginVertical: 8,
  },
  fixToText: {
    flexDirection: 'row',
    justifyContent: 'space-between',
  },
  separator: {
    marginVertical: 8,
    borderBottomColor: '#737373',
    borderBottomWidth: StyleSheet.hairlineWidth,
  },
});

export default class App extends Component {
  constructor(props) {
    super(props);
    this.refProgressModal = React.createRef();
  }
  componentDidMount() {
    Updater.init({
      progressModal: this.refProgressModal.current
    });
  }

  onUpdate() {
    Updater.checkUpdate();
  }
  render() {
    return (
      <SafeAreaView style={styles.container}>
        <Updater.ProgressModal ref={this.refProgressModal} titleBgColor="#f7977a" title="更新下载"></Updater.ProgressModal>
        <View>
          <Text style={styles.title}>
            点击按钮测试更新
          </Text>
          <Button
            title="更新检测"
            onPress={this.onUpdate.bind(this)}
          />
        </View>
        <Separator />
      </SafeAreaView>
    );
  }
}
1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago