2017-01-28 29 views
1

我有一個更一般的問題。在我的應用程序中,我使用React Native Router Flux從一個頁面移動到另一個頁面。我注意到取決於頁面,它會過渡更平滑。特別是,當試圖打開一個利用相機的頁面時,過渡是波濤洶涌和可怕的。顯然有很多利用,因爲相機被調用,並且一旦該頁面被加載,它的實時饋送被加載到頁面中。使轉換更流暢嗎?

是否有任何移動這些轉換看起來不錯,就像在許多其他應用程序?是否有方法像ComponentDidMount或構造函數來避免邏輯?有沒有實施的策略?

任何建議將是不可思議的!

回答

1

您可以使用InteractionManager.runAfterInteractions回調延遲昂貴的渲染,直到當前轉換完成。

class SomeView extends Component { 
    state = { 
    ready: false 
    } 

    componentDidMount() { 
    InteractionManager.runAfterInteractions(() => { 
     this.setState({ready: true}) 
    }); 
    } 

    render() { 
    if (!this.state.ready) { 
     // render some placeholder view 
    } 

    // render the actual view 
    } 
}