-
Notifications
You must be signed in to change notification settings - Fork 13.5k
feat(modal): clicking handle advances to the next breakpoint #25057
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
Changes from all commits
0ab41fc
52ef6a5
744ccfe
ba3e5b7
d76cc58
2460d4b
b76c50b
999f666
8ac0ae4
9f8d1b0
e5fe19a
b4843c7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,7 @@ export class Modal implements ComponentInterface, OverlayInterface { | |
private sortedBreakpoints?: number[]; | ||
private keyboardOpenCallback?: () => void; | ||
private moveSheetToBreakpoint?: (options: MoveSheetToBreakpointOptions) => void; | ||
private sheetAnimation?: Animation; | ||
|
||
private inline = false; | ||
private workingDelegate?: FrameworkDelegate; | ||
|
@@ -550,7 +551,7 @@ export class Modal implements ComponentInterface, OverlayInterface { | |
|
||
ani.progressStart(true, 1); | ||
|
||
const { gesture, moveSheetToBreakpoint } = createSheetGesture( | ||
const { gesture, moveSheetToBreakpoint, animation } = createSheetGesture( | ||
this.el, | ||
this.backdropEl!, | ||
wrapperEl, | ||
|
@@ -570,6 +571,7 @@ export class Modal implements ComponentInterface, OverlayInterface { | |
|
||
this.gesture = gesture; | ||
this.moveSheetToBreakpoint = moveSheetToBreakpoint; | ||
this.sheetAnimation = animation; | ||
|
||
this.gesture.enable(true); | ||
} | ||
|
@@ -719,6 +721,33 @@ export class Modal implements ComponentInterface, OverlayInterface { | |
return this.currentBreakpoint; | ||
} | ||
|
||
private moveToNextBreakpoint() { | ||
const { breakpoints, currentBreakpoint } = this; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tabbing to the handle and pressing Enter multiple times causes the animation to jump. Screen.Recording.2022-04-04.at.6.24.48.PM.movThere was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adjusted this behavior slightly, so that advancing is tied to keyup instead of keydown. Setting the current breakpoint does not currently wait for the previous transition to finish. If you perform an action while a transition is inflight, it will disrupt the transition. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like it's still jumping if you mash Enter; I feel like if there's a transition in progress when you click/activate the handle, it should just do nothing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @amandaesmith3 to confirm, if the user performs any action (clicking the handle or pressing enter), while the sheet modal is actively transitioning, the expected behavior would be to perform no operation (skip the interaction)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking back at the code, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Waiting for the transition feels like it would conflict with the design document for the API of moving to a breakpoint:
Unless we can cancel the current transition and immediately kick-off the new transition without a glitchy experience. I can do some more discovery on this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated the behavior, curious to both of your thoughts/feedback/alternatives. It now won't skip/jitter when you hold the enter key, but it will only performs moving to the next breakpoint when the current animation finishes. Hard to demonstrate in a recording. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So when I try it, pressing Enter twice rapidly makes it only move once. It seems like it'll just eat your input if the animation is currently running. My guess is that since the current breakpoint doesn't actually update until after the animation finishes (triggered here), That said, I'm okay with the behavior as-is. Up to you if you want to change it, though if we stick with it as-is, the code should probably be cleaned up to make it more clear. |
||
if (breakpoints && currentBreakpoint !== undefined) { | ||
const allowedBreakpoints = breakpoints.filter((b) => b !== 0); | ||
const currentBreakpointIndex = allowedBreakpoints.indexOf(currentBreakpoint); | ||
const nextBreakpointIndex = (currentBreakpointIndex + 1) % allowedBreakpoints.length; | ||
const nextBreakpoint = allowedBreakpoints[nextBreakpointIndex]; | ||
|
||
/** | ||
* Sets the current breakpoint to the next available breakpoint. | ||
* If the current breakpoint is the last breakpoint, we set the current | ||
* breakpoint to the first non-zero breakpoint to avoid dismissing the sheet. | ||
*/ | ||
if (this.sheetAnimation?.isRunning()) { | ||
this.sheetAnimation.onFinish(() => { | ||
this.setCurrentBreakpoint(nextBreakpoint); | ||
}, { oneTimeCallback: true }); | ||
} else { | ||
this.setCurrentBreakpoint(nextBreakpoint); | ||
} | ||
} | ||
} | ||
|
||
private onHandleClick = () => { | ||
this.moveToNextBreakpoint(); | ||
}; | ||
|
||
private onBackdropTap = () => { | ||
this.dismiss(undefined, BACKDROP); | ||
}; | ||
|
@@ -786,7 +815,15 @@ export class Modal implements ComponentInterface, OverlayInterface { | |
{mode === 'ios' && <div class="modal-shadow"></div>} | ||
|
||
<div role="dialog" class="modal-wrapper ion-overlay-wrapper" part="content" ref={(el) => (this.wrapperEl = el)}> | ||
{showHandle && <div class="modal-handle" part="handle"></div>} | ||
{showHandle && ( | ||
<button | ||
class="modal-handle" | ||
part="handle" | ||
aria-label="Activate to adjust the size of the card overlaying the screen" | ||
aria-controls={modalId} | ||
onClick={this.onHandleClick} | ||
></button> | ||
)} | ||
<slot></slot> | ||
</div> | ||
</Host> | ||
|
Uh oh!
There was an error while loading. Please reload this page.