Trang sản phẩm
Trang chi tiết sản phẩm: thư viện ảnh theo màu với dải thumbnail, ô màu, size và thanh giỏ hàng.
Hoạt động thế nào
Phần tiêu đề “Hoạt động thế nào”- Thư viện ảnh là một vùng media vuông (
mediaHeight={width},mediaFit="cover",mediaPadding={0}); các màu là các trang của nó. - Slot
Paginationlà dải thumbnail. Khung chọn đọcpositioncủa carousel trên UI thread nên chạy theo ngón tay, chạm vào thì gọiscrollTo(i). - Các ô màu bên dưới gọi
ref.scrollTo(i);onIndexChangegiữ tiêu đề, dòng tồn kho và màu nút giỏ hàng khớp nhau. - Chạm vào ảnh để sang màu kế tiếp (
tapToNavigate={{ area: 'media' }}), không ảnh hưởng tới các nút trên trang. - Nút thông tin tròn phía trên thanh giỏ hàng là expo-morph-menu, gói anh em: Bảng size, Đánh giá và Giao hàng nở ra từ thẻ menu thành route toàn màn hình (
app/(sheet)). Root layout chỉ hiện nút ở trang này (hidden).
Dùng
Mã nguồn đầy đủ
Phần tiêu đề “Mã nguồn đầy đủ”Đây chính là mã đang chạy trong khung điện thoại. Chép về, đổi dữ liệu là dùng được.
import { Ionicons } from '@expo/vector-icons';import { MorphCarousel, type MorphCarouselRef, type PaginationSlotProps } from 'expo-morph-carousel';import { useMemo, useRef, useState } from 'react';import { Image, Pressable, ScrollView, StyleSheet, Text, useWindowDimensions, View } from 'react-native';import Animated, { interpolate, useAnimatedStyle, type SharedValue } from 'react-native-reanimated';import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { photo, photoFor, shopColors } from '../data/demos';import { column, MAX_CONTENT_WIDTH, sides, useContentWidth } from '../data/layout';
/** * A product page from a shopping app. The gallery is a carousel of the * colors: the photos melt into each other, the Pagination slot is a strip of * thumbnails whose frame follows the swipe, and the color swatches below * drive the same carousel through its ref. */
const SIZES = ['38', '39', '40', '41', '42', '43', '44'];const THUMB = 56;const THUMB_GAP = 8;
export default function ShopScreen() { // A square gallery on a phone; on a tablet or in landscape it stops at // 55% of the screen height so the details stay in view. const width = useContentWidth(); const window = useWindowDimensions(); const galleryHeight = Math.min(width, Math.round(window.height * 0.55)); // The cart bar spans the screen; its buttons line up with the column above. const barSide = 16 + Math.max(0, (window.width - MAX_CONTENT_WIDTH) / 2); const insets = useSafeAreaInsets(); const gallery = useRef<MorphCarouselRef>(null); const [color, setColor] = useState(0); const [size, setSize] = useState<string | null>('41'); const [fav, setFav] = useState(false); const [cart, setCart] = useState(0); const components = useMemo(() => ({ Pagination: Thumbnails }), []); const current = shopColors[color];
return ( <View style={styles.screen}> <ScrollView contentInsetAdjustmentBehavior="automatic" contentContainerStyle={[column, { paddingBottom: 110 + insets.bottom }]} > <MorphCarousel ref={gallery} data={shopColors} keyExtractor={(c) => c.id} getImage={(c, _i, target) => ({ uri: photoFor(c.id, target) })} getPlaceholderColor={(c) => c.swatch} mediaHeight={galleryHeight} mediaFit="cover" mediaPadding={0} liquid={{ preserveShape: true }} tapToNavigate={{ area: 'media' }} components={components} onIndexChange={setColor} accessibilityLabel="Product photos" getAccessibilityLabel={(c) => `Color ${c.name}`} style={{ height: galleryHeight + 150 }} renderItem={({ item }) => ( <View style={styles.colorInfo}> <Text style={styles.colorName}>{item.name}</Text> <Text style={[styles.stock, item.stock < 5 && styles.low]}> {item.stock < 5 ? `Only ${item.stock} left` : 'In stock'} </Text> </View> )} />
<View style={styles.body}> <View style={styles.titleRow}> <View style={styles.flex}> <Text style={styles.brand}>STRIDE LAB</Text> <Text style={styles.title}>Cloud Runner 2 — {current.name}</Text> </View> <Pressable onPress={() => setFav((f) => !f)} hitSlop={10} accessibilityRole="button" accessibilityLabel="Favorite" > <Ionicons name={fav ? 'heart' : 'heart-outline'} size={28} color={fav ? '#ff2d55' : '#1c1c1e'} /> </Pressable> </View> <View style={styles.ratingRow}> {[0, 1, 2, 3, 4].map((i) => ( <Ionicons key={i} name={i < 4 ? 'star' : 'star-half'} size={15} color="#ffb400" /> ))} <Text style={styles.rating}>4.6 · 2,184 reviews</Text> </View> <View style={styles.priceRow}> <Text style={styles.price}>$89</Text> <Text style={styles.was}>$129</Text> <View style={styles.badge}> <Text style={styles.badgeText}>-31%</Text> </View> </View> <View style={styles.live}> <Ionicons name="flame" size={16} color="#ff6b00" /> <Text style={styles.liveText}>18 people are looking at this right now</Text> </View>
<Text style={styles.label}>Color</Text> <View style={styles.swatches}> {shopColors.map((c, i) => ( <Pressable key={c.id} onPress={() => gallery.current?.scrollTo(i)} style={[styles.swatchRing, i === color && { borderColor: c.swatch }]} accessibilityRole="button" accessibilityLabel={c.name} accessibilityState={{ selected: i === color }} > <View style={[styles.swatch, { backgroundColor: c.swatch }]} /> </Pressable> ))} </View>
<Text style={styles.label}>Size (EU)</Text> <View style={styles.sizes}> {SIZES.map((s) => ( <Pressable key={s} onPress={() => setSize(s)} style={[styles.size, s === size && styles.sizeOn]} accessibilityRole="button" accessibilityState={{ selected: s === size }} > <Text style={[styles.sizeText, s === size && styles.sizeTextOn]}>{s}</Text> </Pressable> ))} </View>
<Text style={styles.label}>About</Text> <Text style={styles.about}> A light everyday runner with a breathable knit upper, a soft foam midsole and a grippy rubber outsole. Free returns within 30 days. </Text> </View> </ScrollView>
<View style={[styles.cartBar, sides(insets, barSide), { paddingBottom: insets.bottom + 12 }]}> <Pressable style={styles.cartIcon} accessibilityRole="button" accessibilityLabel={`Cart, ${cart} items`} > <Ionicons name="bag-outline" size={24} color="#1c1c1e" /> {cart > 0 && ( <View style={styles.cartCount}> <Text style={styles.cartCountText}>{cart}</Text> </View> )} </Pressable> <Pressable style={[styles.add, { backgroundColor: current.swatch }]} onPress={() => setCart((c) => c + 1)} accessibilityRole="button" > <Text style={styles.addText}>Add to cart · size {size}</Text> </Pressable> </View> </View> );}
/** Pagination slot: thumbnails of the colors, with a frame that follows the swipe. */function Thumbnails({ count, index, position, scrollTo }: PaginationSlotProps) { return ( <View style={styles.thumbs}> {shopColors.slice(0, count).map((c, i) => ( <Pressable key={c.id} onPress={() => scrollTo(i)} accessibilityRole="button" accessibilityLabel={`Photo ${i + 1}, ${c.name}`} accessibilityState={{ selected: i === index }} > <Thumb id={c.id} i={i} position={position} /> </Pressable> ))} </View> );}
function Thumb({ id, i, position }: { id: string; i: number; position: SharedValue<number> }) { const frame = useAnimatedStyle(() => { const near = interpolate(Math.abs(position.value - i), [0, 1], [1, 0], 'clamp'); return { borderColor: `rgba(28,28,30,${near})`, transform: [{ scale: 0.9 + near * 0.1 }] }; }); return ( <Animated.View style={[styles.thumb, frame]}> <Image source={{ uri: photo(id, 160, 160) }} style={styles.thumbImage} /> </Animated.View> );}
const styles = StyleSheet.create({ screen: { flex: 1, backgroundColor: '#fff' }, flex: { flex: 1 }, colorInfo: { flexDirection: 'row', justifyContent: 'space-between', paddingHorizontal: 16, paddingTop: 10 }, colorName: { fontSize: 15, fontWeight: '700', color: '#1c1c1e' }, stock: { fontSize: 14, color: '#2b8a3e', fontWeight: '600' }, low: { color: '#e03131' }, thumbs: { flexDirection: 'row', gap: THUMB_GAP, paddingHorizontal: 16 }, thumb: { width: THUMB, height: THUMB, borderRadius: 12, borderWidth: 2, padding: 2 }, thumbImage: { flex: 1, borderRadius: 8, backgroundColor: '#eee' }, body: { paddingHorizontal: 16, gap: 10 }, titleRow: { flexDirection: 'row', alignItems: 'flex-start', gap: 12 }, brand: { fontSize: 12, fontWeight: '800', letterSpacing: 1.2, color: '#868e96' }, title: { fontSize: 22, fontWeight: '800', color: '#1c1c1e' }, ratingRow: { flexDirection: 'row', alignItems: 'center', gap: 2 }, rating: { marginLeft: 6, fontSize: 13, color: '#6e6e73' }, priceRow: { flexDirection: 'row', alignItems: 'baseline', gap: 10 }, price: { fontSize: 28, fontWeight: '800', color: '#1c1c1e' }, was: { fontSize: 15, color: '#8e8e93', textDecorationLine: 'line-through' }, badge: { backgroundColor: '#ff3b30', borderRadius: 6, paddingHorizontal: 6, paddingVertical: 2 }, badgeText: { color: '#fff', fontSize: 12, fontWeight: '800' }, live: { flexDirection: 'row', alignItems: 'center', gap: 6, backgroundColor: '#fff4e6', borderRadius: 10, padding: 10, }, liveText: { fontSize: 13, color: '#d9480f', fontWeight: '600' }, label: { fontSize: 15, fontWeight: '700', color: '#1c1c1e', marginTop: 8 }, swatches: { flexDirection: 'row', gap: 10 }, swatchRing: { padding: 3, borderRadius: 22, borderWidth: 2, borderColor: 'transparent' }, swatch: { width: 32, height: 32, borderRadius: 16 }, sizes: { flexDirection: 'row', flexWrap: 'wrap', gap: 8 }, size: { minWidth: 52, paddingVertical: 10, borderRadius: 12, borderWidth: 1, borderColor: '#d0d0d5', alignItems: 'center', }, sizeOn: { backgroundColor: '#1c1c1e', borderColor: '#1c1c1e' }, sizeText: { fontSize: 15, fontWeight: '600', color: '#1c1c1e' }, sizeTextOn: { color: '#fff' }, about: { fontSize: 14, lineHeight: 20, color: '#495057' }, cartBar: { position: 'absolute', left: 0, right: 0, bottom: 0, flexDirection: 'row', alignItems: 'center', gap: 12, paddingTop: 12, backgroundColor: '#ffffffee', borderTopWidth: StyleSheet.hairlineWidth, borderTopColor: '#d0d0d5', }, cartIcon: { width: 50, height: 50, borderRadius: 14, borderWidth: 1, borderColor: '#d0d0d5', alignItems: 'center', justifyContent: 'center', }, cartCount: { position: 'absolute', top: 4, right: 4, minWidth: 18, height: 18, borderRadius: 9, backgroundColor: '#ff3b30', alignItems: 'center', justifyContent: 'center', paddingHorizontal: 4, }, cartCountText: { color: '#fff', fontSize: 11, fontWeight: '800' }, add: { flex: 1, height: 50, borderRadius: 14, alignItems: 'center', justifyContent: 'center' }, addText: { color: '#fff', fontSize: 16, fontWeight: '700' },});/** * Data for the real-world demos (stories, vertical feed, flash sale, shop, * memories, albums). Photos from Unsplash, free to use under the Unsplash * License (https://unsplash.com/license), loaded at the size the carousel * asks for through imgix (`w`, `h`, `fit=crop`). */
import { WIDTH_STEPS, type ImageTarget } from 'expo-morph-carousel';
/** An Unsplash photo URL cropped to the given size, in physical pixels. */export function photo(id: string, width: number, height: number, extra = '') { return `https://images.unsplash.com/photo-${id}?w=${Math.round(width)}&h=${Math.round(height)}&fit=crop&q=80&fm=jpg${extra}`;}
/** * The photo for a carousel's media area. imgix crops to exactly the box we * ask for, so ask for the area itself (in physical pixels, the width rounded * up to a step so neighbors share cache entries). `target.width` is sized * from the longer side for `cover`, which suits images the server does not * crop but is far too big for a tall full-screen area. */export function photoFor(id: string, target: ImageTarget) { const px = target.layoutWidth * target.pixelRatio; const width = WIDTH_STEPS.find((s) => s >= px) ?? WIDTH_STEPS[WIDTH_STEPS.length - 1]; return photo(id, width, (width * target.layoutHeight) / Math.max(1, target.layoutWidth));}
/** A round avatar crop centered on the face. */export const avatar = (id: string, size = 96) => photo(id, size, size, '&crop=faces');
/* --- stories ------------------------------------------------------------- */
export type StoryUser = { id: string; name: string; avatar: string; color: string; frames: { id: string; caption: string; time: string }[];};
export const storyUsers: StoryUser[] = [ { id: 'maya', name: 'maya.brews', avatar: '1544005313-94ddf0286df2', color: '#c77d4a', frames: [ { id: '1564327368633-151ef1d45021', caption: 'Sunday brunch spot ☕', time: '2h' }, { id: '1516213335993-159eca2981af', caption: 'Latte art level: finally', time: '2h' }, { id: '1528699633788-424224dc89b5', caption: 'Fresh out of the oven', time: '1h' }, ], }, { id: 'leo', name: 'leo.outdoors', avatar: '1627686011747-74adda3d2343', color: '#2f8a7a', frames: [ { id: '1528543606781-2f6e6857f318', caption: 'Bridge run at dawn', time: '5h' }, { id: '1502003148287-a82ef80a6abc', caption: 'Lake day', time: '4h' }, { id: '1520329612326-d6038d1395a1', caption: 'Found the waterfall', time: '3h' }, ], }, { id: 'ana', name: 'ana.nights', avatar: '1558507652-2d9626c4e67a', color: '#3b5bdb', frames: [ { id: '1514439827219-9137a0b99245', caption: 'City lights', time: '8h' }, { id: '1529619768328-e37af76c6fe5', caption: 'Long exposure test', time: '7h' }, { id: '1611416370495-50fac9e1b382', caption: 'Skyline from the roof', time: '6h' }, ], }, { id: 'kai', name: 'kai.moves', avatar: '1498551172505-8ee7ad69f235', color: '#d6336c', frames: [ { id: '1512264815082-9999c2d4894d', caption: 'Freeze', time: '12h' }, { id: '1543893424-907f9ebc6a5d', caption: 'Rehearsal', time: '11h' }, { id: '1511750931603-12cb2c8d28cc', caption: 'Street session', time: '10h' }, ], },];
/* --- vertical feed ------------------------------------------------------- */
export type FeedPost = { id: string; user: string; avatar: string; caption: string; sound: string; likes: number; comments: number; color: string;};
export const feedPosts: FeedPost[] = [ { id: '1592252054006-0570a10f0838', user: 'kai.moves', avatar: '1498551172505-8ee7ad69f235', caption: 'One take, no cuts. Swipe up for the slow-mo 👀 #dance', sound: 'Original sound · kai.moves', likes: 48200, comments: 1312, color: '#3b4a6b', }, { id: '1580895456895-cfdf02e4c23f', user: 'ana.nights', avatar: '1558507652-2d9626c4e67a', caption: 'Rainy walk home through the neon district', sound: 'Midnight drive · lofi mix', likes: 12900, comments: 402, color: '#5a2a4a', }, { id: '1530174883092-c2a7aa3f1cfe', user: 'maya.brews', avatar: '1544005313-94ddf0286df2', caption: 'The perfect espresso in 25 seconds ⏱️ #coffee', sound: 'Morning jazz · cafe set', likes: 30400, comments: 877, color: '#5b3a24', }, { id: '1589739401762-670be815e704', user: 'leo.outdoors', avatar: '1627686011747-74adda3d2343', caption: 'Packing list for a 3-day hike, in the comments', sound: 'Trail mix · acoustic', likes: 8700, comments: 219, color: '#2f3b33', }, { id: '1517328894681-0f5dfabd463c', user: 'ana.nights', avatar: '1558507652-2d9626c4e67a', caption: 'Street lamps and old stories', sound: 'Night city · ambient', likes: 21500, comments: 655, color: '#3a3326', }, { id: '1771345207885-d1d91f4e663f', user: 'leo.outdoors', avatar: '1627686011747-74adda3d2343', caption: 'This bridge is covered in flowers every spring 🌸', sound: 'Spring · piano', likes: 64100, comments: 2048, color: '#6b5a4a', },];
/* --- flash sale ---------------------------------------------------------- */
export type Banner = { id: string; title: string; subtitle: string; color: string };
export const banners: Banner[] = [ { id: '1483985988355-763728e1935b', title: 'Mid-season sale', subtitle: 'Up to 60% off fashion', color: '#b0476c', }, { id: '1520006403909-838d6b92c22e', title: 'New arrivals', subtitle: 'Fresh picks every morning', color: '#7a5c3e', }, { id: '1555529669-e69e7aa0ba9a', title: 'Free shipping', subtitle: 'On orders over $35', color: '#3e6b7a' }, { id: '1758520387283-303b0b332e89', title: 'Weekend deals', subtitle: 'Ends Sunday at midnight', color: '#8a6a2a', },];
export type Deal = { id: string; name: string; price: number; was: number; sold: number; stock: number; color: string;};
export const deals: Deal[] = [ { id: '1542291026-7eec264c27ff', name: 'Runner sneakers', price: 59, was: 119, sold: 412, stock: 480, color: '#c92a2a', }, { id: '1505740420928-5e560c06d30e', name: 'Wireless headphones', price: 79, was: 149, sold: 238, stock: 400, color: '#e8b923', }, { id: '1546868871-7041f2a55e12', name: 'Smart watch', price: 199, was: 279, sold: 96, stock: 200, color: '#495057', }, { id: '1613040809024-b4ef7ba99bc3', name: 'Studio headphones', price: 89, was: 129, sold: 177, stock: 220, color: '#f783ac', }, { id: '1540925819815-17a59df70d64', name: 'Vintage camera', price: 129, was: 189, sold: 51, stock: 120, color: '#7a4a2a', }, { id: '1763987300634-7b0822cbf390', name: 'Rose perfume', price: 39, was: 65, sold: 301, stock: 340, color: '#d6336c', }, { id: '1629198688000-71f23e745b6e', name: 'Skincare set', price: 29, was: 52, sold: 389, stock: 420, color: '#f0c36d', }, { id: '1600185365926-3a2ce3cdb9eb', name: 'Court sneakers', price: 69, was: 99, sold: 140, stock: 300, color: '#e8590c', },];
/* --- shop ---------------------------------------------------------------- */
export type ShopColor = { id: string; name: string; swatch: string; stock: number };
export const shopColors: ShopColor[] = [ { id: '1542291026-7eec264c27ff', name: 'Crimson', swatch: '#c92a2a', stock: 12 }, { id: '1606107557195-0e29a4b5b4aa', name: 'Volt', swatch: '#a9e34b', stock: 4 }, { id: '1491553895911-0055eca6402d', name: 'Graphite', swatch: '#495057', stock: 23 }, { id: '1600185365483-26d7a4cc7519', name: 'Coral', swatch: '#ff8787', stock: 9 }, { id: '1525966222134-fcfa99b8ae77', name: 'Burgundy', swatch: '#862e3c', stock: 2 },];
/* --- memories ------------------------------------------------------------ */
export type Memory = { id: string; place: string; color: string };
export const memories: Memory[] = [ { id: '1506905925346-21bda4d32df4', place: 'Above the clouds', color: '#5b6478' }, { id: '1501785888041-af3ef285b470', place: 'Alpine lake', color: '#2fa7a0' }, { id: '1470071459604-3b5ec3a7fe05', place: 'Misty valley', color: '#6e7a5a' }, { id: '1441974231531-c6227db76b6e', place: 'Forest path', color: '#3e4a2c' }, { id: '1433086966358-54859d0ed716', place: 'The waterfall', color: '#3f6b3a' }, { id: '1507525428034-b723cf961d3e', place: 'Last sunset', color: '#7fc4c8' },];
/* --- albums -------------------------------------------------------------- */
export type Album = { id: string; title: string; artist: string; color: string; length: number };
export const albums: Album[] = [ { id: '1618005198919-d3d4b5a92ead', title: 'Soft Spheres', artist: 'Nova Lane', color: '#7aa2e3', length: 214, }, { id: '1604076913837-52ab5629fba9', title: 'Afterglow', artist: 'The Paper Suns', color: '#e8705a', length: 187, }, { id: '1620641788421-7a1c342ea42e', title: 'Ultraviolet', artist: 'Mira K', color: '#8e44ad', length: 243 }, { id: '1635776062127-d379bfcba9f8', title: 'Night Bloom', artist: 'Halcyon', color: '#5b2c83', length: 199, }, { id: '1669295384050-a1d4357bd1d7', title: 'Tidal', artist: 'Blue Hours', color: '#1c7c7d', length: 226 }, { id: '1604079628040-94301bb21b91', title: 'Ember', artist: 'Juniper & Ash', color: '#e67e22', length: 205, }, { id: '1573655349936-de6bed86f839', title: 'Prism', artist: 'Lumen Club', color: '#2c3e50', length: 238 },];
/** 48200 → "48.2K". */export function compact(n: number) { if (n >= 1e6) return `${(n / 1e6).toFixed(1).replace(/\.0$/, '')}M`; if (n >= 1e3) return `${(n / 1e3).toFixed(1).replace(/\.0$/, '')}K`; return `${n}`;}import { Ionicons } from '@expo/vector-icons';import type { MorphItem } from 'expo-morph-menu';
/** * The info button on the shop product page is expo-morph-menu, the sister * package (https://anhtuank7c.github.io/expo-morph-menu/): the button grows * into a card, a row grows into a full-screen route, `app/(sheet)/[key].tsx`. */
export type ShopInfo = { key: string; label: string; icon: keyof typeof Ionicons.glyphMap; lines: string[] };
export const SHOP_INFO: ShopInfo[] = [ { key: 'size-guide', label: 'Size guide', icon: 'resize-outline', lines: [ '38 · 24.0 cm', '39 · 24.7 cm', '40 · 25.3 cm', '41 · 26.0 cm', '42 · 26.7 cm', '43 · 27.3 cm', '44 · 28.0 cm', ], }, { key: 'reviews', label: 'Reviews', icon: 'star-outline', lines: [ '★★★★★ Light and comfy from day one.', '★★★★★ True to size, the knit breathes well.', '★★★★☆ Great for walks, a bit soft for runs.', ], }, { key: 'shipping', label: 'Shipping & returns', icon: 'cube-outline', lines: ['Free shipping on orders over $35.', 'Delivered in 2–4 days.', 'Free returns within 30 days.'], },];
export const SHOP_MENU: MorphItem[] = SHOP_INFO.map((info) => ({ key: info.key, label: info.label, tint: '#1c1c1e', icon: ({ size, color }) => <Ionicons name={info.icon} size={size} color={color} />, href: { pathname: '/(sheet)/[key]', params: { key: info.key } },}));
/** The button's icon: product info rather than the default plus. */export function ShopMenuIcon({ size, color }: { size: number; color: string }) { return <Ionicons name="information" size={size} color={color} />;}import { MorphCloseButton } from 'expo-morph-menu';import { useLocalSearchParams } from 'expo-router';import { ScrollView, StyleSheet, Text, View } from 'react-native';import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { column } from '../../data/layout';import { SHOP_INFO } from '../../data/shopMenu';
/** A row of the shop's info menu, full screen. Closing shrinks it back into the menu card. */export default function ShopInfoScreen() { const { key } = useLocalSearchParams<{ key: string }>(); const info = SHOP_INFO.find((i) => i.key === key) ?? SHOP_INFO[0]; const insets = useSafeAreaInsets(); return ( <View style={styles.page}> <ScrollView contentContainerStyle={[column, styles.content, { paddingTop: insets.top + 16 }]}> <View style={styles.header}> <Text style={styles.title}>{info.label}</Text> <MorphCloseButton /> </View> {info.lines.map((line) => ( <Text key={line} style={styles.line}> {line} </Text> ))} </ScrollView> </View> );}
const styles = StyleSheet.create({ page: { flex: 1, backgroundColor: '#fff' }, content: { paddingHorizontal: 20, gap: 12 }, header: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', marginBottom: 8 }, title: { fontSize: 28, fontWeight: '800', color: '#1c1c1e' }, line: { fontSize: 16, lineHeight: 22, color: '#343a40' },});import Constants from 'expo-constants';import { configureSkiaWeb } from 'expo-morph-carousel';import { MorphMenu, MorphProvider, morphSheetScreenOptions } from 'expo-morph-menu';import { Stack, usePathname } from 'expo-router';import { StatusBar } from 'expo-status-bar';import { Platform } from 'react-native';import { GestureHandlerRootView } from 'react-native-gesture-handler';import { SafeAreaProvider } from 'react-native-safe-area-context';
import { SHOP_MENU, ShopMenuIcon } from '../data/shopMenu';
// Served from a sub path (the documentation site): CanvasKit is there too.const base = Constants.expoConfig?.experiments?.baseUrl;if (Platform.OS === 'web' && base) configureSkiaWeb({ locateFile: (file) => `${base}/${file}` });
/** Height of the shop page's cart bar above the safe area: the menu button sits on top of it. */const CART_BAR = 74;
export default function RootLayout() { // The expo-morph-menu button (product info) only shows on the shop page. const pathname = usePathname(); return ( <SafeAreaProvider> <GestureHandlerRootView style={{ flex: 1 }}> <MorphProvider items={SHOP_MENU} fabIcon={ShopMenuIcon}> <StatusBar style="dark" /> <Stack screenOptions={{ headerShadowVisible: false, contentStyle: { backgroundColor: '#f2f2f7' } }}> <Stack.Screen name="index" options={{ title: 'Morph Carousel' }} /> <Stack.Screen name="basic" options={{ title: 'Getting started' }} /> <Stack.Screen name="product" options={{ title: 'Product' }} /> <Stack.Screen name="onboarding" options={{ headerShown: false }} /> <Stack.Screen name="playground" options={{ title: 'Playground' }} /> <Stack.Screen name="remote" options={{ title: 'Remote images' }} /> <Stack.Screen name="layouts" options={{ title: 'Layouts' }} /> <Stack.Screen name="slots" options={{ title: 'Slots' }} /> <Stack.Screen name="order" options={{ title: 'Order' }} /> <Stack.Screen name="stress" options={{ title: 'Stress test' }} /> <Stack.Screen name="stories" options={{ title: 'Stories' }} /> <Stack.Screen name="feed" options={{ headerShown: false }} /> <Stack.Screen name="flash-sale" options={{ title: 'Flash sale' }} /> <Stack.Screen name="shop" options={{ title: '', headerTransparent: true }} /> <Stack.Screen name="memories" options={{ headerShown: false }} /> <Stack.Screen name="albums" options={{ title: '', headerTransparent: true, headerTintColor: '#fff' }} /> <Stack.Screen name="(sheet)" options={morphSheetScreenOptions} /> </Stack> <MorphMenu hidden={pathname !== '/shop'} bottomOffset={CART_BAR} fabAccessibilityLabel="Product info" /> </MorphProvider> </GestureHandlerRootView> </SafeAreaProvider> );}Xem trên GitHub: app/shop.tsxXem trên GitHub: data/demos.tsXem trên GitHub: data/shopMenu.tsxXem trên GitHub: app/(sheet)/[key].tsxXem trên GitHub: app/_layout.tsx