-
Notifications
You must be signed in to change notification settings - Fork 3.1k
docs(gesture): add playground example for basic usage #3038
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
79f5c6c
docs(gesture): add playground example for basic usage
sean-perkins b5c34f8
chore: use gestureName
sean-perkins b911d6a
chore: remove legacy basic example
sean-perkins caabed7
chore: remove extra whitespace
sean-perkins 465e885
docs: add explanation for example
sean-perkins 84765c7
chore: content updates
sean-perkins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
14 changes: 14 additions & 0 deletions
14
static/usage/v7/gestures/basic/angular/example_component_css.md
This file contains hidden or 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,14 @@ | ||
```css | ||
ion-card { | ||
position: absolute; | ||
|
||
left: 0; | ||
right: 0; | ||
|
||
user-select: none; | ||
} | ||
|
||
ion-card.active { | ||
box-shadow: var(--ion-color-warning) 0px 4px 16px; | ||
} | ||
``` |
10 changes: 10 additions & 0 deletions
10
static/usage/v7/gestures/basic/angular/example_component_html.md
This file contains hidden or 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,10 @@ | ||
```html | ||
<ion-card [class.active]="isCardActive"> | ||
<ion-card-header> | ||
<ion-card-subtitle>Pan the Screen</ion-card-subtitle> | ||
</ion-card-header> | ||
<ion-card-content> | ||
<p #debug>Gesture information will display after interaction.</p> | ||
</ion-card-content> | ||
</ion-card> | ||
``` |
50 changes: 50 additions & 0 deletions
50
static/usage/v7/gestures/basic/angular/example_component_ts.md
This file contains hidden or 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,50 @@ | ||
```ts | ||
import { ChangeDetectorRef, Component, ElementRef, ViewChild } from '@angular/core'; | ||
import type { GestureDetail } from '@ionic/angular'; | ||
import { GestureController, IonCard } from '@ionic/angular'; | ||
|
||
@Component({ | ||
selector: 'app-example', | ||
templateUrl: 'example.component.html', | ||
styleUrls: ['example.component.css'], | ||
}) | ||
export class ExampleComponent { | ||
@ViewChild(IonCard, { read: ElementRef }) card: ElementRef<HTMLIonCardElement>; | ||
@ViewChild('debug', { read: ElementRef }) debug: ElementRef<HTMLParagraphElement>; | ||
|
||
isCardActive = false; | ||
|
||
constructor(private el: ElementRef, private gestureCtrl: GestureController, private cdRef: ChangeDetectorRef) {} | ||
|
||
ngAfterViewInit() { | ||
const gesture = this.gestureCtrl.create({ | ||
el: this.el.nativeElement.closest('ion-content'), | ||
onStart: () => this.onStart(), | ||
onMove: (detail) => this.onMove(detail), | ||
onEnd: () => this.onEnd(), | ||
gestureName: 'example', | ||
}); | ||
|
||
gesture.enable(); | ||
} | ||
|
||
private onStart() { | ||
this.isCardActive = true; | ||
this.cdRef.detectChanges(); | ||
} | ||
|
||
private onMove(detail: GestureDetail) { | ||
const { type, currentX, deltaX, velocityX } = detail; | ||
this.debug.nativeElement.innerHTML = ` | ||
<div>Type: ${type}</div> | ||
<div>Current X: ${currentX}</div> | ||
<div>Delta X: ${deltaX}</div> | ||
<div>Velocity X: ${velocityX}</div>`; | ||
} | ||
|
||
private onEnd() { | ||
this.isCardActive = false; | ||
this.cdRef.detectChanges(); | ||
} | ||
} | ||
``` |
This file contains hidden or 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,81 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Gesture</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 p = document.querySelector('#debug'); | ||
const target = document.querySelector('ion-content'); | ||
const card = document.querySelector('ion-card'); | ||
|
||
const onMove = (detail) => { | ||
const { type, currentX, deltaX, velocityX } = detail; | ||
p.innerHTML = ` | ||
<div>Type: ${type}</div> | ||
<div>Current X: ${currentX}</div> | ||
<div>Delta X: ${deltaX}</div> | ||
<div>Velocity X: ${velocityX}</div>`; | ||
}; | ||
|
||
const onStart = () => { | ||
card.classList.add('active'); | ||
}; | ||
|
||
const onEnd = () => { | ||
card.classList.remove('active'); | ||
}; | ||
|
||
const gesture = createGesture({ | ||
el: target, | ||
onStart, | ||
onMove, | ||
onEnd, | ||
gestureName: 'example', | ||
}); | ||
|
||
gesture.enable(); | ||
</script> | ||
|
||
<style> | ||
.container { | ||
flex-direction: column; | ||
} | ||
|
||
ion-card { | ||
position: absolute; | ||
|
||
left: 0; | ||
right: 0; | ||
|
||
user-select: none; | ||
} | ||
|
||
ion-card.active { | ||
box-shadow: var(--ion-color-warning) 0px 4px 16px; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<div class="container"> | ||
<ion-content> | ||
<ion-card> | ||
<ion-card-header> | ||
<ion-card-subtitle>Pan the Screen</ion-card-subtitle> | ||
</ion-card-header> | ||
<ion-card-content> | ||
<p id="debug">Gesture information will display after interaction.</p> | ||
</ion-card-content> | ||
</ion-card> | ||
</ion-content> | ||
</div> | ||
</body> | ||
</html> |
This file contains hidden or 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_css from './react/main_css.md'; | ||
import react_main_tsx from './react/main_tsx.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/basic/demo.html" | ||
/> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.