Skip to content

Commit

Permalink
fix(action-sheet): iOS dismiss animation respects safe area (#28915)
Browse files Browse the repository at this point in the history
Issue number: resolves #28541

---------

<!-- Please do not submit updates to dependencies unless it fixes an
issue. -->

<!-- Please try to limit your pull request to one type (bugfix, feature,
etc). Submit multiple pull requests if needed. -->

## What is the current behavior?
<!-- Please describe the current behavior that you are modifying. -->

On iOS when dismissing the `ion-action-sheet`, the animation does not
account for the safe area of the device. This results in the action
sheet not completely animating off the visible viewport on a device with
safe area enabled.



## What is the new behavior?
<!-- Please describe the behavior or changes that are being added by
this PR. -->

- The `ion-action-sheet` will animate consistently off the viewport when
dismissing, including the safe area.

To better support custom animations not needing to account for the safe
area, the safe area has been added to the padding of the action sheet
container. This results in the height increasing based on the bottom
safe area and animating correctly when translating between [`100%` and
`0%`](https://github.com/ionic-team/ionic-framework/blob/9d57758e3ec1095c6eb951d2640b95084b711bbc/core/src/components/action-sheet/animations/ios.enter.ts#L23).


|Before|After|
|---|---|
|<video
src="https://github.com/ionic-team/ionic-framework/assets/13732623/d9475a54-f1b9-4283-ae1a-86e2b71a9d9e"></video>|<video
src="https://github.com/ionic-team/ionic-framework/assets/13732623/d051b4d9-4f45-4a51-b522-510f8cddef74"></video>|

In the recorded examples the bottom safe area is exaggerated to show the
dismiss animation differences.

## Does this introduce a breaking change?

- [ ] Yes
- [x] No

<!--
  If this introduces a breaking change:
1. Describe the impact and migration path for existing applications
below.
  2. Update the BREAKING.md file with the breaking change.
3. Add "BREAKING CHANGE: [...]" to the commit description when merging.
See
https://github.com/ionic-team/ionic-framework/blob/main/.github/CONTRIBUTING.md#footer
for more information.
-->


## Other information

<!-- Any other information that is important to this PR such as
screenshots of how the component looks before and after the change. -->

To test this PR, I would recommend adding the following styles to the
action sheet basic test:
```html
<style>
ion-action-sheet {
  --ion-safe-area-bottom: 100px;
}
</style>
```


You can then open dev-tools and slow the animation speed to 10%:

![CleanShot 2024-01-29 at 19 49
32@2x](https://github.com/ionic-team/ionic-framework/assets/13732623/535fa663-213c-4a09-b94a-db334e4d3d29)

- Open and dismiss the action sheet tied to the "Basic" button. 
- Verify that the action sheet animates completely off the view when
dismissed.
- Open the and dismiss the action sheet tied to the "Custom CSS Class"
button. This implementation customizes the `--height` of the action
sheet.
- Verify that the action sheet animates completely off the view when
dismissed.

---------

Co-authored-by: ionitron <[email protected]>
Co-authored-by: Liam DeBeasi <[email protected]>
  • Loading branch information
3 people authored Feb 6, 2024
1 parent 5777ce2 commit 7449fb4
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion core/src/components/action-sheet/action-sheet.ios.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,24 @@
// ---------------------------------------------------

.action-sheet-wrapper {
@include margin(var(--ion-safe-area-top, 0), auto, var(--ion-safe-area-bottom, 0), auto);
@include margin(var(--ion-safe-area-top, 0), auto, null, auto);
/**
* Bottom safe area is applied as padding so that it impacts the bounding box.
* When the action sheet is shown/hidden, this element is transformed by translating
* 100% of its height. This translation needs to include the bottom safe area
* otherwise part of the action sheet will still be visible at the end of
* the show transition.
*
* If this code is changed, reviewers should verify that the action
* sheet still translates out of the viewport completely when the bottom
* safe area is a positive value.
*/
@include padding(null, null, var(--ion-safe-area-bottom, 0), null);

// Using content-box to increase the height of the action sheet
// wrapper by the bottom padding (safe area) to animate the
// action sheet completely off the screen when safe area is set.
box-sizing: content-box;
}

// iOS Action Sheet Container
Expand Down

0 comments on commit 7449fb4

Please sign in to comment.