Implement drawerLockMode

This commit is contained in:
Brent Vatne
2018-11-27 13:35:58 -08:00
committed by satyajit.happy
parent 3aa02d2f5e
commit 5bd63e2f3e

View File

@@ -1,7 +1,5 @@
/* eslint-disable */ /* eslint-disable */
// @flow
// ######################################################### // #########################################################
// This is vendored from react-native-gesture-handler! // This is vendored from react-native-gesture-handler!
// ######################################################### // #########################################################
@@ -17,7 +15,6 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import { Animated, StyleSheet, View, Keyboard, StatusBar, I18nManager } from 'react-native'; import { Animated, StyleSheet, View, Keyboard, StatusBar, I18nManager } from 'react-native';
import invariant from '../utils/invariant'; import invariant from '../utils/invariant';
import { AnimatedEvent } from 'react-native/Libraries/Animated/src/AnimatedEvent';
import { import {
PanGestureHandler, PanGestureHandler,
@@ -52,9 +49,11 @@ export type PropType = {
overlayColor: string, overlayColor: string,
contentContainerStyle?: any, contentContainerStyle?: any,
// Added in this fork, needs to be upstreamed
drawerLockMode?: 'unlocked' | 'locked-closed' | 'locked-open',
// Properties not yet supported // Properties not yet supported
// onDrawerSlide?: Function // onDrawerSlide?: Function
// drawerLockMode?: 'unlocked' | 'locked-closed' | 'locked-open',
}; };
export type StateType = { export type StateType = {
@@ -82,6 +81,7 @@ export default class DrawerLayout extends Component<PropType, StateType> {
edgeWidth: 20, edgeWidth: 20,
minSwipeDistance: 3, minSwipeDistance: 3,
overlayColor: 'black', overlayColor: 'black',
drawerLockMode: 'unlocked',
}; };
static positions = { static positions = {
@@ -89,7 +89,7 @@ export default class DrawerLayout extends Component<PropType, StateType> {
Right: 'right', Right: 'right',
}; };
_openValue: ?Animated.Interpolation; _openValue: ?Animated.Interpolation;
_onGestureEvent: ?AnimatedEvent; _onGestureEvent: any;
constructor(props: PropType, context: any) { constructor(props: PropType, context: any) {
super(props, context); super(props, context);
@@ -227,7 +227,11 @@ export default class DrawerLayout extends Component<PropType, StateType> {
}; };
_onTapHandlerStateChange = ({ nativeEvent }) => { _onTapHandlerStateChange = ({ nativeEvent }) => {
if (this.state.drawerShown && nativeEvent.oldState === State.ACTIVE) { if (
this.state.drawerShown &&
nativeEvent.oldState === State.ACTIVE &&
this.props.drawerLockMode !== 'locked-open'
) {
this.closeDrawer(); this.closeDrawer();
} }
}; };
@@ -407,8 +411,7 @@ export default class DrawerLayout extends Component<PropType, StateType> {
: styles.containerInFront, : styles.containerInFront,
containerStyles, containerStyles,
contentContainerStyle, contentContainerStyle,
]} ]}>
>
{typeof this.props.children === 'function' {typeof this.props.children === 'function'
? this.props.children(this._openValue) ? this.props.children(this._openValue)
: this.props.children} : this.props.children}
@@ -417,8 +420,7 @@ export default class DrawerLayout extends Component<PropType, StateType> {
<Animated.View <Animated.View
pointerEvents="box-none" pointerEvents="box-none"
accessibilityViewIsModal={drawerShown} accessibilityViewIsModal={drawerShown}
style={[styles.drawerContainer, drawerStyles]} style={[styles.drawerContainer, drawerStyles]}>
>
<View style={[styles.drawer, dynamicDrawerStyles]}> <View style={[styles.drawer, dynamicDrawerStyles]}>
{this.props.renderNavigationView(this._openValue)} {this.props.renderNavigationView(this._openValue)}
</View> </View>
@@ -433,6 +435,7 @@ export default class DrawerLayout extends Component<PropType, StateType> {
const { const {
drawerPosition, drawerPosition,
drawerType, drawerType,
drawerLockMode,
edgeWidth, edgeWidth,
minSwipeDistance, minSwipeDistance,
} = this.props; } = this.props;
@@ -457,9 +460,11 @@ export default class DrawerLayout extends Component<PropType, StateType> {
minOffsetX={gestureOrientation * minSwipeDistance} minOffsetX={gestureOrientation * minSwipeDistance}
maxDeltaY={15} maxDeltaY={15}
onGestureEvent={this._onGestureEvent} onGestureEvent={this._onGestureEvent}
enabled={
drawerLockMode !== 'locked-closed' && drawerLockMode !== 'locked-open'
}
onHandlerStateChange={this._openingHandlerStateChange} onHandlerStateChange={this._openingHandlerStateChange}
ref={this.props.gestureRef} ref={this.props.gestureRef}>
>
{this._renderDrawer()} {this._renderDrawer()}
</PanGestureHandler> </PanGestureHandler>
); );