zoukankan      html  css  js  c++  java
  • React Native Alert、ActionSheet

    /**
    * Created by apple on 2016/10/12.
    */
    /**
 Sample React Native App

    * https://github.com/facebook/react-native

    * @flow
 */


    "use strict"

    import React, {Component} from 'react'
    import {
    AppRegistry,
    View,
    Alert,
    ActionSheetIOS,
    TouchableHighlight,
    Text,
    StyleSheet
    } from 'react-native'

    var BUTTONS = [
    'Option 0',
    'Option 1',
    'Option 2',
    'Delete',
    'Cancel',
    ];
    var DESTRUCTIVE_INDEX = 3;
    var CANCEL_INDEX = 4;


    class HelloWorld extends Component {


    // 弹出 ActionSheet
    popActionSheet() {

    /**
    * Display an iOS action sheet. The `options` object must contain one or more
    * of:
    *
    * - `options` (array of strings) - a list of button titles (required)
    * - `cancelButtonIndex` (int) - index of cancel button in `options`
    * - `destructiveButtonIndex` (int) - index of destructive button in `options`
    * - `title` (string) - a title to show above the action sheet
    * - `message` (string) - a message to show below the title
    */

    // showActionSheetWithOptions(options: Object, callback: Function) {
    ActionSheetIOS.showActionSheetWithOptions({
    options: BUTTONS, // 字符串数组
    cancelButtonIndex: CANCEL_INDEX, // 第几个元素(索引)是cancelButton
    destructiveButtonIndex: DESTRUCTIVE_INDEX, // 第几个元素(索引)destructiveButton
    title: 'ActionSheet',

    },
    (buttonIndex) => this.actionSheetClick(buttonIndex)
    )
    }

    actionSheetClick(buttonIndex) {

    Alert.alert(
    'Alert Title',
    BUTTONS[buttonIndex]
    )
    }

    // 弹出 Alert
    popAlert() {

    console.log('弹出alert')

    Alert.alert(
    'Alert Title',
    'Alert Message',
    [
    {text: 'OK', onPress: () => this.alertOK()},
    {text: 'Cancel', onPress: () => this.alertCancel()}
    ]
    )
    }

    alertOK() {
    console.log('弹出alertOK')

    }

    alertCancel() {
    console.log('弹出alertCancel')

    }

    render() {
    return (
    <View style={styles.container}>
    <TouchableHighlight style={{borderRadius: 5, backgroundColor: 'red'}}
    onPress={() => this.popAlert()}>
    <Text style={styles.text}>{'pop alert'}</Text>
    </TouchableHighlight>
    <TouchableHighlight style={{borderRadius: 5, backgroundColor: 'red', marginTop: 30}}
    onPress={() => this.popActionSheet()}>
    <Text style={styles.text}>{'pop actionSheet'}</Text>
    </TouchableHighlight>
    </View>
    );
    }
    }

    const styles = StyleSheet.create({

    container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    flexDirection: 'column',
    backgroundColor: '#F5FCFF'
    },
    text: {
    flex: 1,
    backgroundColor: 'red',
    justifyContent:'center',
    alignItems: 'center',
    borderRadius: 5,
    },
    pickerViewContainer: {
    flex: 1,
    flexDirection: 'row',
    paddingTop: 30

    },
    pickerItem: {
    flex: 1,
    }
    })


    AppRegistry.registerComponent('HelloWorld', () => HelloWorld);

    ***************************** 效果图 ****************************

       

    
    
  • 相关阅读:
    九度oj 题目1465:最简真分数
    九度oj 题目1083:特殊乘法 清华大学2010年机试题目
    九度oj 题目1084:整数拆分 清华大学2010年机试题目
    九度oj 题目1085:求root(N, k) 清华2010年机试题目
    九度oj 题目1460:Oil Deposit
    九度oj 题目1459:Prime ring problem
    九度oj 题目1458:汉诺塔III
    九度oj 题目1457:非常可乐
    题目1451:不容易系列之一
    移动端滚动不流畅,添加-webkit-overflow-scrolling属性 值为touch
  • 原文地址:https://www.cnblogs.com/madaha/p/5955415.html
Copyright © 2011-2022 走看看