Skip to content
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

feat(refresher): add ionEnd event #24526

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion angular/src/directives/proxies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1324,6 +1324,13 @@ called when the async operation has completed.
* Emitted when the user begins to start pulling down.
*/
ionStart: EventEmitter<CustomEvent<void>>;
/**
* Emitted after the pull gesture has ended and the refresher has returned to
the INACTIVE state. It doesn't matter where the pull gesture ended; whether
the user pulled far enough for a refresh, let go in the middle of a pull,
or reversed the pull and released with the content at the top.
*/
ionEnd: EventEmitter<CustomEvent<void>>;

}

Expand All @@ -1343,7 +1350,7 @@ export class IonRefresher {
constructor(c: ChangeDetectorRef, r: ElementRef, protected z: NgZone) {
c.detach();
this.el = r.nativeElement;
proxyOutputs(this, this.el, ['ionRefresh', 'ionPull', 'ionStart']);
proxyOutputs(this, this.el, ['ionRefresh', 'ionPull', 'ionStart', 'ionEnd']);
}
}

Expand Down
1 change: 1 addition & 0 deletions core/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,7 @@ ion-refresher,prop,snapbackDuration,string,'280ms',false,false
ion-refresher,method,cancel,cancel() => Promise<void>
ion-refresher,method,complete,complete() => Promise<void>
ion-refresher,method,getProgress,getProgress() => Promise<number>
ion-refresher,event,ionEnd,void,true
ion-refresher,event,ionPull,void,true
ion-refresher,event,ionRefresh,RefresherEventDetail,true
ion-refresher,event,ionStart,void,true
Expand Down
4 changes: 4 additions & 0 deletions core/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5758,6 +5758,10 @@ declare namespace LocalJSX {
* If `true`, the refresher will be hidden.
*/
"disabled"?: boolean;
/**
* Emitted after the pull gesture has ended and the refresher has returned to the INACTIVE state. It doesn't matter where the pull gesture ended; whether the user pulled far enough for a refresh, let go in the middle of a pull, or reversed the pull and released with the content at the top.
*/
"onIonEnd"?: (event: CustomEvent<void>) => void;
/**
* Emitted while the user is pulling down the content and exposing the refresher.
*/
Expand Down
11 changes: 6 additions & 5 deletions core/src/components/refresher/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,12 @@ export default defineComponent({

## Events

| Event | Description | Type |
| ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------- |
| `ionPull` | Emitted while the user is pulling down the content and exposing the refresher. | `CustomEvent<void>` |
| `ionRefresh` | Emitted when the user lets go of the content and has pulled down further than the `pullMin` or pulls the content down and exceeds the pullMax. Updates the refresher state to `refreshing`. The `complete()` method should be called when the async operation has completed. | `CustomEvent<RefresherEventDetail>` |
| `ionStart` | Emitted when the user begins to start pulling down. | `CustomEvent<void>` |
| Event | Description | Type |
| ------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------- |
| `ionEnd` | Emitted after the pull gesture has ended and the refresher has returned to the INACTIVE state. It doesn't matter where the pull gesture ended; whether the user pulled far enough for a refresh, let go in the middle of a pull, or reversed the pull and released with the content at the top. | `CustomEvent<void>` |
| `ionPull` | Emitted while the user is pulling down the content and exposing the refresher. | `CustomEvent<void>` |
| `ionRefresh` | Emitted when the user lets go of the content and has pulled down further than the `pullMin` or pulls the content down and exceeds the pullMax. Updates the refresher state to `refreshing`. The `complete()` method should be called when the async operation has completed. | `CustomEvent<RefresherEventDetail>` |
| `ionStart` | Emitted when the user begins to start pulling down. | `CustomEvent<void>` |


## Methods
Expand Down
26 changes: 25 additions & 1 deletion core/src/components/refresher/refresher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ export class Refresher implements ComponentInterface {
*/
@Event() ionStart!: EventEmitter<void>;

/**
* Emitted after the pull gesture has ended and the refresher has returned to
* the INACTIVE state. It doesn't matter where the pull gesture ended; whether
* the user pulled far enough for a refresh, let go in the middle of a pull,
* or reversed the pull and released with the content at the top.
*/
@Event() ionEnd!: EventEmitter<void>;

private async checkNativeRefresher() {
const useNativeRefresher = await shouldUseNativeRefresher(this.el, getIonMode(this));
if (useNativeRefresher && !this.nativeRefresher) {
Expand All @@ -159,6 +167,10 @@ export class Refresher implements ComponentInterface {
await translateElement(el, undefined, 300);
} else {
await transitionEndAsync(this.el.querySelector('.refresher-refreshing-icon'), 200);
// TODO Does something have to happen here to emit the ionEnd event?
// And if so, can it happen anywhere in resetNativeRefresher()?
// Or does something have to happen in the onEnd gesture events that
// are created within the setup[iOS/MD]NativeRefresher functions?
}

this.didRefresh = false;
Expand Down Expand Up @@ -640,13 +652,16 @@ export class Refresher implements ComponentInterface {
if (this.state === RefresherState.Ready) {
// they pulled down far enough, so it's ready to refresh
this.beginRefresh();

} else if (this.state === RefresherState.Pulling) {
// they were pulling down, but didn't pull down far enough
// set the content back to it's original location
// and close the refresher
// set that the refresh is actively cancelling
this.cancel();
} else if (this.state === RefresherState.Inactive) {
// they pulled down, but reversed the gesture and released
// when deltaY was <= 0 (i.e. getProgress was at 0).
this.ionEnd.emit();
}
}

Expand All @@ -669,6 +684,15 @@ export class Refresher implements ComponentInterface {

// create fallback timer incase something goes wrong with transitionEnd event
setTimeout(() => {

// The comment above setTimeout() is worrisome because I don't want this to
// emit more than once (though that wouldn't be a big deal). I don't know
// enough about transitionEnd to know if that's possible and this
// conditional might not be necessary.
if (this.state !== RefresherState.Inactive) {
this.ionEnd.emit();
}

this.state = RefresherState.Inactive;
this.progress = 0;
this.didStart = false;
Expand Down
4 changes: 4 additions & 0 deletions core/src/components/refresher/test/spec/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@
refresher.addEventListener('ionStart', () => {
console.log('ionStart');
});

refresher.addEventListener('ionEnd', () => {
console.log('ionEnd');
});

refresher.addEventListener('ionRefresh', async function () {
console.log('Loading data...');
Expand Down
3 changes: 2 additions & 1 deletion packages/vue/src/proxies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,8 @@ export const IonRefresher = /*@__PURE__*/ defineContainer<JSX.IonRefresher>('ion
'disabled',
'ionRefresh',
'ionPull',
'ionStart'
'ionStart',
'ionEnd'
]);


Expand Down