refactor: don't pass drawerPosition as a prop to drawerContent

This commit is contained in:
Satyajit Sahoo
2020-01-31 02:02:48 +01:00
parent 0e8fda3196
commit d448cdc11f
4 changed files with 17 additions and 14 deletions

View File

@@ -128,10 +128,6 @@ export type DrawerContentComponentProps<T = DrawerContentOptions> = T & {
* `0` is closed, `1` is open.
*/
progress: Animated.Node<number>;
/**
* Position of the drawer on the screen.
*/
drawerPosition: 'left' | 'right';
};
export type DrawerContentOptions = {

View File

@@ -0,0 +1,3 @@
import * as React from 'react';
export default React.createContext<'left' | 'right' | undefined>(undefined);

View File

@@ -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 (

View File

@@ -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 (
<DrawerPositionContext.Provider value={drawerPosition}>
{drawerContent({
...drawerContentOptions,
progress: progress,
state: state,
navigation: navigation,
descriptors: descriptors,
})}
</DrawerPositionContext.Provider>
);
};
const renderContent = () => {