Skip to content

fix: add enableElevation prop to ActionSheet for shadow support #438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/pages/reference/actionsheet.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,16 @@ Choose how far off the user needs to drag the action sheet to make it snap to ne

Default: `50`

## `enableElevation`

Enable elevation on the action sheet container.

| Type | Required |
| --------- | -------- |
| `boolean` | no |

Default: `true`

## `elevation`

Set elevation to the ActionSheet container.
Expand Down
17 changes: 11 additions & 6 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export default forwardRef<ActionSheetRef, ActionSheetProps>(
closeOnPressBack = true,
springOffset = 50,
elevation = 5,
enableElevation = true,
defaultOverlayOpacity = 0.3,
overlayColor = 'black',
closable = true,
Expand Down Expand Up @@ -268,15 +269,15 @@ export default forwardRef<ActionSheetRef, ActionSheetProps>(
...config,
velocity: typeof velocity !== 'number' ? undefined : velocity,
}).start();
}else {
} else {
Animated.spring(animations.translateY, {
toValue: initialValue.current,
useNativeDriver: true,
...config,
velocity: typeof velocity !== 'number' ? undefined : velocity,
}).start();
}

notifySnapIndexChanged();
},
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down Expand Up @@ -349,7 +350,9 @@ export default forwardRef<ActionSheetRef, ActionSheetProps>(
if (drawUnderStatusBar || props.onChange) {
animationListener = animations.translateY.addListener(value => {
const correctedValue =
value.value > minTranslateValue.current ? value.value - minTranslateValue.current : 0;
value.value > minTranslateValue.current
? value.value - minTranslateValue.current
: 0;
props?.onChange?.(correctedValue, actionSheetHeight.current);
if (drawUnderStatusBar) {
if (lock.current) return;
Expand Down Expand Up @@ -1531,9 +1534,11 @@ export default forwardRef<ActionSheetRef, ActionSheetProps>(
borderRadius:
props.containerStyle?.borderRadius || undefined,
width: props.containerStyle?.width || '100%',
...getElevation(
typeof elevation === 'number' ? elevation : 5,
),
...(enableElevation
? getElevation(
typeof elevation === 'number' ? elevation : 5,
)
: {}),
flex: undefined,
height: dimensions.height,
maxHeight: dimensions.height,
Expand Down
7 changes: 7 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@ export type ActionSheetProps<SheetId extends keyof Sheets = never> = {
*/
keyboardHandlerEnabled?: boolean;

/**
* Enable elevation. This will add a shadow to the ActionSheet.
*
* Default: `true`
*/
enableElevation?: boolean;

/**
* Add elevation to the ActionSheet container.
*
Expand Down