Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native 是否在react native中的createDrawerNavigator项上设置为按?_React Native_Navigation Drawer_Drawerlayout_Stack Navigator_React Navigation Drawer - Fatal编程技术网

React native 是否在react native中的createDrawerNavigator项上设置为按?

React native 是否在react native中的createDrawerNavigator项上设置为按?,react-native,navigation-drawer,drawerlayout,stack-navigator,react-navigation-drawer,React Native,Navigation Drawer,Drawerlayout,Stack Navigator,React Navigation Drawer,我有一个抽屉项目“共享应用程序”,我想在其中打开警报并显示消息,而不是在react native中打开整个屏幕。我的代码如下: const Screen6_StackNavigator = createStackNavigator({ //All the screen from the Screen6 will be indexed here Sixth: { screen: ShareApp, //don't want this screen title:'Share'

我有一个抽屉项目“共享应用程序”,我想在其中打开警报并显示消息,而不是在react native中打开整个屏幕。我的代码如下:

const Screen6_StackNavigator = createStackNavigator({
  //All the screen from the Screen6 will be indexed here
  Sixth: {
    screen: ShareApp, //don't want this screen
    title:'Share',
    navigationOptions: ({ navigation }) => ({
      headerLeft: () => <NavigationDrawerStructure navigationProps={navigation} />,
      headerStyle: {
        backgroundColor: '#138808',
      },
      headerTintColor: '#fff',
    }),
  },
});

const DrawerNavigatorExample = createDrawerNavigator({
  ShareApp: {
    //Title
    screen: Screen6_StackNavigator,
    navigationOptions: {
      drawerLabel: 'Share App',
      drawerIcon: (<Entypo name="share" size={20} color='black'></Entypo>)

    },
  },
);

const Screen6\u StackNavigator=createStackNavigator({
//Screen6中的所有屏幕都将在此处编制索引
第六:{
screen:ShareApp,//不需要此屏幕
标题:“股份”,
导航选项:({navigation})=>({
headerLeft:()=>,,
头型:{
背景颜色:“#138808”,
},
标题颜色:“#fff”,
}),
},
});
const paurernavigatorexample=createpaurernavigator({
ShareApp:{
//头衔
屏幕:屏幕6\u StackNavigator,
导航选项:{
抽屉标签:“共享应用程序”,
付款人:()
},
},
);
我在哪里添加onPress参数来调用函数?我不希望屏幕参数,只希望在单击共享应用程序时调用函数

如何在react native中做到这一点

请帮助我,因为我是新来的


谢谢。

您可以创建一个自定义抽屉内容组件,并将其传递给
DrawerNavigatorConfig
中的
contentComponent
选项

创建自定义抽屉内容:
DrawerItems
应该从
react navigation drawer

导入,这很有效。但是无法在TouchableOpacity的onPress上调用函数。如何执行此操作?您可以通过将示例中的警报行替换为正常的
警报(1)进行测试吗
检查它是否实际被调用?因为警报在
web上不起作用
。所以,如果还没有,请在实际设备上进行测试。是的..警报正常,但无法在press={()=>this.testFunction()}上调用函数,显示的错误是:_this2.testFunction不是函数。(在'_this2.testFunction()中)“,“'u this2.testFunction'未定义)哦,我明白了。是的,那是因为
CustomDrawerContentComponent
是一个功能组件,所以您不使用
这个
const CustomDrawerContentComponent = (props) => (
  <ScrollView>
    <SafeAreaView
      style={{ flex: 1 }}
      forceInset={{ top: 'always', horizontal: 'never' }}>
      <TouchableOpacity
        onPress={() => {
          // Do something...
          Alert.alert('Heading', 'Body');
        }}
        style={{ left: 15, flexDirection: 'row', alignItems: 'center' }}>
        <Entypo name="share" size={20} color='black'></Entypo>
        <Text style={{ marginLeft: 30, fontWeight: 'bold' }}>Share App</Text>
      </TouchableOpacity>
      <DrawerItems {...props} />
    </SafeAreaView>
  </ScrollView>
);
const DrawerNavigatorExample = createDrawerNavigator(
  {
    Screen1: {
      // Properties...
    },
    // Other screens...
  },
  {
    // Pass custom drawer content component...
    contentComponent: props => <CustomDrawerContentComponent {...props} />,
    // Other configurations...
  },
);