React Native 中的 viewWillAppear

编程入门 行业动态 更新时间:2024-10-08 04:24:23
本文介绍了React Native 中的 viewWillAppear的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用 React Native 在 View 中流式传输来自相机的视频.问题是,如果用户按下主页按钮,暂时离开应用并切换回来,流 URL 将被更改.

I'm trying to stream video from the camera in a View with React Native. The problem is, if the user presses the home button, temporarily leave the app and switch back, the stream URL will be changed.

所以我需要在一个类似于 viewWillAppear 的函数中更新 URL,就像在原生 iOS 框架中一样.对此有什么建议吗?

So I need to update the URL in a function similar to viewWillAppear as in native iOS framework. Any suggestion on this?

推荐答案

是的 @Danny Want 是对的,您可以使用 AppState.可以这样使用:

Yes @Danny Want is right you can use AppState. It can be used like this:

getInitialState: function() { return { currentAppState: AppState.currentState, }; }, componentDidMount: function() { AppState.addEventListener('change', this._handleAppStateChange); }, componentWillUnmount: function() { AppState.removeEventListener('change', this._handleAppStateChange); }, _handleAppStateChange: function(currentAppState) { this.setState({ currentAppState, }); }, render: function() { return ( <Text>Current state is: {this.state.currentAppState}</Text> ); },

在 AppState 处理程序中做你想做的事:_handleAppStateChange.有关更多详细信息,请查看此处

Do what you wanna do in the AppState handler: _handleAppStateChange. For more details please check out here

更多推荐

React Native 中的 viewWillAppear

本文发布于:2023-11-27 21:28:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639669.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:React   Native   viewWillAppear

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!