Giter Site home page Giter Site logo

react-native-actionsheet's Introduction

react-native-actionsheet

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.

Install

npm install react-native-actionsheet --save

Usage

import ActionSheet from '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 '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/beefe/react-native-actionsheet/blob/master/lib/options.js

Prop name Description Type Default
title PropTypes.string or PropTypes.element
message PropTypes.string or PropTypes.element
options PropTypes.arrayOf([PropTypes.string, PropTypes.element])
tintColor PropTypes.string
cancelButtonIndex PropTypes.number
destructiveButtonIndex PropTypes.number
onPress PropTypes.func (index) => {}
styles only for ActionSheetCustom {}

react-native-actionsheet's People

Contributors

appden avatar jaaberg avatar littlelin avatar mj0826 avatar moughxyz avatar rodrigobdz avatar steffeydev avatar xiaoyann avatar zoontek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-actionsheet's Issues

styles in actionsheet not effect in android

I'm trying to change style in actionsheet but it not effect at all

          <ActionSheet
                        ref={o => this.ActionSheet = o}
                        options={options}
                        cancelButtonIndex={2}
                        onPress={(index) => { this._imagePick(index) }}
                        styles={{messageBox: { height: 60 },body:{backgroundColor:'red'}}}
                        />

the backgroundcolor style stay white

About the version of react

In dependencies, the version of react is "15.4.0". Now I'm using react 15.3.2, so when I do yarn install this package, there is a warning incorrect peer dependency "react@>=15.4.0".
But I find it can still work in react 15.3.2 even there is a warning. I want to know why you set the version of react to "15.4.0". And I wonder if you could downgrade the react version to the lowest one, since the low version(al least 15.3.2) can still work well.

点击问题

为什么我在点击取消按钮时,会显示 i like Cancel ?????

AllowFontScaling for text elements

Is there any way to set the allowFontScaling={false} for text components inside the ActionSheet? I'm having issues in iOS when users change the default font scaling setting globally in the phone.

Thanks.

Flashback

test two times ,happened Flashback on iPhone 8plus 11.2

ActionSheet.show() throws error

ActionSheet.show() throws an error after upgrading to RN 0.50.4.
Has anyone else faced similar issue ?

2017-12-18 12:32:11.183 [fatal][tid:com.facebook.react.JavaScript] Error calling RCTEventEmitter.receiveTouches

Unhandled JS Exception: Exception calling object as function: C++ exception in 'nativeFlushQueueImmediate'

Malformed calls from JS: field sizes are different.

screen shot 2017-12-18 at 12 59 54 pm

Can't disable some options

For the project i'm working on i need to disable some of the options (still show them, but greyed out and not clickable)
Could their be a similar function, by for example simply passing an array of index for the disabled objects?

Thanks

actionsheet复用

我在一个页面上,有很多个acttionsheet,想复用,想每次点击弹出不同的buttons,比如点击A按钮,弹出 三个选择,点击B按钮,弹出4个选择,如过动态修改弹出actionsheet。

Message cut off

Hi all,

Great component, works flawlessly, except for one small detail: on Android the message seems to be cut off (see image). Strangely in the example screenshots provided in the readme it appears normal though (note though that I did not run the example on an emulator). Do you know if there's a fix for this?

Thank you!

message cut off

Can't show the last item on MEIZU

As title said, can't show the last item because of MEIZU mobile has a smart bar at the bottom of screen, so I think if component can pass the styles to actionsheet will be more appropriate. So I can add customer styles( such as {{ marginBottom: SMART_BAR_HEIGHT }} ) to resolve my issue.

<Animated.View 
  style={[sheetStyle.bd, 
{height: this.translateY, transform: [{translateY: sheetAnim}]}, 
this.props.style]}>

ActionSheetCustom Create Problem

Hello Team,
When I am using ActionSheetCustom with any Image picker then it not working properly in iOS.
When I choose to pick an image from the gallery after first-time selection when user open gallery (Picker) then it auto-dismissed.

The same works fine in Android.

Can you please provide any solution regarding it.

Dynamically change actionsheet title

Is it possible to dynamically change the title for the action sheet?

For example, I have a ListView with several items, and I want that when the user presses on an item then the title would be set to a prop in that item

I tried this.ActionSheet.title = 'new title' but it doesn't work

Inconsistent user experience on iOS tablet

Is it by design that the cancel option is not shown on iOS tablets and the user only has the destructive option available?

Also, the options pop up in the middle of the screen instead of sliding in from below.

Everything works as expected on Android tablets.

Automation testing with Appium

How do I test the calendar with Appium? I tried passing the accessibilityId to the component but it does not recognise it.

declarative api

its uncommon for react to have components with imperative api ("show", "hide")

we therefore need to have a visible: Boolean property that controls whether the actionsheet is visible or not

Actionsheet not working on android

Android Pixel XL 2 physical device

None of the action sheet buttons work including the options and cancel button. I can only close the actionsheet by using the back button.

rejectResponderTermination might help. It has for me in the past.

Problems with dynamically setting options array on Android

Using RN 0.39.

When I have a static array of options it works (buttons below), while dynamically setting them (at time of rendering) (otherButtons below) does not.

let buttons = ['Cancel', 'Option 1', 'Option 2', 'Option 3'];
let otherButtons = ['Cancel'];

for (let i = 0; i < array.length; i++) {
	otherButtons.push(array[i].value);
}

<ActionSheet
	ref={(o) => this.ActionSheet = o}
	title={CartTexts.action_sheet_title}
	options={buttons}
	// options={otherButtons} <-- Does not work
	cancelButtonIndex={0}
	onPress={this._handleActionSheetPress.bind(this)}
/>

Render title as element

Is it possible to render title as react.element?
It's defined in Docs, but when I try to set it, it gives me warning that title only accepts string as prop.

image

Multiple Destructive Button Indexes or custom text style

Is there a way to to have MORE THAN ONE destructiveButtonIndex? Maybe destructiveButtonIndex can accept an array of ints/indexes that you want to display in red.

or a style option to add custom text color per option in action sheet?

MAX_HEIGHT on Android

MAX_HEIGHT should be a prop?

As shown in screenshots list fits on iOS but not Android

iOS

screen shot 2017-11-09 at 6 07 57 pm

Android

screen shot 2017-11-09 at 6 06 36 pm

发现一个bug

当点击actionsheet的灰色背景时,自动调用了onPress函数,其index参数值为undefined,
我不知道你是故意这样设计,还是一个bug

个人认为点击actionsheet的灰色背景,不应该调用onPress函数,
即使调用,index参数值也应该和cancelButtonIndex值相同

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.