2017-11-03 4 views
1

내가 내가 내가 열심히 노력 내 탐색 넣어에서 매개 변수 아무것도 :(가 TabNavigator 및 소품

navigation.js

import React, { Component } from 'react'; 
import { TabNavigator } from 'react-navigation'; 

import ListingScreen from './listing'; 
import PreferencesScreen from './preferences'; 
import AddScreen from './add'; 
import CalendarScreen from './calendar'; 
import ProfessionalScreen from './professional'; 

const navigation = TabNavigator({ 
    Listing: {screen: ListingScreen}, 
    Preferences: {screen: PreferencesScreen, screenProps: {option: "My first option"}}, 
    Add: {screen: AddScreen}, 
    Calendar: {screen: CalendarScreen}, 
    Professional: {screen: ProfessionalScreen}, 
}, { 
    tabBarOptions: { 
     activeTintColor: 'blue', 
     activeBackgroundColor: 'grey', 
     inactiveTintColor: 'black', 
    }, 
}); 

<navigation 
    screenProps="I am a Props !" 
/> 

export default navigation; 

내 다른 화면을 통과하고 싶습니다 ...가 TabNavigator에 문제가 : preferences.js 내 생성자에서

import React, { Component } from 'react'; 
import {View, Text} from 'react-native'; 

export default class Preferences extends Component { 
    static navigationOptions = { 
     title: 'Preferences', 
    }; 

    constructor(props) { 
     super(props); 
     console.log("Constructor"); 
     console.log(this.props) 
    } 
    render() { 
     return (
      <View> 
       <Text style={{marginTop: '80%', marginLeft: '40%'}}> Preferences </Text> 
      </View> 
     ); 
    } 
} 

내가 소품을 표시하려고 (그들은 동일하다)하지만 난 그이 ...

Console.log()

누군가 알고 있겠습니까?

+0

가 문자열이 아닌 객체로'screenProps'을 전달하십시오. –

답변

1

이 시도 :

import React, { Component } from 'react'; 
import { TabNavigator } from 'react-navigation'; 

import PreferencesScreen from './preferences'; 

const Navigation = TabNavigator({ 
    Preferences: {screen: PreferencesScreen}, 
}, { 
    tabBarOptions: { 
    activeTintColor: 'blue', 
    activeBackgroundColor: 'grey', 
    inactiveTintColor: 'black', 
    }, 
}); 

export default class Index extends Component { 
    render() { 
    return <Navigation screenProps="I am a Props !"/>; 
    } 
}