RN-ActionSheetIOS

分享或者彈出更多選項(xiàng)操作, ActionSheetIOS

ActionSheetIOS提供了兩個(gè)靜態(tài)方法, 對應(yīng)兩種功能

1 操作表

* showActionSheetWithOptions(options, callback) 彈出一個(gè)分類菜單
* 方法中第一個(gè)參數(shù) options 是一個(gè)對象,該對象里各個(gè)屬性介紹如下:
  options:表示可選項(xiàng)的名稱,是一個(gè)字符串?dāng)?shù)組。 
  cancelButtonIndex:表示“取消”按鈕的位置,即“取消”按鈕在 options 數(shù)組中的索引。
  destructiveButtonIndex:表示不能使用的按鈕位置,即不能使用的按鈕在 options 數(shù)組中的索引。

2 分享框

* showShareActionSheetWithOptions(options, failureCallback, successCallback) 作用是分享一個(gè) url
    options:表示分享的 url
    failureCallback:失敗的回調(diào)函數(shù)
    successCallback:成功的回調(diào)函數(shù)

3 代碼效果


/**
 * Created by licc on 2017/7/9.
 */

import React, {Component } from 'react';
import {
    StyleSheet,
    View,
    Text,
    ActionSheetIOS
} from 'react-native';

import NavigationBar from './NavigationBar'

export default class ActionSheetExample extends Component {

    render(){
        return(
            <View style={styles.container}>
                <NavigationBar
                    title={'ActionSheetIOS'}
                    statusBar={{backgroundColor:'blue'}}
                />
                <Text style={styles.item} onPress={this.doSheet.bind(this)}>打開操作表</Text>
                <Text style={styles.item} onPress={this.doShare.bind(this)}>打開分享框</Text>
            </View>
        );
    }

    doSheet(){
        ActionSheetIOS.showActionSheetWithOptions({
            options:[
                '撥打電話',
                '發(fā)送郵件',
                '發(fā)送短信',
                '取消'
            ],
            cancelButtonIndex: 3,
            destructiveButtonIndex: 0
        },
            (index)=>{
            alert('您點(diǎn)擊了:' + index);
            }
        );
    }

    doShare(){
        ActionSheetIOS.showShareActionSheetWithOptions({
            url:''
        },
            (error)=>{
                alert(error)
            },
            (e)=>{
                alert(e)
            }
        );
    }
}

const styles = StyleSheet.create({

    container:{
        flex:1
    },

    item:{
        marginTop:10,
        marginLeft:5,
        marginRight:5,
        height:30,
        borderWidth:1,
        padding:6,
        borderColor:'#ddd',
        textAlign:'center'
    },
});

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 179,048評(píng)論 25 709
  • 發(fā)現(xiàn) 關(guān)注 消息 iOS 第三方庫、插件、知名博客總結(jié) 作者大灰狼的小綿羊哥哥關(guān)注 2017.06.26 09:4...
    肇東周閱讀 15,342評(píng)論 4 61
  • 我走過山時(shí),山不說話, 我路過海時(shí),海不說話, 小毛驢滴滴答答,倚天劍伴我走天涯。 大家都說我因?yàn)閻壑鴹钸^大俠,才...
    白羊鐵蛋閱讀 200評(píng)論 0 0
  • 當(dāng)你走進(jìn)人群, 你會(huì)發(fā)現(xiàn), 唯一和你同路的, 只有你自己。
    李放fun閱讀 638評(píng)論 6 13

友情鏈接更多精彩內(nèi)容