【问题标题】:React Native + NativeBase Content component and Carousel (not displaying)React Native + NativeBase 内容组件和轮播(不显示)
【发布时间】:2016-12-29 02:37:44
【问题描述】:

早安,

这是我使用 NativeBase 组件的 React Native 应用程序的一个小问题。问题出在 NativeBase 的 <Content /> 组件中。我想使用来自github的<Carousel />组件react-native-carousel

代码如下:

index.android.js

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

import {
  Container,
  Header,
  Content,
  Title,
  Icon,
  Button,
} from 'native-base';

import Carousel from 'react-native-carousel';

import styles from './src/styles/styles';

export default class iABC extends Component {
  render() {
    return (
      <Container>
        <Header backgroundColor='#ffffff' height={50}>
          <Button transparent>
            <Icon name='md-menu' style={styles.header.icon} />
          </Button>

          <Title style={styles.header.title}>
            iABC
          </Title>

          <Button transparent>
            <Icon name='md-person' style={styles.header.icon} />
          </Button>
        </Header>

        <Content>
          <View style={styles.global.content}>            
            <Carousel width={375}
              hideIndicators={false}
              indicatorColor='#000000'
              indicatorSize={25}
              indicatorSpace={20}
              indicatorAtBottom={true}
              indicatorOffset={250}
              indicatorText='>'
              animate={true}
              delay={2000}
              loop={true}>

              <View style={styles.carousel.page1}>
                <Text>Page 1</Text>
              </View>
              <View style={styles.carousel.page1}>
                <Text>Page 2</Text>
              </View>
              <View style={styles.carousel.page1}>
                <Text>Page 3</Text>
              </View>
            </Carousel>
          </View>          
        </Content>
      </Container>
    );
  }
}

AppRegistry.registerComponent('iABC', () => iABC);

样式:carousel.js

'use strict'
import { StyleSheet } from 'react-native';

export default StyleSheet.create({
  page1: {
    flex: 1,
    height: 150,
    width: 375,
    backgroundColor: '#cdcdcd',
    justifyContent: 'center',
    alignItems: 'center',
  }
})

样式:global.js

'use strict'
import { StyleSheet } from 'react-native';

export default StyleSheet.create({
  content: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
  },
})

我尝试了很多东西,设计轮播组件,给它一个单独的视图,同时设计两者,但不幸的是它不起作用。但是,只要我删除 NativeBase 的 &lt;Content /&gt; 组件,它就可以正常工作。我很确定问题出在 NativeBase 组件上。

提前致谢。

【问题讨论】:

    标签: javascript react-native react-jsx react-native-android native-base


    【解决方案1】:

    关于react-native-carousel

    • 渲染Carousel
    • Carousel 渲染 CarouselPager
    • CarouselPagerrenders ScrollView RN

    关于NativeBaseContent,它渲染了RN的ScrollView。因此不需要将其包装在另一个 ScrollView 中并导致问题。

    尝试排除 NB 的内容。

    了解更多关于 NativeBase 的替换组件 - CheatSheet

    【讨论】:

    • 谢谢,知道了。不确定 NB 的 Content 返回什么,以为它只是返回 View 组件 :( 试图避免使用 NB 的 Component 并使用 react-native-carousel-component 中的另一个 Carousel 组件。
    • 我认为您不需要避免所有 NB 的组件。只有在这种情况下才能避免。您可以查看 NB 的文档,其中包含所有组件的详细信息
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-08-01
    • 1970-01-01
    • 2021-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-19
    相关资源
    最近更新 更多