非常教程

React native参考手册

Components: Modal

Modal

模态组件是在封闭视图上呈现内容的简单方法。

注意:如果您需要更多控制如何在应用程序的其他部分展示模块,请考虑使用顶级导航器。

import React, { Component } from 'react';
import { Modal, Text, TouchableHighlight, View } from 'react-native';

class ModalExample extends Component {

  state = {
    modalVisible: false,
  }

  setModalVisible(visible) {
    this.setState({modalVisible: visible});
  }

  render() {
    return (
      <View style={{marginTop: 22}}>
        <Modal
          animationType="slide"
          transparent={false}
          visible={this.state.modalVisible}
          onRequestClose={() => {alert("Modal has been closed.")}}
          >
         <View style={{marginTop: 22}}>
          <View>
            <Text>Hello World!</Text>

            <TouchableHighlight onPress={() => {
              this.setModalVisible(!this.state.modalVisible)
            }}>
              <Text>Hide Modal</Text>
            </TouchableHighlight>

          </View>
         </View>
        </Modal>

        <TouchableHighlight onPress={() => {
          this.setModalVisible(true)
        }}>
          <Text>Show Modal</Text>
        </TouchableHighlight>

      </View>
    );
  }
}

道具

animated?: bool

弃用

改用animationTypeprop。

animationType?: enum('none', 'slide', 'fade')

animationType道具如何控制模态动画。

  • slide 从底部滑入
  • fade 淡入视野
  • none 没有动画出现

默认设置为none

onRequestClose?: (Platform.isTVOS || Platform.OS === 'android') ? PropTypes.func.isRequired : PropTypes.func

onRequestClose当用户点击Android上的硬件返回按钮或Apple TV上的菜单按钮时,会调用该回调。

onShow?: function

onShow道具允许传递一个函数,一旦模态被显示,该函数将被调用。

transparent?: bool

transparent道具决定了你是否模式将填补整个视图。将其设置为true将在透明背景上渲染模式。

visible?: bool

visible道具决定了你的模式是否可见。

androidhardwareAccelerated?: bool

hardwareAccelerated道具控制是否强制底层窗口的硬件加速。

iosonOrientationChange?: function

onOrientationChange当在显示模态方向变化回调被调用。提供的方向只是“肖像”或“风景”。不管当前的方向如何,此回调也在初始渲染时调用。

iospresentationStyle?: enum('fullScreen', 'pageSheet', 'formSheet', 'overFullScreen')

presentationStyle道具控制着模式的显示方式(通常用于iPad或大尺寸iPhone等较大的设备上)。有关详细信息,请参阅https://developer.apple.com/reference/uikit/uimodalpresentationstyle。

  • fullScreen 完全覆盖屏幕
  • pageSheet 涵盖居中的纵向宽度视图(仅适用于较大的设备)
  • formSheet 涵盖居中的窄视图(仅适用于较大的设备)
  • overFullScreen 完全覆盖屏幕,但允许透明度

默认设置为overFullScreenfullScreen取决于transparent属性。

iossupportedOrientations?: [enum('portrait', 'portrait-upside-down', 'landscape', 'landscape-left', 'landscape-right')]

所述supportedOrientations支柱允许模式被旋转到任何指定的取向。在iOS上,模态仍受限于应用的Info.plist的UISupportedInterfaceOrientations字段中指定的内容。当使用presentationStylepageSheet还是formSheet,这个属性会被iOS的被忽略。

Components: Modal相关

React native

React Native 是一个 JavaScript 的框架,用来撰写实时的、可原生呈现 iOS 和 Android 的应用。

主页 https://facebook.github.io/react-native/
源码 https://github.com/facebook/react-native
发布版本 0.49

React native目录

1.开始 | Getting Started
2.指南 | Guides
3.APIs
4.组件:ActivityIndicator | Components: ActivityIndicator
5.组件:按钮 | Components: Button
6.组件:CheckBox | Components: CheckBox
7.组件:DatePickerIOS | Components: DatePickerIOS
8.组件:DrawerLayoutAndroid | Components: DrawerLayoutAndroid
9.组件:FlatList | Components: FlatList
10.组件:图像 | Components: Image
11.组件:KeyboardAvoidingView | Components: KeyboardAvoidingView
12.Components: ListView
13.Components: MaskedViewIOS
14.Components: Modal
15.Components: NavigatorIOS
16.Components: Picker
17.Components: PickerIOS
18.Components: ProgressBarAndroid
19.Components: ProgressViewIOS
20.Components: RefreshControl
21.Components: ScrollView
22.Components: SectionList
23.Components: SegmentedControlIOS
24.Components: Slider
25.Components: SnapshotViewIOS
26.Components: StatusBar
27.Components: Switch
28.Components: TabBarIOS
29.Components: TabBarIOS.Item
30.Components: Text
31.Components: TextInput
32.Components: ToolbarAndroid
33.Components: TouchableHighlight
34.Components: TouchableNativeFeedback
35.Components: TouchableOpacity
36.Components: TouchableWithoutFeedback
37.Components: View
38.Components: ViewPagerAndroid
39.Components: VirtualizedList
40.Components: WebView
41.创建 | Contributing
42.指南(Android) | Guides (Android)
43.指南(IOS) | Guides (iOS)
44.其他 | Miscellaneous