英文:
react-native-ble-plx disconnects from BLE device whenever I use navigation.navigate()
问题
我正在使用React Native上下文将数据从一个简单的react-native-ble-plx脚本传递到我的应用程序中的不同屏幕。我在这些屏幕上使用react-native-navigation。每当我调用navigation.navigate()时,我成功地导航到另一个屏幕,但即使我导航回原始屏幕,蓝牙通信也不再有效。如何在我的BLE上下文中继续将数据发送到应用程序的不同屏幕,而不断开连接?
英文:
I am using React Native context to pass data from a simple react-native-ble-plx script to different screens in my app. I'm using react-native-navigation for these screens. Whenever I call navigation.navigate(), I successfully navigate to another screen, but I no longer have bluetooth communication, even if I navigate back to the original screen. How do I keep sending data from my BLE context to the different screens in my app, without disconnecting?
答案1
得分: 1
我相信这是因为您在页面上处理/监控连接,而不是通过服务来处理。将BLE功能与UI分开应该可以解决这个问题。请查看以下链接获取更多信息:
英文:
I believe that this is happening because you are handling/monitoring the connection on the page instead of doing it via a service. Separating BLE functionality from the UI should fix this issue. Have a look at the links below for more information:-
答案2
得分: 0
这不是真正的一个“解决方案”,但我通过从我的项目中移除React Navigation,并像这样手动处理屏幕来解决了这个问题:
<View>
{showScreen1 && <View></View>}
{showScreen2 && <View></View>}
</View>
英文:
This is not really a "solution" but I solved this problem by removing React Navigation from my project, and just handling the screens manually like this:
<View>
{showScreen1 && <View></View>}
{showScreen2 && <View></View>}
</View>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论