分享或者彈出更多選項操作, ActionSheetIOS
ActionSheetIOS提供了兩個靜態(tài)方法歼跟, 對應(yīng)兩種功能
1 操作表
* showActionSheetWithOptions(options, callback) 彈出一個分類菜單
* 方法中第一個參數(shù) options 是一個對象吕世,該對象里各個屬性介紹如下:
options:表示可選項的名稱,是一個字符串?dāng)?shù)組扩劝。
cancelButtonIndex:表示“取消”按鈕的位置,即“取消”按鈕在 options 數(shù)組中的索引蕴坪。
destructiveButtonIndex:表示不能使用的按鈕位置聚假,即不能使用的按鈕在 options 數(shù)組中的索引。
2 分享框
* showShareActionSheetWithOptions(options, failureCallback, successCallback) 作用是分享一個 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('您點擊了:' + 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'
},
});