Skip to content

Commit

Permalink
Add disableIndexes support to ActionSheetIOS for parity w/ `Actio…
Browse files Browse the repository at this point in the history
…nSheetCustom` + clean-up
  • Loading branch information
jzaleski committed Mar 25, 2023
1 parent b431605 commit e3b6a8b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,12 @@ https://github.com/alessiocancian/react-native-actionsheet/blob/master/lib/optio
<td></td>
<td></td>
</tr>
<tr>
<td>disabledIndexes</td>
<td>number[]</td>
<td></td>
<td></td>
</tr>
<tr>
<td>onPress</td>
<td>function</td>
Expand Down
7 changes: 2 additions & 5 deletions lib/ActionSheetCustom.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,11 @@ class ActionSheet extends React.Component {
_createButton (title, index) {
const styles = getMergedStyles(this.props.styles)
const { buttonUnderlayColor, cancelButtonIndex, destructiveButtonIndex, disabledIndexes, disabledColor } = this.props
const isDisabled = disabledIndexes.indexOf(index) !== -1
const tintColor = this.props.tintColor || (this._isDarkMode() ? "#4793FF" : "#007AFF")
const fontColor = destructiveButtonIndex === index ? WARN_COLOR : tintColor
const fontColor = isDisabled ? disabledColor : (destructiveButtonIndex === index ? WARN_COLOR : tintColor)
const isCancel = cancelButtonIndex === index
const buttonBoxStyle = isCancel ? styles.cancelButtonBox : styles.buttonBox
const isDisabled = disabledIndexes.indexOf(index) !== -1
if (isDisabled) {
fontColor = disabledColor
}
return (
<TouchableHighlight
key={index}
Expand Down
5 changes: 5 additions & 0 deletions lib/ActionSheetIOS.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ class ActionSheet extends React.Component {
options[name] = value
}
})
const disabledIndexes = options.disabledIndexes
if (typeof disabledIndexes !== 'undefined') {
options['disabledButtonIndices'] = disabledIndexes
}
delete options.disabledIndexes
const callback = options.onPress
delete options.onPress
ActionSheetIOS.showActionSheetWithOptions(options, callback)
Expand Down
6 changes: 6 additions & 0 deletions lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ export default [
*/
'destructiveButtonIndex',

/**
* a list of disabled button indices (optional)
* @type int[]
*/
'disabledIndexes',

/**
* a title to show above the action sheet
* @type string
Expand Down
4 changes: 3 additions & 1 deletion lib/ts/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ type Props = {
tintColor?: string;
cancelButtonIndex?: number;
destructiveButtonIndex?: number;
disabledIndexes?: number[];

/**
* Only for Android or ActionSheetCustom
*/
Expand Down Expand Up @@ -77,4 +79,4 @@ type ActionSheetCustomProps = Props | {

export class ActionSheetCustom extends Component<ActionSheetCustomProps> {
public show: () => void;
}
}

0 comments on commit e3b6a8b

Please sign in to comment.