2017-05-04 85 views
0

進出口特林添加漢堡包圖標,打開抽屜上的反應,native.but即時得到這個錯誤陣營本地導航加入漢堡圖標

對象是不是一個做出反應的孩子有效(發現:對象,具有鍵{}左)。如果您打算渲染一組兒童,請改用數組,或者使用React附加組件中的createFragment(object)來包裝對象。

Check the render method of `View`. 

這是routes.js

import { StackNavigator, TabNavigator, DrawerNavigator } from 'react-navigation'; 

const DrawerIcon = ({ navigate }) => { 

return(
     <Icon 
      name = "md-menu" 
      size = {38} 
      color = "black" 
      style = {{paddingLeft : 20}} 
      onPress = {() => navigate('DrawerOpen')} 
/> 

    ); 
}; 

export const Stack1 = StackNavigator({ 
    Screen1: { 
     screen: screen1, 
     navigationOptions: { 
      header: (props) => ({ 
       left: <DrawerIcon { ...props } /> 
      }), 
     } 
    }, 
    Screen2: { 
     screen: screen2, 
    }, 
    Screen3: { 
     screen: screen3, 
    }, 



}) 

export const Drawer = DrawerNavigator({ 
    Home:{ 
     screen: Stack1, 
     navigationOption: { 
      brawerLabel: 'Home', 

     } 
    }, 
    Camera:{ 
     screen: Stack2, 
     navigationOption: { 
      brawerLabel: 'Camera', 

     } 
    }, 
    Info:{ 
     screen: Stack3, 
     navigationOption: { 
      brawerLabel: 'Info', 
     } 
    } 
}) 

我怎樣才能解決這個error.Thanks。

回答

1
static navigationOptions = ({ navigation }) => ({ 
    headerTitle: "Home", 
    ...css.header, 
    headerLeft: 
    <View style={{paddingLeft:16}}> 
     <Icon 
      name="md-menu" 
      size={30} 
      color='white' 
      onPress={() => navigation.navigate('DrawerOpen')} /> 
    </View>, 
}) 

密切關注我添加了不斷的呼叫報頭

export const header = { 
    // background 
    headerStyle: { 
    backgroundColor: colors.secondary_blue, 
    }, 
    // arrows 
    headerTintColor: colors.text_light, 
    // my own styles for titleAndIcon 
    container: { 
    flex: 1, 
    flexDirection: 'row', 
    justifyContent: 'flex-start', 

    alignItems: 'center', 
    paddingLeft: 8, 
    }, 
    // my own styles for titleAndIcon 
    text: { 

    paddingLeft: 8, 
    color: colors.text_light, 
    fontFamily: values.font_body, 
    fontSize: values.font_title_size, 
    } 

}; 
1

export default class Home extends React.Component { static navigationOptions = { headerTitle: "User Index", headerRight: <Button title="Info" onPress={()=> alert('right button')} />, }; render(){ return(<UserTabNavigator />); } };


我有同樣的問題,上面的style.js工作對我來說這條線

headerRight: <Button title="Info" onPress={()=> alert('right button')} />,

+0

但是當我在側面調用'this.props.navigation.navigate('DrawerOpen')'headerRight:

1

沒有一個以前的答案是非常可擴展的,所以我認爲我會重視我的解決方案。爲了保持完整性,我在示例中使用了react-native-vector-icons

import { StackNavigator, DrawerNavigator } from 'react-navigation'; 
import Icon from 'react-native-vector-icons/Octicons'; 

const MenuIcon = ({ navigate }) => <Icon 
    name='three-bars' 
    size={30} 
    color='#000' 
    onPress={() => navigate('DrawerOpen')} 
/>; 

const Stack = { 
    FirstView: { 
     screen: Login, 
     navigationOptions: ({ navigation }) => ({ 
      headerRight: MenuIcon(navigation) 
     }) 
    } 
}; 

// ...Remaining navigation code etc. 

這使得你會想相同的圖標打開抽屜(這確實應該是大多數用例)的假設。