Skip to content

Commit 51a2ce8

Browse files
committed
docs(modal): add console for snap changes
1 parent 0e2099e commit 51a2ce8

5 files changed

Lines changed: 58 additions & 5 deletions

File tree

static/usage/v8/modal/sheet/drag-move-event/angular/example_component_ts.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,20 @@ import type { ModalDragEventDetail } from '@ionic/angular/standalone';
1212
export class ExampleComponent {
1313
@ViewChild('header', { read: ElementRef })
1414
header!: ElementRef<HTMLIonHeaderElement>;
15+
// Assign the current snap breakpoint to the initial breakpoint so
16+
// that we can track changes during the drag
17+
currentSnap = 0.25;
1518

1619
onDragMove(event: CustomEvent<ModalDragEventDetail>) {
1720
// `progress` is a value from 1 (top) to 0 (bottom)
18-
const { progress } = event.detail;
21+
// `snapBreakpoint` tells us which snap point the modal will animate to after the drag ends
22+
const { progress, snapBreakpoint } = event.detail;
23+
24+
if (this.currentSnap !== snapBreakpoint) {
25+
this.currentSnap = snapBreakpoint as number;
26+
27+
console.log('Current snap breakpoint:', snapBreakpoint);
28+
}
1929

2030
const headerEl = this.header.nativeElement;
2131
/**
@@ -31,6 +41,7 @@ export class ExampleComponent {
3141
onDragEnd(event: CustomEvent<ModalDragEventDetail>) {
3242
console.log('Drag ended', event.detail);
3343

44+
// `progress` is a value from 1 (top) to 0 (bottom)
3445
// `snapBreakpoint` tells us which snap point the modal will animate to after the drag ends
3546
const { progress, snapBreakpoint } = event.detail;
3647
const headerEl = this.header.nativeElement;

static/usage/v8/modal/sheet/drag-move-event/demo.html

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,20 @@
3939
<script>
4040
const modal = document.querySelector('ion-modal');
4141
const header = document.querySelector('ion-header');
42+
// Assign the current snap breakpoint to the initial breakpoint so
43+
// that we can track changes during the drag
44+
let currentSnap = 0.25;
4245
modal.breakpoints = [0, 0.25, 0.5, 0.75, 1];
4346

4447
modal.addEventListener('ionDragMove', (event) => {
4548
// `progress` is a value from 1 (top) to 0 (bottom)
46-
const { progress } = event.detail;
49+
const { progress, snapBreakpoint } = event.detail;
50+
51+
if (currentSnap !== snapBreakpoint) {
52+
currentSnap = snapBreakpoint;
53+
54+
console.log('Current snap breakpoint:', snapBreakpoint);
55+
}
4756

4857
/**
4958
* Inverse relationship:
@@ -58,6 +67,7 @@
5867
modal.addEventListener('ionDragEnd', (event) => {
5968
console.log('Drag ended');
6069

70+
// `progress` is a value from 1 (top) to 0 (bottom)
6171
// `snapBreakpoint` tells us which snap point the modal will animate to after the drag ends
6272
const { progress, snapBreakpoint } = event.detail;
6373

static/usage/v8/modal/sheet/drag-move-event/javascript.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,21 @@
1919
<script>
2020
const modal = document.querySelector('ion-modal');
2121
const header = document.querySelector('ion-header');
22+
// Assign the current snap breakpoint to the initial breakpoint so
23+
// that we can track changes during the drag
24+
let currentSnap = 0.25;
2225
modal.breakpoints = [0, 0.25, 0.5, 0.75, 1];
2326
2427
modal.addEventListener('ionDragMove', (event) => {
2528
// `progress` is a value from 1 (top) to 0 (bottom)
26-
const { progress } = event.detail;
29+
// `snapBreakpoint` tells us which snap point the modal will animate to after the drag ends
30+
const { progress, snapBreakpoint } = event.detail;
31+
32+
if (currentSnap !== snapBreakpoint) {
33+
currentSnap = snapBreakpoint;
34+
35+
console.log('Current snap breakpoint:', snapBreakpoint);
36+
}
2737
2838
/**
2939
* Inverse relationship:

static/usage/v8/modal/sheet/drag-move-event/react.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,22 @@ import type { ModalDragEventDetail } from '@ionic/react';
55

66
function Example() {
77
const header = useRef<HTMLIonHeaderElement>(null);
8+
// Assign the current snap breakpoint to the initial breakpoint so
9+
// that we can track changes during the drag
10+
const currentSnap = useRef(0.25);
811

912
const onDragMove = (event: CustomEvent<ModalDragEventDetail>) => {
1013
// `progress` is a value from 1 (top) to 0 (bottom)
11-
const { progress } = event.detail;
14+
// `snapBreakpoint` tells us which snap point the modal will animate to after the drag ends
15+
const { progress, snapBreakpoint } = event.detail;
1216
const headerEl = header.current!;
1317

18+
if (currentSnap.current !== snapBreakpoint) {
19+
currentSnap.current = snapBreakpoint as number;
20+
21+
console.log('Current snap breakpoint:', snapBreakpoint);
22+
}
23+
1424
/**
1525
* Inverse relationship:
1626
* 1.0 progress = 0 opacity
@@ -24,6 +34,7 @@ function Example() {
2434
const onDragEnd = (event: CustomEvent<ModalDragEventDetail>) => {
2535
console.log('Drag ended', event.detail);
2636

37+
// `progress` is a value from 1 (top) to 0 (bottom)
2738
// `snapBreakpoint` tells us which snap point the modal will animate to after the drag ends
2839
const { progress, snapBreakpoint } = event.detail;
2940
const headerEl = header.current!;

static/usage/v8/modal/sheet/drag-move-event/vue.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,22 @@ import { IonButton, IonModal, IonHeader, IonContent, IonToolbar, IonTitle, IonLa
3131
import type { ModalDragEventDetail } from '@ionic/vue';
3232
3333
const header = ref<InstanceType<typeof IonHeader>>();
34+
// Assign the current snap breakpoint to the initial breakpoint so
35+
// that we can track changes during the drag
36+
let currentSnap = 0.25;
3437
3538
const onDragMove = (event: CustomEvent<ModalDragEventDetail>) => {
3639
// `progress` is a value from 1 (top) to 0 (bottom)
37-
const { progress } = event.detail;
40+
// `snapBreakpoint` tells us which snap point the modal will animate to after the drag ends
41+
const { progress, snapBreakpoint } = event.detail;
3842
const headerEl = header.value!.$el;
3943
44+
if (currentSnap !== snapBreakpoint) {
45+
currentSnap = snapBreakpoint;
46+
47+
console.log('Current snap breakpoint:', snapBreakpoint);
48+
}
49+
4050
/**
4151
* Inverse relationship:
4252
* 1.0 progress = 0 opacity
@@ -50,6 +60,7 @@ const onDragMove = (event: CustomEvent<ModalDragEventDetail>) => {
5060
const onDragEnd = (event: CustomEvent<ModalDragEventDetail>) => {
5161
console.log('Drag ended', event.detail);
5262
63+
// `progress` is a value from 1 (top) to 0 (bottom)
5364
// `snapBreakpoint` tells us which snap point the modal will animate to after the drag ends
5465
const { progress, snapBreakpoint } = event.detail;
5566
const headerEl = header.value!.$el;

0 commit comments

Comments
 (0)