UNPKG

5.89 kBTypeScriptView Raw
1import * as React from 'react';
2import { Component } from 'react';
3import { Animated, StatusBarAnimation, StyleProp, ViewStyle } from 'react-native';
4import { UserSelect, ActiveCursor, MouseButton } from '../handlers/gestureHandlerCommon';
5import { PanGestureHandler } from '../handlers/PanGestureHandler';
6export type DrawerPosition = 'left' | 'right';
7export type DrawerState = 'Idle' | 'Dragging' | 'Settling';
8export type DrawerType = 'front' | 'back' | 'slide';
9export type DrawerLockMode = 'unlocked' | 'locked-closed' | 'locked-open';
10export type DrawerKeyboardDismissMode = 'none' | 'on-drag';
11type AnimatedInterpolation = ReturnType<Animated.Value['interpolate']>;
12export interface DrawerLayoutProps {
13 /**
14 * This attribute is present in the standard implementation already and is one
15 * of the required params. Gesture handler version of DrawerLayout make it
16 * possible for the function passed as `renderNavigationView` to take an
17 * Animated value as a parameter that indicates the progress of drawer
18 * opening/closing animation (progress value is 0 when closed and 1 when
19 * opened). This can be used by the drawer component to animated its children
20 * while the drawer is opening or closing.
21 */
22 renderNavigationView: (progressAnimatedValue: Animated.Value) => React.ReactNode;
23 drawerPosition?: DrawerPosition;
24 drawerWidth?: number;
25 drawerBackgroundColor?: string;
26 drawerLockMode?: DrawerLockMode;
27 keyboardDismissMode?: DrawerKeyboardDismissMode;
28 /**
29 * Called when the drawer is closed.
30 */
31 onDrawerClose?: () => void;
32 /**
33 * Called when the drawer is opened.
34 */
35 onDrawerOpen?: () => void;
36 /**
37 * Called when the status of the drawer changes.
38 */
39 onDrawerStateChanged?: (newState: DrawerState, drawerWillShow: boolean) => void;
40 useNativeAnimations?: boolean;
41 drawerType?: DrawerType;
42 /**
43 * Defines how far from the edge of the content view the gesture should
44 * activate.
45 */
46 edgeWidth?: number;
47 minSwipeDistance?: number;
48 /**
49 * When set to true Drawer component will use
50 * {@link https://reactnative.dev/docs/statusbar StatusBar} API to hide the OS
51 * status bar whenever the drawer is pulled or when its in an "open" state.
52 */
53 hideStatusBar?: boolean;
54 /**
55 * @default 'slide'
56 *
57 * Can be used when hideStatusBar is set to true and will select the animation
58 * used for hiding/showing the status bar. See
59 * {@link https://reactnative.dev/docs/statusbar StatusBar} documentation for
60 * more details
61 */
62 statusBarAnimation?: StatusBarAnimation;
63 /**
64 * @default black
65 *
66 * Color of a semi-transparent overlay to be displayed on top of the content
67 * view when drawer gets open. A solid color should be used as the opacity is
68 * added by the Drawer itself and the opacity of the overlay is animated (from
69 * 0% to 70%).
70 */
71 overlayColor?: string;
72 contentContainerStyle?: StyleProp<ViewStyle>;
73 drawerContainerStyle?: StyleProp<ViewStyle>;
74 /**
75 * Enables two-finger gestures on supported devices, for example iPads with
76 * trackpads. If not enabled the gesture will require click + drag, with
77 * `enableTrackpadTwoFingerGesture` swiping with two fingers will also trigger
78 * the gesture.
79 */
80 enableTrackpadTwoFingerGesture?: boolean;
81 onDrawerSlide?: (position: number) => void;
82 onGestureRef?: (ref: PanGestureHandler) => void;
83 children?: React.ReactNode | ((openValue?: AnimatedInterpolation) => React.ReactNode);
84 /**
85 * @default 'none'
86 * Defines which userSelect property should be used.
87 * Values: 'none'|'text'|'auto'
88 */
89 userSelect?: UserSelect;
90 /**
91 * @default 'auto'
92 * Defines which cursor property should be used when gesture activates.
93 * Values: see CSS cursor values
94 */
95 activeCursor?: ActiveCursor;
96 /**
97 * @default 'MouseButton.LEFT'
98 * Allows to choose which mouse button should underlying pan handler react to.
99 */
100 mouseButton?: MouseButton;
101 /**
102 * @default 'false if MouseButton.RIGHT is specified'
103 * Allows to enable/disable context menu.
104 */
105 enableContextMenu?: boolean;
106}
107export type DrawerLayoutState = {
108 dragX: Animated.Value;
109 touchX: Animated.Value;
110 drawerTranslation: Animated.Value;
111 containerWidth: number;
112 drawerState: DrawerState;
113 drawerOpened: boolean;
114};
115export type DrawerMovementOption = {
116 velocity?: number;
117 speed?: number;
118};
119export default class DrawerLayout extends Component<DrawerLayoutProps, DrawerLayoutState> {
120 static defaultProps: {
121 drawerWidth: number;
122 drawerPosition: string;
123 useNativeAnimations: boolean;
124 drawerType: string;
125 edgeWidth: number;
126 minSwipeDistance: number;
127 overlayColor: string;
128 drawerLockMode: string;
129 enableTrackpadTwoFingerGesture: boolean;
130 };
131 constructor(props: DrawerLayoutProps);
132 shouldComponentUpdate(props: DrawerLayoutProps, state: DrawerLayoutState): boolean;
133 private openValue?;
134 private onGestureEvent?;
135 private accessibilityIsModalView;
136 private pointerEventsView;
137 private panGestureHandler;
138 private drawerShown;
139 static positions: {
140 Left: string;
141 Right: string;
142 };
143 private updateAnimatedEvent;
144 private handleContainerLayout;
145 private emitStateChanged;
146 private openingHandlerStateChange;
147 private onTapHandlerStateChange;
148 private handleRelease;
149 private updateShowing;
150 private animateDrawer;
151 openDrawer: (options?: DrawerMovementOption) => void;
152 closeDrawer: (options?: DrawerMovementOption) => void;
153 private renderOverlay;
154 private renderDrawer;
155 private setPanGestureRef;
156 render(): React.JSX.Element;
157}
158export {};