-1

我如何在反应原生快照轮播中显示以下输出

  <Carousel
                autoplayInterval={4000}
                // slideStyle={{ flex: 1,
                // marginRight:10}}
                ref={ (c) => { this._carousel = c; } }
                data={this.state.featuredBusinessData}
                scrollInterpolator={stackScrollInterpolator}
                slideInterpolatedStyle={stackAnimatedStyles}
                useScrollView={true}
                renderItem={this._renderItemFeaturedBusiness.bind(this)}
                onSnapToItem={this.handleSnapToItem.bind(this)}
                sliderWidth={deviceWidth}
                // itemWidth={deviceWidth/2.5 }
                itemWidth={deviceWidth/3 }
                layout={'default'}
                // loopClonesPerSide={this.state.videos.length-1}
                firstItem={2}
                autoplay={true}
                loop={true}
                useScrollView={true}
                enableMomentum={true}
                lockScrollWhileSnapping={false}
                
                />

因为我是 RN 新手,请任何人告诉我如何在 react native snap carousel 中显示以下输出

4

2 回答 2

3

输出:

在此处输入图像描述

@Waheed Akhtar 为您提供了完美的建议,但如果您在实施中仍有一些困难,这里是完整的工作示例:


import * as React from 'react';
import { Text, View, StyleSheet, FlatList, Image } from 'react-native';
import Constants from 'expo-constants';

// You can import from local files
import AssetExample from './components/AssetExample';

// or any pure javascript modules available in npm
import { Card } from 'react-native-paper';

export default function App() {
  const videos = [
    {
      id: 'WpIAc9by5iU',
      thumbnail: 'https://source.unsplash.com/random',
      title: 'Led Zeppelin - Stairway To Heaven',
    },
    {
      id: 'sNPnbI1arSE',
      thumbnail: 'https://img.youtube.com/vi/sNPnbI1arSE/hqdefault.jpg',
      title: 'Eminem - My Name Is',
    },
    {
      id: 'VOgFZfRVaww',
      thumbnail: 'https://img.youtube.com/vi/VOgFZfRVaww/hqdefault.jpg',
      title: 'some title',
    },{
      id: 'WpIAc9by5iU',
      thumbnail: 'https://source.unsplash.com/random',
      title: 'Led Zeppelin - Stairway To Heaven',
    },
    {
      id: 'sNPnbI1arSE',
      thumbnail: 'https://source.unsplash.com/random',
      title: 'Eminem - My Name Is',
    },
    {
      id: 'VOgFZfRVaww',
      thumbnail: 'https://img.youtube.com/vi/VOgFZfRVaww/hqdefault.jpg',
      title: 'some title',
    },
  ];
  return (
    <View style={styles.container}>
      <FlatList
        horizontal
        data={videos}
        renderItem={({ item }) => (
          <View style={styles.card_template}>
        <Image
          style={styles.card_image}
          source={{
            uri:
              item.thumbnail,
          }}
        />
        <View style={styles.text_container}>
          <Text style={styles.card_title}>{item.title.toUpperCase().substr(0, 10)+"..."}</Text>
          <Text style={styles.card_subtitle}>{item.id}</Text>
        </View>
        
      </View>
        )}
      />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    paddingTop: Constants.statusBarHeight,
    backgroundColor: '#ecf0f1',
    padding: 8,
  },
  card_template: {
    width: 150,
    height: 150,
    marginLeft: 10,
    marginTop: 20,
    boxShadow: '20px 20px 17px -12px rgba(0,0,0,0.75)',
    borderRadius: 10,
  },
  card_image: {
    width: 150,
    height: 150,
    borderRadius: 10,
  },
  text_container: {
    position: 'absolute',
    width: 150,
    height: 50,
    bottom: 0,
    paddingVertical: 2,
    backgroundColor: 'rgba(255,255,255, 1)',
    borderBottomLeftRadius: 10,
    borderBottomRightRadius: 10,
  },
  card_title: {
    color: 'black',
    fontSize: 14,
    marginLeft: 10,
  },
  card_subtitle:{
    color: 'grey',
    fontSize: 14,
    marginLeft: 10,
  }
});

您可以在这里使用工作代码:Expo Snack

于 2020-12-02T20:05:38.880 回答
0

使用ScrollvieworFlatlist来渲染上面的 ListItems 和horizontal={true}props

https://reactnative.dev/docs/scrollview#horizo​​ntal

于 2020-12-02T19:41:20.800 回答