[英]How to detect screen orientation change in react-native app with a funtion component
[英]How to catch when screen orientation change in react native with mobx?
你能解釋一下在使用 mobX 的反應本機應用程序中處理方向變化的正確方法嗎? 現在我試過做這樣的事情:
@observer
export class ChartSTMWork extends Component {
currwidth = Dimensions.get("window").width;
render() {
this.currwidth = Dimensions.get("window").width;
return();
}
}
但是此代碼僅在渲染調用時才更改 currWidth。 並且在我已經渲染表格並在此渲染之后更改智能手機方向的情況下,對 currWidth 變量沒有影響。
或者我可能需要使用一些小計時器來檢查 Dimensions.get("window").width 並使 currWidth 可觀察?
@observer
export class ChartSTMWork extends Component {
@observable currwidth = Dimensions.get("window").width;
someTimerEvery200ms(){
currwidth = Dimensions.get("window").width
}
}
但是這個解決方案看起來像是骯臟的解決方案。
我需要如何以正確的方式處理這個問題?
用這個解決方案解決。 也許這對某人有幫助
eventToDemension = Dimensions.addEventListener("change", (e) => {
this.currwidth = e.window.width;
});
@observable currwidth = Dimensions.get("window").width;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.