Add TestConsole
This commit is contained in:
parent
ca7878a9db
commit
0ccacc2f7b
73
Example/testHotUpdate/src/TestConsole.js
Normal file
73
Example/testHotUpdate/src/TestConsole.js
Normal file
@ -0,0 +1,73 @@
|
||||
import React from 'react';
|
||||
import {
|
||||
ActivityIndicator,
|
||||
Alert,
|
||||
Modal,
|
||||
TextInput,
|
||||
Button,
|
||||
NativeModules,
|
||||
StyleSheet,
|
||||
SafeAreaView,
|
||||
Text,
|
||||
View,
|
||||
} from 'react-native';
|
||||
|
||||
const Pushy = NativeModules.Pushy;
|
||||
export default function TestConsole({visible}) {
|
||||
const [text, setText] = React.useState('');
|
||||
const [running, setRunning] = React.useState(false);
|
||||
return (
|
||||
<Modal visible={visible}>
|
||||
<SafeAreaView style={{flex: 1, padding: 10}}>
|
||||
<Text>调试Pushy方法(方法名,参数,值换行)</Text>
|
||||
<TextInput
|
||||
style={{
|
||||
borderWidth: StyleSheet.hairlineWidth * 4,
|
||||
borderColor: 'black',
|
||||
height: '30%',
|
||||
marginTop: 20,
|
||||
marginBottom: 20,
|
||||
padding: 10,
|
||||
fontSize: 20,
|
||||
}}
|
||||
textAlignVertical="top"
|
||||
multiline={true}
|
||||
value={text}
|
||||
onChangeText={setText}
|
||||
/>
|
||||
{running && <ActivityIndicator />}
|
||||
<Button
|
||||
title="执行"
|
||||
onPress={async () => {
|
||||
setRunning(true);
|
||||
try {
|
||||
const inputs = text.split('\n');
|
||||
const methodName = inputs[0];
|
||||
let params;
|
||||
if (inputs.length === 1) {
|
||||
await Pushy[methodName]();
|
||||
} else {
|
||||
if (inputs.length === 2) {
|
||||
params = inputs[1];
|
||||
} else {
|
||||
params = {};
|
||||
for (let i = 1; i < inputs.length; i += 2) {
|
||||
params[inputs[i]] = inputs[i + 1];
|
||||
}
|
||||
console.log({inputs, params});
|
||||
}
|
||||
await Pushy[methodName](params);
|
||||
}
|
||||
Alert.alert('done');
|
||||
} catch (e) {
|
||||
Alert.alert(e.message);
|
||||
}
|
||||
setRunning(false);
|
||||
}}></Button>
|
||||
<View style={{marginTop: 15}}>
|
||||
<Button title="重置" onPress={() => setText('')} />
|
||||
</View>
|
||||
</SafeAreaView>
|
||||
</Modal>
|
||||
);
|
||||
}
|
@ -8,7 +8,6 @@ import {
|
||||
TouchableOpacity,
|
||||
Linking,
|
||||
Image,
|
||||
NativeModules,
|
||||
} from 'react-native';
|
||||
|
||||
import {
|
||||
@ -25,12 +24,15 @@ import {
|
||||
cInfo,
|
||||
} from 'react-native-update';
|
||||
|
||||
import TestConsole from './TestConsole';
|
||||
|
||||
import _updateConfig from '../update.json';
|
||||
const {appKey} = _updateConfig[Platform.OS];
|
||||
export default class App extends Component {
|
||||
state = {
|
||||
received: 0,
|
||||
total: 0,
|
||||
showTestConsole: false,
|
||||
};
|
||||
componentDidMount() {
|
||||
if (isRolledBack) {
|
||||
@ -56,7 +58,7 @@ export default class App extends Component {
|
||||
);
|
||||
}
|
||||
}
|
||||
doUpdate = async (info) => {
|
||||
doUpdate = async info => {
|
||||
try {
|
||||
const hash = await downloadUpdate(info, {
|
||||
onDownloadProgress: ({received, total}) => {
|
||||
@ -141,7 +143,7 @@ export default class App extends Component {
|
||||
};
|
||||
|
||||
render() {
|
||||
const {received, total} = this.state;
|
||||
const {received, total, showTestConsole} = this.state;
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
<Text style={styles.welcome}>欢迎使用热更新服务</Text>
|
||||
@ -167,12 +169,13 @@ export default class App extends Component {
|
||||
<TouchableOpacity
|
||||
style={{marginTop: 15}}
|
||||
onLongPress={() => {
|
||||
// TODO 调试pushy方法
|
||||
this.setState({showTestConsole: true});
|
||||
}}>
|
||||
<Text style={styles.instructions}>
|
||||
react-native-update版本:{cInfo.pushy}
|
||||
</Text>
|
||||
</TouchableOpacity>
|
||||
<TestConsole visible={showTestConsole} />
|
||||
{/* <WebView style={{flex:1}} source={{uri: require('../www/index.html')}}/> */}
|
||||
</View>
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user