본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

ion-refresher

원문 보기 위키 갱신

콘텐츠 컴포넌트에 풀투리프레시(pull-to-refresh) 기능을 제공하는 컴포넌트예요. 사용자가 데이터 목록을 아래로 당겨 새 데이터를 불러오는 패턴을 구현할 때 사용합니다.

출처: 문서

본문

Refresher는 콘텐츠 컴포넌트에 풀투리프레시 기능을 제공해요. 이 패턴은 사용자가 데이터 목록을 아래로 당겨 더 많은 데이터를 가져올 수 있게 해 줍니다.

데이터는 refresher의 출력 이벤트 동안 수정되어야 해요. 비동기 작업이 완료되고 새로고침을 끝내야 할 때는 refresher에서 complete()를 호출해야 합니다.

Basic Usage

JavaScript

<ion-header>
  <ion-toolbar>
    <ion-title>Pull to Refresh</ion-title>
  </ion-toolbar>
</ion-header>

<ion-content class="ion-padding">
  <ion-refresher id="refresher" slot="fixed">
    <ion-refresher-content></ion-refresher-content>
  </ion-refresher>

  <p>Pull this content down to trigger the refresh.</p>
</ion-content>

<script>
  const refresher = document.getElementById('refresher');

  refresher.addEventListener('ionRefresh', () => {
    setTimeout(() => {
      // Any calls to load data go here
      refresher.complete();
    }, 2000);
  });
</script>

Angular

src/app/example.component.html

<ion-header>
  <ion-toolbar>
    <ion-title>Pull to Refresh</ion-title>
  </ion-toolbar>
</ion-header>

<ion-content class="ion-padding">
  <ion-refresher slot="fixed" (ionRefresh)="handleRefresh($event)">
    <ion-refresher-content></ion-refresher-content>
  </ion-refresher>

  <p>Pull this content down to trigger the refresh.</p>
</ion-content>

src/app/example.component.ts

import { Component } from '@angular/core';
import {
  IonContent,
  IonHeader,
  IonRefresher,
  IonRefresherContent,
  IonTitle,
  IonToolbar,
  RefresherCustomEvent,
} from '@ionic/angular';

@Component({
  selector: 'app-example',
  templateUrl: 'example.component.html',
  styleUrls: ['example.component.css'],
  imports: [IonContent, IonHeader, IonRefresher, IonRefresherContent, IonTitle, IonToolbar],
})
export class ExampleComponent {
  handleRefresh(event: RefresherCustomEvent) {
    setTimeout(() => {
      // Any calls to load data go here
      event.target.complete();
    }, 2000);
  }
}

React

import React from 'react';
import {
  IonContent,
  IonHeader,
  IonRefresher,
  IonRefresherContent,
  IonTitle,
  IonToolbar,
  RefresherCustomEvent,
} from '@ionic/react';

function Example() {
  function handleRefresh(event: RefresherCustomEvent) {
    setTimeout(() => {
      // Any calls to load data go here
      event.detail.complete();
    }, 2000);
  }

  return (
    <>
      <IonHeader>
        <IonToolbar>
          <IonTitle>Pull to Refresh</IonTitle>
        </IonToolbar>
      </IonHeader>

      <IonContent className="ion-padding">
        <IonRefresher slot="fixed" onIonRefresh={handleRefresh}>
          <IonRefresherContent></IonRefresherContent>
        </IonRefresher>

        <p>Pull this content down to trigger the refresh.</p>
      </IonContent>
    </>
  );
}
export default Example;

Vue

<template>
  <ion-header>
    <ion-toolbar>
      <ion-title>Pull to Refresh</ion-title>
    </ion-toolbar>
  </ion-header>

  <ion-content class="ion-padding">
    <ion-refresher slot="fixed" @ionRefresh="handleRefresh($event)">
      <ion-refresher-content></ion-refresher-content>
    </ion-refresher>

    <p>Pull this content down to trigger the refresh.</p>
  </ion-content>
</template>

<script setup lang="ts">
  import {
    IonContent,
    IonHeader,
    IonRefresher,
    IonRefresherContent,
    IonTitle,
    IonToolbar,
    RefresherCustomEvent,
  } from '@ionic/vue';

  const handleRefresh = (event: RefresherCustomEvent) => {
    setTimeout(() => {
      // Any calls to load data go here
      event.target.complete();
    }, 2000);
  };
</script>

Pull Properties

refresher에는 당김 제스처를 커스터마이즈하는 여러 프로퍼티가 있어요. pullFactor로 당기는 속도를, pullMin 프로퍼티로 사용자가 아래로 당겨야 하는 최소 거리를, pullMax 프로퍼티로 refresher가 refreshing 상태에 들어가기 전에 사용자가 당겨야 하는 최대 거리를 설정할 수 있습니다.

이 프로퍼티들은 네이티브 refresher가 활성화되면 적용되지 않아요.

JavaScript

<ion-header>
  <ion-toolbar>
    <ion-title>Pull to Refresh</ion-title>
  </ion-toolbar>
</ion-header>

<ion-content class="ion-padding">
  <ion-refresher id="refresher" slot="fixed" pull-factor="0.5" pull-min="100" pull-max="200">
    <ion-refresher-content></ion-refresher-content>
  </ion-refresher>

  <p>Pull this content down to trigger the refresh.</p>
</ion-content>

<script>
  const refresher = document.getElementById('refresher');

  refresher.addEventListener('ionRefresh', () => {
    setTimeout(() => {
      // Any calls to load data go here
      refresher.complete();
    }, 2000);
  });
</script>

Angular

src/app/example.component.html

<ion-header>
  <ion-toolbar>
    <ion-title>Pull to Refresh</ion-title>
  </ion-toolbar>
</ion-header>

<ion-content class="ion-padding">
  <ion-refresher slot="fixed" [pullFactor]="0.5" [pullMin]="100" [pullMax]="200" (ionRefresh)="handleRefresh($event)">
    <ion-refresher-content></ion-refresher-content>
  </ion-refresher>

  <p>Pull this content down to trigger the refresh.</p>
</ion-content>

