import Constants, { AppOwnership } from 'expo-constants'; import * as Linking from 'expo-linking'; import React from 'react'; import { ScrollView, StyleSheet, TextInput, View } from 'react-native'; import Button from '../components/Button'; import MonoText from '../components/MonoText'; import Colors from '../constants/Colors'; async function canOpenURL(url: string): Promise { if ( Constants.appOwnership === AppOwnership.Expo || Constants.appOwnership === AppOwnership.Guest ) { return true; } return Linking.canOpenURL(url); } function TextInputButton({ text }: { text: string }) { const [link, setLink] = React.useState(text); const [parsed, setParsed] = React.useState(''); const [canOpen, setCanOpen] = React.useState(false); React.useEffect(() => { onChangeText(text); }, [text]); const onChangeText = async (text: string) => { let parsedTextResult = ''; const supported = await canOpenURL(text); if (supported) { const parsedText = await Linking.parse(text); parsedTextResult = JSON.stringify(parsedText, null, 2); } setLink(text); setParsed(parsedTextResult); setCanOpen(supported); }; const handleClick = async () => { try { const supported = await canOpenURL(link); if (supported) { Linking.openURL(link); } else { const message = `Don't know how to open URI: ${link}`; console.log(message); alert(message); } } catch ({ message }) { console.error(message); } }; const buttonTitle = canOpen ? 'Open 😁' : 'Cannot Open 😕'; return (