Skip to content

jadedrepublic/capacitor-native-pull-to-refresh

Repository files navigation

capacitor-native-pull-to-refresh

Native pull to refresh plugin for capacitor

Install

npm install capacitor-native-pull-to-refresh
npx cap sync
import { PullToRefresh } from "capacitor-native-pull-to-refresh";

This plugin Is a WIP, only iOS supported atm.

API

enable()

enable() => Promise<PullToRefreshResponse>

Enables the pull-to-refresh functionality.

Returns: Promise<PullToRefreshResponse>


disable()

disable() => Promise<PullToRefreshResponse>

Disables the pull-to-refresh functionality.

Returns: Promise<PullToRefreshResponse>


endRefreshing()

endRefreshing() => Promise<PullToRefreshStateResponse>

Ends the refreshing state initiated by pull-to-refresh.

Returns: Promise<PullToRefreshStateResponse>


setScrollPosition(...)

setScrollPosition(options: SetScrollPositionOptions) => void

Sets the scroll position of the webView.scrollView.

Param Type Description
options SetScrollPositionOptions Configuration options for setting the scroll position. Optional to use, default behavior of UIRefreshControl() only works with the main scrollview, so a workaround is needed for additional scroll containers e.g. modals.

manuallyTriggerRefreshingState(...)

manuallyTriggerRefreshingState(options: ManuallyTriggerRefreshingStateOptions) => void

Used with @setScrollPosition

Example Usage:

const threshold = 100;

scrollContainer.addEventListener("scroll", async function () { if (scrollContainer.scrollTop < 0) { PullToRefresh.setScrollPosition({ scroll_position: scrollContainer.scrollTop, threshold: threshold }) } });

scrollContainer.addEventListener("touchend", async function () { if (scrollContainer.scrollTop <= threshold) { PullToRefresh.manuallyTriggerRefreshingState({ offset: -30 }) } })

PullToRefresh.addListener("state", function ({ refreshing }) { if (refreshing) { setTimeout(() => { PullToRefresh.endRefreshing() }, 3000) } })

Param Type Description
options ManuallyTriggerRefreshingStateOptions Configuration options when manually triggering refreshing state.

addListener('state', ...)

addListener(eventName: 'state', listenerFunc: (data: PullToRefreshStateResponse) => void) => Promise<PluginListenerHandle> & PluginListenerHandle

Adds a listener for the "state" event which is triggered when the pull-to-refresh state changes.

Param Type Description
eventName 'state' The name of the event to listen for.
listenerFunc (data: PullToRefreshStateResponse) => void The function to be executed when the event is triggered.

Returns: Promise<PluginListenerHandle> & PluginListenerHandle


removeAllListeners()

removeAllListeners() => Promise<void>

Interfaces

PullToRefreshResponse

Prop Type
enabled boolean

PullToRefreshStateResponse

Prop Type
refreshing boolean

SetScrollPositionOptions

Prop Type
scroll_position number
threshold number

ManuallyTriggerRefreshingStateOptions

Prop Type
offset number

PluginListenerHandle

Prop Type
remove () => Promise<void>

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published