diff --git a/App.js b/App.js
index a64d1de..412ec42 100644
--- a/App.js
+++ b/App.js
@@ -1,13 +1,10 @@
import React, { Component } from 'react';
import {
- Platform,
StyleSheet,
Text,
View,
Image,
- Dimensions,
- TouchableOpacity,
ImageBackground,
} from 'react-native';
@@ -19,9 +16,6 @@ import DeviceInfo from "react-native-device-info";
import * as Animatable from 'react-native-animatable';
-// 取得屏幕的宽高Dimensions
-const { width, height } = Dimensions.get('window');
-
contentItemDefault = {
coverImg:'',
qrcode:[],
@@ -45,23 +39,21 @@ export default class MyPage extends Component {
constructor(props) {
super(props);
this.state = {
-
baseInfo: baseInfoDefault,
-
adDataList:[],
-
contentItem1:contentItemDefault,
-
contentItem2:contentItemDefault,
-
contentItem3:contentItemDefault,
+ syncMessage: "INIT" ,
+ progress: {
+ receivedBytes:0,
+ totalBytes:0
+ },
+ macAddress: "NULL",
+
text:'',
-
- restartAllowed: true ,
- syncMessage: "syncMessage" ,
- progress: false,
- macAddress: "NULL"
+ versionInfo:'UNKNOWN'
};
DeviceInfo.getMACAddress().then(mac=>{this.setState({macAddress:mac})})
DeviceInfo.getIPAddress().then(mac=>{this.setState({macAddress:mac})})
@@ -102,45 +94,7 @@ codePushStatusDidChange(syncStatus) {
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)
- );
- }
-
-
-getAdDataList() {
+ getAdDataList() {
HttpUtils.get('https://mall.youlane.cn/api/wxDeviceScreenAd/list?deviceId=11%3AAA%3A33%3ABB%3A44&pageNum=1&pageSize=5')
.then(result => {
this.setState({
@@ -150,32 +104,56 @@ getAdDataList() {
contentItem1 : this.state.adDataList[0]});
})
.catch(error => console.error(error))
-}
+ }
-getBaseInfo() {
+ getBaseInfo() {
HttpUtils.get('https://mall.youlane.cn/api/wxDeviceScreenAd/info?deviceId=11%3AAA%3A33%3ABB%3A44')
.then(result => {
this.setState({
baseInfo:result.data});
})
.catch(error => console.error(error))
-}
+ }
componentDidMount() {
+ CodePush.allowRestart();
+ CodePush.sync(
+ { installMode: CodePush.InstallMode.IMMEDIATE,
+ dialog:{} },
+ this.codePushStatusDidChange.bind(this),
+ this.codePushDownloadDidProgress.bind(this)
+ );
+
+ CodePush.getUpdateMetadata(CodePush.UpdateState.RUNNING)
+ .then((metadata: LocalPackage) => {
+ this.setState({ versionInfo: metadata ? metadata.appVersion + "-" + metadata.label : "Unknown"});
+ }, (error: any) => {
+ this.setState({ versionInfo: "Unknown"});
+ });
+
this.getBaseInfo()
this.getAdDataList()
+
}
render() {
- let progressView;
if (this.state.progress) {
- progressView = (
- {this.state.progress.receivedBytes} of {this.state.progress.totalBytes} bytes received
+ if (this.state.progress.totalBytes > 0)
+ return (
+ {this.state.syncMessage}{'\n'}
+ {this.state.progress.receivedBytes} of {this.state.progress.totalBytes} bytes received{'\n'}
+ {this.state.text}
+
+ );
+ return (
+ {this.state.syncMessage}{'\n'}
+ {this.state.text}
+
);
- }
+ }
return (
@@ -303,7 +281,7 @@ render() {
- {this.state.text}
+ {this.state.versionInfo}
@@ -313,6 +291,18 @@ render() {
}
const styles = StyleSheet.create({
+ updatePage:{
+ flex: 2,
+ width:'100%',
+ height:'100%',
+ backgroundColor:'yellow',
+ textAlign :'center',
+ textAlignVertical:'center',
+ fontSize: 24,
+ color: 'green'
+ },
+
+
//layer background
background:{
@@ -415,7 +405,11 @@ render() {
flex: 8,
width:'100%',
height:'100%',
- backgroundColor:'transparent'
+ backgroundColor:'transparent',
+ textAlign :'right',
+ textAlignVertical:'bottom',
+ fontSize: 10,
+ color : 'gray'
},
//layer content item
@@ -591,4 +585,5 @@ render() {
textDecorationLine: 'line-through',
color : 'gray'
},
+
});