StackNavigator:超级表达式必须为null或函数,且未定义

时间:2018-09-02 15:27:58

标签: react-native error-handling navigation stack-navigator

import React, { Component } from "react";
import {
  StyleSheet,
  Text,
  Image,
  View,
  TextInput,
  Button,
  FlatList,
  TouchableOpacity,
  ActivityIndicator,
  ScrollView,
  Alert,
  Linking,
  TouchableHighlight,
  RefreshControl
} from "react-native";
import {
  Ionicons,
  Entypo,
  FontAwesome,
  MaterialIcons
} from "@expo/vector-icons";
import moment from "moment";
import InfoScreen from "./InfoScreen";

const AppNavigator = StackNavigator({
  InfoScreen: { screen: InfoScreen }
});

export default class FutureLaunches extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      isLoading: true,
      dataSource: null,
      refreshing: false
    };
  }

  _onRefresh = () => {
    this.setState({ refreshing: true });
    this.componentDidMount().then(() => {
      this.setState({ refreshing: false });
    });
  };

  onPress() {
    Alert.alert("Blahblachadwiad");
  }
  componentDidMount() {
    return fetch("https://launchlibrary.net/1.4/launch?mode=verbose")
      .then(response => response.json())
      .then(responseJson => {
        this.setState({
          isLoading: false,
          dataSource: responseJson.launches
        });
      })
      .catch(error => {
        console.log(error);
      });
  }

  render() {
    if (this.state.isLoading) {
      return (
        <View style={styles.container}>
          <ActivityIndicator />
        </View>
      );
    } else {
      let launches = this.state.dataSource.map((item, key) => {
        let LaunchDate = moment(item.isostart, moment.ISO_8601).format("llll");
        return (
          <View key={key} style={styles.container}>
            <Image
              style={{ width: 350, height: 520, borderRadius: 10 }}
              source={{ uri: item.rocket.imageURL }}
            />
            <Entypo
              name="map"
              color={"white"}
              size={24}
              style={styles.MapIcon}
              onPress={() => Linking.openURL(item.location.pads[0].mapURL)}
            />
            <FontAwesome
              name="heart-o"
              color={"white"}
              size={25}
              style={{
                backgroundColor: "transparent",
                position: "absolute",
                marginTop: "6.5%",
                marginLeft: "50%"
              }}
            />
            <Entypo
              name="video-camera"
              color={"white"}
              size={24}
              style={styles.VideoIcon}
              onPress={() => {
                if (item.vidURLs.length > 0) {
                  Linking.openURL(item.vidURLs[0]);
                } else if (item.vidURLs.length == 0) {
                  Alert.alert("There is no livestream available.");
                }
              }}
            />
            <TouchableHighlight onPress={this.onPress.bind(this)}>
              <View style={styles.subcontainer}>
                <Text style={styles.Title}>{item.missions[0].name}</Text>
                <Text style={{ paddingBottom: 3 }}>
                  <Text style={styles.TextHeader}>Launch Date: </Text>
                  <Text style={styles.Text}>{LaunchDate}</Text>
                </Text>
                <Text style={{ paddingBottom: 3 }}>
                  <Text style={styles.TextHeader}>Location: </Text>
                  <Text style={styles.Text}>{item.location.name}</Text>
                </Text>
                <Text style={{ paddingBottom: 3 }}>
                  <Text style={styles.TextHeader}>Service Provider: </Text>
                  <Text style={styles.Text}>{item.lsp.name}</Text>
                </Text>
                <Text style={{ paddingBottom: 3 }}>
                  <Text style={styles.TextHeader}>Rocket: </Text>
                  <Text style={styles.Text}>{item.rocket.name}</Text>
                </Text>
              </View>
            </TouchableHighlight>
          </View>
        );
      });

      return (
        <View style={styles.Background}>
          <AppNavigator />
          <ScrollView
            contentContainerStyle={styles.contentContainer}
            refreshControl={
              <RefreshControl
                refreshing={this.state.refreshing}
                onRefresh={this._onRefresh}
              />
            }
          >
            {launches}
          </ScrollView>
        </View>
      );
    }
  }
}

当尝试实现堆栈导航器时,遇到一个错误,即“超级表达式必须为null或函数,且未定义。”并且错误消息仅在我尝试实现它时出现,其他都没有。我查找了此错误的解决方案,但似乎无济于事。我确保拼写/大写正确,并且React已更新,但仍然从未找到解决方案。我正在尝试使它成为屏幕顶部的堆栈导航器,一旦按下Touchable Highlight,它将带您进入信息屏幕。

0 个答案:

没有答案