mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
at samuel/exp-cli 111 lines 3.5 kB view raw
1import {useCallback} from 'react' 2import {View} from 'react-native' 3import {msg, Trans} from '@lingui/macro' 4import {useLingui} from '@lingui/react' 5 6import {useOpenLink} from '#/lib/hooks/useOpenLink' 7import {isWeb} from '#/platform/detection' 8import {useSetInAppBrowser} from '#/state/preferences/in-app-browser' 9import {atoms as a, useTheme} from '#/alf' 10import {Button, ButtonIcon, ButtonText} from '#/components/Button' 11import * as Dialog from '#/components/Dialog' 12import {SquareArrowTopRight_Stroke2_Corner0_Rounded as External} from '#/components/icons/SquareArrowTopRight' 13import {Text} from '#/components/Typography' 14import {useGlobalDialogsControlContext} from './Context' 15 16export function InAppBrowserConsentDialog() { 17 const {inAppBrowserConsentControl} = useGlobalDialogsControlContext() 18 19 if (isWeb) return null 20 21 return ( 22 <Dialog.Outer 23 control={inAppBrowserConsentControl.control} 24 nativeOptions={{preventExpansion: true}} 25 onClose={inAppBrowserConsentControl.clear}> 26 <Dialog.Handle /> 27 <InAppBrowserConsentInner href={inAppBrowserConsentControl.value} /> 28 </Dialog.Outer> 29 ) 30} 31 32function InAppBrowserConsentInner({href}: {href?: string}) { 33 const control = Dialog.useDialogContext() 34 const {_} = useLingui() 35 const t = useTheme() 36 const setInAppBrowser = useSetInAppBrowser() 37 const openLink = useOpenLink() 38 39 const onUseIAB = useCallback(() => { 40 control.close(() => { 41 setInAppBrowser(true) 42 if (href) { 43 openLink(href, true) 44 } 45 }) 46 }, [control, setInAppBrowser, href, openLink]) 47 48 const onUseLinking = useCallback(() => { 49 control.close(() => { 50 setInAppBrowser(false) 51 if (href) { 52 openLink(href, false) 53 } 54 }) 55 }, [control, setInAppBrowser, href, openLink]) 56 57 const onCancel = useCallback(() => { 58 control.close() 59 }, [control]) 60 61 return ( 62 <Dialog.ScrollableInner label={_(msg`How should we open this link?`)}> 63 <View style={[a.gap_2xl]}> 64 <View style={[a.gap_sm]}> 65 <Text style={[a.font_heavy, a.text_2xl]}> 66 <Trans>How should we open this link?</Trans> 67 </Text> 68 <Text style={[t.atoms.text_contrast_high, a.leading_snug, a.text_md]}> 69 <Trans> 70 Your choice will be remembered for future links. You can change it 71 at any time in settings. 72 </Trans> 73 </Text> 74 </View> 75 <View style={[a.gap_sm]}> 76 <Button 77 label={_(msg`Use in-app browser`)} 78 onPress={onUseIAB} 79 size="large" 80 variant="solid" 81 color="primary"> 82 <ButtonText> 83 <Trans>Use in-app browser</Trans> 84 </ButtonText> 85 </Button> 86 <Button 87 label={_(msg`Use my default browser`)} 88 onPress={onUseLinking} 89 size="large" 90 variant="solid" 91 color="secondary"> 92 <ButtonText> 93 <Trans>Use my default browser</Trans> 94 </ButtonText> 95 <ButtonIcon position="right" icon={External} /> 96 </Button> 97 <Button 98 label={_(msg`Cancel`)} 99 onPress={onCancel} 100 size="large" 101 variant="ghost" 102 color="secondary"> 103 <ButtonText> 104 <Trans>Cancel</Trans> 105 </ButtonText> 106 </Button> 107 </View> 108 </View> 109 </Dialog.ScrollableInner> 110 ) 111}