Нарушение инварианта: текстовые строки должны отображаться в текстовом компоненте - PullRequest
0 голосов
/ 16 сентября 2018

введите описание изображения здесь Я пытаюсь добавить свой CardsSection компонент в мой Card компонент, однако я получаю эту ошибку о нарушении текста, но я даже не использую какой-либо текст в моих Tournament, Card или CardSection. JS файлы. Я не понимаю, почему я получаю эту ошибку. Может кто-нибудь сказать мне, что делать и почему?

Tournament.js

import React from "react";
import { View, Text, Image, ScrollView } from "react-native";
import { Card, Button, Spinner, CardSection } from "../common";

class Tournaments extends React.Component {
  static navigationOptions = {
    tabBarLabel: "Tournaments"
  };
  render() {
    return (
      <View style={styles.containerStyle}>
        <Card>
          <View style={styles.logoContainer}>
            <Image
              style={styles.logo}
              source={require("../../Images/ShoeJackCityLogo.png")}
            />
          </View>
          <View style={styles.formContainer} />
        </Card>
        <ScrollView horizontal>
          <Card>
            <View style={{ flex: 1, flexDirection: "row" }}>
              <CardSection>
                <Image
                  style={styles.product}
                  source={require("../../Images/aj_4_toro.png")}
                />
              </CardSection>
              <CardSection>
                <Image
                  style={styles.product}
                  source={require("../../Images/aj_4_toro.png")}
                />
              </CardSection>
              <CardSection>
                <Image
                  style={styles.product}
                  source={require("../../Images/aj_4_toro.png")}
                />
              </CardSection>
            </View>
          </Card>
        </ScrollView>
      </View>
    );
  }
}
const styles = {
  containerStyle: {
    flex: 1,
    backgroundColor: "#F13C20",
    paddingBottom: 20
  },
  logoContainer: {
    alignItems: "center",
    flexGrow: 1,
    justifyContent: "flex-start",
    paddingBottom: 15
  },
  logo: {
    paddingTop: 15,
    width: 50,
    height: 50
  },
  product: {
    width: 100,
    height: 100,
    paddingBottom: 15,
    marginRight: 50
  }
};
export default Tournaments;

CardSection.js

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

const CardSection = (props) => (
    <View style={styles.containerStyle}>
    {props.children};
    </View>
  );

const styles = {
  containerStyle: {
    borderBottomWidth: 1,
    padding: 5,
    backgroundColor: 'white',
    justifyContent: 'flex-start',
    flexDirection: 'row',
    borderColor: '#ddd',
    position: 'relative'
  }
};

export { CardSection };

Card.js

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

const Card = (props) => (
    <View style={styles.containerStyle}>
      {props.children}
    </View>
  );

const styles = {
  containerStyle: {
    borderBottomWidth: 0,
    shadowColor: '#000',
    shadowOffset: { width: 0, height: 2 },
    shadowOpacity: 0.1,
    shadowRadius: 2,
    elevation: 1,
    marginLeft: 5,
    marginRight: 5,
    marginTop: 30,
}
};

export { Card };

Ответы [ 2 ]

0 голосов
/ 19 сентября 2018

Попробуйте удалить все пробелы (и, возможно, окончания строк) из родительского тега.

Facebook говорит, что это не ошибка и она работает как задумано (в связанном отчете об ошибке), и что они не внесли никаких изменений в .56, но это не так, как на самом деле работает, и работает явно не так, как в предыдущих версиях.

Также у Expo нет проблем с лишними пробелами. Как ты собираешься это сделать, я не могу тебе сказать.

0 голосов
/ 17 сентября 2018

У вас есть точка с запятой, соединенная сразу после ваших детей в компоненте CardSection. Эта точка с запятой интерпретируется как текст, и поскольку каждый текст должен быть в компоненте <Text>, выдается ошибка.

Чтобы исправить проблему, просто измените

const CardSection = (props) => (
  <View style={styles.containerStyle}>
  {props.children};
  </View>
);

до

const CardSection = (props) => (
  <View style={styles.containerStyle}>
  {props.children}
  </View>
);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...