Skip to content

Commit

Permalink
feat: added pull to refresh implementaion
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhom committed Jun 6, 2021
1 parent 8f34990 commit 016a01f
Show file tree
Hide file tree
Showing 38 changed files with 471 additions and 168 deletions.
6 changes: 5 additions & 1 deletion example/src/components/contactList/ContactList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface ContactListProps {
count?: number;
style?: ViewStyle;
onItemPress?: () => void;
onRefresh?: () => void;
}

const keyExtractor = (item: any, index: number) => `${item.name}.${index}`;
Expand All @@ -29,6 +30,7 @@ const handleGetCount = (data: any[]) => data.length;
const ContactList = ({
type,
count = 25,
onRefresh,
style,
onItemPress,
}: ContactListProps) => {
Expand Down Expand Up @@ -97,6 +99,8 @@ const ContactList = ({
return (
<BottomSheetFlatList
data={data}
refreshing={false}
onRefresh={onRefresh}
keyExtractor={keyExtractor}
initialNumToRender={5}
bounces={true}
Expand Down Expand Up @@ -182,7 +186,7 @@ const styles = StyleSheet.create({
flex: 1,
},
contentContainer: {
paddingHorizontal: 24,
paddingHorizontal: 16,
overflow: 'visible',
},
});
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion example/src/components/contactListContainer/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useMemo } from 'react';
import { StyleProp, StyleSheet, ViewStyle } from 'react-native';
import { StyleProp, StyleSheet, Text, ViewStyle } from 'react-native';
import { BottomSheetHandleProps } from '@gorhom/bottom-sheet';
import Animated, {
Extrapolate,
Expand All @@ -10,11 +10,16 @@ import Animated, {
import { toRad } from 'react-native-redash';
import { transformOrigin } from '../../utilities/transformOrigin';

interface HandleProps extends BottomSheetHandleProps {
interface CustomHandleProps extends BottomSheetHandleProps {
title: string;
style?: StyleProp<ViewStyle>;
}

const Handle: React.FC<HandleProps> = ({ style, animatedIndex }) => {
const CustomHandle: React.FC<CustomHandleProps> = ({
title,
style,
animatedIndex,
}) => {
//#region animations

const indicatorTransformOriginY = useDerivedValue(() =>
Expand All @@ -23,7 +28,7 @@ const Handle: React.FC<HandleProps> = ({ style, animatedIndex }) => {
//#endregion

//#region styles
const containerStyle = useMemo(() => [styles.header, style], [style]);
const containerStyle = useMemo(() => [styles.container, style], [style]);
const containerAnimatedStyle = useAnimatedStyle(() => {
const borderTopRadius = interpolate(
animatedIndex.value,
Expand Down Expand Up @@ -100,23 +105,25 @@ const Handle: React.FC<HandleProps> = ({ style, animatedIndex }) => {
<Animated.View
style={[rightIndicatorStyle, rightIndicatorAnimatedStyle]}
/>
<Text style={styles.title}>{title}</Text>
</Animated.View>
);
};

export default Handle;
export default CustomHandle;

const styles = StyleSheet.create({
header: {
container: {
alignContent: 'center',
alignItems: 'center',
justifyContent: 'center',
backgroundColor: 'white',
paddingVertical: 14,
paddingBottom: 12,
paddingHorizontal: 16,
borderBottomWidth: 1,
borderBottomColor: '#fff',
borderBottomColor: 'rgba(0,0,0,0.125)',
zIndex: 99999,
},
indicator: {
marginTop: 10,
position: 'absolute',
width: 10,
height: 4,
Expand All @@ -130,4 +137,11 @@ const styles = StyleSheet.create({
borderTopEndRadius: 2,
borderBottomEndRadius: 2,
},
title: {
marginTop: 26,
fontSize: 20,
lineHeight: 20,
textAlign: 'center',
fontWeight: 'bold',
},
});
1 change: 1 addition & 0 deletions example/src/components/customHandle/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './CustomHandle';
1 change: 0 additions & 1 deletion example/src/components/handle/index.ts

This file was deleted.

49 changes: 49 additions & 0 deletions example/src/components/headerHandle/HeaderHandle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import React, { memo } from 'react';
import { StyleSheet, Text } from 'react-native';
import {
BottomSheetHandle,
BottomSheetHandleProps,
} from '@gorhom/bottom-sheet';

interface HeaderHandleProps extends BottomSheetHandleProps {
children?: string | React.ReactNode | React.ReactNode[];
}

const HeaderHandle = ({ children, ...rest }: HeaderHandleProps) => {
return (
<BottomSheetHandle
style={styles.container}
indicatorStyle={styles.indicator}
{...rest}
>
{typeof children === 'string' ? (
<Text style={styles.title}>{children}</Text>
) : (
children
)}
</BottomSheetHandle>
);
};

const styles = StyleSheet.create({
container: {
paddingBottom: 12,
paddingHorizontal: 16,
borderBottomWidth: 1,
borderBottomColor: 'rgba(0,0,0,0.125)',
zIndex: 99999,
},
title: {
marginTop: 16,
fontSize: 20,
lineHeight: 20,
textAlign: 'center',
fontWeight: 'bold',
},
indicator: {
height: 4,
opacity: 0.5,
},
});

export default memo(HeaderHandle);
1 change: 1 addition & 0 deletions example/src/components/headerHandle/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './HeaderHandle';
10 changes: 8 additions & 2 deletions example/src/screens/advanced/BackdropExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import React, { useCallback, useMemo, useRef, useState } from 'react';
import { View, StyleSheet } from 'react-native';
import BottomSheet, { BottomSheetBackdrop } from '@gorhom/bottom-sheet';
import Button from '../../components/button';
import ContactListContainer from '../../components/contactListContainer';
import ContactList from '../../components/contactList';
import HeaderHandle from '../../components/headerHandle';

const BackdropExample = () => {
// state
Expand Down Expand Up @@ -45,6 +46,10 @@ const BackdropExample = () => {
),
[backdropPressBehavior]
);
const renderHeaderHandle = useCallback(
props => <HeaderHandle {...props} children="Backdrop Example" />,
[]
);
return (
<View style={styles.container}>
<Button
Expand All @@ -58,8 +63,9 @@ const BackdropExample = () => {
ref={bottomSheetRef}
snapPoints={snapPoints}
backdropComponent={renderBackdrop}
handleComponent={renderHeaderHandle}
>
<ContactListContainer type="View" count={4} title="Backdrop Example" />
<ContactList type="FlatList" count={10} />
</BottomSheet>
</View>
);
Expand Down
18 changes: 10 additions & 8 deletions example/src/screens/advanced/CustomBackgroundExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { View, StyleSheet } from 'react-native';
import BottomSheet from '@gorhom/bottom-sheet';
import CustomBackground from '../../components/customBackground';
import Button from '../../components/button';
import ContactListContainer from '../../components/contactListContainer';
import ContactList from '../../components/contactList';
import HeaderHandle from '../../components/headerHandle';

const CustomBackgroundExample = () => {
// hooks
Expand All @@ -25,6 +26,12 @@ const CustomBackgroundExample = () => {
const handleClosePress = useCallback(() => {
bottomSheetRef.current?.close();
}, []);

// render
const renderHeaderHandle = useCallback(
props => <HeaderHandle {...props} children="Custom Background Example" />,
[]
);
return (
<View style={styles.container}>
<Button label="Snap To 450" onPress={() => handleSnapPress(1)} />
Expand All @@ -34,17 +41,12 @@ const CustomBackgroundExample = () => {
<Button label="Close" onPress={handleClosePress} />
<BottomSheet
ref={bottomSheetRef}
index={1}
snapPoints={snapPoints}
animateOnMount={true}
handleComponent={renderHeaderHandle}
backgroundComponent={CustomBackground}
>
<ContactListContainer
type="View"
count={3}
title="Custom Background Example"
headerStyle={styles.headerContainer}
/>
<ContactList type="View" count={5} />
</BottomSheet>
</View>
);
Expand Down
17 changes: 8 additions & 9 deletions example/src/screens/advanced/CustomHandleExample.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { useCallback, useMemo, useRef } from 'react';
import { View, StyleSheet } from 'react-native';
import BottomSheet from '@gorhom/bottom-sheet';
import Handle from '../../components/handle';
import CustomHandle from '../../components/customHandle';
import Button from '../../components/button';
import ContactListContainer from '../../components/contactListContainer';
import ContactList from '../../components/contactList';

const CustomHandleExample = () => {
// hooks
Expand All @@ -27,6 +27,10 @@ const CustomHandleExample = () => {
}, []);

// renders
const renderCustomHandle = useCallback(
props => <CustomHandle title="Custom Handle Example" {...props} />,
[]
);
return (
<View style={styles.container}>
<Button label="Snap To 450" onPress={() => handleSnapPress(2)} />
Expand All @@ -37,15 +41,10 @@ const CustomHandleExample = () => {
<Button label="Close" onPress={handleClosePress} />
<BottomSheet
ref={bottomSheetRef}
index={1}
snapPoints={snapPoints}
handleComponent={Handle}
handleComponent={renderCustomHandle}
>
<ContactListContainer
count={10}
type="FlatList"
title="Custom Handle Example"
/>
<ContactList count={10} type="FlatList" />
</BottomSheet>
</View>
);
Expand Down
1 change: 0 additions & 1 deletion example/src/screens/advanced/DynamicSnapPointExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ const DynamicSnapPointExample = () => {
index={1}
snapPoints={snapPoints}
animateOnMount={true}
animationDuration={250}
>
<BottomSheetView
style={contentContainerStyle}
Expand Down
2 changes: 1 addition & 1 deletion example/src/screens/advanced/FooterExample.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { useCallback, useMemo, useRef, useState } from 'react';
import { View, StyleSheet, Text } from 'react-native';
import BottomSheet, { BottomSheetFooter } from '@gorhom/bottom-sheet';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import SearchHandle from '../../components/searchHandle';
import Button from '../../components/button';
import ContactList from '../../components/contactList';
import { useSafeAreaInsets } from 'react-native-safe-area-context';

const FooterExample = () => {
// state
Expand Down
6 changes: 4 additions & 2 deletions example/src/screens/advanced/KeyboardHandlingExample.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import React, { useCallback, useMemo, useRef, useState } from 'react';
import { View, StyleSheet } from 'react-native';
import BottomSheet from '@gorhom/bottom-sheet';
import SearchHandle from '../../components/searchHandle';
import SearchHandle, {
SEARCH_HANDLE_HEIGHT,
} from '../../components/searchHandle';
import Button from '../../components/button';
import ContactList from '../../components/contactList';

Expand All @@ -16,7 +18,7 @@ const KeyboardHandlingExample = () => {
const bottomSheetRef = useRef<BottomSheet>(null);

// variables
const snapPoints = useMemo(() => [100, 300], []);
const snapPoints = useMemo(() => [SEARCH_HANDLE_HEIGHT, 300], []);

// callbacks
const handleToggleKeyboardBehavior = useCallback(() => {
Expand Down
Loading

0 comments on commit 016a01f

Please sign in to comment.