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 Snap Carousel组件未正确显示_React Native_Carousel_Native Base - Fatal编程技术网

React native React Native Snap Carousel组件未正确显示

React native React Native Snap Carousel组件未正确显示,react-native,carousel,native-base,React Native,Carousel,Native Base,我正在react原生应用程序中使用NPM包。我能够成功加载页面,但旋转木马没有按预期显示子组件。旋转木马中的卡呈现非常小(高度非常小,不清晰) 如果我在NativeBase的组件中使用卡组件,卡的效果会非常好,但如果在carousel组件下使用相同的卡组件,卡就会乱七八糟。它很可能与carousel子组件的样式有关 这就是carousel在Android上的外观(未在iOS上测试): 下面是代码 BusinessCarousel.js import React, { Component } f

我正在react原生应用程序中使用NPM包。我能够成功加载页面,但旋转木马没有按预期显示子组件。旋转木马中的卡呈现非常小(高度非常小,不清晰)

如果我在NativeBase的
组件中使用卡组件,卡的效果会非常好,但如果在carousel组件下使用相同的卡组件,卡就会乱七八糟。它很可能与carousel子组件的样式有关

这就是carousel在Android上的外观(未在iOS上测试):

下面是代码

BusinessCarousel.js

import React, { Component } from 'react';
import { Dimensions } from 'react-native';
import { Text, View } from 'native-base';
import Carousel from 'react-native-snap-carousel';
import BusinessCard from './card';

export class BusinessCarousel extends Component {
  _renderItem({ item, index }) {
    return <BusinessCard business={item} />;
  }

  render() {
    const businesses = [
      {
        name: 'business 1',
        details:
          'Business 1 details Business 1 details Business 1 details Business 1 details Business 1 details ',
        address: {
          fullAddress: 'some address'
        }
      },
      {
        name: 'business 2',
        details:
          'Business 1 details Business 1 details Business 1 details Business 1 details Business 1 details ',
        address: {
          fullAddress: 'some address'
        }
      },
      {
        name: 'business 3',
        details:
          'Business 1 details Business 1 details Business 1 details Business 1 details Business 1 details ',
        address: {
          fullAddress: 'some address'
        }
      }
    ];

    return (
        <Carousel
          ref={c => {
            this._carousel = c;
          }}
          data={businesses}
          renderItem={this._renderItem}
          sliderWidth={Dimensions.get('window').width}
          itemWidth={Dimensions.get('window').width * 0.8}
          containerCustomStyle={{ overflow: 'visible' }}
          contentContainerCustomStyle={{ overflow: 'visible' }}
        />
    );
  }
}
import React, { Component } from 'react';
import {
  Card,
  CardItem,
  Left,
  Right,
  Thumbnail,
  Image,
  Text,
  View,
  Button,
  Body,
  Icon
} from 'native-base';

export default class BusinessCard extends Component {
  _getLogoURL() {
    const { business } = this.props;
    if (business.logo && business.logo.url) return { uri: business.logo.url };
    return require('../../public/no-image-available.png');
  }

  render() {
    const { business } = this.props;
    return (
      <Card>
        <CardItem>
          <Left>
            <Thumbnail source={this._getLogoURL()} />
            <Body>
              <Text>{business.name}</Text>
              <Text note numberOfLines={1}>
                {(business.address && business.address.fullAddress) || ''}
              </Text>
            </Body>
          </Left>
          <Right>
            <Icon name="create" />
          </Right>
        </CardItem>
        <CardItem>
          <Body>
            <Text>{business.details}</Text>
          </Body>
        </CardItem>
      </Card>
    );
  }
}
import React,{Component}来自'React';
从“react native”导入{Dimensions};
从'native base'导入{Text,View};
从“react native snap Carousel”导入转盘;
从“./card”导入名片;
导出类BusinessCarousel扩展组件{
_renderItem({item,index}){
返回;
}
render(){
常数业务=[
{
名称:“业务1”,
细节:
“业务1详情业务1详情业务1详情业务1详情业务1详情业务1详情”,
地址:{
fullAddress:“某个地址”
}
},
{
名称:‘业务2’,
细节:
“业务1详情业务1详情业务1详情业务1详情业务1详情业务1详情”,
地址:{
fullAddress:“某个地址”
}
},
{
名称:“业务3”,
细节:
“业务1详情业务1详情业务1详情业务1详情业务1详情业务1详情”,
地址:{
fullAddress:“某个地址”
}
}
];
返回(
{
这个。_carousel=c;
}}
数据={business}
renderItem={this.\u renderItem}
sliderWidth={Dimensions.get('window').width}
itemWidth={Dimensions.get('window')。宽度*0.8}
containerCustomStyle={{overflow:'visible'}}
contentContainerCustomStyle={{overflow:'visible'}}
/>
);
}
}
名片(card.js)

import React,{Component}来自'React';
进口{
卡片
卡迪姆,
左边
正确的,
缩略图,
形象,,
文本,
看法
按钮
身体,
偶像
}来自“本土基地”;
导出默认类名片扩展组件{
_getLogoURL(){
const{business}=this.props;
if(business.logo&&business.logo.url)返回{uri:business.logo.url};
返回require('../../public/no image available.png');
}
render(){
const{business}=this.props;
返回(
{business.name}
{(business.address&&business.address.fullAddress)| |'''}
{business.details}
);
}
}

您是否尝试过使用NativeBase中的容器组件包装卡片组件?没有。您可以在上面的代码中看到,
Card.js
正在将
作为顶级组件返回。我想您可能已经尝试过了。那你能试试吗?你试过用纯视图作为旋转木马元素吗?我猜是由于本机基本组件的某些样式导致了这种行为。也许是一个“flex:1”我也有类似的问题检查这个:这可能会帮助你