React-Native项目技术分享(2)

安卓BackAndroid返回键

/**
 * index.android.js
 * 
 */
'use strict'
import React, { Component } from 'react'
import { 
   AppRegistry,
   StyleSheet,
   BackAndroid, 
   Navigator, 
   StatusBar, 
   View
 } from 'react-native'
import HomePage from './jscore/HomePage'

class ReactNativeGank extends Component {
  constructor (props) {
    super(props)
    this.handleBack = this._handleBack.bind(this)
  }

  componentDidMount () {
    BackAndroid.addEventListener('hardwareBackPress', this.handleBack)
  }

  componentWillUnmount () {
    BackAndroid.removeEventListener('hardwareBackPress', this.handleBack)
  }

  _handleBack () {
    var navigator = this.navigator

    if (navigator && navigator.getCurrentRoutes().length > 1) {
      navigator.pop()
      return true
    }
    return false
  }

  render () {
    // return ();
    return (
      
        
         this.navigator = component}
          initialRoute={{
            component: HomePage
          }}
          renderScene={(route, navigator) => { // 用来渲染navigator栈顶的route里的component页面
            // route={component: xxx, name: xxx, ...}, navigator.......route 用来在对应界面获取其他键值
          return // {...route.passProps}即就是把passProps里的键值对全部以给属性赋值的方式展开 如:test={10}
        }}/>
      
    )
  }
}

var styles = StyleSheet.create({
  container: {
    flex: 1
  }
})

AppRegistry.registerComponent('ReactNativeGank', () => ReactNativeGank)

/**
 * Sample React Native App
 * index.ios.js
 */
'use strict'

import React, { Component } from 'react'
import { AppRegistry, StyleSheet, Navigator } from 'react-native'
import HomePage from './jscore/HomePage'

class ReactNativeGank extends Component {
  constructor (props) {
    super(props)
  }

  render () {
    // return ();
    return (
       { // 用来渲染navigator栈顶的route里的component页面
          // route={component: xxx, name: xxx, ...}, navigator.......route 用来在对应界面获取其他键值
          return // {...route.passProps}即就是把passProps里的键值对全部以给属性赋值的方式展开 如:test={10}
        }}/>
    )
  }
}

var styles = StyleSheet.create({
  container: {
    flex: 1
  }
})

AppRegistry.registerComponent('ReactNativeGank', () => ReactNativeGank)

StatusBar使用

/**
 * @author Lei
 * @repo https://github.com/stoneWeb/elm-react-native
 */
'use strict';

import React, { Component } from 'react'
import { 
  Navigator, 
  View, 
  StatusBar, 
  Platform 
} from 'react-native'
import Wrapper from './component/Wrapper'
//import Events from './util/event'

export default class Navigation extends Component{
    constructor(props){
      super(props)
    }
    render(){

        return Platform.OS == "ios"?(
           Navigator.SceneConfigs.FloatFromRight}
            renderScene={(route, navigator) => {
                  return 
                }
            }
          />
        ):(
          
            
             Navigator.SceneConfigs.FloatFromRight}
              renderScene={(route, navigator) => {
                    return 
                  }
              }
            />
          
        )
    }
}

你可能感兴趣的:(React-Native项目技术分享(2))