src/app/example.component.ts

import { Component } from '@angular/core';
import {
  IonContent,
  IonHeader,
  IonRefresher,
  IonRefresherContent,
  IonTitle,
  IonToolbar,
  RefresherCustomEvent,
} from '@ionic/angular';

@Component({
  selector: 'app-example',
  templateUrl: 'example.component.html',
  styleUrls: ['example.component.css'],
  imports: [IonContent, IonHeader, IonRefresher, IonRefresherContent, IonTitle, IonToolbar],
})
export class ExampleComponent {
  handleRefresh(event: RefresherCustomEvent) {
    setTimeout(() => {
      // Any calls to load data go here
      event.target.complete();
    }, 2000);
  }
}

React

import React from 'react';
import {
  IonContent,
  IonHeader,
  IonRefresher,
  IonRefresherContent,
  IonTitle,
  IonToolbar,
  RefresherCustomEvent,
} from '@ionic/react';

function Example() {
  function handleRefresh(event: RefresherCustomEvent) {
    setTimeout(() => {
      // Any calls to load data go here
      event.detail.complete();
    }, 2000);
  }

  return (
    <>
      <IonHeader>
        <IonToolbar>
          <IonTitle>Pull to Refresh</IonTitle>
        </IonToolbar>
      </IonHeader>

      <IonContent className="ion-padding">
        <IonRefresher slot="fixed" pullFactor={0.5} pullMin={100} pullMax={200} onIonRefresh={handleRefresh}>
          <IonRefresherContent></IonRefresherContent>
        </IonRefresher>

        <p>Pull this content down to trigger the refresh.</p>
      </IonContent>
    </>
  );
}
export default Example;

Vue

<template>
  <ion-header>
    <ion-toolbar>
      <ion-title>Pull to Refresh</ion-title>
    </ion-toolbar>
  </ion-header>

  <ion-content class="ion-padding">
    <ion-refresher slot="fixed" :pull-factor="0.5" :pull-min="100" :pull-max="200" @ionRefresh="handleRefresh($event)">
      <ion-refresher-content></ion-refresher-content>
    </ion-refresher>

    <p>Pull this content down to trigger the refresh.</p>
  </ion-content>
</template>

<script setup lang="ts">
  import {
    IonContent,
    IonHeader,
    IonRefresher,
    IonRefresherContent,
    IonTitle,
    IonToolbar,
    RefresherCustomEvent,
  } from '@ionic/vue';

  const handleRefresh = (event: RefresherCustomEvent) => {
    setTimeout(() => {
      // Any calls to load data go here
      event.target.complete();
    }, 2000);
  };
</script>

Custom Refresher Content

기본 아이콘, 스피너, 텍스트는 refresher의 상태가 pulling인지 refreshing인지에 따라 refresher content에서 커스터마이즈할 수 있어요.

pullingIcon을 설정하면 네이티브 refresher가 비활성화됩니다.

JavaScript

<ion-header>
  <ion-toolbar>
    <ion-title>Pull to Refresh</ion-title>
  </ion-toolbar>
</ion-header>

<ion-content class="ion-padding">
  <ion-refresher id="refresher" slot="fixed">
    <ion-refresher-content
      pulling-icon="chevron-down-circle-outline"
      pulling-text="Pull to refresh"
      refreshing-spinner="circles"
      refreshing-text="Refreshing..."
    >
    </ion-refresher-content>
  </ion-refresher>

  <p>Pull this content down to trigger the refresh.</p>
</ion-content>

<script>
  const refresher = document.getElementById('refresher');

  refresher.addEventListener('ionRefresh', () => {
    setTimeout(() => {
      // Any calls to load data go here
      refresher.complete();
    }, 2000);
  });
</script>

Angular

src/app/example.component.html

<ion-header>
  <ion-toolbar>
    <ion-title>Pull to Refresh</ion-title>
  </ion-toolbar>
</ion-header>

<ion-content class="ion-padding">
  <ion-refresher slot="fixed" (ionRefresh)="handleRefresh($event)">
    <ion-refresher-content
      pullingIcon="chevron-down-circle-outline"
      pullingText="Pull to refresh"
      refreshingSpinner="circles"
      refreshingText="Refreshing..."
    >
    </ion-refresher-content>
  </ion-refresher>

  <p>Pull this content down to trigger the refresh.</p>
</ion-content>

src/app/example.component.ts

import { Component } from '@angular/core';
import {
  IonContent,
  IonHeader,
  IonRefresher,
  IonRefresherContent,
  IonTitle,
  IonToolbar,
  RefresherCustomEvent,
} from '@ionic/angular';

@Component({
  selector: 'app-example',
  templateUrl: 'example.component.html',
  styleUrls: ['example.component.css'],
  imports: [IonContent, IonHeader, IonRefresher, IonRefresherContent, IonTitle, IonToolbar],
})
export class ExampleComponent {
  handleRefresh(event: RefresherCustomEvent) {
    setTimeout(() => {
      // Any calls to load data go here
      event.target.complete();
    }, 2000);
  }
}

React

import React from 'react';
import {
  IonContent,
  IonHeader,
  IonRefresher,
  IonRefresherContent,
  IonTitle,
  IonToolbar,
  RefresherCustomEvent,
} from '@ionic/react';
import { chevronDownCircleOutline } from 'ionicons/icons';

function Example() {
  function handleRefresh(event: RefresherCustomEvent) {
    setTimeout(() => {
      // Any calls to load data go here
      event.detail.complete();
    }, 2000);
  }

  return (
    <>
      <IonHeader>
        <IonToolbar>
          <IonTitle>Pull to Refresh</IonTitle>
        </IonToolbar>
      </IonHeader>

      <IonContent className="ion-padding">
        <IonRefresher slot="fixed" onIonRefresh={handleRefresh}>
          <IonRefresherContent
            pullingIcon={chevronDownCircleOutline}
            pullingText="Pull to refresh"
            refreshingSpinner="circles"
            refreshingText="Refreshing..."
          ></IonRefresherContent>
        </IonRefresher>

        <p>Pull this content down to trigger the refresh.</p>
      </IonContent>
    </>
  );
}
export default Example;

Vue

<template>
  <ion-header>
    <ion-toolbar>
      <ion-title>Pull to Refresh</ion-title>
    </ion-toolbar>
  </ion-header>

  <ion-content class="ion-padding">
    <ion-refresher slot="fixed" @ionRefresh="handleRefresh($event)">
      <ion-refresher-content
        :pulling-icon="chevronDownCircleOutline"
        pulling-text="Pull to refresh"
        refreshing-spinner="circles"
        refreshing-text="Refreshing..."
      >
      </ion-refresher-content>
    </ion-refresher>

    <p>Pull this content down to trigger the refresh.</p>
  </ion-content>
</template>

<script setup lang="ts">
  import {
    IonContent,
    IonHeader,
    IonRefresher,
    IonRefresherContent,
    IonTitle,
    IonToolbar,
    RefresherCustomEvent,
  } from '@ionic/vue';
  import { chevronDownCircleOutline } from 'ionicons/icons';

  const handleRefresh = (event: RefresherCustomEvent) => {
    setTimeout(() => {
      // Any calls to load data go here
      event.target.complete();
    }, 2000);
  };
</script>

Native Refreshers

iOS와 Android 플랫폼 모두 각 기기가 노출하는 프로퍼티를 사용해 풀투리프레시가 부드럽고 네이티브처럼 느껴지게 해 주는 refresher를 제공해요.

iOS와 Material Design 네이티브 refresher는 Ionic에서 기본적으로 활성화됩니다. 하지만 네이티브 iOS refresher는 제대로 동작하려면 러버 밴드 스크롤링(rubber band scrolling)에 의존하며, 그 결과 iOS 기기에서만 호환됩니다. 우리는 러버 밴드 스크롤링을 지원하지 않는 기기에서 iOS 모드로 실행되는 앱을 위한 대체(fallback) refresher도 제공해요.

네이티브 refresher는 Material Design에서는 circular 스피너를, iOS에서는 lines 스피너를 사용합니다. iOS에서는 페이지를 아래로 당길수록 틱 표시가 점점 나타나요.

Pull Properties, closeDuration, snapbackDuration 같은 일부 refresher 프로퍼티는 네이티브 refresher의 대부분이 스크롤 기반이라 호환되지 않습니다. 지원하지 않는 프로퍼티에 대한 자세한 내용은 Properties를 참고하세요.

네이티브 refresher는 refresher content의 pullingIcon을 어떤 아이콘이나 스피너로 설정하면 비활성화됩니다. 허용되는 값은 Ionicons 및 Spinner 문서를 참고하세요.

Usage with Virtual Scroll

Refresher는 동작하려면 스크롤 컨테이너가 필요해요. 가상 스크롤(virtual scrolling) 솔루션을 사용할 때는 ion-content에서 스크롤을 비활성화하고, .ion-content-scroll-host 클래스 대상으로 어떤 요소 컨테이너가 스크롤 컨테이너 역할을 하는지 지정해 주어야 합니다.

개발자는 스크롤 가능한 컨테이너에 다음 CSS를 적용해야 해요. 이 CSS는 iOS에서 네이티브 iOS refresher가 제대로 동작할 수 있게 해 주는 "러버 밴드" 스크롤링 효과를 추가합니다:

.ion-content-scroll-host::before,
.ion-content-scroll-host::after {
  position: absolute;

  width: 1px;
  height: 1px;

  content: '';
}

.ion-content-scroll-host::before {
  bottom: -1px;
}

.ion-content-scroll-host::after {
  top: -1px;
}

JavaScript

<ion-header>
  <ion-toolbar>
    <ion-title>Pull to Refresh</ion-title>
  </ion-toolbar>
</ion-header>

<ion-content scroll-y="false">
  <ion-refresher id="refresher" slot="fixed">
    <ion-refresher-content></ion-refresher-content>
  </ion-refresher>

  <div class="ion-content-scroll-host ion-padding">
    <p>Pull this content down to trigger the refresh.</p>
  </div>
</ion-content>

<script>
  const refresher = document.getElementById('refresher');

  refresher.addEventListener('ionRefresh', () => {
    setTimeout(() => {
      // Any calls to load data go here
      refresher.complete();
    }, 2000);
  });
</script>

<style>
  .ion-content-scroll-host {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 100%;
    overflow-y: auto;
  }

  .ion-content-scroll-host::before,
  .ion-content-scroll-host::after {
    position: absolute;

    width: 1px;
    height: 1px;

    content: '';
  }

  .ion-content-scroll-host::before {
    bottom: -1px;
  }

  .ion-content-scroll-host::after {
    top: -1px;
  }
</style>

Angular

src/app/example.component.html

<ion-header>
  <ion-toolbar>
    <ion-title>Pull to Refresh</ion-title>
  </ion-toolbar>
</ion-header>

<ion-content [scrollY]="false">
  <ion-refresher slot="fixed" (ionRefresh)="handleRefresh($event)">
    <ion-refresher-content></ion-refresher-content>
  </ion-refresher>

  <div class="ion-content-scroll-host ion-padding">
    <p>Pull this content down to trigger the refresh.</p>
  </div>
</ion-content>

src/app/example.component.ts

import { Component } from '@angular/core';
import {
  IonContent,
  IonHeader,
  IonRefresher,
  IonRefresherContent,
  IonTitle,
  IonToolbar,
  RefresherCustomEvent,
} from '@ionic/angular';

@Component({
  selector: 'app-example',
  templateUrl: 'example.component.html',
  styleUrls: ['example.component.css'],
  imports: [IonContent, IonHeader, IonRefresher, IonRefresherContent, IonTitle, IonToolbar],
})
export class ExampleComponent {
  handleRefresh(event: RefresherCustomEvent) {
    setTimeout(() => {
      // Any calls to load data go here
      event.target.complete();
    }, 2000);
  }
}

React

src/main.tsx

import React from 'react';
import {
  IonContent,
  IonHeader,
  IonRefresher,
  IonRefresherContent,
  IonTitle,
  IonToolbar,
  RefresherCustomEvent,
} from '@ionic/react';

import './main.css';

function Example() {
  function handleRefresh(event: RefresherCustomEvent) {
    setTimeout(() => {
      // Any calls to load data go here
      event.detail.complete();
    }, 2000);
  }

  return (
    <>
      <IonHeader>
        <IonToolbar>
          <IonTitle>Pull to Refresh</IonTitle>
        </IonToolbar>
      </IonHeader>

      <IonContent scrollY={false}>
        <IonRefresher slot="fixed" onIonRefresh={handleRefresh}>
          <IonRefresherContent></IonRefresherContent>
        </IonRefresher>

        <div className="ion-content-scroll-host ion-padding">
          <p>Pull this content down to trigger the refresh.</p>
        </div>
      </IonContent>
    </>
  );
}
export default Example;

src/main.css

.ion-content-scroll-host {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 100%;
  overflow-y: auto;
}

.ion-content-scroll-host::before,
.ion-content-scroll-host::after {
  position: absolute;

  width: 1px;
  height: 1px;

  content: '';
}

.ion-content-scroll-host::before {
  bottom: -1px;
}

.ion-content-scroll-host::after {
  top: -1px;
}

Vue

<template>
  <ion-header>
    <ion-toolbar>
      <ion-title>Pull to Refresh</ion-title>
    </ion-toolbar>
  </ion-header>

  <ion-content :scroll-y="false">
    <ion-refresher slot="fixed" @ionRefresh="handleRefresh($event)">
      <ion-refresher-content></ion-refresher-content>
    </ion-refresher>

    <div class="ion-content-scroll-host ion-padding">
      <p>Pull this content down to trigger the refresh.</p>
    </div>
  </ion-content>
</template>

<script setup lang="ts">
  import {
    IonContent,
    IonHeader,
    IonRefresher,
    IonRefresherContent,
    IonTitle,
    IonToolbar,
    RefresherCustomEvent,
  } from '@ionic/vue';

  const handleRefresh = (event: RefresherCustomEvent) => {
    setTimeout(() => {
      // Any calls to load data go here
      event.target.complete();
    }, 2000);
  };
</script>

<style scoped>
  .ion-content-scroll-host {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 100%;
    overflow-y: auto;
  }

  .ion-content-scroll-host::before,
  .ion-content-scroll-host::after {
    position: absolute;

    width: 1px;
    height: 1px;

    content: '';
  }

  .ion-content-scroll-host::before {
    bottom: -1px;
  }

  .ion-content-scroll-host::after {
    top: -1px;
  }
</style>

Advanced Usage

refresher는 어떤 종류의 콘텐츠와도 사용할 수 있지만, 네이티브 앱에서 흔한 사용 사례는 새로고침 시 업데이트되는 데이터 목록을 표시하는 것입니다. 아래 예시에서 앱은 데이터 목록을 생성한 다음 새로고침이 완료되면 목록의 맨 위에 데이터를 추가해요. 실제 앱에서는 네트워크나 데이터베이스 호출로 요청을 보낸 후 데이터를 받아 업데이트할 것입니다.

JavaScript

index.html

<ion-header>
  <ion-toolbar>
    <ion-title>Pull to Refresh</ion-title>
  </ion-toolbar>
</ion-header>

<ion-content>
  <ion-refresher id="refresher" slot="fixed">
    <ion-refresher-content></ion-refresher-content>
  </ion-refresher>

  <ion-list id="list"></ion-list>
</ion-content>

<script>
  const refresher = document.getElementById('refresher');
  const names = [
    'Burt Bear',
    'Charlie Cheetah',
    'Donald Duck',
    'Eva Eagle',
    'Ellie Elephant',
    'Gino Giraffe',
    'Isabella Iguana',
    'Karl Kitten',
    'Lionel Lion',
    'Molly Mouse',
    'Paul Puppy',
    'Rachel Rabbit',
    'Ted Turtle',
  ];

  refresher.addEventListener('ionRefresh', () => {
    setTimeout(() => {
      addItems(3, true);
      refresher.complete();
    }, 2000);
  });

  const list = document.querySelector('ion-list');
  addItems(5, false);

  function chooseRandomName() {
    return names[Math.floor(Math.random() * names.length)];
  }

  function addItems(count, unread) {
    for (let i = 0; i < count; i++) {
      list.insertBefore(createItem(unread), list.firstChild);
    }
  }

  function createItem(unread = false) {
    const name = chooseRandomName();
    let item = document.createElement('ion-item');
    item.button = true;

    item.innerHTML += `
      <ion-icon color="primary" name="${unread ? 'ellipse' : ''}" slot="start"></ion-icon>
      <ion-label>
        <h2>${name}</h2>
        <p>New message from ${name}</p>
      </ion-label>
    `;

    return item;
  }
</script>

<style>
  ion-item {
    --padding-start: 8px;
  }

  ion-icon {
    font-size: 12px;
    align-self: start;
    margin: 15px 8px;
  }
</style>

index.ts

import { defineCustomElements } from '@ionic/core/loader';

import { addIcons } from 'ionicons';
import { ellipse } from 'ionicons/icons';

/* Core CSS required for Ionic components to work properly */
import '@ionic/core/css/core.css';

/* Basic CSS for apps built with Ionic */
import '@ionic/core/css/normalize.css';
import '@ionic/core/css/structure.css';
import '@ionic/core/css/typography.css';

/* Optional CSS utils that can be commented out */
import '@ionic/core/css/padding.css';
import '@ionic/core/css/float-elements.css';
import '@ionic/core/css/text-alignment.css';
import '@ionic/core/css/text-transformation.css';
import '@ionic/core/css/flex-utils.css';
import '@ionic/core/css/display.css';

/**
 * Ionic Dark Palette
 * -----------------------------------------------------
 * For more information, please see:
 * https://ionicframework.com/docs/theming/dark-mode
 */

// import '@ionic/core/css/palettes/dark.always.css';
// import '@ionic/core/css/palettes/dark.class.css';
import '@ionic/core/css/palettes/dark.system.css';

/* Theme variables */
import './theme/variables.css';

/**
 * On Ionicons 7.2+ this icon
 * gets mapped to an "ellipse" key.
 * Alternatively, developers can do:
 * addIcons({ 'ellipse': ellipse });
 */
addIcons({ ellipse });

defineCustomElements();

Angular

src/app/example.component.html

<ion-header>
  <ion-toolbar>
    <ion-title>Pull to Refresh</ion-title>
  </ion-toolbar>
</ion-header>

<ion-content>
  <ion-refresher slot="fixed" (ionRefresh)="handleRefresh($event)">
    <ion-refresher-content></ion-refresher-content>
  </ion-refresher>

  <ion-list>
    @for (item of items(); track item) {
    <ion-item [button]="true">
      <ion-icon slot="start" color="primary" [name]="item.unread ? 'ellipse' : ''"></ion-icon>
      <ion-label>
        <h2>{{ item.name }}</h2>
        <p>New message from {{ item.name }}</p>
      </ion-label>
    </ion-item>
    }
  </ion-list>
</ion-content>

src/app/example.component.ts

import { Component, signal } from '@angular/core';
import {
  IonContent,
  IonHeader,
  IonIcon,
  IonItem,
  IonLabel,
  IonList,
  IonRefresher,
  IonRefresherContent,
  IonTitle,
  IonToolbar,
  RefresherCustomEvent,
} from '@ionic/angular';

import { addIcons } from 'ionicons';
import { ellipse } from 'ionicons/icons';

interface Item {
  name: string;
  unread: boolean;
}

@Component({
  selector: 'app-example',
  templateUrl: 'example.component.html',
  styleUrls: ['./example.component.css'],
  imports: [
    IonContent,
    IonHeader,
    IonIcon,
    IonItem,
    IonLabel,
    IonList,
    IonRefresher,
    IonRefresherContent,
    IonTitle,
    IonToolbar,
  ],
})
export class ExampleComponent {
  public names = [
    'Burt Bear',
    'Charlie Cheetah',
    'Donald Duck',
    'Eva Eagle',
    'Ellie Elephant',
    'Gino Giraffe',
    'Isabella Iguana',
    'Karl Kitten',
    'Lionel Lion',
    'Molly Mouse',
    'Paul Puppy',
    'Rachel Rabbit',
    'Ted Turtle',
  ];
  readonly items = signal<Item[]>([]);

  constructor() {
    /**
     * Any icons you want to use in your application
     * can be registered in app.component.ts and then
     * referenced by name anywhere in your application.
     */
    addIcons({ ellipse });
  }

  ngOnInit() {
    this.addItems(5);
  }

  chooseRandomName() {
    return this.names[Math.floor(Math.random() * this.names.length)];
  }

  addItems(count: number, unread = false) {
    const newItems: Item[] = [];
    for (let i = 0; i < count; i++) {
      newItems.unshift({
        name: this.chooseRandomName(),
        unread: unread,
      });
    }
    this.items.update((items) => [...newItems, ...items]);
  }

  handleRefresh(event: RefresherCustomEvent) {
    setTimeout(() => {
      this.addItems(3, true);
      event.target.complete();
    }, 2000);
  }
}

src/app/example.component.css

ion-item {
  --padding-start: 8px;
}

ion-icon {
  font-size: 12px;
  align-self: start;
  margin: 15px 8px;
}

React

src/main.tsx

import React, { useEffect, useState } from 'react';
import {
  IonContent,
  IonHeader,
  IonIcon,
  IonItem,
  IonLabel,
  IonList,
  IonRefresher,
  IonRefresherContent,
  IonTitle,
  IonToolbar,
  RefresherCustomEvent,
} from '@ionic/react';
import { ellipse } from 'ionicons/icons';

import './main.css';

function Example() {
  const names = [
    'Burt Bear',
    'Charlie Cheetah',
    'Donald Duck',
    'Eva Eagle',
    'Ellie Elephant',
    'Gino Giraffe',
    'Isabella Iguana',
    'Karl Kitten',
    'Lionel Lion',
    'Molly Mouse',
    'Paul Puppy',
    'Rachel Rabbit',
    'Ted Turtle',
  ];
  const [items, setItems] = useState<{ name: string; unread: boolean }[]>([]);

  let didInit = false;

  useEffect(() => {
    if (!didInit) {
      didInit = true;
      addItems(5);
    }
  }, []);

  function handleRefresh(event: RefresherCustomEvent) {
    setTimeout(() => {
      addItems(3, true);
      event.detail.complete();
    }, 2000);
  }

  function chooseRandomName() {
    return names[Math.floor(Math.random() * names.length)];
  }

  function addItems(count: number, unread = false) {
    for (let i = 0; i < count; i++) {
      setItems((current) => [{ name: chooseRandomName(), unread }, ...current]);
    }
  }

  return (
    <>
      <IonHeader>
        <IonToolbar>
          <IonTitle>Pull to Refresh</IonTitle>
        </IonToolbar>
      </IonHeader>

      <IonContent>
        <IonRefresher slot="fixed" onIonRefresh={handleRefresh}>
          <IonRefresherContent></IonRefresherContent>
        </IonRefresher>

        <IonList>
          {items.map((item) => (
            <IonItem button={true}>
              <IonIcon slot="start" color="primary" icon={item.unread ? ellipse : ''}></IonIcon>
              <IonLabel>
                <h2>{item.name}</h2>
                <p>New message from {item.name}</p>
              </IonLabel>
            </IonItem>
          ))}
        </IonList>
      </IonContent>
    </>
  );
}
export default Example;

src/main.css

ion-item {
  --padding-start: 8px;
}

ion-icon {
  font-size: 12px;
  align-self: start;
  margin: 15px 8px;
}

Vue

<template>
  <ion-header>
    <ion-toolbar>
      <ion-title>Pull to Refresh</ion-title>
    </ion-toolbar>
  </ion-header>

  <ion-content>
    <ion-refresher slot="fixed" @ionRefresh="handleRefresh($event)">
      <ion-refresher-content></ion-refresher-content>
    </ion-refresher>

    <ion-list>
      <ion-item :button="true" v-for="item in items">
        <ion-icon slot="start" color="primary" :icon="item.unread ? ellipse : ''"></ion-icon>
        <ion-label>
          <h2>{{ item.name }}</h2>
          <p>New message from {{ item.name }}</p>
        </ion-label>
      </ion-item>
    </ion-list>
  </ion-content>
</template>

<script setup lang="ts">
  import {
    IonContent,
    IonHeader,
    IonIcon,
    IonItem,
    IonLabel,
    IonList,
    IonRefresher,
    IonRefresherContent,
    IonTitle,
    IonToolbar,
    RefresherCustomEvent,
  } from '@ionic/vue';
  import { ref } from 'vue';
  import { ellipse } from 'ionicons/icons';

  const names = [
    'Burt Bear',
    'Charlie Cheetah',
    'Donald Duck',
    'Eva Eagle',
    'Ellie Elephant',
    'Gino Giraffe',
    'Isabella Iguana',
    'Karl Kitten',
    'Lionel Lion',
    'Molly Mouse',
    'Paul Puppy',
    'Rachel Rabbit',
    'Ted Turtle',
  ];
  const items = ref([]);

  const chooseRandomName = () => {
    return names[Math.floor(Math.random() * names.length)];
  };

  const addItems = (count, unread = false) => {
    for (let i = 0; i < count; i++) {
      items.value.unshift({ name: chooseRandomName(), unread });
    }
  };

  addItems(5);

  const handleRefresh = (event: RefresherCustomEvent) => {
    setTimeout(() => {
      addItems(3, true);
      event.target.complete();
    }, 2000);
  };
</script>

<style scoped>
  ion-item {
    --padding-start: 8px;
  }

  ion-icon {
    font-size: 12px;
    align-self: start;
    margin: 15px 8px;
  }
</style>

Event Handling

Using ionPullStart and ionPullEnd

ionPullStart 이벤트는 사용자가 당김 제스처를 시작할 때 발생해요. 이 이벤트는 사용자가 refresher를 아래로 당기기 시작할 때 발생합니다.

ionPullEnd 이벤트는 refresher가 비활성 상태로 돌아왔을 때 발생하며, 리프레시 작업이 성공적으로 완료됐는지 아니면 취소됐는지를 나타내는 'complete' 또는 'cancel' 값의 reason 프로퍼티를 가집니다.

JavaScript

<ion-header>
  <ion-toolbar>
    <ion-title>Pull to Refresh</ion-title>
  </ion-toolbar>
</ion-header>

<ion-content class="ion-padding">
  <ion-refresher id="refresher" slot="fixed">
    <ion-refresher-content></ion-refresher-content>
  </ion-refresher>

  <p>Pull this content down to trigger the refresh.</p>

  <ion-list lines="full">
    <ion-item>
      <ion-checkbox slot="start"></ion-checkbox>
      <ion-label>Finalize Q1 budget proposal</ion-label>
    </ion-item>
    <ion-item>
      <ion-checkbox slot="start" checked></ion-checkbox>
      <ion-label>Review design mockups</ion-label>
    </ion-item>
    <ion-item>
      <ion-checkbox slot="start" checked></ion-checkbox>
      <ion-label>Sync with engineering on API docs</ion-label>
    </ion-item>
    <ion-item>
      <ion-checkbox slot="start"></ion-checkbox>
      <ion-label>Approve PTO requests for March</ion-label>
    </ion-item>
    <ion-item>
      <ion-checkbox slot="start"></ion-checkbox>
      <ion-label>Draft monthly newsletter</ion-label>
    </ion-item>
  </ion-list>
</ion-content>

<script>
  const refresher = document.getElementById('refresher');
  const checkboxes = document.querySelectorAll('ion-checkbox');

  refresher.addEventListener('ionPullStart', () => {
    console.log('Pull started');
    // Disable the checkboxes when the pull starts
    checkboxes.forEach((checkbox) => {
      checkbox.disabled = true;
    });
  });

  refresher.addEventListener('ionRefresh', () => {
    setTimeout(() => {
      // Any calls to load data go here
      refresher.complete();
      console.log('Refresh completed');
    }, 2000);
  });

  refresher.addEventListener('ionPullEnd', (event) => {
    console.log('Pull ended with reason: "' + event.detail.reason + '"');
    // Enable the checkboxes when the pull ends
    checkboxes.forEach((checkbox) => {
      checkbox.disabled = false;
    });
  });
</script>

Angular

src/app/example.component.html

<ion-header>
  <ion-toolbar>
    <ion-title>Pull to Refresh</ion-title>
  </ion-toolbar>
</ion-header>

<ion-content class="ion-padding">
  <ion-refresher
    id="refresher"
    slot="fixed"
    (ionPullStart)="handlePullStart()"
    (ionPullEnd)="handlePullEnd($event)"
    (ionRefresh)="handleRefresh($event)"
  >
    <ion-refresher-content></ion-refresher-content>
  </ion-refresher>

  <p>Pull this content down to trigger the refresh.</p>

  <ion-list lines="full">
    @for (item of items; track item; let i = $index) {
    <ion-item>
      <ion-checkbox slot="start" [checked]="item.checked" [disabled]="item.disabled"></ion-checkbox>
      <ion-label>{{ item.label }}</ion-label>
    </ion-item>
    }
  </ion-list>
</ion-content>

src/app/example.component.ts

import { Component } from '@angular/core';
import {
  IonCheckbox,
  IonContent,
  IonHeader,
  IonItem,
  IonLabel,
  IonList,
  IonRefresher,
  IonRefresherContent,
  IonTitle,
  IonToolbar,
  RefresherCustomEvent,
  RefresherPullEndCustomEvent,
} from '@ionic/angular/standalone';

@Component({
  selector: 'app-example',
  templateUrl: 'example.component.html',
  styleUrls: ['example.component.css'],
  imports: [
    IonCheckbox,
    IonContent,
    IonHeader,
    IonItem,
    IonLabel,
    IonList,
    IonRefresher,
    IonRefresherContent,
    IonTitle,
    IonToolbar,
  ],
})
export class ExampleComponent {
  items = [
    { label: 'Finalize Q1 budget proposal', checked: false, disabled: false },
    { label: 'Review design mockups', checked: true, disabled: false },
    { label: 'Sync with engineering on API docs', checked: true, disabled: false },
    { label: 'Approve PTO requests for March', checked: false, disabled: false },
    { label: 'Draft monthly newsletter', checked: false, disabled: false },
  ];

  constructor() {}

  handlePullStart() {
    console.log('Pull started');

    // Disable the checkboxes when the pull starts
    this.items.forEach((item) => {
      item.disabled = true;
    });
  }

  handlePullEnd(event: RefresherPullEndCustomEvent) {
    console.log('Pull ended with reason: "' + event.detail.reason + '"');

    // Enable the checkboxes when the pull ends
    this.items.forEach((item) => {
      item.disabled = false;
    });
  }

  handleRefresh(event: RefresherCustomEvent) {
    setTimeout(() => {
      // Any calls to load data go here
      event.target.complete();
      console.log('Refresh completed');
    }, 2000);
  }
}

React

import React, { useState } from 'react';
import {
  IonCheckbox,
  IonContent,
  IonHeader,
  IonItem,
  IonLabel,
  IonList,
  IonTitle,
  IonToolbar,
  IonRefresher,
  IonRefresherContent,
  RefresherCustomEvent,
  RefresherPullEndCustomEvent,
} from '@ionic/react';

interface TodoItem {
  label: string;
  checked: boolean;
  disabled: boolean;
}

function Example() {
  const [items, setItems] = useState<TodoItem[]>([
    { label: 'Finalize Q1 budget proposal', checked: false, disabled: false },
    { label: 'Review design mockups', checked: true, disabled: false },
    { label: 'Sync with engineering on API docs', checked: true, disabled: false },
    { label: 'Approve PTO requests for March', checked: false, disabled: false },
    { label: 'Draft monthly newsletter', checked: false, disabled: false },
  ]);

  function handlePullStart() {
    console.log('Pull started');

    // Disable the checkboxes when the pull starts
    setItems((prev) => prev.map((item) => ({ ...item, disabled: true })));
  }

  function handlePullEnd(event: RefresherPullEndCustomEvent) {
    console.log('Pull ended with reason: "' + event.detail.reason + '"');

    // Enable the checkboxes when the pull ends
    setItems((prev) => prev.map((item) => ({ ...item, disabled: false })));
  }

  function handleRefresh(event: RefresherCustomEvent) {
    setTimeout(() => {
      // Any calls to load data go here
      event.target.complete();
      console.log('Refresh completed');
    }, 2000);
  }

  return (
    <>
      <IonHeader>
        <IonToolbar>
          <IonTitle>Pull to Refresh</IonTitle>
        </IonToolbar>
      </IonHeader>

      <IonContent class="ion-padding">
        <IonRefresher
          id="refresher"
          slot="fixed"
          onIonPullStart={handlePullStart}
          onIonPullEnd={handlePullEnd}
          onIonRefresh={handleRefresh}
        >
          <IonRefresherContent></IonRefresherContent>
        </IonRefresher>

        <p>Pull this content down to trigger the refresh.</p>

        <IonList lines="full">
          {items.map((item: TodoItem) => (
            <IonItem key={item.label}>
              <IonCheckbox slot="start" checked={item.checked} disabled={item.disabled}></IonCheckbox>
              <IonLabel>{item.label}</IonLabel>
            </IonItem>
          ))}
        </IonList>
      </IonContent>
    </>
  );
}

export default Example;

Vue

<template>
  <ion-header>
    <ion-toolbar>
      <ion-title>Pull to Refresh</ion-title>
    </ion-toolbar>
  </ion-header>

  <ion-content class="ion-padding">
    <ion-refresher
      id="refresher"
      slot="fixed"
      @ionPullStart="handlePullStart()"
      @ionPullEnd="handlePullEnd($event)"
      @ionRefresh="handleRefresh($event)"
    >
      <ion-refresher-content></ion-refresher-content>
    </ion-refresher>

    <p>Pull this content down to trigger the refresh.</p>

    <ion-list lines="full">
      <ion-item v-for="item in items" :key="item.label">
        <ion-checkbox slot="start" v-model="item.checked" :disabled="item.disabled"></ion-checkbox>
        <ion-label>{{ item.label }}</ion-label>
      </ion-item>
    </ion-list>
  </ion-content>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import {
  IonCheckbox,
  IonContent,
  IonHeader,
  IonItem,
  IonLabel,
  IonList,
  IonRefresher,
  IonRefresherContent,
  IonTitle,
  IonToolbar,
  RefresherCustomEvent,
  RefresherPullEndCustomEvent,
} from '@ionic/vue';

const items = ref([
  { label: 'Finalize Q1 budget proposal', checked: false, disabled: false },
  { label: 'Review design mockups', checked: true, disabled: false },
  { label: 'Sync with engineering on API docs', checked: true, disabled: false },
  { label: 'Approve PTO requests for March', checked: false, disabled: false },
  { label: 'Draft monthly newsletter', checked: false, disabled: false },
]);

const handlePullStart = () => {
  console.log('Pull started');

  // Disable the checkboxes when the pull starts
  items.value.forEach((item) => {
    item.disabled = true;
  });
};

const handlePullEnd = (event: RefresherPullEndCustomEvent) => {
  console.log('Pull ended with reason: "' + event.detail.reason + '"');

  // Enable the checkboxes when the pull ends
  items.value.forEach((item) => {
    item.disabled = false;
  });
};

const handleRefresh = (event: RefresherCustomEvent) => {
  setTimeout(() => {
    // Any calls to load data go here
    event.target.complete();
    console.log('Refresh completed');
  }, 2000);
};
</script>

Console Console messages will appear here when logged from the example above.

Interfaces

RefresherEventDetail

interface RefresherEventDetail {
  complete(): void;
}

RefresherPullEndEventDetail

interface RefresherPullEndEventDetail {
  reason: 'complete' | 'cancel';
}

RefresherCustomEvent

필수는 아니지만, 이 컴포넌트에서 발생하는 Ionic 이벤트에 대해 더 강력한 타입을 제공하려면 CustomEvent 인터페이스 대신 이 인터페이스를 사용할 수 있어요.

interface RefresherCustomEvent extends CustomEvent {
  detail: RefresherEventDetail;
  target: HTMLIonRefresherElement;
}

RefresherPullEndCustomEvent

필수는 아니지만, ionPullEnd 이벤트에 대해 더 강력한 타입을 제공하려면 CustomEvent 인터페이스 대신 이 인터페이스를 사용할 수 있어요.

interface RefresherPullEndCustomEvent extends CustomEvent {
  detail: RefresherPullEndEventDetail;
  target: HTMLIonRefresherElement;
}

Properties

closeDuration

Description: refresher를 닫는 데 걸리는 시간이에요. refresher 콘텐츠가 스피너를 사용해 네이티브 refresher를 활성화하면 적용되지 않아요.

Attribute: close-duration

Type: string

Default: '280ms'

disabled

Description: true로 설정하면 refresher가 숨겨집니다.

Attribute: disabled

Type: boolean

Default: false

mode

Description: 모드는 어떤 플랫폼 스타일을 사용할지 결정해요. 이 값은 초기화 중에 한 번 설정되며 초기 렌더 후 값을 변경해도 업데이트되지 않는 가상 프로퍼티예요.

Attribute: mode

Type: "ios" | "md"

Default: undefined

pullFactor

Description: 당김 속도를 곱할 배수예요. 당김 애니메이션을 느리게 하려면 1보다 작은 숫자를, 빠르게 하려면 1보다 큰 숫자를 전달하세요. 기본값은 1이며 커서의 속도와 같아요. 음수 값이 전달되면 factor는 1이 됩니다. 예를 들어 전달된 값이 1.2이고 콘텐츠를 10픽셀 드래그했다면, 10픽셀 대신 12픽셀(20퍼센트 증가)만큼 당겨집니다. 전달된 값이 0.8이면 드래그된 양은 8픽셀로, 커서가 움직인 양보다 적어요. refresher 콘텐츠가 스피너를 사용해 네이티브 refresher를 활성화하면 적용되지 않습니다.

Attribute: pull-factor

Type: number

Default: 1

pullMax

Description: refresher가 자동으로 refreshing 상태에 들어가기 전에 당길 수 있는 최대 거리예요. 기본값은 pullMin + 60의 결과입니다. refresher 콘텐츠가 스피너를 사용해 네이티브 refresher를 활성화하면 적용되지 않아요.

Attribute: pull-max

Type: number

Default: this.pullMin + 60

pullMin

Description: refresher가 refreshing 상태에 들어가기 전에 사용자가 아래로 당겨야 하는 최소 거리예요. refresher 콘텐츠가 스피너를 사용해 네이티브 refresher를 활성화하면 적용되지 않습니다.

Attribute: pull-min

Type: number

Default: 60

snapbackDuration

Description: refresher가 refreshing 상태로 스냅백(snap back)하는 데 걸리는 시간이에요. refresher 콘텐츠가 스피너를 사용해 네이티브 refresher를 활성화하면 적용되지 않아요.

Attribute: snapback-duration

Type: string

Default: '280ms'

Events

Name Description Bubbles
ionPull 사용자가 콘텐츠를 당겨 refresher를 노출하는 동안 발생해요. true
ionPullEnd 당김 제스처 후 refresher가 비활성 상태로 돌아왔을 때 발생해요. 새로고침이 성공적으로 완료됐든 취소됐든 발생합니다. true
ionPullStart 사용자가 아래로 당기기 시작할 때 발생해요. true
ionRefresh 사용자가 콘텐츠를 놓으면서 pullMin보다 더 아래로 당겼거나, 콘텐츠를 당겨 pullMax를 초과할 때 발생해요. refresher 상태를 refreshing으로 업데이트합니다. 비동기 작업이 완료되면 complete() 메서드를 호출해야 해요. true
ionStart(deprecated) 사용자가 아래로 당기기 시작할 때 발생해요. Deprecated — 대신 ionPullStart를 사용하세요. true

Methods

cancel

Description: refresher의 상태를 refreshing에서 cancelling으로 바꿔요.

Signature: cancel() => Promise<void>

complete

Description: 비동기 작업이 완료되면 complete()를 호출하세요. 예를 들어 refreshing 상태는 앱이 AJAX 요청으로 더 많은 데이터를 받는 것 같은 비동기 작업을 수행하는 동안의 상태예요. 데이터를 받은 후 이 메서드를 호출해 새로고침이 완료됐음을 알리고 refresher를 닫을 수 있습니다. 이 메서드는 refresher의 상태를 refreshing에서 completing으로도 바꿔요.

Signature: complete() => Promise<void>

getProgress

Description: 사용자가 얼마나 아래로 당겼는지를 나타내는 숫자예요. 숫자 0은 사용자가 전혀 당기지 않았음을 나타내고, 숫자 1과 그보다 큰 값은 사용자가 놓았을 때 새로고침이 발생할 만큼 충분히 아래로 당겼음을 나타냅니다. 사용자가 놓았는데 숫자가 1보다 작으면 새로고침은 발생하지 않고 콘텐츠는 원래 위치로 돌아가요.

Signature: getProgress() => Promise<number>

CSS Shadow Parts

이 컴포넌트에는 사용할 수 있는 CSS shadow part가 없어요.

CSS Custom Properties

이 컴포넌트에는 사용할 수 있는 CSS 커스텀 프로퍼티가 없어요.

Slots

이 컴포넌트에는 사용할 수 있는 슬롯이 없어요.

더 알아보기 (Learn more)

ion-refresher는 목록을 당겨 새로고침하는 흔한 패턴을 쉽게 구현하게 해 줘요. 당김 감도(pullFactor, pullMin, pullMax)와 네이티브 refresher 여부를 조절할 수 있고, 보여줄 아이콘·스피너·텍스트는 ion-refresher-content에서 바꿀 수 있습니다.