|
| 1 | +/* eslint-disable react-native/no-inline-styles */ |
| 2 | +/* eslint-disable @typescript-eslint/no-explicit-any */ |
| 3 | + |
| 4 | +import { useCallback, useState, useMemo } from 'react'; |
| 5 | +import { |
| 6 | + StyleSheet, |
| 7 | + View, |
| 8 | + Text, |
| 9 | + FlatList, |
| 10 | + StatusBar, |
| 11 | + Image, |
| 12 | + TouchableOpacity, |
| 13 | +} from 'react-native'; |
| 14 | +import { SafeAreaView } from 'react-native-safe-area-context'; |
| 15 | +import * as IconPack from '@/components/icons'; |
| 16 | +import PhosphorLogo from '@/assets/images/phosphor-mark-tight-yellow.png'; |
| 17 | + |
| 18 | +// eslint-disable-next-line @typescript-eslint/no-unused-vars |
| 19 | +const { IconContext, ...Icons } = IconPack; |
| 20 | + |
| 21 | +const weights = ['thin', 'light', 'regular', 'bold', 'fill', 'duotone']; |
| 22 | + |
| 23 | +export default function HomeScreen() { |
| 24 | + const [weightIdx, setWeightIdx] = useState(2); |
| 25 | + const [iconColor, setIconColor] = useState(undefined); |
| 26 | + const [mirrorActive, setMirrorActive] = useState(false); |
| 27 | + |
| 28 | + const weight: IconPack.IconWeight = useMemo( |
| 29 | + () => weights[weightIdx] as any, |
| 30 | + [weightIdx] |
| 31 | + ); |
| 32 | + |
| 33 | + const handleChangeWeight = useCallback(() => { |
| 34 | + setWeightIdx((weightIdx + 1) % weights.length); |
| 35 | + }, [weightIdx]); |
| 36 | + |
| 37 | + const handleChangeIconColor = useCallback(() => { |
| 38 | + setIconColor(`#${Math.floor(Math.random() * 16777215).toString(16)}`); |
| 39 | + }, []); |
| 40 | + |
| 41 | + const handleToggleMirror = useCallback(() => { |
| 42 | + setMirrorActive(!mirrorActive); |
| 43 | + }, [mirrorActive]); |
| 44 | + |
| 45 | + return ( |
| 46 | + <View style={styles.rootView}> |
| 47 | + <StatusBar barStyle="light-content" /> |
| 48 | + |
| 49 | + <SafeAreaView style={styles.headerContainer}> |
| 50 | + <View style={styles.header}> |
| 51 | + <Image source={PhosphorLogo} style={styles.logoImage} /> |
| 52 | + <View |
| 53 | + style={{ |
| 54 | + flex: 1, |
| 55 | + alignItems: 'flex-start', |
| 56 | + justifyContent: 'center', |
| 57 | + paddingStart: 10, |
| 58 | + }} |
| 59 | + > |
| 60 | + <Text style={styles.headerText}>Phosphor React Native</Text> |
| 61 | + <Text |
| 62 | + style={{ |
| 63 | + color: '#fff', |
| 64 | + opacity: 0.8, |
| 65 | + textTransform: 'capitalize', |
| 66 | + }} |
| 67 | + > |
| 68 | + {weight} |
| 69 | + </Text> |
| 70 | + </View> |
| 71 | + <TouchableOpacity |
| 72 | + style={styles.weightSelect} |
| 73 | + onPress={handleChangeIconColor} |
| 74 | + > |
| 75 | + <IconPack.Palette color="#FFF" weight={weight} /> |
| 76 | + </TouchableOpacity> |
| 77 | + <TouchableOpacity |
| 78 | + style={styles.weightSelect} |
| 79 | + onPress={handleChangeWeight} |
| 80 | + > |
| 81 | + <IconPack.PencilLine color="#FFF" weight={weight} /> |
| 82 | + </TouchableOpacity> |
| 83 | + <TouchableOpacity |
| 84 | + style={styles.weightSelect} |
| 85 | + onPress={handleToggleMirror} |
| 86 | + > |
| 87 | + <IconPack.Swap color="#FFF" weight={weight} /> |
| 88 | + </TouchableOpacity> |
| 89 | + </View> |
| 90 | + </SafeAreaView> |
| 91 | + <FlatList |
| 92 | + style={styles.scrollView} |
| 93 | + contentContainerStyle={styles.main} |
| 94 | + data={Object.entries(Icons).filter(([, Icon]) => !!Icon) as any[]} |
| 95 | + keyExtractor={(item) => item[0]} |
| 96 | + numColumns={3} |
| 97 | + renderItem={({ item: [name, Icon] }) => ( |
| 98 | + <View style={styles.iconItem}> |
| 99 | + <Icon |
| 100 | + size={48} |
| 101 | + weight={weight} |
| 102 | + mirrored={mirrorActive} |
| 103 | + color={iconColor} |
| 104 | + /> |
| 105 | + <Text style={styles.iconName}>{name}</Text> |
| 106 | + </View> |
| 107 | + )} |
| 108 | + /> |
| 109 | + </View> |
| 110 | + ); |
| 111 | +} |
| 112 | + |
| 113 | +const styles = StyleSheet.create({ |
| 114 | + rootView: { |
| 115 | + flex: 1, |
| 116 | + backgroundColor: '#FFF', |
| 117 | + }, |
| 118 | + headerContainer: { |
| 119 | + backgroundColor: '#e76f51', |
| 120 | + }, |
| 121 | + header: { |
| 122 | + backgroundColor: '#e76f51', |
| 123 | + alignItems: 'center', |
| 124 | + justifyContent: 'center', |
| 125 | + flexDirection: 'row', |
| 126 | + paddingBottom: 16, |
| 127 | + paddingHorizontal: 16, |
| 128 | + }, |
| 129 | + logoImage: { |
| 130 | + width: 40, |
| 131 | + height: 40, |
| 132 | + borderRadius: 20, |
| 133 | + }, |
| 134 | + headerText: { |
| 135 | + color: '#FFF', |
| 136 | + fontSize: 18, |
| 137 | + fontWeight: 'bold', |
| 138 | + flex: 1, |
| 139 | + textAlign: 'center', |
| 140 | + }, |
| 141 | + weightSelect: { |
| 142 | + width: 35, |
| 143 | + }, |
| 144 | + scrollView: { |
| 145 | + flex: 1, |
| 146 | + }, |
| 147 | + main: { |
| 148 | + backgroundColor: 'white', |
| 149 | + paddingHorizontal: 8, |
| 150 | + paddingBottom: 16, |
| 151 | + }, |
| 152 | + iconItem: { |
| 153 | + width: '33%', |
| 154 | + height: 100, |
| 155 | + alignItems: 'center', |
| 156 | + justifyContent: 'center', |
| 157 | + padding: 8, |
| 158 | + }, |
| 159 | + iconName: { |
| 160 | + textAlign: 'center', |
| 161 | + opacity: 0.8, |
| 162 | + marginTop: 4, |
| 163 | + }, |
| 164 | +}); |
0 commit comments