Created
July 8, 2023 13:12
-
-
Save ephraimduncan/a2a1d332a2531eecdc875e93c23a0866 to your computer and use it in GitHub Desktop.
Implementation of Modal Presentation for iOS in React Native
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
import React, { useState } from "react"; | |
import { | |
Alert, | |
Modal, | |
Text, | |
Pressable, | |
View, | |
SafeAreaView, | |
} from "react-native"; | |
const App = () => { | |
const [modalVisible, setModalVisible] = useState(false); | |
return ( | |
<SafeAreaView> | |
<View className="h-full flex items-center justify-center"> | |
<Modal | |
animationType="slide" | |
visible={modalVisible} | |
presentationStyle="pageSheet" | |
onRequestClose={() => { | |
Alert.alert("Modal has been closed."); | |
setModalVisible(!modalVisible); | |
}} | |
> | |
<View> | |
<View className="bg-white h-full flex items-center justify-center"> | |
<Text className="text-2xl my-4">Hello World!</Text> | |
<Pressable onPress={() => setModalVisible(!modalVisible)}> | |
<Text className="font-bold">Hide Modal</Text> | |
</Pressable> | |
</View> | |
</View> | |
</Modal> | |
<Pressable onPress={() => setModalVisible(true)}> | |
<Text className="font-bold">Show Modal</Text> | |
</Pressable> | |
</View> | |
</SafeAreaView> | |
); | |
}; | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Demo
Simulator.Screen.Recording.-.iPhone.14.Pro.-.2023-07-08.at.13.04.54.mp4