Skip to content

Commit

Permalink
fix: add pull to refresh to home and accounts, ref LEA-1814
Browse files Browse the repository at this point in the history
  • Loading branch information
pete-watters committed Dec 6, 2024
1 parent b2cdbf6 commit 010c91b
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion apps/mobile/src/components/page/page.layout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useRef } from 'react';
import { useCallback, useRef, useState } from 'react';
import { RefreshControl } from 'react-native';
import { ScrollView } from 'react-native-gesture-handler';
import { useSafeAreaInsets } from 'react-native-safe-area-context';

Expand All @@ -7,6 +8,7 @@ import {
ActionBarContext,
createOnScrollHandler,
} from '@/components/action-bar/action-bar-container';
import { queryClient } from '@/queries/query';
import { HasChildren } from '@/utils/types';

import { Box } from '@leather.io/ui/native';
Expand All @@ -18,6 +20,15 @@ export function PageLayout({ children }: HasChildren) {
const actionBarRef = useRef<ActionBarMethods>(null);
const contentOffsetBottom = bottom + ACTION_BAR_TOTAL_HEIGHT;
const contentOffsetTop = top;
const [refreshing, setRefreshing] = useState(false);

const onRefresh = useCallback(() => {
setRefreshing(true);
queryClient.invalidateQueries();
setTimeout(() => {
setRefreshing(false);
}, 2000);
}, []);

return (
<ActionBarContext.Provider value={{ ref: actionBarRef }}>
Expand All @@ -29,6 +40,13 @@ export function PageLayout({ children }: HasChildren) {
contentOffsetBottom,
})}
contentInset={{ bottom: contentOffsetBottom }}
refreshControl={
<RefreshControl
refreshing={refreshing}
onRefresh={onRefresh}
progressViewOffset={contentOffsetTop}
/>
}
>
{children}
</ScrollView>
Expand Down

0 comments on commit 010c91b

Please sign in to comment.