File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import * as React from 'react' ;
22import {
3- StyleSheet ,
4- Text ,
5- Image ,
6- View ,
7- ScrollView ,
8- findNodeHandle ,
93 AccessibilityInfo ,
4+ findNodeHandle ,
5+ Image ,
106 Platform ,
7+ ScrollView ,
8+ StyleSheet ,
9+ Text ,
1110 UIManager ,
11+ View ,
1212} from 'react-native' ;
1313import TouchableNativeFeedbackSafe from './TouchableNativeFeedbackSafe' ;
1414import { ActionSheetOptions } from '../types' ;
@@ -46,6 +46,14 @@ const focusViewOnRender = (ref: React.Component | null) => {
4646 }
4747} ;
4848
49+ const isIndexDestructive = ( index : number , destructiveIndex ?: number | number [ ] ) => {
50+ if ( Array . isArray ( destructiveIndex ) ) {
51+ return destructiveIndex . includes ( index ) ;
52+ }
53+
54+ return index === destructiveIndex ;
55+ } ;
56+
4957export default class ActionGroup extends React . Component < Props > {
5058 static defaultProps = {
5159 title : null ,
@@ -126,7 +134,7 @@ export default class ActionGroup extends React.Component<Props> {
126134 const defaultColor = tintColor
127135 ? tintColor
128136 : ( textStyle || { } ) . color || BLACK_87PC_TRANSPARENT ;
129- const color = i === destructiveButtonIndex ? destructiveColor : defaultColor ;
137+ const color = isIndexDestructive ( i , destructiveButtonIndex ) ? destructiveColor : defaultColor ;
130138 const iconSource = icons != null ? icons [ i ] : null ;
131139
132140 optionViews . push (
@@ -169,7 +177,7 @@ const styles = StyleSheet.create({
169177 width : 24 ,
170178 height : 24 ,
171179 marginRight : 32 ,
172- justifyContent : " center" ,
180+ justifyContent : ' center' ,
173181 } ,
174182 message : {
175183 marginTop : 12 ,
Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ export default class ActionSheet extends React.Component<Props> {
3434 anchor : dataOptions . anchor || undefined ,
3535 userInterfaceStyle : dataOptions . userInterfaceStyle || undefined ,
3636 } ;
37+ // @ts -ignore: Even though ActionSheetIOS supports array of numbers for `destructiveIndex` the types are not yet updated. See https://github.com/facebook/react-native/pull/18254.
3738 ActionSheetIOS . showActionSheetWithOptions ( iosOptions , onSelect ) ;
3839 }
3940}
Original file line number Diff line number Diff line change @@ -2,7 +2,10 @@ import * as React from 'react';
22import { TextStyle , ViewStyle } from 'react-native' ;
33
44export interface ActionSheetProps {
5- showActionSheetWithOptions : ( options : ActionSheetOptions , callback : ( i : number ) => void | Promise < void > ) => void ;
5+ showActionSheetWithOptions : (
6+ options : ActionSheetOptions ,
7+ callback : ( i : number ) => void | Promise < void >
8+ ) => void ;
69}
710
811// for iOS
@@ -12,7 +15,7 @@ export interface ActionSheetIOSOptions {
1215 message ?: string ;
1316 tintColor ?: string ;
1417 cancelButtonIndex ?: number ;
15- destructiveButtonIndex ?: number ;
18+ destructiveButtonIndex ?: number | number [ ] ;
1619 anchor ?: number ;
1720 userInterfaceStyle ?: 'light' | 'dark' ;
1821}
You can’t perform that action at this time.
0 commit comments