模态框
Modal 组件是一种在包裹视图上方展示内容的基本方式。
示例
参考
Props
View Props
继承自 View Props。
🗑️ animated
请改用 animationType 属性。
animationType
animationType 属性控制模态框的动画方式。
可能的值:
slide从底部滑入fade淡入显示none不带动画显示
| Type | Default |
|---|---|
enum('none', 'slide', 'fade') | none |
backdropColor
模态框的 backdropColor(或模态框容器的背景色)。如果未提供且 transparent 为 false,默认值为 white。如果 transparent 为 true,则忽略。
| Type | Default |
|---|---|
| color | white |
hardwareAccelerated Android
hardwareAccelerated 属性控制是否为底层窗口强制启用硬件加速。
| Type | Default |
|---|---|
| bool | false |
navigationBarTranslucent Android
navigationBarTranslucent 属性决定模态框是否应显示在系统导航栏下方。不过,要使导航栏透明,还需要将 statusBarTranslucent 设为 true。
| Type | Default |
|---|---|
| bool | false |
onDismiss iOS
onDismiss 属性允许传入一个函数,该函数会在模态框被关闭后调用。
| Type |
|---|
| function |
onOrientationChange iOS
当模态框显示时,onOrientationChange 回调会在屏幕方向变化时调用。提供的方向仅为 'portrait' 或 'landscape'。无论当前方向如何,此回调也会在初始渲染时调用。
| Type |
|---|
| function |
allowSwipeDismissal iOS
控制在 iOS 上是否可以通过向下滑动关闭模态框。
这需要你实现 onRequestClose 属性来处理关闭。
| Type | Default |
|---|---|
| bool | false |
ref
挂载时会分配给一个 element node 的 ref 赋值器。
onRequestClose
当用户在 Android 上点击硬件返回按钮或在 Apple TV 上点击菜单按钮时,会调用 onRequestClose 回调。因此由于这是必需属性,请注意只要模态框打开,BackHandler 事件就不会被触发。
在 iOS 上,当使用 presentationStyle 为 pageSheet 或 formSheet 的拖拽手势关闭 Modal 时,会调用此回调。启用 allowSwipeDismissal 后,在关闭模态框之后也会调用此回调。
| Type |
|---|
| function 必需 Android TV function iOS |
onShow
onShow 属性允许传入一个函数,该函数会在模态框显示后调用。
| Type |
|---|
| function |
presentationStyle iOS
presentationStyle 属性控制模态框的显示方式(通常用于 iPad 或更大屏幕的 iPhone)。详见 https://developer.apple.com/reference/uikit/uimodalpresentationstyle。
可能的值:
fullScreen完全覆盖屏幕pageSheet覆盖居中的竖屏宽度视图(仅在较大设备上)formSheet覆盖居中的窄宽度视图(仅在较大设备上)overFullScreen完全覆盖屏幕,但允许透明
| Type | Default |
|---|---|
enum('fullScreen', 'pageSheet', 'formSheet', 'overFullScreen') | transparent={false} 时为 fullScreentransparent={true} 时为 overFullScreen |
statusBarTranslucent Android
statusBarTranslucent 属性决定模态框是否应显示在系统状态栏下方。
| Type | Default |
|---|---|
| bool | false |
supportedOrientations iOS
supportedOrientations 属性允许模态框旋转到所指定的任意方向。在 iOS 上,模态框仍受应用 Info.plist 中 UISupportedInterfaceOrientations 字段的限制。
当 presentationStyle 为 pageSheet 或 formSheet 时,此属性在 iOS 上将被忽略。
| Type | Default |
|---|---|
array of enums('portrait', 'portrait-upside-down', 'landscape', 'landscape-left', 'landscape-right') | ['portrait'] |
transparent
transparent 属性决定模态框是否会填满整个视图。将其设为 true 时,会在透明背景上渲染模态框。
| Type | Default |
|---|---|
| bool | false |
visible
visible 属性决定模态框是否可见。
| Type | Default |
|---|---|
| bool | true |