如何在使用 mobx 进行反应本机时捕捉屏幕方向变化?
您能否向我解释使用MOBX在React Native应用中处理方向更改方向的正确方法。 目前,我尝试过这样的事情:
@observer
export class ChartSTMWork extends Component {
currwidth = Dimensions.get("window").width;
render() {
this.currwidth = Dimensions.get("window").width;
return();
}
}
但是,只有在渲染调用时,此代码才会更改Currwidth。在此渲染后我已经渲染表并更改智能手机方向的情况下,Currwidth变量没有影响。
或者,也许我需要使用一些小型计时器来检查尺寸。get(“窗口”)。宽度并使Currwidth可观察到?
@observer
export class ChartSTMWork extends Component {
@observable currwidth = Dimensions.get("window").width;
someTimerEvery200ms(){
currwidth = Dimensions.get("window").width
}
}
但是该解决方案看起来像是肮脏的解决方案。
我需要如何以正确的方式处理它?
Can you explain me the right way to handle orientation changing in react native app with mobX.
For now I have tried make something like this:
@observer
export class ChartSTMWork extends Component {
currwidth = Dimensions.get("window").width;
render() {
this.currwidth = Dimensions.get("window").width;
return();
}
}
But this code change the currWidth only if render call. And in situation when I have already rendered table and change orientation of smartphone after this render, there is no effect to currWidth variable.
Or maybe I need to use some small timer to check Dimensions.get("window").width and make currWidth observable?
@observer
export class ChartSTMWork extends Component {
@observable currwidth = Dimensions.get("window").width;
someTimerEvery200ms(){
currwidth = Dimensions.get("window").width
}
}
But this solution is looks like dirty solution.
How I need to handle this in right way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
按此解法求解。也许这对某人有帮助
Solve by this solution. Maybe it's will be heplful for someone