不幸的是,我很难真正掌握这个库是如何工作的,特别是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',
thumbnail: require('./assets/splash.png'),
},
{
title: 'Text 2',
thumbnail: require('./assets/splash.png'),
},
];
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',
},
});发布于 2021-05-31 13:41:30
我认为你需要用source={item.thumbnail}替换source={{uri: item.thumbnail}},因为uri像https://image.png一样用于web图像url,而require用于本地图像。我在我的安卓上测试过了,现在工作正常
https://stackoverflow.com/questions/67744619
复制相似问题