Bỏ qua để đến nội dung

Cách dùng

Demo chạy thật. Vuốt, chạm thử.Mở toàn màn hình ↗
import { MorphCarousel } from 'expo-morph-carousel';
const products = [
{ id: 'watch', title: 'Watch', description: '…', image: require('./assets/watch.png') },
{ id: 'phone', title: 'Phone', description: '…', image: require('./assets/phone.png') },
{ id: 'laptop', title: 'Laptop', description: '…', image: { uri: 'https://…/laptop.png' } },
];
export function Showcase() {
return (
<MorphCarousel
data={products}
keyExtractor={(p) => p.id}
getImage={(p) => p.image}
getAccessibilityLabel={(p) => p.title}
style={{ height: 520, borderRadius: 28, backgroundColor: '#fff' }}
renderItem={({ item }) => (
<View style={{ alignItems: 'center', padding: 24, gap: 8 }}>
<Text style={{ fontSize: 24, fontWeight: '700' }}>{item.title}</Text>
<Text style={{ textAlign: 'center' }}>{item.description}</Text>
</View>
)}
renderFooter={({ item, next }) => <Button title="Continue" onPress={next} />}
/>
);
}

Carousel cần có kích thước: đặt height hoặc flex: 1 trong style. Vùng media chiếm mediaHeight ở trên (hoặc cả carousel với mediaPosition="background"), các trang chiếm phần còn lại, chấm phân trang và footer nằm bên dưới.

Hiệu ứng liquid đẹp nhất với ảnh nền trong suốt như ảnh sản phẩm, icon hay hình minh họa, nơi đường viền của vật thể thay đổi giữa các trang. Với ảnh chụp (mediaFit="cover"), nó làm các hình chữ nhật tan vào nhau.

example/app/basic.tsx
import { MorphCarousel } from 'expo-morph-carousel';
import { Pressable, StyleSheet, Text, View } from 'react-native';
/**
* The smallest useful carousel: images that melt into each other, a title
* and a description per page, dots and a button. This is the snippet of the
* Getting started page, as it runs.
*/
const shapes = [
{
id: 'orb',
title: 'Meet Orb',
description: 'A glossy sphere. Swipe to watch it melt into the next shape.',
image: require('../assets/shapes/orb.png'),
},
{
id: 'tile',
title: 'Explore Tile',
description: 'A rounded square with a warm gradient.',
image: require('../assets/shapes/tile.png'),
},
{
id: 'ring',
title: 'Discover Ring',
description: 'The liquid fills the hole, then opens it again.',
image: require('../assets/shapes/ring.png'),
},
{
id: 'heart',
title: 'Love Heart',
description: 'Watch the point grow out of the blob.',
image: require('../assets/shapes/heart.png'),
},
];
export default function Basic() {
return (
<View style={styles.screen}>
<MorphCarousel
data={shapes}
keyExtractor={(s) => s.id}
getImage={(s) => s.image}
getAccessibilityLabel={(s) => s.title}
style={styles.card}
renderItem={({ item }) => (
<View style={styles.page}>
<Text style={styles.title}>{item.title}</Text>
<Text style={styles.description}>{item.description}</Text>
</View>
)}
renderFooter={({ next }) => (
<Pressable style={styles.button} onPress={next}>
<Text style={styles.buttonText}>Continue</Text>
</Pressable>
)}
/>
</View>
);
}
const styles = StyleSheet.create({
screen: {
flex: 1,
padding: 16,
justifyContent: 'center',
width: '100%',
maxWidth: 600,
alignSelf: 'center',
},
card: { height: 520, borderRadius: 28, backgroundColor: '#fff' },
page: { alignItems: 'center', paddingHorizontal: 24, paddingTop: 12, gap: 8 },
title: { fontSize: 24, fontWeight: '700', color: '#1c1c1e' },
description: { fontSize: 15, lineHeight: 21, color: '#6e6e73', textAlign: 'center' },
button: {
alignSelf: 'stretch',
marginHorizontal: 24,
paddingVertical: 14,
borderRadius: 14,
alignItems: 'center',
backgroundColor: '#1c1c1e',
},
buttonText: { color: '#fff', fontSize: 16, fontWeight: '600' },
});