“react-native-ble-plx”在我使用navigation.navigate()时会断开与BLE设备的连接。

huangapple go评论59阅读模式
英文:

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:

&lt;View&gt;
  {showScreen1 &amp;&amp; &lt;View&gt;&lt;/View&gt;} 
  {showScreen2 &amp;&amp; &lt;View&gt;&lt;/View&gt;}
&lt;/View&gt;

huangapple
  • 本文由 发表于 2023年2月14日 06:48:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/75441903.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定