UNPKG

daniel-pull-to-refresh

Version:
37 lines (36 loc) 1.44 kB
import React, { Component } from 'react'; import { findNodeHandle, requireNativeComponent, UIManager } from 'react-native'; const NativePullToRefreshFooter = requireNativeComponent('RefreshFooter'); const PullToRefreshFooterCommands = { setNativeRefreshing(componentOrHandle, refreshing) { UIManager.dispatchViewManagerCommand(findNodeHandle(componentOrHandle), 'setNativeRefreshing', [refreshing]); }, }; class PullToRefreshFooter extends Component { _nativeRef = null; _lastNativeRefreshing = false; _onRefresh = () => { this._lastNativeRefreshing = true; this.props?.onRefresh?.(); this.forceUpdate(); }; _setNativeRef = (ref) => { this._nativeRef = ref; }; componentDidMount() { this._lastNativeRefreshing = this.props.refreshing; } componentDidUpdate(prevProps) { if (this.props.refreshing !== prevProps.refreshing) { this._lastNativeRefreshing = this.props.refreshing; } else if (this.props.refreshing !== this._lastNativeRefreshing && this._nativeRef) { PullToRefreshFooterCommands.setNativeRefreshing(this._nativeRef, this.props.refreshing); this._lastNativeRefreshing = this.props.refreshing; } } render() { return <NativePullToRefreshFooter {...this.props} ref={this._setNativeRef} onRefresh={this._onRefresh}/>; } } export { PullToRefreshFooter };