2016-11-19 65 views
2

另一個屏幕,我有這個屏幕反應本土打開的反應母語

import React, { Component } from 'react'; 
    import { AppRegistry,TouchableOpacity, Text ,Button,Image,TextInput,PropTypes,StyleSheet,View,NavigatorIOS,TouchableHighlight} from 'react-native'; 


    class LoginView extends Component { 

     render() { 
      return (
       <View style={styles.container}> 
        <Text style={styles.title}> 
         HYGEX 
        </Text> 
        <View> 
         <TextInput 
          placeholder="Username" 
          style={styles.formInput} 
          /> 
         <TextInput 
          placeholder="Password" 
          secureTextEntry={true} 
          style={styles.formInput1} 
          /> 

        <TouchableHighlight style={styles.button} 
        onPress={() => this.move()}> 
        <Text style={styles.buttonText}>Login</Text> 
        </TouchableHighlight> 

        </View> 
       </View> 
      ); 
     } 

     move() { 
     //what i can do here to go to Socrce screen ??? 
     } 
     } 

像登錄界面的東西,現在當我點擊進入TouchableHighlight 我需要打開這個屏幕

'use strict'; 
import React, { Component } from 'react'; 
import { AppRegistry, ListView, Text, View } from 'react-native'; 

class HygexListView extends Component { 

    constructor(props) { 
    super(props); 
    const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2}); 
    this.state = { 
     dataSource: ds.cloneWithRows([ 
     'John', 'Joel', 'James', 'Jimmy', 'Jackson', 'Jillian', 'Julie', 'Devin' 
     ]) 
    }; 
    } 
    render() { 
    return (
     <View style={{flex: 1, paddingTop: 22}}> 
     <ListView 
      dataSource={this.state.dataSource} 
      renderRow={(rowData) => <Text>{rowData}</Text>} 
     /> 
     </View> 
    ); 
    } 
} 
module.exports = HygexListView; 

我試圖實施移動方法,但我失敗了!任何想法爲什麼?

反應是否母語必須改變屏幕時,點擊進入TouchableHighlight的方法?

回答

0

你必須實現一個導航儀,這大概是管理與屏幕的所有東西的組成部分,並與後退按鈕標題欄等

當你是一個初學者,我建議你去看看此鏈接文檔:

https://facebook.github.io/react-native/docs/navigator.html

對不起,我簡短的回答,我是我的手機上。

祝你好運!

+0

我試過,但我不能做這個申請我的情況 –

+0

爲什麼不呢?!提供更多詳細信息... –

+0

我嘗試了很多示例,並且總是在props.this.novigator中遇到錯誤或者類似的東西,如果您知道如何實現此方法,請告訴我因爲我需要爲我的所有項目使用此方法! –

-1

您必須使用導航器。請閱讀下面提到的文檔。如果你需要的話,我會分享你的代碼。

下面是一個例子:NavigatorExample

+0

我看到很多文檔,但我不能申請我的情況:\ –

+0

嗨@Bokerjy Zahgan我在鏈接中創建了一個示例。在這個例子中,我使用導航器在兩個不同的屏幕上創建了兩個應用程序文件夾中的文件,請參閱以及您有問題可以詢問我。鏈接在這裏https://github.com/Anuj-786/NavigatorExapple –

2

正如其他人所指出的,你必須使用的Navigator實例屏幕之間的轉換。也許你可以看看React Native回購中的example apps。我也發現this router package很容易設置,它還包括一個示例應用程序,您可以使用它作爲一個起點。然後

import React, { 
    Component, 
} from 'react'; 
import { 
    StyleSheet, 
    Text, 
    View, 
} from 'react-native'; 
import LoginView from './LoginView'; 
import HygexListView from './HygexListView'; 
import { 
    Scene, 
    Router, 
    Actions, 
} from 'react-native-router-flux'; 

const styles = StyleSheet.create({ 
    container: { flex: 1, backgroundColor: 'transparent', justifyContent: 'center', 
    alignItems: 'center', 
    }, 
    tabBarStyle: { 
    backgroundColor: '#eee', 
    }, 
    tabBarSelectedItemStyle: { 
    backgroundColor: '#ddd', 
    }, 
}); 


// define this based on the styles/dimensions you use 
const getSceneStyle = (/* NavigationSceneRendererProps */ props, computedProps) => { 
    const style = { 
    flex: 1, 
    backgroundColor: '#fff', 
    shadowColor: null, 
    shadowOffset: null, 
    shadowOpacity: null, 
    shadowRadius: null, 
    }; 
    if (computedProps.isActive) { 
    style.marginTop = computedProps.hideNavBar ? 0 : 64; 
    style.marginBottom = computedProps.hideTabBar ? 0 : 50; 
    } 
    return style; 
}; 

class Example extends Component { 
    render() { 
    return (
     <Router getSceneStyle={getSceneStyle}> 
     <Scene key="login" component={LoginView} initial={true}/> 
     <Scene key="hygex" component={HygexListView } /> 
     </Router> 
    ); 
    } 
} 

export default Example; 

,在組件的move功能:

編輯 作爲使用反應本地路由器通量一個簡單的例子,你可以編輯Example.js文件中的Example目錄看起來像這樣,你必須做到以下幾點:

move(){ 
    Actions.hygex(); // This will perform a slide transition, but you can customize it. Have a look at the docs for that. 

我還沒有測試代碼,所以可能有一些錯別字/缺少進口/代碼,但它笑你可以告訴你你必須做什麼。 }

+0

謝謝你,你可以申請這個爲我的情況? –

+0

你走了。這應該讓你啓動並運行。 – martinarroyo

+0

謝謝@martinarroyo,當我運行應用程序時,我得到了這個錯誤, 「undefined不是函數(evalutiongreactNativeRouterFLux.Actions.hygex())!! –