1
0
Code Issues Pull Requests Packages Projects Releases Wiki Activity GitHub Gitee

Add TestConsole

This commit is contained in:
sunnylqm 2021-04-09 22:42:43 +08:00
parent ca7878a9db
commit 0ccacc2f7b
2 changed files with 80 additions and 4 deletions

View 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>
);
}

View File

@ -8,7 +8,6 @@ import {
TouchableOpacity, TouchableOpacity,
Linking, Linking,
Image, Image,
NativeModules,
} from 'react-native'; } from 'react-native';
import { import {
@ -25,12 +24,15 @@ import {
cInfo, cInfo,
} from 'react-native-update'; } from 'react-native-update';
import TestConsole from './TestConsole';
import _updateConfig from '../update.json'; import _updateConfig from '../update.json';
const {appKey} = _updateConfig[Platform.OS]; const {appKey} = _updateConfig[Platform.OS];
export default class App extends Component { export default class App extends Component {
state = { state = {
received: 0, received: 0,
total: 0, total: 0,
showTestConsole: false,
}; };
componentDidMount() { componentDidMount() {
if (isRolledBack) { if (isRolledBack) {
@ -56,7 +58,7 @@ export default class App extends Component {
); );
} }
} }
doUpdate = async (info) => { doUpdate = async info => {
try { try {
const hash = await downloadUpdate(info, { const hash = await downloadUpdate(info, {
onDownloadProgress: ({received, total}) => { onDownloadProgress: ({received, total}) => {
@ -141,7 +143,7 @@ export default class App extends Component {
}; };
render() { render() {
const {received, total} = this.state; const {received, total, showTestConsole} = this.state;
return ( return (
<View style={styles.container}> <View style={styles.container}>
<Text style={styles.welcome}>欢迎使用热更新服务</Text> <Text style={styles.welcome}>欢迎使用热更新服务</Text>
@ -167,12 +169,13 @@ export default class App extends Component {
<TouchableOpacity <TouchableOpacity
style={{marginTop: 15}} style={{marginTop: 15}}
onLongPress={() => { onLongPress={() => {
// TODO 调试pushy方法 this.setState({showTestConsole: true});
}}> }}>
<Text style={styles.instructions}> <Text style={styles.instructions}>
react-native-update版本{cInfo.pushy} react-native-update版本{cInfo.pushy}
</Text> </Text>
</TouchableOpacity> </TouchableOpacity>
<TestConsole visible={showTestConsole} />
{/* <WebView style={{flex:1}} source={{uri: require('../www/index.html')}}/> */} {/* <WebView style={{flex:1}} source={{uri: require('../www/index.html')}}/> */}
</View> </View>
); );