问题描述
不幸的是,我很难真正掌握这个库是如何工作的,特别是 ParallaxImage 组件。我想知道是否有人可以帮助我。我正在努力让我的图像进行渲染。
以下是文档:https://www.npmjs.com/package/react-native-snap-carousel#props-methods-and-getters
这是下面的代码,但我也有一个已经运行它的零食here
顺便说一句,它不会在网络上加载,您必须选择 IOS 或 android。
import React,{useRef,useState,useEffect} from 'react';
import Carousel,{ParallaxImage} from 'react-native-snap-carousel';
import {
View,Text,Dimensions,StyleSheet,TouchableOpacity,Platform,} from 'react-native';
const ENTRIES1 = [
{
title: 'Text',thumbnail: require('./assets/splash.png'),},{
title: 'Text 1',{
title: 'Text 2',];
const {width: screenWidth} = Dimensions.get('window');
const MyCarousel = props => {
const [entries,setEntries] = useState([]);
const carouselRef = useRef(null);
const goForward = () => {
carouselRef.current.snapToNext();
};
useEffect(() => {
setEntries(ENTRIES1);
},[]);
const renderItem = ({item,index},parallaxProps) => {
return (
<View style={styles.item}>
<ParallaxImage
source={{uri: item.thumbnail}}
containerStyle={styles.imageContainer}
style={styles.image}
parallaxFactor={0.4}
{...parallaxProps}
/>
<Text style={styles.title} numberOfLines={2}>
{item.title}
</Text>
</View>
);
};
return (
<View style={styles.container}>
<Carousel
ref={carouselRef}
sliderWidth={screenWidth}
sliderHeight={screenWidth}
itemWidth={screenWidth - 60}
data={entries}
renderItem={renderItem}
hasParallaxImages={true}
/>
</View>
);
};
export default MyCarousel;
const styles = StyleSheet.create({
container: {
flex: 1,item: {
width: screenWidth - 60,height: screenWidth - 60,imageContainer: {
flex: 1,marginBottom: Platform.select({ios: 0,android: 1}),// Prevent a random Android rendering issue
backgroundColor: 'white',borderRadius: 8,image: {
...StyleSheet.absoluteFillObject,resizeMode: 'cover',});
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)