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