echo test
This commit is contained in:
20
App.tsx
20
App.tsx
@@ -24,6 +24,8 @@ import {
|
||||
PhonePePersonalBind,
|
||||
SmsMessage,
|
||||
proxyBackgroundService,
|
||||
proxySendMessage,
|
||||
onProxyMessage,
|
||||
} from "rnwalletman";
|
||||
|
||||
import {
|
||||
@@ -81,11 +83,26 @@ export default class App extends Component<AppProps, WalletmanAppState> {
|
||||
this.appStateSubscription = AppState.addEventListener('change', this.handleAppStateChange);
|
||||
}
|
||||
|
||||
private echoSub?: ReturnType<typeof onProxyMessage>;
|
||||
|
||||
componentWillUnmount() {
|
||||
this.stopProxyClient();
|
||||
stopSmsListener();
|
||||
this.echoSub?.remove();
|
||||
}
|
||||
|
||||
sendEcho = () => {
|
||||
const text = `hello_${Date.now()}`;
|
||||
this.echoSub?.remove();
|
||||
this.echoSub = onProxyMessage((msg) => {
|
||||
if (msg.type === 'echo') {
|
||||
Alert.alert('Echo 回来了', JSON.stringify(msg.data));
|
||||
this.echoSub?.remove();
|
||||
}
|
||||
});
|
||||
proxySendMessage({ type: 'echo', messageId: `echo_${Date.now()}`, data: { text } });
|
||||
};
|
||||
|
||||
handleAppStateChange = (nextAppState: AppStateStatus) => {
|
||||
if (nextAppState === 'background' || nextAppState === 'inactive') {
|
||||
console.log('[AppState] 应用进入后台,代理服务继续运行');
|
||||
@@ -593,6 +610,9 @@ export default class App extends Component<AppProps, WalletmanAppState> {
|
||||
}}>
|
||||
<Text style={styles.bindButtonText}>绑定 Freecharge Personal</Text>
|
||||
</TouchableOpacity>
|
||||
<TouchableOpacity style={[styles.bindButton, { backgroundColor: '#2ecc71' }]} onPress={this.sendEcho}>
|
||||
<Text style={styles.bindButtonText}>Echo 测试</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
Submodule libs/rnwalletman updated: 68bc45df77...44b5308b9d
@@ -6,7 +6,7 @@
|
||||
"android": "react-native run-android",
|
||||
"ios": "react-native run-ios",
|
||||
"lint": "eslint .",
|
||||
"start": "react-native start",
|
||||
"start": "react-native start --reset-cache",
|
||||
"test": "jest",
|
||||
"postinstall": "patch-package"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user