Skip to content

Commit

Permalink
update index with new props
Browse files Browse the repository at this point in the history
  • Loading branch information
TchernyavskyDaniil committed Nov 10, 2019
1 parent edd7154 commit bf1f7d6
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,51 @@ import PropTypes from 'prop-types';

import { useUnmount } from './useUnmount';

export const CustomRefreshControl = ({ callbackError, callback, callbackParams }) => {
export const CustomRefreshControl = ({
callbackError,
callback,
callbackParams,
delay,
delayCallback,
controlParams,
}) => {
const [refreshing, setRefreshing] = useState(false);

const cancelRefreshing = useCallback(() => setRefreshing(false), []);

const setClearedInterval = useCallback(async () => {
if (delay) {
setTimeout(delayCallback, delay)
}

if (callback) {
try {
await callback(callbackParams);
await callback(callbackParams)
} catch (e) {
callbackError(e);
callbackError(e)
}
}

cancelRefreshing();
}, [callback, callbackError, callbackParams, cancelRefreshing]);
cancelRefreshing()
}, [callback, callbackError, callbackParams, cancelRefreshing, delay, delayCallback]);

const handleOnRefresh = useCallback(async () => {
setRefreshing(true);
await setClearedInterval();
await setClearedInterval()
}, [setClearedInterval]);

const cancelRefreshing = useCallback(() => setRefreshing(false), []);

useUnmount(cancelRefreshing);

return (
<RefreshControl refreshing={refreshing} onRefresh={handleOnRefresh} />
)
return <RefreshControl refreshing={refreshing} onRefresh={handleOnRefresh} {...controlParams} />
};

CustomRefreshControl.defaultProps = {
callback: null,
callbackError: () => {},
callbackParams: undefined,
controlParams: {},
delay: null,
delayCallback: () => {},
};

CustomRefreshControl.propTypes = {
Expand All @@ -47,4 +59,7 @@ CustomRefreshControl.propTypes = {
PropTypes.object,
PropTypes.oneOf([undefined]),
]),
controlParams: PropTypes.object,
delay: PropTypes.number,
delayCallback: PropTypes.func,
};

0 comments on commit bf1f7d6

Please sign in to comment.