Skip to content

Commit fa6b85a

Browse files
authored
Feat/action sheet allow overriding dialog props (#2211)
* ActionSheet - prettify * ActionSheet - allow overriding Dialog's props
1 parent bbb8a98 commit fa6b85a

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

src/components/actionSheet/index.tsx

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import Image from '../image';
1212
import ListItem from '../listItem';
1313
import PanningProvider from '../panningViews/panningProvider';
1414

15-
1615
const VERTICAL_PADDING = 8;
1716
type ActionSheetOnOptionPress = (index: number) => void;
1817

@@ -75,19 +74,22 @@ type ActionSheetProps = {
7574
* Render custom action
7675
* Note: you will need to call onOptionPress so the option's onPress will be called
7776
*/
78-
renderAction?: (
79-
option: ButtonProps,
80-
index: number,
81-
onOptionPress: ActionSheetOnOptionPress
82-
) => JSX.Element;
77+
renderAction?: (option: ButtonProps, index: number, onOptionPress: ActionSheetOnOptionPress) => JSX.Element;
8378
/**
84-
* Called once the modal has been dismissed (iOS only, modal only)
79+
* Called once the modal has been dismissed completely
8580
*/
8681
onModalDismissed?: DialogProps['onDialogDismissed'];
8782
/**
8883
* Whether or not to handle SafeArea
8984
*/
9085
useSafeArea?: boolean;
86+
/**
87+
* Additional props to send to the Dialog
88+
*/
89+
dialogProps?: Omit<
90+
DialogProps,
91+
'useSafeArea' | 'testID' | 'containerStyle' | 'visible' | 'onDismiss' | 'onDialogDismissed'
92+
>;
9193
/**
9294
* testID for e2e tests
9395
*/
@@ -124,16 +126,14 @@ class ActionSheet extends Component<ActionSheetProps> {
124126
cancelBtnIndex = optionsArray.length - 1;
125127
}
126128

127-
ActionSheetIOS.showActionSheetWithOptions(
128-
{
129-
title,
130-
message,
131-
options: optionsArray.map(option => option?.label || ''),
132-
cancelButtonIndex: cancelBtnIndex,
133-
destructiveButtonIndex
134-
},
135-
this.onOptionPress
136-
);
129+
ActionSheetIOS.showActionSheetWithOptions({
130+
title,
131+
message,
132+
options: optionsArray.map(option => option?.label || ''),
133+
cancelButtonIndex: cancelBtnIndex,
134+
destructiveButtonIndex
135+
},
136+
this.onOptionPress);
137137
}
138138
}
139139

@@ -146,7 +146,7 @@ class ActionSheet extends Component<ActionSheetProps> {
146146
// @ts-ignore
147147
let source = option.icon;
148148
if (!source) {
149-
source = _.isFunction(option.iconSource) ? option.iconSource() : option.iconSource as ImageProps['source'];
149+
source = _.isFunction(option.iconSource) ? option.iconSource() : (option.iconSource as ImageProps['source']);
150150
}
151151
return source && this.renderIcon(source);
152152
};
@@ -214,7 +214,7 @@ class ActionSheet extends Component<ActionSheetProps> {
214214
}
215215

216216
render() {
217-
const {useNativeIOS, visible, onDismiss, dialogStyle, onModalDismissed, testID, useSafeArea} =
217+
const {useNativeIOS, visible, onDismiss, dialogStyle, onModalDismissed, testID, useSafeArea, dialogProps} =
218218
this.props;
219219

220220
if (Constants.isIOS && useNativeIOS) {
@@ -223,16 +223,17 @@ class ActionSheet extends Component<ActionSheetProps> {
223223

224224
return (
225225
<Dialog
226-
useSafeArea={useSafeArea}
227-
testID={testID}
228226
bottom
229227
centerH
230228
width="100%"
229+
panDirection={PanningProvider.Directions.DOWN}
230+
{...dialogProps}
231+
useSafeArea={useSafeArea}
232+
testID={testID}
231233
containerStyle={[styles.dialog, dialogStyle]}
232234
visible={visible}
233235
onDismiss={onDismiss}
234236
onDialogDismissed={onModalDismissed}
235-
panDirection={PanningProvider.Directions.DOWN}
236237
>
237238
{this.renderSheet()}
238239
</Dialog>

0 commit comments

Comments
 (0)