React native 导航未定义

React native 导航未定义,react-native,React Native,我想知道是否有人能帮我。我在另一个文件夹中创建了一个图像库,我正试图在个人资料页面上调用它。不幸的是,我收到了“导航未定义”错误消息。它发生在我的onPress函数中,你可以在下面看到。我导入了{withNavigation},并将图像库组件导出如下: 使用导航导出默认值(图像库) 有人知道为什么会发生这种情况吗 import React from "react"; import { View, Text, StyleSheet, Image, Button, Imag

我想知道是否有人能帮我。我在另一个文件夹中创建了一个图像库,我正试图在个人资料页面上调用它。不幸的是,我收到了“导航未定义”错误消息。它发生在我的onPress函数中,你可以在下面看到。我导入了{withNavigation},并将图像库组件导出如下: 使用导航导出默认值(图像库)

有人知道为什么会发生这种情况吗

import React from "react";

import {
  View,
  Text,
  StyleSheet,
  Image,
  Button,
  ImageBackground
} from "react-native";

import ImageGallery from "./ImageGallery";

import { withNavigation } from "react-navigation";

class CharacterProfiles extends React.Component {
  static navigationOptions = {
    title: "The Simpsons",
    headerStyle: {
      backgroundColor: "#53b4e6"
    },
    headerTintColor: "#f6c945",
    headerTitleStyle: {
      fontWeight: "bold"
    },
    headerRight: (
      <Button
        onPress={() => navigation.navigate("ImageGallery")}
        title="Gallery"
        color="#f6c945"
      />
    )
  };
从“React”导入React;
进口{
看法
文本,
样式表,
形象,,
按钮
图像背景
}从“反应本族语”;
从“/ImageGallery”导入ImageGallery;
从“反应导航”导入{withNavigation};
类CharacterProfiles扩展了React.Component{
静态导航选项={
标题:“辛普森一家”,
头型:{
背景颜色:“53b4e6”
},
标题颜色:“f6c945”,
头饰样式:{
fontWeight:“粗体”
},
头灯:(
导航。导航(“ImageGallery”)}
title=“画廊”
color=“#f6c945”
/>
)
};

您需要使用文档[1]中描述的导航选项的动态配置,以便访问
导航对象:

class CharacterProfiles extends React.Component {
  // note that `navigationOptions` is now a function that receives `navigation`
  static navigationOptions = ({navigation}) => ({
    title: "The Simpsons",
    headerStyle: {
      backgroundColor: "#53b4e6"
    },
    headerTintColor: "#f6c945",
    headerTitleStyle: {
      fontWeight: "bold"
    },
    headerRight: (
      <Button
        onPress={() => navigation.navigate("ImageGallery")}
        title="Gallery"
        color="#f6c945"
      />
    )
  });
类CharacterProfiles扩展了React.Component{
//注意,“导航选项”现在是一个接收“导航”的函数`
静态导航选项=({navigation})=>({
标题:“辛普森一家”,
头型:{
背景颜色:“53b4e6”
},
标题颜色:“f6c945”,
头饰样式:{
fontWeight:“粗体”
},
头灯:(
导航。导航(“ImageGallery”)}
title=“画廊”
color=“#f6c945”
/>
)
});

[1] 您需要使用文档[1]中描述的导航选项的动态配置,以便访问
导航对象:

class CharacterProfiles extends React.Component {
  // note that `navigationOptions` is now a function that receives `navigation`
  static navigationOptions = ({navigation}) => ({
    title: "The Simpsons",
    headerStyle: {
      backgroundColor: "#53b4e6"
    },
    headerTintColor: "#f6c945",
    headerTitleStyle: {
      fontWeight: "bold"
    },
    headerRight: (
      <Button
        onPress={() => navigation.navigate("ImageGallery")}
        title="Gallery"
        color="#f6c945"
      />
    )
  });
类CharacterProfiles扩展了React.Component{
//注意,“导航选项”现在是一个接收“导航”的函数`
静态导航选项=({navigation})=>({
标题:“辛普森一家”,
头型:{
背景颜色:“53b4e6”
},
标题颜色:“f6c945”,
头饰样式:{
fontWeight:“粗体”
},
头灯:(
导航。导航(“ImageGallery”)}
title=“画廊”
color=“#f6c945”
/>
)
});
[1]