diff options
| author | jciespuertodelacruz <jc.iespuertodelacruz@gmx.es> | 2026-01-20 08:49:52 +0000 |
|---|---|---|
| committer | jciespuertodelacruz <jc.iespuertodelacruz@gmx.es> | 2026-01-20 08:49:52 +0000 |
| commit | c6f2b6f85d151d6d2a2cc68eb05edd7a1e448106 (patch) | |
| tree | 1080219bee426d5d1372da6c31f138482c1544d7 /components/ui | |
Initial commit
Generated by create-expo-app 3.5.3.
Diffstat (limited to 'components/ui')
| -rw-r--r-- | components/ui/collapsible.tsx | 45 | ||||
| -rw-r--r-- | components/ui/icon-symbol.ios.tsx | 32 | ||||
| -rw-r--r-- | components/ui/icon-symbol.tsx | 41 |
3 files changed, 118 insertions, 0 deletions
diff --git a/components/ui/collapsible.tsx b/components/ui/collapsible.tsx new file mode 100644 index 0000000..6345fde --- /dev/null +++ b/components/ui/collapsible.tsx @@ -0,0 +1,45 @@ +import { PropsWithChildren, useState } from 'react'; +import { StyleSheet, TouchableOpacity } from 'react-native'; + +import { ThemedText } from '@/components/themed-text'; +import { ThemedView } from '@/components/themed-view'; +import { IconSymbol } from '@/components/ui/icon-symbol'; +import { Colors } from '@/constants/theme'; +import { useColorScheme } from '@/hooks/use-color-scheme'; + +export function Collapsible({ children, title }: PropsWithChildren & { title: string }) { + const [isOpen, setIsOpen] = useState(false); + const theme = useColorScheme() ?? 'light'; + + return ( + <ThemedView> + <TouchableOpacity + style={styles.heading} + onPress={() => setIsOpen((value) => !value)} + activeOpacity={0.8}> + <IconSymbol + name="chevron.right" + size={18} + weight="medium" + color={theme === 'light' ? Colors.light.icon : Colors.dark.icon} + style={{ transform: [{ rotate: isOpen ? '90deg' : '0deg' }] }} + /> + + <ThemedText type="defaultSemiBold">{title}</ThemedText> + </TouchableOpacity> + {isOpen && <ThemedView style={styles.content}>{children}</ThemedView>} + </ThemedView> + ); +} + +const styles = StyleSheet.create({ + heading: { + flexDirection: 'row', + alignItems: 'center', + gap: 6, + }, + content: { + marginTop: 6, + marginLeft: 24, + }, +}); diff --git a/components/ui/icon-symbol.ios.tsx b/components/ui/icon-symbol.ios.tsx new file mode 100644 index 0000000..9177f4d --- /dev/null +++ b/components/ui/icon-symbol.ios.tsx @@ -0,0 +1,32 @@ +import { SymbolView, SymbolViewProps, SymbolWeight } from 'expo-symbols'; +import { StyleProp, ViewStyle } from 'react-native'; + +export function IconSymbol({ + name, + size = 24, + color, + style, + weight = 'regular', +}: { + name: SymbolViewProps['name']; + size?: number; + color: string; + style?: StyleProp<ViewStyle>; + weight?: SymbolWeight; +}) { + return ( + <SymbolView + weight={weight} + tintColor={color} + resizeMode="scaleAspectFit" + name={name} + style={[ + { + width: size, + height: size, + }, + style, + ]} + /> + ); +} diff --git a/components/ui/icon-symbol.tsx b/components/ui/icon-symbol.tsx new file mode 100644 index 0000000..b7ece6b --- /dev/null +++ b/components/ui/icon-symbol.tsx @@ -0,0 +1,41 @@ +// Fallback for using MaterialIcons on Android and web. + +import MaterialIcons from '@expo/vector-icons/MaterialIcons'; +import { SymbolWeight, SymbolViewProps } from 'expo-symbols'; +import { ComponentProps } from 'react'; +import { OpaqueColorValue, type StyleProp, type TextStyle } from 'react-native'; + +type IconMapping = Record<SymbolViewProps['name'], ComponentProps<typeof MaterialIcons>['name']>; +type IconSymbolName = keyof typeof MAPPING; + +/** + * Add your SF Symbols to Material Icons mappings here. + * - see Material Icons in the [Icons Directory](https://icons.expo.fyi). + * - see SF Symbols in the [SF Symbols](https://developer.apple.com/sf-symbols/) app. + */ +const MAPPING = { + 'house.fill': 'home', + 'paperplane.fill': 'send', + 'chevron.left.forwardslash.chevron.right': 'code', + 'chevron.right': 'chevron-right', +} as IconMapping; + +/** + * An icon component that uses native SF Symbols on iOS, and Material Icons on Android and web. + * This ensures a consistent look across platforms, and optimal resource usage. + * Icon `name`s are based on SF Symbols and require manual mapping to Material Icons. + */ +export function IconSymbol({ + name, + size = 24, + color, + style, +}: { + name: IconSymbolName; + size?: number; + color: string | OpaqueColorValue; + style?: StyleProp<TextStyle>; + weight?: SymbolWeight; +}) { + return <MaterialIcons color={color} size={size} name={MAPPING[name]} style={style} />; +} |