Introduction
In this blog, we'll understand modals and their properties and work with examples in react native. Let's begin with the introduction of Modals.
A Modal component is usually used to provide content above an enclosing view. A Modal is a pre-defined component in React Native that aids in creating modal pop-ups. The modal that appears above the screen covers the entire application area. Modal must be imported from the react-native library to use in our application.
In a modal, there are three different types of choices (slide, fade, and none) that determine how the modal appears inside the react native app. Now we have seen what a modal is? Let's look at the modal props.
Also See, Hooks in React JS
Modal props
visible
This prop determines the visibility of your modal.
Type | Default |
---|---|
bool | false |
animated
This property has been retired. Instead, use the animationType prop.
animationType
It determines how the modal animates. There are three different types of animated props:
- slide slides in the modal from the bottom,
- fade fades into view,
- none It makes modals appear without an animation.
Type | Default |
enum( ‘slide’, ‘fade’, ‘none’ ) | none |
supportedOrientations
supportedOrientations enables the modal to be rotated in any preset orientations (portrait, portrait-upside-down, landscape, landscape-left, landscape-right).
Type | Default |
---|---|
array of enums(‘portrait’, ‘portrait-upside-down’, ‘landscape’, ‘landscape-left’, ‘landscape-right’) | [‘portrait’] |
onDissmis
This prop specifies a function called after the modal is dismissed.
Type |
function |
onRequestClose
When the user taps the hardware back button on Android or the menu button on Apple TV, this callback prop is triggered.
Type |
function |
onShow
The onShow prop allows you to specify a function that function will execute after displaying the modal.
Type |
function |
transparent
The transparent prop controls whether or not your modal fills the entire display. The modal will appear on a transparent background if you set this to true.
Type | Default |
---|---|
bool | false |
presentationStyle
It determines how a model appears on large devices. Possible values:
- fullScreen covers the screen entirely.
- pageSheet covers portrait-width view centered only on larger devices.
- formSheet covers narrow-width view centered only on larger devices.
- overFullScreen covers the screen entirely but allows transparency.
Type | Default |
enum(‘fullScreen’, ‘pageSheet’, ‘formSheet’, ‘overFullScreen’) | fullScreen if transparent={false} |
overFullScreen if transparent={true} |
statusBarTranslucent
The statusBarTranslucent prop determines whether your modal should go under the system status bar.
Type | Default |
---|---|
bool | false |
hardwareAccelerated
It determines whether the underlying window should be forced to use hardware acceleration.
Type | Default |
---|---|
bool | false |
Since we have seen the modal props, let's look at an example of a pop-up modal.
Also see, React Native Reanimated