From d448cdc11ff29e50e70d4a90a0a38a288b696284 Mon Sep 17 00:00:00 2001 From: Satyajit Sahoo Date: Fri, 31 Jan 2020 02:02:48 +0100 Subject: [PATCH] refactor: don't pass drawerPosition as a prop to drawerContent --- packages/drawer/src/types.tsx | 4 ---- .../src/utils/DrawerPositionContext.tsx | 3 +++ .../src/views/DrawerContentScrollView.tsx | 4 ++-- packages/drawer/src/views/DrawerView.tsx | 20 +++++++++++-------- 4 files changed, 17 insertions(+), 14 deletions(-) create mode 100644 packages/drawer/src/utils/DrawerPositionContext.tsx diff --git a/packages/drawer/src/types.tsx b/packages/drawer/src/types.tsx index c863a259..161ab1fd 100644 --- a/packages/drawer/src/types.tsx +++ b/packages/drawer/src/types.tsx @@ -128,10 +128,6 @@ export type DrawerContentComponentProps = T & { * `0` is closed, `1` is open. */ progress: Animated.Node; - /** - * Position of the drawer on the screen. - */ - drawerPosition: 'left' | 'right'; }; export type DrawerContentOptions = { diff --git a/packages/drawer/src/utils/DrawerPositionContext.tsx b/packages/drawer/src/utils/DrawerPositionContext.tsx new file mode 100644 index 00000000..d0b862ab --- /dev/null +++ b/packages/drawer/src/utils/DrawerPositionContext.tsx @@ -0,0 +1,3 @@ +import * as React from 'react'; + +export default React.createContext<'left' | 'right' | undefined>(undefined); diff --git a/packages/drawer/src/views/DrawerContentScrollView.tsx b/packages/drawer/src/views/DrawerContentScrollView.tsx index df2d7a57..43040ee7 100644 --- a/packages/drawer/src/views/DrawerContentScrollView.tsx +++ b/packages/drawer/src/views/DrawerContentScrollView.tsx @@ -1,19 +1,19 @@ import * as React from 'react'; import { ScrollView, StyleSheet, ScrollViewProps } from 'react-native'; import { useSafeArea } from 'react-native-safe-area-context'; +import DrawerPositionContext from '../utils/DrawerPositionContext'; type Props = ScrollViewProps & { - drawerPosition: 'left' | 'right'; children: React.ReactNode; }; export default function DrawerContentScrollView({ contentContainerStyle, style, - drawerPosition, children, ...rest }: Props) { + const drawerPosition = React.useContext(DrawerPositionContext); const insets = useSafeArea(); return ( diff --git a/packages/drawer/src/views/DrawerView.tsx b/packages/drawer/src/views/DrawerView.tsx index de700d0c..5fda313b 100644 --- a/packages/drawer/src/views/DrawerView.tsx +++ b/packages/drawer/src/views/DrawerView.tsx @@ -28,6 +28,7 @@ import { DrawerNavigationHelpers, DrawerContentComponentProps, } from '../types'; +import DrawerPositionContext from '../utils/DrawerPositionContext'; type Props = DrawerNavigationConfig & { state: DrawerNavigationState; @@ -145,14 +146,17 @@ export default function DrawerView({ } const renderNavigationView = ({ progress }: any) => { - return drawerContent({ - ...drawerContentOptions, - progress: progress, - state: state, - navigation: navigation, - descriptors: descriptors, - drawerPosition: drawerPosition, - }); + return ( + + {drawerContent({ + ...drawerContentOptions, + progress: progress, + state: state, + navigation: navigation, + descriptors: descriptors, + })} + + ); }; const renderContent = () => {