react-native試玩(27)-上拉菜單API

來源:互聯網
上載者:User

ActionSheetIOS 方法

static showActionSheetWithOptions(options: Object, callback: Function) :顯示上拉菜單

static showShareActionSheetWithOptions(options: Object, failureCallback: Function, successCallback: Function):顯示分享菜單 執行個體

'use strict';var React = require('react-native');var {  ActionSheetIOS,  StyleSheet,  Text,  View,} = React;var BUTTONS = [  'Button Index: 0',  'Button Index: 1',  'Button Index: 2',  'Destruct',  'Cancel',];var DESTRUCTIVE_INDEX = 3;var CANCEL_INDEX = 4;var ActionSheetExample = React.createClass({  getInitialState() {    return {      clicked: 'none',    };  },  render() {    return (      <View>        <Text onPress={this.showActionSheet} style={style.button}>          Click to show the ActionSheet        </Text>        <Text>          Clicked button at index: "{this.state.clicked}"        </Text>      </View>    );  },  showActionSheet() {    ActionSheetIOS.showActionSheetWithOptions({      options: BUTTONS,      cancelButtonIndex: CANCEL_INDEX,      destructiveButtonIndex: DESTRUCTIVE_INDEX,    },    (buttonIndex) => {      this.setState({ clicked: BUTTONS[buttonIndex] });    });  }});var ShareActionSheetExample = React.createClass({  getInitialState() {    return {      text: ''    };  },  render() {    return (      <View>        <Text onPress={this.showShareActionSheet} style={style.button}>          Click to show the Share ActionSheet        </Text>        <Text>          {this.state.text}        </Text>      </View>    );  },  showShareActionSheet() {    ActionSheetIOS.showShareActionSheetWithOptions({      url: 'https://code.facebook.com',    },    (error) => {      console.error(error);    },    (success, method) => {      var text;      if (success) {        text = `Shared via ${method}`;      } else {        text = 'You didn\'t share';      }      this.setState({text})    });  }});var style = StyleSheet.create({  button: {    marginBottom: 10,    fontWeight: '500',  }});exports.title = 'ActionSheetIOS';exports.description = 'Interface to show iOS\' action sheets';exports.examples = [  {    title: 'Show Action Sheet',    render(): ReactElement { return <ActionSheetExample />; }  },  {    title: 'Show Share Action Sheet',    render(): ReactElement { return <ShareActionSheetExample />; }  }];
效果 上拉菜單

分享菜單

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.