Reactネイティブナビゲーションバーの使用方法

okwaves2024-01-25  8

navbar-native から Navbar を操作しようとしていますが、プロジェクトにインポートするとこのエラーが発生します (typeerror unknown はオブジェクトではありません (「_react.proptypes.bool」を評価中))。 コードは次のとおりです:

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

import { navbar } from "navbar-native";

import colors from "../config/colors";


function ViewImageScreen(props) {
  return (
    <View style={styles.container}>
    
    <Navbar
                    title={"Navbar Native"}
                    left={{
                        icon: "ios-arrow-back",
                        label: "Back",
                        onPress: () => {alert('Go back!')}
                    }}
                    right={[{
                        icon: "ios-search",
                        onPress: () => {alert('Search!')}
                    },{
                        icon: "ios-menu",
                        onPress: () => {alert('Toggle menu!')}
                    }]}
                />

      <View style={styles.signinIcon}>
        <Text style={styles.signinText}>Se connecter</Text>
      </View>
      <View style={styles.favoris}>
        <Image style={styles.icon} source={require("../assets/logo-red.png")} />
        <Text style={styles.settingsText}>Favoris</Text>
      </View>
      <View style={styles.newsletter}>
        <Image style={styles.icon} source={require("../assets/logo-red.png")} />
        <Text style={styles.settingsText}>Newsletter</Text>
      </View>
      <View style={styles.aide}>
        <Image style={styles.icon} source={require("../assets/logo-red.png")} />
        <Text style={styles.settingsText}>Aide & Contact</Text>
      </View>
      <View style={styles.apropos}>
        <Image style={styles.icon} source={require("../assets/logo-red.png")} />
        <Text style={styles.settingsText}>A propos</Text>
      </View>
      <View style={styles.signupIcon}>
        <Text style={styles.signupText}>S'enregistrer</Text>
      </View>
    </View>
  );
}

const styles = StyleSheet.create({
  signinIcon: {
    width: "90%",
    height: 50,
    position: "absolute",
    top: 360,
    alignSelf: "center",
    borderColor: colors.fm_blue,
    borderWidth: 2,
    textAlign: "center",
    justifyContent: "center",
    alignItems: "center",
    borderRadius: 5,
  },
  signupIcon: {
    backgroundColor: colors.fm_blue,
    width: "90%",
    height: 50,
    position: "absolute",
    top: 300,
    alignSelf: "center",
    textAlign: "center",
    justifyContent: "center",
    alignItems: "center",
    borderRadius: 5,
  },
  container: {
    backgroundColor: colors.grey,
    flex: 1,
  },
  signinText: {
    fontSize: 16,
    color: colors.fm_blue,
  },
  signupText: {
    fontSize: 16,
    color: colors.white,
  },
  settingsText: {
    fontSize: 14,
    margin: 50,
    color: colors.black,
  },
  favoris: {
    backgroundColor: colors.white,
    width: "100%",
    height: 50,
    position: "absolute",
    top: 40,
    alignSelf: "center",
    borderColor: colors.white,
    textAlign: "center",
    justifyContent: "center",
  },
  newsletter: {
    backgroundColor: colors.white,
    width: "100%",
    height: 50,
    position: "absolute",
    top: 100,
    alignSelf: "center",
    borderColor: colors.white,
    textAlign: "center",
    justifyContent: "center",
  },
  aide: {
    backgroundColor: colors.white,
    width: "100%",
    height: 50,
    position: "absolute",
    top: 160,
    alignSelf: "center",
    borderColor: colors.white,
    textAlign: "center",
    justifyContent: "center",
  },
  apropos: {
    backgroundColor: colors.white,
    width: "100%",
    height: 50,
    position: "absolute",
    top: 220,
    alignSelf: "center",
    borderColor: colors.white,
    textAlign: "center",
    justifyContent: "center",
  },
  icon: {
    margin: 20,
    width: 20,
    height: 20,
    position: "absolute",
    justifyContent: "center",
  },
});

export default ViewImageScreen;

そして、これが私の package.json です:

{
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web",
    "eject": "expo eject"
  },
  "dependencies": {
    "expo": "~38.0.8",
    "expo-status-bar": "^1.0.2",
    "navbar-native": "^1.6.1",
    "prop-types": "^15.7.2",
    "react": "~16.11.0",
    "react-dom": "~16.11.0",
    "react-native": "https://github.com/expo/react-native/archive/sdk-38.0.2.tar.gz",
    "react-native-navbar": "^2.1.0",
    "react-native-vector-icons": "^7.0.0",
    "react-native-web": "~0.11.7"
  },
  "devDependencies": {
    "@babel/core": "^7.8.6",
    "@types/react-native-vector-icons": "^6.4.5",
    "babel-preset-expo": "~8.1.0"
  },
  "private": true
}

Android エミュレータでのエラーのスクリーンショットは次のとおりです。

デッガーエラー



------------------------

まず、Navbar を大文字でインポートする必要があります

import { Navbar } from "navbar-native";

そうでない場合は、こちらを参照してください

https://github.com/redbaron76/navbar-native/issues/12

https://github.com/redbaron76/navbar-native/issウエス/18

https://github.com/redbaron76/navbar-native/issues/21

更新された回答: Navbar をコンテナでラップする必要があります

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

import { Container, Navbar } from 'navbar-native';

class ReactNativeProject extends Component {
    render() {
        return (
            <Container>
                <Navbar
                    title={"Navbar Native"}
                    left={{
                        icon: "ios-arrow-back",
                        label: "Back",
                        onPress: () => {alert('Go back!')}
                    }}
                    right={[{
                        icon: "ios-search",
                        onPress: () => {alert('Search!')}
                    },{
                        icon: "ios-menu",
                        onPress: () => {alert('Toggle menu!')}
                    }]}
                />
                ... other stuff ...
            </Container>
        );
    }
}

2

回答を更新しました。Navbar をコンテナでラップしようとしましたか?

– シン・ホー・タン

2020 年 9 月 3 日 11:58

はい、ドキュメントからまったく同じコードを取得しました。と述べていますが、それでも同じエラーが発生します。

– アンドロイド開発者

2020 年 9 月 3 日 12:41

総合生活情報サイト - OKWAVES
総合生活情報サイト - OKWAVES
生活総合情報サイトokwaves(オールアバウト)。その道のプロ(専門家)が、日常生活をより豊かに快適にするノウハウから業界の最新動向、読み物コラムまで、多彩なコンテンツを発信。