React Native + NativeBase Content组件和Carousel(不展示)

React Native + NativeBase Content component and Carousel (not displaying)

美好的一天,

这是我使用 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 的 <Content /> 组件,它就可以正常工作。我很确定问题出在 NativeBase 组件上。

提前致谢。

关于react-native-carousel

  • 呈现 Carousel
  • Carousel 呈现 CarouselPager
  • 并且 CarouselPager 呈现 ScrollView 的 RN

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

尝试排除NB的内容。

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