GithubHelp home page GithubHelp logo

pizzaliu / react-native-actionsheet Goto Github PK

View Code? Open in Web Editor NEW

This project forked from alessiocancian/react-native-actionsheet

0.0 0.0 1.0 679 KB

An elegant ActionSheet component for React Native.

License: MIT License

JavaScript 100.00%

react-native-actionsheet's Introduction

react-native-actionsheet

npm
Cross platform ActionSheet. This component implements a custom ActionSheet and provides the same way to drawing it on the defferent platforms(iOS and Android). Actually, In order to keep the best effect, it still uses the ActionSheetIOS on iOS.

Starting from v3.0.0 a custom ActionSheet with a native-like UI is available and used as default option for iOS:

A similar UI is available for Android too by passing theme="ios":

Install

npm i -S @alessiocancian/react-native-actionsheet

Usage

import ActionSheet from '@alessiocancian/react-native-actionsheet'

class Demo extends React.Component {
  showActionSheet = () => {
    this.ActionSheet.show()
  }
  render() {
    return (
      <View>
        <Text onPress={this.showActionSheet}>Open ActionSheet</Text>
        <ActionSheet
          ref={o => this.ActionSheet = o}
          title={'Which one do you like ?'}
          options={['Apple', 'Banana', 'cancel']}
          cancelButtonIndex={2}
          destructiveButtonIndex={1}
          onPress={(index) => { /* do something */ }}
        />
      </View>
    )
  }
}

Use ActionSheetCustom directly

so you can customize option and title

import { ActionSheetCustom as ActionSheet } from '@alessiocancian/react-native-actionsheet'

const options = [
  'Cancel', 
  'Apple', 
  <Text style={{color: 'yellow'}}>Banana</Text>,
  'Watermelon', 
  <Text style={{color: 'red'}}>Durian</Text>
]

class Demo extends React.Component {
  showActionSheet = () => {
    this.ActionSheet.show()
  }
  render() {
    return (
      <View>
        <Text onPress={this.showActionSheet}>Open ActionSheet</Text>
        <ActionSheet
          ref={o => this.ActionSheet = o}
          title={<Text style={{color: '#000', fontSize: 18}}>Which one do you like?</Text>}
          options={options}
          cancelButtonIndex={0}
          destructiveButtonIndex={4}
          onPress={(index) => { /* do something */ }}
        />
      </View>
    )
  }
}

How to redesign style ?

The style of ActionSheet is defined in lib/styles.js. We can pass the styles prop to cover default style. See Example .

// example

const styles = {
  titleBox: {
    background: 'pink'
  },
  titleText: {
    fontSize: 16,
    color: '#000'
  }
}

<ActionSheet
  ...
  styles={styles}
/>

Props

https://github.com/alessiocancian/react-native-actionsheet/blob/master/lib/options.js

Prop name Type Description Default
title string or ReactNode ActionSheetCustom needed to use ReactNode for iOS
message string or ReactNode ActionSheetCustom needed to use ReactNode for iOS
options (string | ReactChild)[] ActionSheetCustom needed to use ReactChild options for iOS
tintColor string
cancelButtonIndex number
destructiveButtonIndex number
onPress function
userInterfaceStyle "light" | "dark" RN version >=0.63 System theme
theme "flat" | "ios" flat for Android and native or native-like for iOS
styles only for ActionSheetCustom {}

react-native-actionsheet's People

Contributors

xiaoyann avatar alessiocancian avatar moughxyz avatar zaguiini avatar walaman avatar littlelin avatar jaaberg avatar zoontek avatar im-amir avatar rodrigobdz avatar appden avatar steffeydev avatar vasyiok avatar mj0826 avatar pizzaliu avatar

Forkers

mightyorange

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.