-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(animation): add playground example for double-click gesture (#3042)
Co-authored-by: dillionmegida < [email protected]> Co-authored-by: Maria Hutt <[email protected]>
- Loading branch information
1 parent
4d8f605
commit 1acc6e4
Showing
11 changed files
with
349 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
static/usage/v7/gestures/double-click/angular/example_component_css.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
```css | ||
ion-card { | ||
transform: translateX(0); | ||
user-select: none; | ||
} | ||
``` |
5 changes: 5 additions & 0 deletions
5
static/usage/v7/gestures/double-click/angular/example_component_html.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
```html | ||
<ion-card #card> | ||
<ion-card-content>Double click me to move the card.</ion-card-content> | ||
</ion-card> | ||
``` |
51 changes: 51 additions & 0 deletions
51
static/usage/v7/gestures/double-click/angular/example_component_ts.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
```ts | ||
import { Component, ElementRef, ViewChild } from '@angular/core'; | ||
import { GestureController, IonCard } from '@ionic/angular'; | ||
|
||
@Component({ | ||
selector: 'app-example', | ||
templateUrl: 'example.component.html', | ||
styleUrls: ['./example.component.css'], | ||
}) | ||
export class ExampleComponent { | ||
@ViewChild('card', { read: ElementRef }) card: ElementRef<HTMLIonCardElement>; | ||
|
||
private currentOffset: number = 0; | ||
private lastOnStart: number = 0; | ||
private DOUBLE_CLICK_THRESHOLD: number = 500; | ||
|
||
constructor(private el: ElementRef, private gestureCtrl: GestureController) {} | ||
|
||
ngAfterViewInit() { | ||
const gesture = this.gestureCtrl.create({ | ||
el: this.card.nativeElement, | ||
threshold: 0, | ||
onStart: () => this.onStart(), | ||
gestureName: 'double-click', | ||
}); | ||
|
||
gesture.enable(); | ||
} | ||
|
||
private onStart() { | ||
const now = Date.now(); | ||
|
||
if (Math.abs(now - this.lastOnStart) <= this.DOUBLE_CLICK_THRESHOLD) { | ||
this.card.nativeElement.style.setProperty('transform', this.getNewTransform()); | ||
this.lastOnStart = 0; | ||
} else { | ||
this.lastOnStart = now; | ||
} | ||
} | ||
|
||
private getNewTransform() { | ||
if (this.currentOffset >= 100) { | ||
this.currentOffset = 0; | ||
} else { | ||
this.currentOffset += 20; | ||
} | ||
|
||
return `translateX(${this.currentOffset}px)`; | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Double-Click Gestures</title> | ||
<link rel="stylesheet" href="../../../common.css" /> | ||
<script src="../../../common.js"></script> | ||
<script type="module" src="https://cdn.jsdelivr.net/npm/@ionic/core@7/dist/ionic/ionic.esm.js"></script> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@ionic/core@7/css/ionic.bundle.css" /> | ||
|
||
<script type="module"> | ||
import { createGesture } from 'https://cdn.jsdelivr.net/npm/@ionic/core@7/dist/ionic/index.esm.js'; | ||
window.createGesture = createGesture; | ||
|
||
const DOUBLE_CLICK_THRESHOLD = 500; | ||
const card = document.querySelector('ion-card'); | ||
const gesture = createGesture({ | ||
el: card, | ||
threshold: 0, | ||
onStart: () => onStart(), | ||
gestureName: 'double-click', | ||
}); | ||
|
||
gesture.enable(); | ||
|
||
let lastOnStart = 0; | ||
let currentOffset = 0; | ||
|
||
const onStart = () => { | ||
const now = Date.now(); | ||
|
||
if (Math.abs(now - lastOnStart) <= DOUBLE_CLICK_THRESHOLD) { | ||
card.style.setProperty('transform', getNewTransform()); | ||
lastOnStart = 0; | ||
} else { | ||
lastOnStart = now; | ||
} | ||
}; | ||
|
||
const getNewTransform = () => { | ||
if (currentOffset >= 100) { | ||
currentOffset = 0; | ||
} else { | ||
currentOffset += 20; | ||
} | ||
|
||
return `translateX(${currentOffset}px)`; | ||
}; | ||
</script> | ||
|
||
<style> | ||
ion-card { | ||
transform: translateX(0); | ||
user-select: none; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<ion-content> | ||
<ion-card> | ||
<ion-card-content>Double click me to move the card.</ion-card-content> | ||
</ion-card> | ||
</ion-content> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import Playground from '@site/src/components/global/Playground'; | ||
|
||
import javascript from './javascript.md'; | ||
|
||
import react_main_tsx from './react/main_tsx.md'; | ||
import react_main_css from './react/main_css.md'; | ||
|
||
import vue from './vue.md'; | ||
|
||
import angular_example_component_html from './angular/example_component_html.md'; | ||
import angular_example_component_ts from './angular/example_component_ts.md'; | ||
import angular_example_component_css from './angular/example_component_css.md'; | ||
|
||
<Playground | ||
version="7" | ||
code={{ | ||
javascript, | ||
react: { | ||
files: { | ||
'src/main.tsx': react_main_tsx, | ||
'src/main.css': react_main_css, | ||
}, | ||
}, | ||
vue, | ||
angular: { | ||
files: { | ||
'src/app/example.component.html': angular_example_component_html, | ||
'src/app/example.component.ts': angular_example_component_ts, | ||
'src/app/example.component.css': angular_example_component_css, | ||
}, | ||
}, | ||
}} | ||
src="usage/v7/gestures/double-click/demo.html" | ||
/> |
Oops, something went wrong.
1acc6e4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
ionic-docs – ./
ionic-docs-gqykycf8t.vercel.app
ionic-docs-ionic1.vercel.app
ionic-docs-git-main-ionic1.vercel.app