The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { T, useGT, useMessages } from "gt-react-native"; |
| 2 | import { NativeScrollView } from "../../native/NativeScrollViewMarker"; |
| 3 | import { useSearchToolbarInset } from "../../components/ui/useBarInset"; |
| 4 | import { ScreenScrollView as ScrollView } from "../../components/ui/ScreenScrollView"; |
| 5 | import { LegendList } from "@legendapp/list/react-native"; |
| 6 | import { type StaticScreenProps, useNavigation } from "@react-navigation/native"; |
| 7 | import { |
| 8 | filterThirdPartyLicenseEntries, |
| 9 | findThirdPartyLicenseEntry, |
| 10 | formatLicenseBundles, |
| 11 | thirdPartyLicenseEntryKey, |
| 12 | type ThirdPartyLicenseEntry, |
| 13 | } from "@t3tools/shared/thirdPartyLicenses"; |
| 14 | import { useMemo, useState } from "react"; |
| 15 | import { Platform, Pressable, View } from "react-native"; |
| 16 | import { tryOpenExternalUrl } from "../../lib/openExternalUrl"; |
| 17 | import { useSafeAreaInsets } from "react-native-safe-area-context"; |
| 18 | |
| 19 | import { SymbolView } from "../../components/ui/AppSymbol"; |
| 20 | import { AppText as Text } from "../../components/ui/AppText"; |
| 21 | import { ListRow } from "../../components/ui/ListRow"; |
| 22 | import { SettingsScreen } from "./components/SettingsScreen"; |
| 23 | |
| 24 | import { getMobileThirdPartyLicenses } from "./mobileThirdPartyLicenses"; |
| 25 | |
| 26 | function useMobileThirdPartyLicenses() { |
| 27 | return useMemo(() => { |
| 28 | try { |
| 29 | return getMobileThirdPartyLicenses(); |
| 30 | } catch { |
| 31 | return null; |
| 32 | } |
| 33 | }, []); |
| 34 | } |
| 35 | |
| 36 | function LicenseRow(props: { |
| 37 | readonly entry: ThirdPartyLicenseEntry; |
| 38 | readonly onPress: () => void; |
| 39 | }) { |
| 40 | return ( |
| 41 | <View className="border-b border-border"> |
| 42 | <ListRow |
| 43 | label={props.entry.name} |
| 44 | description={[props.entry.version, props.entry.license].filter(Boolean).join(" · ")} |
| 45 | onPress={props.onPress} |
| 46 | /> |
| 47 | </View> |
| 48 | ); |
| 49 | } |
| 50 | |
| 51 | export function SettingsOpenSourceLicensesRouteScreen() { |
| 52 | const gt = useGT(); |
| 53 | const navigation = useNavigation(); |
| 54 | const insets = useSafeAreaInsets(); |
| 55 | const [query, setQuery] = useState(""); |
| 56 | const search = { |
| 57 | value: query, |
| 58 | onChangeText: setQuery, |
| 59 | placeholder: gt("Search packages"), |
| 60 | accessibilityLabel: gt("Search open-source licenses"), |
| 61 | clearAccessibilityLabel: gt("Clear package search"), |
| 62 | }; |
| 63 | const searchInset = useSearchToolbarInset(search); |
| 64 | const manifest = useMobileThirdPartyLicenses(); |
| 65 | const entries = manifest?.entries ?? []; |
| 66 | const filteredEntries = filterThirdPartyLicenseEntries(entries, query); |
| 67 | const renderItem = ({ item }: { readonly item: ThirdPartyLicenseEntry }) => ( |
| 68 | <LicenseRow |
| 69 | entry={item} |
| 70 | onPress={() => |
| 71 | navigation.navigate("SettingsOpenSourceLicense", { |
| 72 | entryKey: thirdPartyLicenseEntryKey(item), |
| 73 | }) |
| 74 | } |
| 75 | /> |
| 76 | ); |
| 77 | |
| 78 | if (!manifest) { |
| 79 | return ( |
| 80 | <SettingsScreen title={gt("Open source licenses")}> |
| 81 | <View className="flex-1 items-center justify-center px-6"> |
| 82 | <Text className="text-center text-base text-foreground-muted"> |
| 83 | <T>License notices are unavailable in this build.</T> |
| 84 | </Text> |
| 85 | </View> |
| 86 | </SettingsScreen> |
| 87 | ); |
| 88 | } |
| 89 | |
| 90 | return ( |
| 91 | <SettingsScreen title={gt("Open source licenses")} search={search}> |
| 92 | <LegendList |
| 93 | renderScrollComponent={NativeScrollView} |
| 94 | className="flex-1" |
| 95 | contentContainerStyle={{ |
| 96 | paddingBottom: |
| 97 | searchInset + (Platform.OS === "ios" ? 18 : Math.max(insets.bottom, 18) + 18), |
| 98 | }} |
| 99 | contentInsetAdjustmentBehavior="automatic" |
| 100 | data={filteredEntries} |
| 101 | estimatedItemSize={78} |
| 102 | keyboardDismissMode="on-drag" |
| 103 | keyboardShouldPersistTaps="handled" |
| 104 | keyExtractor={thirdPartyLicenseEntryKey} |
| 105 | ListEmptyComponent={ |
| 106 | <View className="items-center px-6 py-12"> |
| 107 | <Text className="text-center text-base text-foreground-muted"> |
| 108 | <T>No licenses match that search.</T> |
| 109 | </Text> |
| 110 | </View> |
| 111 | } |
| 112 | renderItem={renderItem} |
| 113 | showsVerticalScrollIndicator={false} |
| 114 | /> |
| 115 | </SettingsScreen> |
| 116 | ); |
| 117 | } |
| 118 | |
| 119 | type LicenseDetailProps = StaticScreenProps<{ readonly entryKey: string }>; |
| 120 | |
| 121 | export function SettingsOpenSourceLicenseRouteScreen({ route }: LicenseDetailProps) { |
| 122 | const gt = useGT(); |
| 123 | const messages = useMessages(); |
| 124 | const insets = useSafeAreaInsets(); |
| 125 | const manifest = useMobileThirdPartyLicenses(); |
| 126 | const entry = manifest |
| 127 | ? findThirdPartyLicenseEntry(manifest.entries, route.params.entryKey) |
| 128 | : undefined; |
| 129 | const sourceUrl = entry?.sourceUrl?.match(/^https?:\/\//) ? entry.sourceUrl : null; |
| 130 | |
| 131 | if (!entry) { |
| 132 | return ( |
| 133 | <SettingsScreen title={gt("License notice")}> |
| 134 | <View className="flex-1 items-center justify-center px-6"> |
| 135 | <Text className="text-center text-base text-foreground-muted"> |
| 136 | <T>This license notice is unavailable.</T> |
| 137 | </Text> |
| 138 | </View> |
| 139 | </SettingsScreen> |
| 140 | ); |
| 141 | } |
| 142 | |
| 143 | return ( |
| 144 | <SettingsScreen title={gt("License notice")}> |
| 145 | <ScrollView |
| 146 | className="flex-1" |
| 147 | contentInsetAdjustmentBehavior="automatic" |
| 148 | contentContainerClassName="gap-5 px-5 pt-4" |
| 149 | contentContainerStyle={{ paddingBottom: Math.max(insets.bottom, 18) + 18 }} |
| 150 | showsVerticalScrollIndicator={false} |
| 151 | > |
| 152 | <View className="gap-2 px-1"> |
| 153 | <Text className="text-2xl font-t3-bold text-foreground">{entry.name}</Text> |
| 154 | <Text className="text-base leading-normal text-foreground-muted"> |
| 155 | {[entry.version, entry.license, formatLicenseBundles(entry.bundles, messages)] |
| 156 | .filter((value): value is string => Boolean(value)) |
| 157 | .join(" · ")} |
| 158 | </Text> |
| 159 | {sourceUrl ? ( |
| 160 | <Pressable |
| 161 | accessibilityHint={gt("Opens the project website")} |
| 162 | accessibilityRole="link" |
| 163 | onPress={() => void tryOpenExternalUrl(sourceUrl)} |
| 164 | className="min-h-12 flex-row items-center gap-2 self-start py-2 active:opacity-60" |
| 165 | > |
| 166 | <Text className="font-t3-medium text-primary-text"> |
| 167 | <T>Project source</T> |
| 168 | </Text> |
| 169 | <SymbolView |
| 170 | name="arrow.up.right" |
| 171 | size={16} |
| 172 | tintColorClassName={"accent-primary-text"} |
| 173 | type="monochrome" |
| 174 | weight="semibold" |
| 175 | /> |
| 176 | </Pressable> |
| 177 | ) : null} |
| 178 | </View> |
| 179 | |
| 180 | <View className="overflow-hidden rounded-[24px] border-continuous bg-grouped-card p-4"> |
| 181 | <Text selectable className="font-mono text-base leading-normal text-foreground"> |
| 182 | {entry.noticeText} |
| 183 | </Text> |
| 184 | </View> |
| 185 | </ScrollView> |
| 186 | </SettingsScreen> |
| 187 | ); |
| 188 | } |