mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-05-13 10:16:50 +08:00
refactor: don't pass drawerPosition as a prop to drawerContent
This commit is contained in:
@@ -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 = {
|
||||
|
||||
3
packages/drawer/src/utils/DrawerPositionContext.tsx
Normal file
3
packages/drawer/src/utils/DrawerPositionContext.tsx
Normal file
@@ -0,0 +1,3 @@
|
||||
import * as React from 'react';
|
||||
|
||||
export default React.createContext<'left' | 'right' | undefined>(undefined);
|
||||
@@ -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 (
|
||||
|
||||
@@ -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 = () => {
|
||||
|
||||
Reference in New Issue
Block a user