0

再会,

这是我使用 NativeBase 组件的 React Native 应用程序的一个小问题。问题出在<Content />NativeBase 的组件中。我想使用<Carousel />来自 github 的组件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',
  },
})

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

提前致谢。

4

1 回答 1

2

关于react-native-carousel

  • 渲染Carousel
  • Carousel渲染CarouselPager
  • 以及RN 的CarouselPager渲染图ScrollView

关于NativeBase Content,它呈现ScrollViewRN。因此,不需要将其包装在另一个 ScrollView 中并导致问题。

尝试排除 NB 的内容。

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

于 2016-12-29T06:07:52.107 回答