Last active
April 19, 2024 09:27
-
-
Save cipolleschi/68d44f3fc2f17d87b5aaee59bedfafb3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Sample React Native App | |
* https://github.com/facebook/react-native | |
* | |
* @format | |
*/ | |
import React, {useState} from 'react'; | |
import {Button, Modal, SafeAreaView, Text, View} from 'react-native'; | |
import {Colors} from 'react-native/Libraries/NewAppScreen'; | |
function App(): React.JSX.Element { | |
const [authState, setAuthState] = useState< | |
'unknown' | 'waiting' | 'denied' | 'authenticated' | |
>('unknown'); | |
const [modalVisible, setModalVisible] = useState(false); | |
const backgroundStyle = { | |
backgroundColor: Colors.lighter, | |
}; | |
function authenticate() { | |
setAuthState('waiting'); | |
setModalVisible(true); | |
} | |
return ( | |
<SafeAreaView style={backgroundStyle}> | |
<View style={backgroundStyle}> | |
<Button title="Authenticate" onPress={authenticate} /> | |
<Text>Current state: {authState}</Text> | |
</View> | |
<Modal | |
visible={modalVisible} | |
animationType="slide" | |
onDismiss={() => alert('Authentication Completed')}> | |
<SafeAreaView style={backgroundStyle}> | |
<Text>Accept authentication?</Text> | |
<Button | |
title="Yes" | |
onPress={() => { | |
setModalVisible(false); | |
setAuthState('authenticated'); | |
}} | |
/> | |
<Button | |
title="No" | |
onPress={() => { | |
setModalVisible(false); | |
setAuthState('denied'); | |
}} | |
/> | |
</SafeAreaView> | |
</Modal> | |
</SafeAreaView> | |
); | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment