Pull-to-refresh

Pull to refresh lets people request an update by pulling down on scrollable content. A refresh indicator shows that the request is being handled until the new content is ready.

day-pieces wraps that content, starts the app’s refresh action, and displays the refreshing state until the work ends.

Add to your app

This control is included in day-pieces and re-exported through day::prelude::*. No additional crate or control feature is required. The selected toolkit supplies its native implementation; day::pullrefresh::support() reports its availability after the Day runtime starts.

Platforms / toolkitsAvailability
UIKit, Android, ArkUINative refresh control and pull gesture.
AppKit, GTKEmulated indicator with native overscroll detection.
Qt, WinUI, WebComposed indicator; start refresh programmatically rather than relying on a native pull gesture.

Authoring

use day::pullrefresh::pull_to_refresh;

let refreshing = Signal::new(false);

// One reload path for EVERY begin — pull gesture, dayscript toggle, or a button:
watch(move || refreshing.get(), move |now, _| {
    if *now {
        let done = refreshing.setter();
        std::thread::spawn(move || {
            reload();            // off the UI thread
            done.set(false);     // completion hops back and dismisses the indicator
        });
    }
});

pull_to_refresh(refreshing, scroll(rows)).id(id!(feed_refresh))   // or list(items, …)

The bound refreshing: Signal<bool> is two-way (the same contract as UIRefreshControl, SwipeRefreshLayout.setRefreshing, and ArkUI Refresh):

  • a user pull sets it true (and runs the optional .on_refresh(f) sugar);
  • the app sets it false when the reload completes (from a thread via Signal::setter, or inside day::task);
  • the app may set it true to begin a refresh programmatically (a toolbar button, ⌘R, …).

Prefer the watch-on-the-signal idiom above over .on_refresh when a programmatic path exists; it makes every begin take the same route. day_pieces::pullrefresh::support() reports the active toolkit’s indicator tier (Native / Emulated). day::pullrefresh::gesture_support() separately reports whether a user pull can start a refresh. A composed indicator alone does not imply gesture support.

Toolkit implementations

Platform guidance: Android: swipe-to-refresh.

TargetTierMechanism
ios-uikitNativeA passthrough host view attaches a UIRefreshControl to the descendant UIScrollView when day mounts it (didAddSubview:, which covers list(), since a UITableView is a UIScrollView).
android-materialNativeThe Android toolkit’s DayPullRefresh extends SwipeRefreshLayout (AndroidX, added to Gradle via [package.metadata.day.android]); the scrollable mounts directly into it.
harmony-arkuiNativeARKUI_NODE_REFRESH created by the toolkit’s own NDK shim; pull events via NODE_REFRESH_ON_REFRESH, indicator via NODE_REFRESH_REFRESHING.
macos-appkitEmulatedSpinner-chip overlay + the pull gesture from elastic scrolling: the clip view’s bounds go negative during a trackpad rubber-band; crossing ~60 pt begins a refresh.
gtkEmulatedOverlay + GtkScrolledWindow::edge-overshot (Top), GTK’s purpose-built overshoot signal.
Qt / WinUIEmulatedOverlay + programmatic only (desktop Qt has no elastic overscroll; WinUI’s RefreshContainer is touch-only; a native tier is a follow-up for touch devices).
mockEmulatedComposition path; drives the piece’s tests via ToggleChanged.

The emulated indicator is the built-in spinner() in a floating chip, shown while refreshing: pure composition (when + overlay container) with no per-toolkit code.

The container-piece recipe

On the wrap-based platforms the realized node is the native refresh wrapper and day mounts the scrollable as a Day child inside it; see docs/extending (“Container pieces”) for the cx.native + fill-layout + cx.under recipe this piece establishes.

Limits

  • The wrapped child should be the scrollable (scroll(...) or list(...)). If the child’s realized view isn’t scroll-backed, the pull gesture is inert (the overlay + programmatic path still work).
  • iOS: a programmatic begin shows the control’s spinner without auto-revealing it (UIKit’s standard behavior); a user pull reveals it naturally.
  • Emulated gesture thresholds (AppKit ~60 pt, GTK overshoot) are heuristics tuned in the piece.