|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256 |
-
- import React, { Component } from 'react';
- import {
- Platform,
- StyleSheet,
- Text,
- View,
- Image,
- Dimensions,
- TouchableOpacity,
- } from 'react-native';
-
- //引用插件
- import Swiper from 'react-native-swiper';
- import HttpUtils from './HttpUtils.js';
- import CodePush from "react-native-code-push";
-
- // 取得屏幕的宽高Dimensions
- const { width, height } = Dimensions.get('window');
-
- export default class MyPage extends Component {
-
- constructor(props) {
- super(props);
- this.state = {
- swiperShow: false,
- text:'',
- qrcode:[],
- restartAllowed: true ,
- syncMessage: "我是小更新" ,
- progress: false
- };
- }
-
- // 监听更新状态
- codePushStatusDidChange(syncStatus) {
- switch(syncStatus) {
- case CodePush.SyncStatus.CHECKING_FOR_UPDATE:
- this.setState({ syncMessage: "Checking for update." });
- break;
- case CodePush.SyncStatus.DOWNLOADING_PACKAGE:
- this.setState({ syncMessage: "Downloading package." });
- break;
- case CodePush.SyncStatus.AWAITING_USER_ACTION:
- this.setState({ syncMessage: "Awaiting user action." });
- break;
- case CodePush.SyncStatus.INSTALLING_UPDATE:
- this.setState({ syncMessage: "Installing update." });
- break;
- case CodePush.SyncStatus.UP_TO_DATE:
- this.setState({ syncMessage: "App up to date.", progress: false });
- break;
- case CodePush.SyncStatus.UPDATE_IGNORED:
- this.setState({ syncMessage: "Update cancelled by user.", progress: false });
- break;
- case CodePush.SyncStatus.UPDATE_INSTALLED:
- this.setState({ syncMessage: "Update installed and will be applied on restart.", progress: false });
- break;
- case CodePush.SyncStatus.UNKNOWN_ERROR:
- this.setState({ syncMessage: "An unknown error occurred.", progress: false });
- break;
- }
- }
-
-
- codePushDownloadDidProgress(progress) {
- this.setState({ progress });
- }
-
- // 允许重启后更新
- toggleAllowRestart() {
- this.state.restartAllowed
- ? CodePush.disallowRestart()
- : CodePush.allowRestart();
-
- this.setState({ restartAllowed: !this.state.restartAllowed });
- }
-
- // 获取更新数据
- getUpdateMetadata() {
- CodePush.getUpdateMetadata(CodePush.UpdateState.RUNNING)
- .then((metadata: LocalPackage) => {
- this.setState({ syncMessage: metadata ? JSON.stringify(metadata) : "Running binary version", progress: false });
- }, (error: any) => {
- this.setState({ syncMessage: "Error: " + error, progress: false });
- });
- }
-
- /** Update is downloaded silently, and applied on restart (recommended) 自动更新,一键操作 */
- sync() {
- CodePush.sync(
- {},
- this.codePushStatusDidChange.bind(this),
- this.codePushDownloadDidProgress.bind(this)
- );
- }
-
- /** Update pops a confirmation dialog, and then immediately reboots the app 一键更新,加入的配置项 */
- syncImmediate() {
- CodePush.sync(
- { installMode: CodePush.InstallMode.IMMEDIATE, updateDialog: true },
- this.codePushStatusDidChange.bind(this),
- this.codePushDownloadDidProgress.bind(this)
- );
- }
-
- // 轮播图
- renderBanner() {
- if (this.state.swiperShow) {
- console.log ('返回值' + this.state.swiperShow);
- return (
- <Swiper
- style={styles.wrapper}
- showsButtons={false}
- removeClippedSubviews={false} //这个很主要啊,解决白屏问题
- autoplay={true}
- horizontal ={true}
- paginationStyle={styles.paginationStyle}
- dotStyle={styles.dotStyle}
- activeDotStyle={styles.activeDotStyle}
- >
- <Image source={require('./image/page1.jpg')} resizeMode='stretch' style={styles.bannerImg}/>
- <Image source={require('./image/page2.jpg')} resizeMode='stretch' style={styles.bannerImg}/>
- <Image source={require('./image/page3.jpg')} resizeMode='stretch' style={styles.bannerImg}/>
- <Image source={require('./image/page4.jpg')} resizeMode='stretch' style={styles.bannerImg}/>
- </Swiper>
- );
-
- } else {
- return (
- <View style={styles.wrapper}>
- <Image style={{width: 300, height: 300}} source={{uri:'data:image/jpeg;base64,'+ this.state.qrcode}}/>
- <Text style={{marginTop: 16}}>{this.state.text}</Text>
- </View>
- );
- }
- }
-
- get() {
- HttpUtils.get('https://mall.youlane.cn/api/wxDeviceScreenAd/list?deviceId=11%3AAA%3A33%3ABB%3A44&pageNum=1&pageSize=5')
- .then(result => {
- this.setState({
- text: JSON.stringify,
- qrcode: result.data.list[0].qrcode});
- })
- .catch(error => console.error(error))
- }
-
-
- componentDidMount() {
-
- this.get()
- setTimeout(() => {
- this.setState({
- swiperShow: true,
- });
- }, 10000)
- }
-
-
- render() {
- let progressView;
-
- if (this.state.progress) {
- progressView = (
- <Text style={styles.messages}>{this.state.progress.receivedBytes} of {this.state.progress.totalBytes} bytes received</Text>
- );
- }
-
- return (
- <View style={styles.container}>
-
- <Text style={styles.welcome}>
- 可以修改此处文字,查看是否更新成功!
- </Text>
-
- <TouchableOpacity onPress={this.sync.bind(this)}>
- <Text style={styles.syncButton}>Press for background sync</Text>
- </TouchableOpacity>
-
- <TouchableOpacity onPress={this.syncImmediate.bind(this)}>
- <Text style={styles.syncButton}>Press for dialog-driven sync</Text>
- </TouchableOpacity>
-
- {progressView}
-
- <TouchableOpacity onPress={this.toggleAllowRestart.bind(this)}>
- <Text style={styles.restartToggleButton}>Restart { this.state.restartAllowed ? "allowed" : "forbidden"}</Text>
- </TouchableOpacity>
-
- <TouchableOpacity onPress={this.getUpdateMetadata.bind(this)}>
- <Text style={styles.syncButton}>Press for Update Metadata</Text>
- </TouchableOpacity>
-
-
- <Text style={styles.messages}>{this.state.syncMessage || ""}</Text>
-
- </View>
- );
-
- /*
- return (
- <View style={styles.container}>
- {this.renderBanner()}
- </View>
-
- );
- */
- }
- }
-
- const styles = StyleSheet.create({
- container: {
- width:width,
- height:height,
- flex:1
- },
- wrapper: {
- width:width,
- height:height,
- flex:1
- },
- bannerImg: {
- width:width,
- height:height,
- flex:1
- },
- container: {
- flex: 1,
- alignItems: "center",
- backgroundColor: "#F5FCFF",
- paddingTop: 50
- },
- image: {
- margin: 30,
- width: Dimensions.get("window").width - 100,
- height: 365 * (Dimensions.get("window").width - 100) / 651,
- },
- messages: {
- marginTop: 30,
- textAlign: "center",
- },
- restartToggleButton: {
- color: "blue",
- fontSize: 17
- },
- syncButton: {
- color: "green",
- fontSize: 17
- },
- welcome: {
- fontSize: 20,
- textAlign: "center",
- margin: 20
- },
- });
|