|
| 1 | +import { |
| 2 | + FlatList, |
| 3 | + Image, |
| 4 | + type ImageRequireSource, |
| 5 | + StyleSheet, |
| 6 | + Text, |
| 7 | + View, |
| 8 | +} from 'react-native'; |
| 9 | + |
| 10 | +const assets = [ |
| 11 | + { |
| 12 | + source: require('../assets/pic_1.jpg'), |
| 13 | + status: 'Inlined', |
| 14 | + size: '89,400 bytes', |
| 15 | + }, |
| 16 | + { |
| 17 | + source: require('../assets/pic_2.jpg'), |
| 18 | + status: 'Emitted', |
| 19 | + size: '121,569 bytes', |
| 20 | + }, |
| 21 | + { |
| 22 | + source: require('../assets/pic_3.jpg'), |
| 23 | + status: 'Inlined', |
| 24 | + size: '59,862 bytes', |
| 25 | + }, |
| 26 | +]; |
| 27 | + |
| 28 | +const data = assets.map((asset, index) => ({ |
| 29 | + title: `Host asset ${index + 1}`, |
| 30 | + ...asset, |
| 31 | +})); |
| 32 | + |
| 33 | +const AssetRow = ({ |
| 34 | + title, |
| 35 | + source, |
| 36 | + status, |
| 37 | + size, |
| 38 | +}: { |
| 39 | + title: string; |
| 40 | + source: ImageRequireSource; |
| 41 | + status: string; |
| 42 | + size: string; |
| 43 | +}) => ( |
| 44 | + <View style={styles.row}> |
| 45 | + <Image source={source} style={styles.image} /> |
| 46 | + <View style={styles.titleContainer}> |
| 47 | + <View style={styles.titleRow}> |
| 48 | + <Text style={styles.title}>{title}</Text> |
| 49 | + <View |
| 50 | + style={[ |
| 51 | + styles.badge, |
| 52 | + status === 'Inlined' ? styles.inlineBadge : styles.emittedBadge, |
| 53 | + ]} |
| 54 | + > |
| 55 | + <Text |
| 56 | + style={[ |
| 57 | + styles.badgeText, |
| 58 | + status === 'Inlined' |
| 59 | + ? styles.inlineBadgeText |
| 60 | + : styles.emittedBadgeText, |
| 61 | + ]} |
| 62 | + > |
| 63 | + {status} |
| 64 | + </Text> |
| 65 | + </View> |
| 66 | + </View> |
| 67 | + <Text style={styles.size}>{size}</Text> |
| 68 | + <Text style={styles.subtitle}> |
| 69 | + Loaded from the host app bundle to test inline asset size limits |
| 70 | + </Text> |
| 71 | + </View> |
| 72 | + </View> |
| 73 | +); |
| 74 | + |
| 75 | +const HostAssetsScreen = () => { |
| 76 | + return ( |
| 77 | + <FlatList |
| 78 | + contentInsetAdjustmentBehavior="automatic" |
| 79 | + contentContainerStyle={styles.contentContainer} |
| 80 | + data={data} |
| 81 | + keyExtractor={(item) => item.title} |
| 82 | + renderItem={({ item }) => ( |
| 83 | + <AssetRow |
| 84 | + title={item.title} |
| 85 | + source={item.source} |
| 86 | + status={item.status} |
| 87 | + size={item.size} |
| 88 | + /> |
| 89 | + )} |
| 90 | + style={styles.container} |
| 91 | + /> |
| 92 | + ); |
| 93 | +}; |
| 94 | + |
| 95 | +const styles = StyleSheet.create({ |
| 96 | + container: { |
| 97 | + flex: 1, |
| 98 | + backgroundColor: '#F5F9FF', |
| 99 | + }, |
| 100 | + contentContainer: { |
| 101 | + paddingVertical: 20, |
| 102 | + }, |
| 103 | + row: { |
| 104 | + marginBottom: 20, |
| 105 | + marginHorizontal: 15, |
| 106 | + backgroundColor: 'white', |
| 107 | + borderRadius: 10, |
| 108 | + overflow: 'hidden', |
| 109 | + shadowColor: '#2C3E50', |
| 110 | + shadowOffset: { width: 0, height: 2 }, |
| 111 | + shadowOpacity: 0.1, |
| 112 | + shadowRadius: 4, |
| 113 | + elevation: 3, |
| 114 | + }, |
| 115 | + image: { |
| 116 | + width: '100%', |
| 117 | + height: 250, |
| 118 | + resizeMode: 'cover', |
| 119 | + }, |
| 120 | + titleContainer: { |
| 121 | + padding: 15, |
| 122 | + }, |
| 123 | + titleRow: { |
| 124 | + alignItems: 'center', |
| 125 | + flexDirection: 'row', |
| 126 | + gap: 10, |
| 127 | + marginBottom: 5, |
| 128 | + }, |
| 129 | + title: { |
| 130 | + flex: 1, |
| 131 | + fontSize: 18, |
| 132 | + fontWeight: '600', |
| 133 | + color: '#2C3E50', |
| 134 | + }, |
| 135 | + badge: { |
| 136 | + borderRadius: 4, |
| 137 | + paddingHorizontal: 8, |
| 138 | + paddingVertical: 4, |
| 139 | + }, |
| 140 | + inlineBadge: { |
| 141 | + backgroundColor: '#DFF5E7', |
| 142 | + }, |
| 143 | + emittedBadge: { |
| 144 | + backgroundColor: '#FFF1D6', |
| 145 | + }, |
| 146 | + badgeText: { |
| 147 | + fontSize: 12, |
| 148 | + fontWeight: '700', |
| 149 | + }, |
| 150 | + inlineBadgeText: { |
| 151 | + color: '#1E7F45', |
| 152 | + }, |
| 153 | + emittedBadgeText: { |
| 154 | + color: '#9A5A00', |
| 155 | + }, |
| 156 | + size: { |
| 157 | + color: '#7F8C8D', |
| 158 | + fontSize: 13, |
| 159 | + marginBottom: 5, |
| 160 | + }, |
| 161 | + subtitle: { |
| 162 | + fontSize: 14, |
| 163 | + color: '#3498DB', |
| 164 | + fontWeight: '400', |
| 165 | + }, |
| 166 | +}); |
| 167 | + |
| 168 | +export default HostAssetsScreen; |
0 commit comments