Giter VIP home page Giter VIP logo

react-native-android-action-sheet's Introduction

react-native-android-action-sheet

react-native-android-action-sheet is a JavaScript library for React Native, it implements AcionSheet for Android relys on AndroidActionSheet.

Installing react-native-android-action-sheet

npm install react-native-android-action-sheet --save

Android

  • android/setting.gradle
...
include ':react-native-android-action-sheet'
project(':react-native-android-action-sheet').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-android-action-sheet/android')
  • android/app/build.gradle
dependencies {
    ...
    compile project(":react-native-android-action-sheet")
}

In react-native < 0.29.0

  • Register Module (in MainActivity.java)
import cn.zjy.actionsheet.rn.ActionSheetPackage; 

public class MainActivity extends ReactActivity {
    ......
    @Override
    protected List<ReactPackage> getPackages() {
        return Arrays.asList(
            new MainReactPackage(),
            new ActionSheetPackage()
        );
    }
    ......
}

In react-native >= 0.29.0

  • Register Module (in MainApplication.java)
import cn.zjy.actionsheet.rn.ActionSheetPackage; 

public class MainApplication extends Application implements ReactApplication {
    ......
    @Override
    protected List<ReactPackage> getPackages() {
        return Arrays.asList(
            new MainReactPackage(),
            new ActionSheetPackage()
        );
    }
    ......
}

Usage

import ActionSheet from 'react-native-android-action-sheet';

//both on iOS and Android
showActionSheetWithOptions() {
    let btns = [
      'Option 0',
      'Option 1',
      'Option 2',
      'Delete',
      'Cancel',
    ];
    let params = {
      'options': btns,
      'cancelButtonIndex': 4,
      'destructiveButtonIndex': 3,
      'title': 'ActionSheet'
    };
    ActionSheet.showActionSheetWithOptions(params, (index) => {
      console.log('showActionSheetWithOptions', index);
    });
}

//Android only
showActionSheetWithCustomOptions() {
    let title = {
      'title': 'CustomActionSheet',
      'titleColor': '#0000ff'
    };
    let cancelBtn = {
      'btnTitle': 'Cancel',
      'btnTitleColor': '#00ffff'
    };
    let optionBtns = [
      { 'btnTitle': 'Option 0', 'btnTitleColor': '#6aa84f' },
      { 'btnTitle': 'Option 1', 'btnTitleColor': '#000000' },
      { 'btnTitle': 'Option 2', 'btnTitleColor': '#7f6000' },
      { 'btnTitle': 'Delete', 'btnTitleColor': '#ff0000' }
    ];
    let params = {
      'title': title,
      'optionBtns': optionBtns,
      'cancelBtn': cancelBtn
    }
    ActionSheet.showActionSheetWithCustomOptions(params, (index) => {
      console.log('showActionSheetWithCustomOptions', index);
    });
}

Screenshots

showActionSheetWithOptions

showActionSheetWithOptions

showActionSheetWithCustomOptions

showActionSheetWithCustomOptions

react-native-android-action-sheet's People

Contributors

zongjingyao avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.