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