react native 之頁面跳轉

第一章  跳轉的實現react

1.component  中添加這行代碼app

<View style={styles.loginmain}>
          <Text style={styles.logintext} onPress={() => navigator.push({name:'In'})}>註冊</Text>
          <Text style={styles.logintext} onPress={() => navigator.push({name:'Forget'})}>忘記密碼          </Text>
</View>

onPress  主要運用於點擊事件中ide

2.在運行的主頁面中只能運行以下的component  flex


const thunkMiddleWare = (store) => (next) => (action) => {
if (typeof action === 'function') {
return action(store.dispatch, store.getState)
}
return next(action)

export default function () { return (
<Provider store={createStore(reducer, applyMiddleware(thunkMiddleWare))}> <NavigatorApp /> </Provider> ) }

 須要注意的是:a. middleware   是中間件的設置,它有固定的格式.動畫

<view/>  不能包含<Navigator/>這個標籤  但反過來能夠this

3.點擊跳轉的頁面的設置代碼spa

function InComponent({navigator}){
    return (
        <View style={[styles.fullCenter,{backgroundColor:'#CCC',flex:1}]}>
            <Text style={styles.size} onPress={() => navigator.pop()} >註冊</Text>
        </View>
    )

}




function ForgetComponent({navigator}){
    return (
        <View style={[styles.fullCenter,{backgroundColor:'#CCC',flex:1}]}>
            <Text style={styles.size} onPress={() => navigator.pop()} >忘記密碼</Text>
        </View>
    )

}










export default class NavigatorApp extends Component {
    render() {
        return (

            <Navigator
                initialRoute={{name:'Main'}}
                renderScene={this.renderScene}
                navigationBar ={this.navigationBar}
            />

        );
    }



    renderScene(route,navigator){

        if (route.name==="Main"){
            return <App  navigator={navigator}/>
        }

        if (route.name==="In"){
            return <InComponent navigator={navigator}/>
        }

        if (route.name==="Forget"){
            return <ForgetComponent navigator={navigator}/>
        }

        if (route.name==='Nav'){
            return <NavComponent navigator={navigator} />
        }
    }

    // configureScene (route,navigator) {
    //     return Navigator.SceneConfigs.FloatFromBottom
    // }
}

根據name  實現不一樣的跳轉code

 

第二章  跳轉效果的展現component

react  native  中的跳轉效果能夠很輕鬆的設置,不像js 中須要設置相應的動畫效果,它主要是經過這一行代碼設置的中間件

 configureScene (route,navigator) {
        return Navigator.SceneConfigs.FloatFromBottom
    }

這是從下往上跳出的效果.

 

react  native  中還有哪些跳轉效果,後期繼續補充

相關文章
相關標籤/搜索