From 016a01f3705c83c9903a3e28c875e7b90424a128 Mon Sep 17 00:00:00 2001 From: Mo Gorhom Date: Sun, 6 Jun 2021 13:50:41 +0100 Subject: [PATCH] feat: added pull to refresh implementaion --- .../components/contactList/ContactList.tsx | 6 +- .../ContactListContainer.tsx | 51 -------------- .../components/contactListContainer/index.ts | 1 - .../CustomHandle.tsx} | 34 +++++++--- example/src/components/customHandle/index.ts | 1 + example/src/components/handle/index.ts | 1 - .../components/headerHandle/HeaderHandle.tsx | 49 ++++++++++++++ example/src/components/headerHandle/index.ts | 1 + .../src/screens/advanced/BackdropExample.tsx | 10 ++- .../advanced/CustomBackgroundExample.tsx | 18 ++--- .../screens/advanced/CustomHandleExample.tsx | 17 +++-- .../advanced/DynamicSnapPointExample.tsx | 1 - .../src/screens/advanced/FooterExample.tsx | 2 +- .../advanced/KeyboardHandlingExample.tsx | 6 +- .../screens/advanced/PullToRefreshExample.tsx | 58 ++++++++++++++++ .../src/screens/advanced/ShadowExample.tsx | 13 +++- example/src/screens/basic/BasicExamples.tsx | 9 --- example/src/screens/modal/BackdropExample.tsx | 11 ++- example/src/screens/modal/SimpleExample.tsx | 11 ++- example/src/screens/modal/StackExample.tsx | 25 ++++--- example/src/screens/screens.ts | 5 ++ src/components/bottomSheet/BottomSheet.tsx | 12 +++- .../BottomSheetDraggableView.tsx | 11 ++- .../bottomSheetDraggableView/types.d.ts | 5 +- .../bottomSheetHandle/BottomSheetHandle.tsx | 26 +++++-- src/components/bottomSheetHandle/types.d.ts | 24 +++++++ .../BottomSheetRefreshControl.android.tsx | 37 ++++++++++ .../BottomSheetRefreshControl.tsx | 1 + .../bottomSheetRefreshControl/index.ts | 16 +++++ .../createBottomSheetScrollableComponent.tsx | 67 ++++++++++++++++++- .../bottomSheetScrollable/types.d.ts | 8 +-- src/components/view/View.tsx | 13 +--- src/constants.ts | 6 +- src/contexts/internal.ts | 1 + src/hooks/useInteractivePanGestureHandler.ts | 56 ++++++++++++---- src/hooks/useScrollable.ts | 2 + src/hooks/useScrollableInternal.ts | 23 ++++--- src/index.ts | 1 + 38 files changed, 471 insertions(+), 168 deletions(-) delete mode 100644 example/src/components/contactListContainer/ContactListContainer.tsx delete mode 100644 example/src/components/contactListContainer/index.ts rename example/src/components/{handle/Handle.tsx => customHandle/CustomHandle.tsx} (80%) create mode 100644 example/src/components/customHandle/index.ts delete mode 100644 example/src/components/handle/index.ts create mode 100644 example/src/components/headerHandle/HeaderHandle.tsx create mode 100644 example/src/components/headerHandle/index.ts create mode 100644 example/src/screens/advanced/PullToRefreshExample.tsx create mode 100644 src/components/bottomSheetRefreshControl/BottomSheetRefreshControl.android.tsx create mode 100644 src/components/bottomSheetRefreshControl/BottomSheetRefreshControl.tsx create mode 100644 src/components/bottomSheetRefreshControl/index.ts diff --git a/example/src/components/contactList/ContactList.tsx b/example/src/components/contactList/ContactList.tsx index 7ab6f2751..76287b25f 100644 --- a/example/src/components/contactList/ContactList.tsx +++ b/example/src/components/contactList/ContactList.tsx @@ -20,6 +20,7 @@ export interface ContactListProps { count?: number; style?: ViewStyle; onItemPress?: () => void; + onRefresh?: () => void; } const keyExtractor = (item: any, index: number) => `${item.name}.${index}`; @@ -29,6 +30,7 @@ const handleGetCount = (data: any[]) => data.length; const ContactList = ({ type, count = 25, + onRefresh, style, onItemPress, }: ContactListProps) => { @@ -97,6 +99,8 @@ const ContactList = ({ return ( { - title: string; - headerStyle?: ViewStyle; -} - -const ContactListContainerComponent = ({ - count, - type, - title, - headerStyle: _headerStyle, - onItemPress, -}: ContactListContainerProps) => { - const headerStyle = useMemo( - () => [styles.headerContainer, _headerStyle], - [_headerStyle] - ); - return ( - <> - - {title} - - - - ); -}; - -const styles = StyleSheet.create({ - title: { - fontSize: 36, - lineHeight: 46, - fontWeight: '800', - }, - headerContainer: { - padding: 24, - backgroundColor: 'white', - zIndex: 99999, - }, -}); - -const ContactListContainer = memo(ContactListContainerComponent); - -export default ContactListContainer; diff --git a/example/src/components/contactListContainer/index.ts b/example/src/components/contactListContainer/index.ts deleted file mode 100644 index 67c9f0411..000000000 --- a/example/src/components/contactListContainer/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { default } from './ContactListContainer'; diff --git a/example/src/components/handle/Handle.tsx b/example/src/components/customHandle/CustomHandle.tsx similarity index 80% rename from example/src/components/handle/Handle.tsx rename to example/src/components/customHandle/CustomHandle.tsx index e416b78b2..bb16e45fd 100644 --- a/example/src/components/handle/Handle.tsx +++ b/example/src/components/customHandle/CustomHandle.tsx @@ -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, @@ -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; } -const Handle: React.FC = ({ style, animatedIndex }) => { +const CustomHandle: React.FC = ({ + title, + style, + animatedIndex, +}) => { //#region animations const indicatorTransformOriginY = useDerivedValue(() => @@ -23,7 +28,7 @@ const Handle: React.FC = ({ 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, @@ -100,23 +105,25 @@ const Handle: React.FC = ({ style, animatedIndex }) => { + {title} ); }; -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, @@ -130,4 +137,11 @@ const styles = StyleSheet.create({ borderTopEndRadius: 2, borderBottomEndRadius: 2, }, + title: { + marginTop: 26, + fontSize: 20, + lineHeight: 20, + textAlign: 'center', + fontWeight: 'bold', + }, }); diff --git a/example/src/components/customHandle/index.ts b/example/src/components/customHandle/index.ts new file mode 100644 index 000000000..c9d91b754 --- /dev/null +++ b/example/src/components/customHandle/index.ts @@ -0,0 +1 @@ +export { default } from './CustomHandle'; diff --git a/example/src/components/handle/index.ts b/example/src/components/handle/index.ts deleted file mode 100644 index 1b3992686..000000000 --- a/example/src/components/handle/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { default } from './Handle'; diff --git a/example/src/components/headerHandle/HeaderHandle.tsx b/example/src/components/headerHandle/HeaderHandle.tsx new file mode 100644 index 000000000..64770713f --- /dev/null +++ b/example/src/components/headerHandle/HeaderHandle.tsx @@ -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 ( + + {typeof children === 'string' ? ( + {children} + ) : ( + children + )} + + ); +}; + +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); diff --git a/example/src/components/headerHandle/index.ts b/example/src/components/headerHandle/index.ts new file mode 100644 index 000000000..036408a2c --- /dev/null +++ b/example/src/components/headerHandle/index.ts @@ -0,0 +1 @@ +export { default } from './HeaderHandle'; diff --git a/example/src/screens/advanced/BackdropExample.tsx b/example/src/screens/advanced/BackdropExample.tsx index 0eb829481..45039012c 100644 --- a/example/src/screens/advanced/BackdropExample.tsx +++ b/example/src/screens/advanced/BackdropExample.tsx @@ -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 @@ -45,6 +46,10 @@ const BackdropExample = () => { ), [backdropPressBehavior] ); + const renderHeaderHandle = useCallback( + props => , + [] + ); return (