@react-navigation/drawer 6.3.0 → 6.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/views/DrawerView.js +4 -6
- package/lib/commonjs/views/DrawerView.js.map +1 -1
- package/lib/commonjs/views/modern/Drawer.js +9 -4
- package/lib/commonjs/views/modern/Drawer.js.map +1 -1
- package/lib/module/views/DrawerView.js +4 -6
- package/lib/module/views/DrawerView.js.map +1 -1
- package/lib/module/views/modern/Drawer.js +10 -5
- package/lib/module/views/modern/Drawer.js.map +1 -1
- package/lib/typescript/src/types.d.ts +3 -11
- package/lib/typescript/src/views/legacy/Overlay.d.ts +3 -1
- package/lib/typescript/src/views/modern/Overlay.d.ts +3 -1
- package/package.json +3 -3
- package/src/types.tsx +3 -12
- package/src/views/DrawerView.tsx +4 -7
- package/src/views/modern/Drawer.tsx +20 -6
|
@@ -13,7 +13,7 @@ var React = _interopRequireWildcard(require("react"));
|
|
|
13
13
|
|
|
14
14
|
var _reactNative = require("react-native");
|
|
15
15
|
|
|
16
|
-
var
|
|
16
|
+
var Reanimated = _interopRequireWildcard(require("react-native-reanimated"));
|
|
17
17
|
|
|
18
18
|
var _reactNativeSafeAreaContext = require("react-native-safe-area-context");
|
|
19
19
|
|
|
@@ -61,7 +61,7 @@ const getDefaultDrawerWidth = _ref => {
|
|
|
61
61
|
const GestureHandlerWrapper = _GestureHandler.GestureHandlerRootView !== null && _GestureHandler.GestureHandlerRootView !== void 0 ? _GestureHandler.GestureHandlerRootView : _reactNative.View;
|
|
62
62
|
|
|
63
63
|
function DrawerViewBase(_ref2) {
|
|
64
|
-
var
|
|
64
|
+
var _Reanimated$isConfigu;
|
|
65
65
|
|
|
66
66
|
let {
|
|
67
67
|
state,
|
|
@@ -70,11 +70,9 @@ function DrawerViewBase(_ref2) {
|
|
|
70
70
|
defaultStatus,
|
|
71
71
|
drawerContent = props => /*#__PURE__*/React.createElement(_DrawerContent.default, props),
|
|
72
72
|
detachInactiveScreens = _reactNative.Platform.OS === 'web' || _reactNative.Platform.OS === 'android' || _reactNative.Platform.OS === 'ios',
|
|
73
|
-
//
|
|
74
|
-
// @ts-expect-error
|
|
75
|
-
useLegacyImplementation = !global.nativeCallSyncHook || // Reanimated 2 is not configured
|
|
73
|
+
// Reanimated 2 is not configured
|
|
76
74
|
// @ts-expect-error: the type definitions are incomplete
|
|
77
|
-
!((
|
|
75
|
+
useLegacyImplementation = !((_Reanimated$isConfigu = Reanimated.isConfigured) !== null && _Reanimated$isConfigu !== void 0 && _Reanimated$isConfigu.call(Reanimated))
|
|
78
76
|
} = _ref2;
|
|
79
77
|
const Drawer = useLegacyImplementation ? require('./legacy/Drawer').default : require('./modern/Drawer').default;
|
|
80
78
|
const focusedRouteKey = state.routes[state.index].key;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["DrawerView.tsx"],"names":["getDefaultDrawerWidth","height","width","smallerAxisSize","Math","min","isLandscape","isTablet","appBarHeight","Platform","OS","maxWidth","GestureHandlerWrapper","GestureHandlerRootView","View","DrawerViewBase","state","navigation","descriptors","defaultStatus","drawerContent","props","detachInactiveScreens","useLegacyImplementation","global","nativeCallSyncHook","Animated","isConfigured","Drawer","require","default","focusedRouteKey","routes","index","key","drawerHideStatusBarOnOpen","drawerPosition","I18nManager","isRTL","drawerStatusBarAnimation","drawerStyle","drawerType","select","ios","gestureHandlerProps","keyboardDismissMode","overlayColor","swipeEdgeWidth","swipeEnabled","swipeMinDistance","options","loaded","setLoaded","React","useState","includes","dimensions","colors","drawerStatus","handleDrawerOpen","useCallback","dispatch","DrawerActions","openDrawer","target","handleDrawerClose","closeDrawer","useEffect","handleHardwareBack","isFocused","handleEscape","e","subscription","BackHandler","addEventListener","document","body","remove","removeEventListener","renderDrawerContent","renderSceneContent","styles","content","map","route","descriptor","lazy","unmountOnBlur","header","layout","name","headerLeft","sceneContainerStyle","StyleSheet","absoluteFill","zIndex","headerShown","headerTransparent","headerStatusBarHeight","render","backgroundColor","card","borderRightColor","border","borderRightWidth","hairlineWidth","borderLeftColor","borderLeftWidth","DrawerView","rest","create","flex"],"mappings":";;;;;;;AAAA;;AAMA;;AAOA;;AACA;;AAOA;;AACA;;AAWA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;AASA,MAAMA,qBAAqB,GAAG,QAMxB;AAAA,MANyB;AAC7BC,IAAAA,MAD6B;AAE7BC,IAAAA;AAF6B,GAMzB;;AACJ;AACF;AACA;AACA;AACA;AACE,QAAMC,eAAe,GAAGC,IAAI,CAACC,GAAL,CAASJ,MAAT,EAAiBC,KAAjB,CAAxB;AACA,QAAMI,WAAW,GAAGJ,KAAK,GAAGD,MAA5B;AACA,QAAMM,QAAQ,GAAGJ,eAAe,IAAI,GAApC;AACA,QAAMK,YAAY,GAAGC,sBAASC,EAAT,KAAgB,KAAhB,GAAyBJ,WAAW,GAAG,EAAH,GAAQ,EAA5C,GAAkD,EAAvE;AACA,QAAMK,QAAQ,GAAGJ,QAAQ,GAAG,GAAH,GAAS,GAAlC;AAEA,SAAOH,IAAI,CAACC,GAAL,CAASF,eAAe,GAAGK,YAA3B,EAAyCG,QAAzC,CAAP;AACD,CAnBD;;AAqBA,MAAMC,qBAAqB,GAAGC,sCAAH,aAAGA,sCAAH,cAAGA,sCAAH,GAA6BC,iBAAxD;;AAEA,SAASC,cAAT,QAiBU;AAAA;;AAAA,MAjBc;AACtBC,IAAAA,KADsB;AAEtBC,IAAAA,UAFsB;AAGtBC,IAAAA,WAHsB;AAItBC,IAAAA,aAJsB;AAKtBC,IAAAA,aAAa,GAAIC,KAAD,iBACd,oBAAC,sBAAD,EAAmBA,KAAnB,CANoB;AAQtBC,IAAAA,qBAAqB,GAAGb,sBAASC,EAAT,KAAgB,KAAhB,IACtBD,sBAASC,EAAT,KAAgB,SADM,IAEtBD,sBAASC,EAAT,KAAgB,KAVI;AAWtB;AACA;AACAa,IAAAA,uBAAuB,GAAG,CAACC,MAAM,C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AAEd,wBAAWY;AAF9B,KANN,CALW,EAeXjE,WAfW,CAdf;AA+BE,IAAA,YAAY,EAAE;AAAE4D,MAAAA,eAAe,EAAEtD;AAAnB,KA/BhB;AAgCE,IAAA,mBAAmB,EAAEiC,mBAhCvB;AAiCE,IAAA,kBAAkB,EAAEC,kBAjCtB;AAkCE,IAAA,UAAU,EAAExB;AAlCd,IADF,CADF;AAwCD;;AAEc,SAASoD,UAAT,QAAoD;AAAA,MAAhC;AAAE3F,IAAAA,UAAF;AAAc,OAAG4F;AAAjB,GAAgC;AACjE,sBACE,oBAAC,gCAAD,qBACE,oBAAC,qBAAD;AAAuB,IAAA,KAAK,EAAE5B,MAAM,CAACC;AAArC,kBACE,oBAAC,cAAD;AAAgB,IAAA,UAAU,EAAEjE;AAA5B,KAA4C4F,IAA5C,EADF,CADF,CADF;AAOD;;AAED,MAAM5B,MAAM,GAAGY,wBAAWiB,MAAX,CAAkB;AAC/B5B,EAAAA,OAAO,EAAE;AACP6B,IAAAA,IAAI,EAAE;AADC;AADsB,CAAlB,CAAf","sourcesContent":["import {\n getHeaderTitle,\n Header,\n SafeAreaProviderCompat,\n Screen,\n} from '@react-navigation/elements';\nimport {\n DrawerActions,\n DrawerNavigationState,\n DrawerStatus,\n ParamListBase,\n useTheme,\n} from '@react-navigation/native';\nimport * as React from 'react';\nimport {\n BackHandler,\n I18nManager,\n Platform,\n StyleSheet,\n View,\n} from 'react-native';\nimport Animated from 'react-native-reanimated';\nimport { useSafeAreaFrame } from 'react-native-safe-area-context';\n\nimport type {\n DrawerContentComponentProps,\n DrawerDescriptorMap,\n DrawerHeaderProps,\n DrawerNavigationConfig,\n DrawerNavigationHelpers,\n DrawerNavigationProp,\n DrawerProps,\n} from '../types';\nimport DrawerPositionContext from '../utils/DrawerPositionContext';\nimport DrawerStatusContext from '../utils/DrawerStatusContext';\nimport getDrawerStatusFromState from '../utils/getDrawerStatusFromState';\nimport DrawerContent from './DrawerContent';\nimport DrawerToggleButton from './DrawerToggleButton';\nimport { GestureHandlerRootView } from './GestureHandler';\nimport { MaybeScreen, MaybeScreenContainer } from './ScreenFallback';\n\ntype Props = DrawerNavigationConfig & {\n defaultStatus: DrawerStatus;\n state: DrawerNavigationState<ParamListBase>;\n navigation: DrawerNavigationHelpers;\n descriptors: DrawerDescriptorMap;\n};\n\nconst getDefaultDrawerWidth = ({\n height,\n width,\n}: {\n height: number;\n width: number;\n}) => {\n /*\n * Default drawer width is screen width - header height\n * with a max width of 280 on mobile and 320 on tablet\n * https://material.io/components/navigation-drawer\n */\n const smallerAxisSize = Math.min(height, width);\n const isLandscape = width > height;\n const isTablet = smallerAxisSize >= 600;\n const appBarHeight = Platform.OS === 'ios' ? (isLandscape ? 32 : 44) : 56;\n const maxWidth = isTablet ? 320 : 280;\n\n return Math.min(smallerAxisSize - appBarHeight, maxWidth);\n};\n\nconst GestureHandlerWrapper = GestureHandlerRootView ?? View;\n\nfunction DrawerViewBase({\n state,\n navigation,\n descriptors,\n defaultStatus,\n drawerContent = (props: DrawerContentComponentProps) => (\n <DrawerContent {...props} />\n ),\n detachInactiveScreens = Platform.OS === 'web' ||\n Platform.OS === 'android' ||\n Platform.OS === 'ios',\n // Running in chrome debugger\n // @ts-expect-error\n useLegacyImplementation = !global.nativeCallSyncHook ||\n // Reanimated 2 is not configured\n // @ts-expect-error: the type definitions are incomplete\n !Animated.isConfigured?.(),\n}: Props) {\n const Drawer: React.ComponentType<DrawerProps> = useLegacyImplementation\n ? require('./legacy/Drawer').default\n : require('./modern/Drawer').default;\n\n const focusedRouteKey = state.routes[state.index].key;\n const {\n drawerHideStatusBarOnOpen = false,\n drawerPosition = I18nManager.isRTL ? 'right' : 'left',\n drawerStatusBarAnimation = 'slide',\n drawerStyle,\n drawerType = Platform.select({ ios: 'slide', default: 'front' }),\n gestureHandlerProps,\n keyboardDismissMode = 'on-drag',\n overlayColor = 'rgba(0, 0, 0, 0.5)',\n swipeEdgeWidth = 32,\n swipeEnabled = Platform.OS !== 'web' &&\n Platform.OS !== 'windows' &&\n Platform.OS !== 'macos',\n swipeMinDistance = 60,\n } = descriptors[focusedRouteKey].options;\n\n const [loaded, setLoaded] = React.useState([focusedRouteKey]);\n\n if (!loaded.includes(focusedRouteKey)) {\n setLoaded([...loaded, focusedRouteKey]);\n }\n\n const dimensions = useSafeAreaFrame();\n\n const { colors } = useTheme();\n\n const drawerStatus = getDrawerStatusFromState(state);\n\n const handleDrawerOpen = React.useCallback(() => {\n navigation.dispatch({\n ...DrawerActions.openDrawer(),\n target: state.key,\n });\n }, [navigation, state.key]);\n\n const handleDrawerClose = React.useCallback(() => {\n navigation.dispatch({\n ...DrawerActions.closeDrawer(),\n target: state.key,\n });\n }, [navigation, state.key]);\n\n React.useEffect(() => {\n if (drawerStatus === defaultStatus || drawerType === 'permanent') {\n return;\n }\n\n const handleHardwareBack = () => {\n // We shouldn't handle the back button if the parent screen isn't focused\n // This will avoid the drawer overriding event listeners from a focused screen\n if (!navigation.isFocused()) {\n return false;\n }\n\n if (defaultStatus === 'open') {\n handleDrawerOpen();\n } else {\n handleDrawerClose();\n }\n\n return true;\n };\n\n const handleEscape = (e: KeyboardEvent) => {\n if (e.key === 'Escape') {\n handleHardwareBack();\n }\n };\n\n // We only add the listeners when drawer opens\n // This way we can make sure that the listener is added as late as possible\n // This will make sure that our handler will run first when back button is pressed\n const subscription = BackHandler.addEventListener(\n 'hardwareBackPress',\n handleHardwareBack\n );\n\n if (Platform.OS === 'web') {\n document?.body?.addEventListener?.('keyup', handleEscape);\n }\n\n return () => {\n subscription.remove();\n\n if (Platform.OS === 'web') {\n document?.body?.removeEventListener?.('keyup', handleEscape);\n }\n };\n }, [\n defaultStatus,\n drawerStatus,\n drawerType,\n handleDrawerClose,\n handleDrawerOpen,\n navigation,\n ]);\n\n const renderDrawerContent = () => {\n return (\n <DrawerPositionContext.Provider value={drawerPosition}>\n {drawerContent({\n state: state,\n navigation: navigation,\n descriptors: descriptors,\n })}\n </DrawerPositionContext.Provider>\n );\n };\n\n const renderSceneContent = () => {\n return (\n <MaybeScreenContainer\n enabled={detachInactiveScreens}\n hasTwoStates\n style={styles.content}\n >\n {state.routes.map((route, index) => {\n const descriptor = descriptors[route.key];\n const { lazy = true, unmountOnBlur } = descriptor.options;\n const isFocused = state.index === index;\n\n if (unmountOnBlur && !isFocused) {\n return null;\n }\n\n if (lazy && !loaded.includes(route.key) && !isFocused) {\n // Don't render a lazy screen if we've never navigated to it\n return null;\n }\n\n const {\n header = ({ layout, options }: DrawerHeaderProps) => (\n <Header\n {...options}\n layout={layout}\n title={getHeaderTitle(options, route.name)}\n headerLeft={\n options.headerLeft ??\n ((props) => <DrawerToggleButton {...props} />)\n }\n />\n ),\n sceneContainerStyle,\n } = descriptor.options;\n\n return (\n <MaybeScreen\n key={route.key}\n style={[StyleSheet.absoluteFill, { zIndex: isFocused ? 0 : -1 }]}\n visible={isFocused}\n enabled={detachInactiveScreens}\n >\n <Screen\n focused={isFocused}\n route={descriptor.route}\n navigation={descriptor.navigation}\n headerShown={descriptor.options.headerShown}\n headerTransparent={descriptor.options.headerTransparent}\n headerStatusBarHeight={descriptor.options.headerStatusBarHeight}\n header={header({\n layout: dimensions,\n route: descriptor.route,\n navigation:\n descriptor.navigation as DrawerNavigationProp<ParamListBase>,\n options: descriptor.options,\n })}\n style={sceneContainerStyle}\n >\n {descriptor.render()}\n </Screen>\n </MaybeScreen>\n );\n })}\n </MaybeScreenContainer>\n );\n };\n\n return (\n <DrawerStatusContext.Provider value={drawerStatus}>\n <Drawer\n open={drawerStatus !== 'closed'}\n onOpen={handleDrawerOpen}\n onClose={handleDrawerClose}\n gestureHandlerProps={gestureHandlerProps}\n swipeEnabled={swipeEnabled}\n swipeEdgeWidth={swipeEdgeWidth}\n swipeVelocityThreshold={500}\n swipeDistanceThreshold={swipeMinDistance}\n hideStatusBarOnOpen={drawerHideStatusBarOnOpen}\n statusBarAnimation={drawerStatusBarAnimation}\n keyboardDismissMode={keyboardDismissMode}\n drawerType={drawerType}\n drawerPosition={drawerPosition}\n drawerStyle={[\n {\n width: getDefaultDrawerWidth(dimensions),\n backgroundColor: colors.card,\n },\n drawerType === 'permanent' &&\n (drawerPosition === 'left'\n ? {\n borderRightColor: colors.border,\n borderRightWidth: StyleSheet.hairlineWidth,\n }\n : {\n borderLeftColor: colors.border,\n borderLeftWidth: StyleSheet.hairlineWidth,\n }),\n drawerStyle,\n ]}\n overlayStyle={{ backgroundColor: overlayColor }}\n renderDrawerContent={renderDrawerContent}\n renderSceneContent={renderSceneContent}\n dimensions={dimensions}\n />\n </DrawerStatusContext.Provider>\n );\n}\n\nexport default function DrawerView({ navigation, ...rest }: Props) {\n return (\n <SafeAreaProviderCompat>\n <GestureHandlerWrapper style={styles.content}>\n <DrawerViewBase navigation={navigation} {...rest} />\n </GestureHandlerWrapper>\n </SafeAreaProviderCompat>\n );\n}\n\nconst styles = StyleSheet.create({\n content: {\n flex: 1,\n },\n});\n"]}
|
|
1
|
+
{"version":3,"sources":["DrawerView.tsx"],"names":["getDefaultDrawerWidth","height","width","smallerAxisSize","Math","min","isLandscape","isTablet","appBarHeight","Platform","OS","maxWidth","GestureHandlerWrapper","GestureHandlerRootView","View","DrawerViewBase","state","navigation","descriptors","defaultStatus","drawerContent","props","detachInactiveScreens","useLegacyImplementation","Reanimated","isConfigured","Drawer","require","default","focusedRouteKey","routes","index","key","drawerHideStatusBarOnOpen","drawerPosition","I18nManager","isRTL","drawerStatusBarAnimation","drawerStyle","drawerType","select","ios","gestureHandlerProps","keyboardDismissMode","overlayColor","swipeEdgeWidth","swipeEnabled","swipeMinDistance","options","loaded","setLoaded","React","useState","includes","dimensions","colors","drawerStatus","handleDrawerOpen","useCallback","dispatch","DrawerActions","openDrawer","target","handleDrawerClose","closeDrawer","useEffect","handleHardwareBack","isFocused","handleEscape","e","subscription","BackHandler","addEventListener","document","body","remove","removeEventListener","renderDrawerContent","renderSceneContent","styles","content","map","route","descriptor","lazy","unmountOnBlur","header","layout","name","headerLeft","sceneContainerStyle","StyleSheet","absoluteFill","zIndex","headerShown","headerTransparent","headerStatusBarHeight","render","backgroundColor","card","borderRightColor","border","borderRightWidth","hairlineWidth","borderLeftColor","borderLeftWidth","DrawerView","rest","create","flex"],"mappings":";;;;;;;AAAA;;AAMA;;AAOA;;AACA;;AAOA;;AACA;;AAWA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;AASA,MAAMA,qBAAqB,GAAG,QAMxB;AAAA,MANyB;AAC7BC,IAAAA,MAD6B;AAE7BC,IAAAA;AAF6B,GAMzB;;AACJ;AACF;AACA;AACA;AACA;AACE,QAAMC,eAAe,GAAGC,IAAI,CAACC,GAAL,CAASJ,MAAT,EAAiBC,KAAjB,CAAxB;AACA,QAAMI,WAAW,GAAGJ,KAAK,GAAGD,MAA5B;AACA,QAAMM,QAAQ,GAAGJ,eAAe,IAAI,GAApC;AACA,QAAMK,YAAY,GAAGC,sBAASC,EAAT,KAAgB,KAAhB,GAAyBJ,WAAW,GAAG,EAAH,GAAQ,EAA5C,GAAkD,EAAvE;AACA,QAAMK,QAAQ,GAAGJ,QAAQ,GAAG,GAAH,GAAS,GAAlC;AAEA,SAAOH,IAAI,CAACC,GAAL,CAASF,eAAe,GAAGK,YAA3B,EAAyCG,QAAzC,CAAP;AACD,CAnBD;;AAqBA,MAAMC,qBAAqB,GAAGC,sCAAH,aAAGA,sCAAH,cAAGA,sCAAH,GAA6BC,iBAAxD;;AAEA,SAASC,cAAT,QAcU;AAAA;;AAAA,MAdc;AACtBC,IAAAA,KADsB;AAEtBC,IAAAA,UAFsB;AAGtBC,IAAAA,WAHsB;AAItBC,IAAAA,aAJsB;AAKtBC,IAAAA,aAAa,GAAIC,KAAD,iBACd,oBAAC,sBAAD,EAAmBA,KAAnB,CANoB;AAQtBC,IAAAA,qBAAqB,GAAGb,sBAASC,EAAT,KAAgB,KAAhB,IACtBD,sBAASC,EAAT,KAAgB,SADM,IAEtBD,sBAASC,EAAT,KAAgB,KAVI;AAWtB;AACA;AACAa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,EAAEd,wBAAWY;AAF9B,KANN,CALW,EAeXjE,WAfW,CAdf;AA+BE,IAAA,YAAY,EAAE;AAAE4D,MAAAA,eAAe,EAAEtD;AAAnB,KA/BhB;AAgCE,IAAA,mBAAmB,EAAEiC,mBAhCvB;AAiCE,IAAA,kBAAkB,EAAEC,kBAjCtB;AAkCE,IAAA,UAAU,EAAExB;AAlCd,IADF,CADF;AAwCD;;AAEc,SAASoD,UAAT,QAAoD;AAAA,MAAhC;AAAEzF,IAAAA,UAAF;AAAc,OAAG0F;AAAjB,GAAgC;AACjE,sBACE,oBAAC,gCAAD,qBACE,oBAAC,qBAAD;AAAuB,IAAA,KAAK,EAAE5B,MAAM,CAACC;AAArC,kBACE,oBAAC,cAAD;AAAgB,IAAA,UAAU,EAAE/D;AAA5B,KAA4C0F,IAA5C,EADF,CADF,CADF;AAOD;;AAED,MAAM5B,MAAM,GAAGY,wBAAWiB,MAAX,CAAkB;AAC/B5B,EAAAA,OAAO,EAAE;AACP6B,IAAAA,IAAI,EAAE;AADC;AADsB,CAAlB,CAAf","sourcesContent":["import {\n getHeaderTitle,\n Header,\n SafeAreaProviderCompat,\n Screen,\n} from '@react-navigation/elements';\nimport {\n DrawerActions,\n DrawerNavigationState,\n DrawerStatus,\n ParamListBase,\n useTheme,\n} from '@react-navigation/native';\nimport * as React from 'react';\nimport {\n BackHandler,\n I18nManager,\n Platform,\n StyleSheet,\n View,\n} from 'react-native';\nimport * as Reanimated from 'react-native-reanimated';\nimport { useSafeAreaFrame } from 'react-native-safe-area-context';\n\nimport type {\n DrawerContentComponentProps,\n DrawerDescriptorMap,\n DrawerHeaderProps,\n DrawerNavigationConfig,\n DrawerNavigationHelpers,\n DrawerNavigationProp,\n DrawerProps,\n} from '../types';\nimport DrawerPositionContext from '../utils/DrawerPositionContext';\nimport DrawerStatusContext from '../utils/DrawerStatusContext';\nimport getDrawerStatusFromState from '../utils/getDrawerStatusFromState';\nimport DrawerContent from './DrawerContent';\nimport DrawerToggleButton from './DrawerToggleButton';\nimport { GestureHandlerRootView } from './GestureHandler';\nimport { MaybeScreen, MaybeScreenContainer } from './ScreenFallback';\n\ntype Props = DrawerNavigationConfig & {\n defaultStatus: DrawerStatus;\n state: DrawerNavigationState<ParamListBase>;\n navigation: DrawerNavigationHelpers;\n descriptors: DrawerDescriptorMap;\n};\n\nconst getDefaultDrawerWidth = ({\n height,\n width,\n}: {\n height: number;\n width: number;\n}) => {\n /*\n * Default drawer width is screen width - header height\n * with a max width of 280 on mobile and 320 on tablet\n * https://material.io/components/navigation-drawer\n */\n const smallerAxisSize = Math.min(height, width);\n const isLandscape = width > height;\n const isTablet = smallerAxisSize >= 600;\n const appBarHeight = Platform.OS === 'ios' ? (isLandscape ? 32 : 44) : 56;\n const maxWidth = isTablet ? 320 : 280;\n\n return Math.min(smallerAxisSize - appBarHeight, maxWidth);\n};\n\nconst GestureHandlerWrapper = GestureHandlerRootView ?? View;\n\nfunction DrawerViewBase({\n state,\n navigation,\n descriptors,\n defaultStatus,\n drawerContent = (props: DrawerContentComponentProps) => (\n <DrawerContent {...props} />\n ),\n detachInactiveScreens = Platform.OS === 'web' ||\n Platform.OS === 'android' ||\n Platform.OS === 'ios',\n // Reanimated 2 is not configured\n // @ts-expect-error: the type definitions are incomplete\n useLegacyImplementation = !Reanimated.isConfigured?.(),\n}: Props) {\n const Drawer: React.ComponentType<DrawerProps> = useLegacyImplementation\n ? require('./legacy/Drawer').default\n : require('./modern/Drawer').default;\n\n const focusedRouteKey = state.routes[state.index].key;\n const {\n drawerHideStatusBarOnOpen = false,\n drawerPosition = I18nManager.isRTL ? 'right' : 'left',\n drawerStatusBarAnimation = 'slide',\n drawerStyle,\n drawerType = Platform.select({ ios: 'slide', default: 'front' }),\n gestureHandlerProps,\n keyboardDismissMode = 'on-drag',\n overlayColor = 'rgba(0, 0, 0, 0.5)',\n swipeEdgeWidth = 32,\n swipeEnabled = Platform.OS !== 'web' &&\n Platform.OS !== 'windows' &&\n Platform.OS !== 'macos',\n swipeMinDistance = 60,\n } = descriptors[focusedRouteKey].options;\n\n const [loaded, setLoaded] = React.useState([focusedRouteKey]);\n\n if (!loaded.includes(focusedRouteKey)) {\n setLoaded([...loaded, focusedRouteKey]);\n }\n\n const dimensions = useSafeAreaFrame();\n\n const { colors } = useTheme();\n\n const drawerStatus = getDrawerStatusFromState(state);\n\n const handleDrawerOpen = React.useCallback(() => {\n navigation.dispatch({\n ...DrawerActions.openDrawer(),\n target: state.key,\n });\n }, [navigation, state.key]);\n\n const handleDrawerClose = React.useCallback(() => {\n navigation.dispatch({\n ...DrawerActions.closeDrawer(),\n target: state.key,\n });\n }, [navigation, state.key]);\n\n React.useEffect(() => {\n if (drawerStatus === defaultStatus || drawerType === 'permanent') {\n return;\n }\n\n const handleHardwareBack = () => {\n // We shouldn't handle the back button if the parent screen isn't focused\n // This will avoid the drawer overriding event listeners from a focused screen\n if (!navigation.isFocused()) {\n return false;\n }\n\n if (defaultStatus === 'open') {\n handleDrawerOpen();\n } else {\n handleDrawerClose();\n }\n\n return true;\n };\n\n const handleEscape = (e: KeyboardEvent) => {\n if (e.key === 'Escape') {\n handleHardwareBack();\n }\n };\n\n // We only add the listeners when drawer opens\n // This way we can make sure that the listener is added as late as possible\n // This will make sure that our handler will run first when back button is pressed\n const subscription = BackHandler.addEventListener(\n 'hardwareBackPress',\n handleHardwareBack\n );\n\n if (Platform.OS === 'web') {\n document?.body?.addEventListener?.('keyup', handleEscape);\n }\n\n return () => {\n subscription.remove();\n\n if (Platform.OS === 'web') {\n document?.body?.removeEventListener?.('keyup', handleEscape);\n }\n };\n }, [\n defaultStatus,\n drawerStatus,\n drawerType,\n handleDrawerClose,\n handleDrawerOpen,\n navigation,\n ]);\n\n const renderDrawerContent = () => {\n return (\n <DrawerPositionContext.Provider value={drawerPosition}>\n {drawerContent({\n state: state,\n navigation: navigation,\n descriptors: descriptors,\n })}\n </DrawerPositionContext.Provider>\n );\n };\n\n const renderSceneContent = () => {\n return (\n <MaybeScreenContainer\n enabled={detachInactiveScreens}\n hasTwoStates\n style={styles.content}\n >\n {state.routes.map((route, index) => {\n const descriptor = descriptors[route.key];\n const { lazy = true, unmountOnBlur } = descriptor.options;\n const isFocused = state.index === index;\n\n if (unmountOnBlur && !isFocused) {\n return null;\n }\n\n if (lazy && !loaded.includes(route.key) && !isFocused) {\n // Don't render a lazy screen if we've never navigated to it\n return null;\n }\n\n const {\n header = ({ layout, options }: DrawerHeaderProps) => (\n <Header\n {...options}\n layout={layout}\n title={getHeaderTitle(options, route.name)}\n headerLeft={\n options.headerLeft ??\n ((props) => <DrawerToggleButton {...props} />)\n }\n />\n ),\n sceneContainerStyle,\n } = descriptor.options;\n\n return (\n <MaybeScreen\n key={route.key}\n style={[StyleSheet.absoluteFill, { zIndex: isFocused ? 0 : -1 }]}\n visible={isFocused}\n enabled={detachInactiveScreens}\n >\n <Screen\n focused={isFocused}\n route={descriptor.route}\n navigation={descriptor.navigation}\n headerShown={descriptor.options.headerShown}\n headerTransparent={descriptor.options.headerTransparent}\n headerStatusBarHeight={descriptor.options.headerStatusBarHeight}\n header={header({\n layout: dimensions,\n route: descriptor.route,\n navigation:\n descriptor.navigation as DrawerNavigationProp<ParamListBase>,\n options: descriptor.options,\n })}\n style={sceneContainerStyle}\n >\n {descriptor.render()}\n </Screen>\n </MaybeScreen>\n );\n })}\n </MaybeScreenContainer>\n );\n };\n\n return (\n <DrawerStatusContext.Provider value={drawerStatus}>\n <Drawer\n open={drawerStatus !== 'closed'}\n onOpen={handleDrawerOpen}\n onClose={handleDrawerClose}\n gestureHandlerProps={gestureHandlerProps}\n swipeEnabled={swipeEnabled}\n swipeEdgeWidth={swipeEdgeWidth}\n swipeVelocityThreshold={500}\n swipeDistanceThreshold={swipeMinDistance}\n hideStatusBarOnOpen={drawerHideStatusBarOnOpen}\n statusBarAnimation={drawerStatusBarAnimation}\n keyboardDismissMode={keyboardDismissMode}\n drawerType={drawerType}\n drawerPosition={drawerPosition}\n drawerStyle={[\n {\n width: getDefaultDrawerWidth(dimensions),\n backgroundColor: colors.card,\n },\n drawerType === 'permanent' &&\n (drawerPosition === 'left'\n ? {\n borderRightColor: colors.border,\n borderRightWidth: StyleSheet.hairlineWidth,\n }\n : {\n borderLeftColor: colors.border,\n borderLeftWidth: StyleSheet.hairlineWidth,\n }),\n drawerStyle,\n ]}\n overlayStyle={{ backgroundColor: overlayColor }}\n renderDrawerContent={renderDrawerContent}\n renderSceneContent={renderSceneContent}\n dimensions={dimensions}\n />\n </DrawerStatusContext.Provider>\n );\n}\n\nexport default function DrawerView({ navigation, ...rest }: Props) {\n return (\n <SafeAreaProviderCompat>\n <GestureHandlerWrapper style={styles.content}>\n <DrawerViewBase navigation={navigation} {...rest} />\n </GestureHandlerWrapper>\n </SafeAreaProviderCompat>\n );\n}\n\nconst styles = StyleSheet.create({\n content: {\n flex: 1,\n },\n});\n"]}
|
|
@@ -120,7 +120,7 @@ function Drawer(_ref) {
|
|
|
120
120
|
hideStatusBar(true);
|
|
121
121
|
};
|
|
122
122
|
|
|
123
|
-
const
|
|
123
|
+
const onGestureFinish = () => {
|
|
124
124
|
endInteraction();
|
|
125
125
|
}; // FIXME: Currently hitSlop is broken when on Android when drawer is on right
|
|
126
126
|
// https://github.com/software-mansion/react-native-gesture-handler/issues/569
|
|
@@ -180,7 +180,9 @@ function Drawer(_ref) {
|
|
|
180
180
|
(event.velocityX === 0 ? event.translationX : event.velocityX) > 0 : // If swiped to left, open the drawer, otherwise close it
|
|
181
181
|
(event.velocityX === 0 ? event.translationX : event.velocityX) < 0 : open;
|
|
182
182
|
toggleDrawer(nextOpen, event.velocityX);
|
|
183
|
-
|
|
183
|
+
},
|
|
184
|
+
onFinish: () => {
|
|
185
|
+
(0, _reactNativeReanimated.runOnJS)(onGestureFinish)();
|
|
184
186
|
}
|
|
185
187
|
});
|
|
186
188
|
const translateX = (0, _reactNativeReanimated.useDerivedValue)(() => {
|
|
@@ -214,11 +216,13 @@ function Drawer(_ref) {
|
|
|
214
216
|
return translateX;
|
|
215
217
|
});
|
|
216
218
|
const drawerAnimatedStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => {
|
|
219
|
+
const distanceFromEdge = dimensions.width - drawerWidth;
|
|
217
220
|
return {
|
|
218
221
|
transform: drawerType === 'permanent' ? // Reanimated needs the property to be present, but it results in Browser bug
|
|
219
222
|
// https://bugs.chromium.org/p/chromium/issues/detail?id=20574
|
|
220
223
|
[] : [{
|
|
221
|
-
translateX:
|
|
224
|
+
translateX: // The drawer stays in place when `drawerType` is `back`
|
|
225
|
+
(drawerType === 'back' ? 0 : translateX.value) + (drawerPosition === 'left' ? _reactNative.I18nManager.isRTL ? -distanceFromEdge : 0 : _reactNative.I18nManager.isRTL ? 0 : distanceFromEdge)
|
|
222
226
|
}]
|
|
223
227
|
};
|
|
224
228
|
});
|
|
@@ -227,7 +231,8 @@ function Drawer(_ref) {
|
|
|
227
231
|
transform: drawerType === 'permanent' ? // Reanimated needs the property to be present, but it results in Browser bug
|
|
228
232
|
// https://bugs.chromium.org/p/chromium/issues/detail?id=20574
|
|
229
233
|
[] : [{
|
|
230
|
-
translateX:
|
|
234
|
+
translateX: // The screen content stays in place when `drawerType` is `front`
|
|
235
|
+
drawerType === 'front' ? 0 : translateX.value + drawerWidth * (drawerPosition === 'left' ? 1 : -1)
|
|
231
236
|
}]
|
|
232
237
|
};
|
|
233
238
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["Drawer.tsx"],"names":["SWIPE_DISTANCE_MINIMUM","DEFAULT_DRAWER_WIDTH","minmax","value","start","end","Math","min","max","Drawer","dimensions","drawerPosition","drawerStyle","drawerType","gestureHandlerProps","hideStatusBarOnOpen","keyboardDismissMode","onClose","onOpen","open","overlayStyle","renderDrawerContent","renderSceneContent","statusBarAnimation","swipeDistanceThreshold","swipeEdgeWidth","swipeEnabled","swipeVelocityThreshold","getDrawerWidth","width","StyleSheet","flatten","endsWith","percentage","Number","replace","isFinite","drawerWidth","isOpen","isRight","getDrawerTranslationX","React","useCallback","hideStatusBar","hide","StatusBar","setHidden","useEffect","interactionHandleRef","useRef","startInteraction","current","InteractionManager","createInteractionHandle","endInteraction","clearInteractionHandle","hideKeyboard","Keyboard","dismiss","onGestureStart","onGestureEnd","hitSlop","right","undefined","left","touchStartX","touchX","translationX","gestureState","GestureState","UNDETERMINED","toggleDrawer","velocity","translateX","stiffness","damping","mass","overshootClamping","restDisplacementThreshold","restSpeedThreshold","onGestureEvent","onStart","event","ctx","startX","state","x","onActive","onEnd","nextOpen","abs","velocityX","touchDistance","ACTIVE","drawerAnimatedStyle","transform","contentAnimatedStyle","progress","styles","main","flexDirection","content","Platform","OS","container","position","zIndex","create","top","bottom","maxWidth","flex","select","web","default","overflow"],"mappings":";;;;;;;AAAA;;AACA;;AAQA;;AAKA;;AAWA;;AACA;;;;;;;;;;AAEA,MAAMA,sBAAsB,GAAG,CAA/B;AACA,MAAMC,oBAAoB,GAAG,KAA7B;;AAEA,MAAMC,MAAM,GAAG,CAACC,KAAD,EAAgBC,KAAhB,EAA+BC,GAA/B,KAA+C;AAC5D;;AAEA,SAAOC,IAAI,CAACC,GAAL,CAASD,IAAI,CAACE,GAAL,CAASL,KAAT,EAAgBC,KAAhB,CAAT,EAAiCC,GAAjC,CAAP;AACD,CAJD;;AAMe,SAASI,MAAT,OAmBC;AAAA,MAnBe;AAC7BC,IAAAA,UAD6B;AAE7BC,IAAAA,cAF6B;AAG7BC,IAAAA,WAH6B;AAI7BC,IAAAA,UAJ6B;AAK7BC,IAAAA,mBAL6B;AAM7BC,IAAAA,mBAN6B;AAO7BC,IAAAA,mBAP6B;AAQ7BC,IAAAA,OAR6B;AAS7BC,IAAAA,MAT6B;AAU7BC,IAAAA,IAV6B;AAW7BC,IAAAA,YAX6B;AAY7BC,IAAAA,mBAZ6B;AAa7BC,IAAAA,kBAb6B;AAc7BC,IAAAA,kBAd6B;AAe7BC,IAAAA,sBAf6B;AAgB7BC,IAAAA,cAhB6B;AAiB7BC,IAAAA,Y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AAO,EAAE;AAAEC,QAAAA,QAAQ,EAAE;AAAZ;AAJQ,KAAhB;AAFC;AAVyB,CAAlB,CAAf","sourcesContent":["import * as React from 'react';\nimport {\n InteractionManager,\n Keyboard,\n Platform,\n StatusBar,\n StyleSheet,\n View,\n} from 'react-native';\nimport {\n PanGestureHandler,\n PanGestureHandlerGestureEvent,\n State as GestureState,\n} from 'react-native-gesture-handler';\nimport Animated, {\n interpolate,\n runOnJS,\n useAnimatedGestureHandler,\n useAnimatedStyle,\n useDerivedValue,\n useSharedValue,\n withSpring,\n} from 'react-native-reanimated';\n\nimport type { DrawerProps } from '../../types';\nimport DrawerProgressContext from '../../utils/DrawerProgressContext';\nimport Overlay from './Overlay';\n\nconst SWIPE_DISTANCE_MINIMUM = 5;\nconst DEFAULT_DRAWER_WIDTH = '80%';\n\nconst minmax = (value: number, start: number, end: number) => {\n 'worklet';\n\n return Math.min(Math.max(value, start), end);\n};\n\nexport default function Drawer({\n dimensions,\n drawerPosition,\n drawerStyle,\n drawerType,\n gestureHandlerProps,\n hideStatusBarOnOpen,\n keyboardDismissMode,\n onClose,\n onOpen,\n open,\n overlayStyle,\n renderDrawerContent,\n renderSceneContent,\n statusBarAnimation,\n swipeDistanceThreshold,\n swipeEdgeWidth,\n swipeEnabled,\n swipeVelocityThreshold,\n}: DrawerProps) {\n const getDrawerWidth = (): number => {\n const { width = DEFAULT_DRAWER_WIDTH } =\n StyleSheet.flatten(drawerStyle) || {};\n\n if (typeof width === 'string' && width.endsWith('%')) {\n // Try to calculate width if a percentage is given\n const percentage = Number(width.replace(/%$/, ''));\n\n if (Number.isFinite(percentage)) {\n return dimensions.width * (percentage / 100);\n }\n }\n\n return typeof width === 'number' ? width : 0;\n };\n\n const drawerWidth = getDrawerWidth();\n\n const isOpen = drawerType === 'permanent' ? true : open;\n const isRight = drawerPosition === 'right';\n\n const getDrawerTranslationX = React.useCallback(\n (open: boolean) => {\n 'worklet';\n\n if (drawerPosition === 'left') {\n return open ? 0 : -drawerWidth;\n }\n\n return open ? 0 : drawerWidth;\n },\n [drawerPosition, drawerWidth]\n );\n\n const hideStatusBar = React.useCallback(\n (hide: boolean) => {\n if (hideStatusBarOnOpen) {\n StatusBar.setHidden(hide, statusBarAnimation);\n }\n },\n [hideStatusBarOnOpen, statusBarAnimation]\n );\n\n React.useEffect(() => {\n hideStatusBar(isOpen);\n\n return () => hideStatusBar(false);\n }, [isOpen, hideStatusBarOnOpen, statusBarAnimation, hideStatusBar]);\n\n const interactionHandleRef = React.useRef<number | null>(null);\n\n const startInteraction = () => {\n interactionHandleRef.current = InteractionManager.createInteractionHandle();\n };\n\n const endInteraction = () => {\n if (interactionHandleRef.current != null) {\n InteractionManager.clearInteractionHandle(interactionHandleRef.current);\n interactionHandleRef.current = null;\n }\n };\n\n const hideKeyboard = () => {\n if (keyboardDismissMode === 'on-drag') {\n Keyboard.dismiss();\n }\n };\n\n const onGestureStart = () => {\n startInteraction();\n hideKeyboard();\n hideStatusBar(true);\n };\n\n const onGestureEnd = () => {\n endInteraction();\n };\n\n // FIXME: Currently hitSlop is broken when on Android when drawer is on right\n // https://github.com/software-mansion/react-native-gesture-handler/issues/569\n const hitSlop = isRight\n ? // Extend hitSlop to the side of the screen when drawer is closed\n // This lets the user drag the drawer from the side of the screen\n { right: 0, width: isOpen ? undefined : swipeEdgeWidth }\n : { left: 0, width: isOpen ? undefined : swipeEdgeWidth };\n\n const touchStartX = useSharedValue(0);\n const touchX = useSharedValue(0);\n const translationX = useSharedValue(getDrawerTranslationX(open));\n const gestureState = useSharedValue<GestureState>(GestureState.UNDETERMINED);\n\n const toggleDrawer = React.useCallback(\n (open: boolean, velocity?: number) => {\n 'worklet';\n\n const translateX = getDrawerTranslationX(open);\n\n touchStartX.value = 0;\n touchX.value = 0;\n translationX.value = withSpring(\n translateX,\n {\n velocity,\n stiffness: 1000,\n damping: 500,\n mass: 3,\n overshootClamping: true,\n restDisplacementThreshold: 0.01,\n restSpeedThreshold: 0.01,\n },\n () => {\n if (translationX.value === getDrawerTranslationX(true)) {\n runOnJS(onOpen)();\n } else if (translationX.value === getDrawerTranslationX(false)) {\n runOnJS(onClose)();\n }\n }\n );\n },\n [getDrawerTranslationX, onClose, onOpen, touchStartX, touchX, translationX]\n );\n\n React.useEffect(() => toggleDrawer(open), [open, toggleDrawer]);\n\n const onGestureEvent = useAnimatedGestureHandler<\n PanGestureHandlerGestureEvent,\n { startX: number }\n >({\n onStart: (event, ctx) => {\n ctx.startX = translationX.value;\n gestureState.value = event.state;\n touchStartX.value = event.x;\n\n runOnJS(onGestureStart)();\n },\n onActive: (event, ctx) => {\n touchX.value = event.x;\n translationX.value = ctx.startX + event.translationX;\n gestureState.value = event.state;\n },\n onEnd: (event) => {\n gestureState.value = event.state;\n\n const nextOpen =\n (Math.abs(event.translationX) > SWIPE_DISTANCE_MINIMUM &&\n Math.abs(event.translationX) > swipeVelocityThreshold) ||\n Math.abs(event.translationX) > swipeDistanceThreshold\n ? drawerPosition === 'left'\n ? // If swiped to right, open the drawer, otherwise close it\n (event.velocityX === 0 ? event.translationX : event.velocityX) > 0\n : // If swiped to left, open the drawer, otherwise close it\n (event.velocityX === 0 ? event.translationX : event.velocityX) < 0\n : open;\n\n toggleDrawer(nextOpen, event.velocityX);\n runOnJS(onGestureEnd)();\n },\n });\n\n const translateX = useDerivedValue(() => {\n // Comment stolen from react-native-gesture-handler/DrawerLayout\n //\n // While closing the drawer when user starts gesture outside of its area (in greyed\n // out part of the window), we want the drawer to follow only once finger reaches the\n // edge of the drawer.\n // E.g. on the diagram below drawer is illustrate by X signs and the greyed out area by\n // dots. The touch gesture starts at '*' and moves left, touch path is indicated by\n // an arrow pointing left\n // 1) +---------------+ 2) +---------------+ 3) +---------------+ 4) +---------------+\n // |XXXXXXXX|......| |XXXXXXXX|......| |XXXXXXXX|......| |XXXXX|.........|\n // |XXXXXXXX|......| |XXXXXXXX|......| |XXXXXXXX|......| |XXXXX|.........|\n // |XXXXXXXX|......| |XXXXXXXX|......| |XXXXXXXX|......| |XXXXX|.........|\n // |XXXXXXXX|......| |XXXXXXXX|.<-*..| |XXXXXXXX|<--*..| |XXXXX|<-----*..|\n // |XXXXXXXX|......| |XXXXXXXX|......| |XXXXXXXX|......| |XXXXX|.........|\n // |XXXXXXXX|......| |XXXXXXXX|......| |XXXXXXXX|......| |XXXXX|.........|\n // |XXXXXXXX|......| |XXXXXXXX|......| |XXXXXXXX|......| |XXXXX|.........|\n // +---------------+ +---------------+ +---------------+ +---------------+\n //\n // For the above to work properly we define animated value that will keep start position\n // of the gesture. Then we use that value to calculate how much we need to subtract from\n // the translationX. If the gesture started on the greyed out area we take the distance from the\n // edge of the drawer to the start position. Otherwise we don't subtract at all and the\n // drawer be pulled back as soon as you start the pan.\n //\n // This is used only when drawerType is \"front\"\n const touchDistance =\n drawerType === 'front' && gestureState.value === GestureState.ACTIVE\n ? minmax(\n drawerPosition === 'left'\n ? touchStartX.value - drawerWidth\n : dimensions.width - drawerWidth - touchStartX.value,\n 0,\n dimensions.width\n )\n : 0;\n\n const translateX =\n drawerPosition === 'left'\n ? minmax(translationX.value + touchDistance, -drawerWidth, 0)\n : minmax(translationX.value - touchDistance, 0, drawerWidth);\n\n return translateX;\n });\n\n const drawerAnimatedStyle = useAnimatedStyle(() => {\n return {\n transform:\n drawerType === 'permanent'\n ? // Reanimated needs the property to be present, but it results in Browser bug\n // https://bugs.chromium.org/p/chromium/issues/detail?id=20574\n []\n : [\n {\n translateX: drawerType === 'back' ? 0 : translateX.value,\n },\n ],\n };\n });\n\n const contentAnimatedStyle = useAnimatedStyle(() => {\n return {\n transform:\n drawerType === 'permanent'\n ? // Reanimated needs the property to be present, but it results in Browser bug\n // https://bugs.chromium.org/p/chromium/issues/detail?id=20574\n []\n : [\n {\n translateX:\n drawerType === 'front'\n ? 0\n : drawerPosition === 'left'\n ? drawerWidth + translateX.value\n : translateX.value - drawerWidth,\n },\n ],\n };\n });\n\n const progress = useDerivedValue(() => {\n return drawerType === 'permanent'\n ? 1\n : interpolate(\n translateX.value,\n [getDrawerTranslationX(false), getDrawerTranslationX(true)],\n [0, 1]\n );\n });\n\n return (\n <DrawerProgressContext.Provider value={progress}>\n <PanGestureHandler\n activeOffsetX={[-SWIPE_DISTANCE_MINIMUM, SWIPE_DISTANCE_MINIMUM]}\n failOffsetY={[-SWIPE_DISTANCE_MINIMUM, SWIPE_DISTANCE_MINIMUM]}\n hitSlop={hitSlop}\n enabled={drawerType !== 'permanent' && swipeEnabled}\n onGestureEvent={onGestureEvent}\n {...gestureHandlerProps}\n >\n {/* Immediate child of gesture handler needs to be an Animated.View */}\n <Animated.View\n style={[\n styles.main,\n {\n flexDirection:\n drawerType === 'permanent' && !isRight ? 'row-reverse' : 'row',\n },\n ]}\n >\n <Animated.View style={[styles.content, contentAnimatedStyle]}>\n <View\n accessibilityElementsHidden={isOpen && drawerType !== 'permanent'}\n importantForAccessibility={\n isOpen && drawerType !== 'permanent'\n ? 'no-hide-descendants'\n : 'auto'\n }\n style={styles.content}\n >\n {renderSceneContent()}\n </View>\n {drawerType !== 'permanent' ? (\n <Overlay\n progress={progress}\n onPress={() => toggleDrawer(false)}\n style={overlayStyle}\n />\n ) : null}\n </Animated.View>\n <Animated.View\n accessibilityViewIsModal={isOpen && drawerType !== 'permanent'}\n removeClippedSubviews={Platform.OS !== 'ios'}\n style={[\n styles.container,\n {\n position: drawerType === 'permanent' ? 'relative' : 'absolute',\n zIndex: drawerType === 'back' ? -1 : 0,\n },\n drawerAnimatedStyle,\n drawerStyle as any,\n ]}\n >\n {renderDrawerContent()}\n </Animated.View>\n </Animated.View>\n </PanGestureHandler>\n </DrawerProgressContext.Provider>\n );\n}\n\nconst styles = StyleSheet.create({\n container: {\n top: 0,\n bottom: 0,\n maxWidth: '100%',\n width: DEFAULT_DRAWER_WIDTH,\n },\n content: {\n flex: 1,\n },\n main: {\n flex: 1,\n ...Platform.select({\n // FIXME: We need to hide `overflowX` on Web so the translated content doesn't show offscreen.\n // But adding `overflowX: 'hidden'` prevents content from collapsing the URL bar.\n web: null,\n default: { overflow: 'hidden' },\n }),\n },\n});\n"]}
|
|
1
|
+
{"version":3,"sources":["Drawer.tsx"],"names":["SWIPE_DISTANCE_MINIMUM","DEFAULT_DRAWER_WIDTH","minmax","value","start","end","Math","min","max","Drawer","dimensions","drawerPosition","drawerStyle","drawerType","gestureHandlerProps","hideStatusBarOnOpen","keyboardDismissMode","onClose","onOpen","open","overlayStyle","renderDrawerContent","renderSceneContent","statusBarAnimation","swipeDistanceThreshold","swipeEdgeWidth","swipeEnabled","swipeVelocityThreshold","getDrawerWidth","width","StyleSheet","flatten","endsWith","percentage","Number","replace","isFinite","drawerWidth","isOpen","isRight","getDrawerTranslationX","React","useCallback","hideStatusBar","hide","StatusBar","setHidden","useEffect","interactionHandleRef","useRef","startInteraction","current","InteractionManager","createInteractionHandle","endInteraction","clearInteractionHandle","hideKeyboard","Keyboard","dismiss","onGestureStart","onGestureFinish","hitSlop","right","undefined","left","touchStartX","touchX","translationX","gestureState","GestureState","UNDETERMINED","toggleDrawer","velocity","translateX","stiffness","damping","mass","overshootClamping","restDisplacementThreshold","restSpeedThreshold","onGestureEvent","onStart","event","ctx","startX","state","x","onActive","onEnd","nextOpen","abs","velocityX","onFinish","touchDistance","ACTIVE","drawerAnimatedStyle","distanceFromEdge","transform","I18nManager","isRTL","contentAnimatedStyle","progress","styles","main","flexDirection","content","Platform","OS","container","position","zIndex","create","top","bottom","maxWidth","flex","select","web","default","overflow"],"mappings":";;;;;;;AAAA;;AACA;;AASA;;AAKA;;AAWA;;AACA;;;;;;;;;;AAEA,MAAMA,sBAAsB,GAAG,CAA/B;AACA,MAAMC,oBAAoB,GAAG,KAA7B;;AAEA,MAAMC,MAAM,GAAG,CAACC,KAAD,EAAgBC,KAAhB,EAA+BC,GAA/B,KAA+C;AAC5D;;AAEA,SAAOC,IAAI,CAACC,GAAL,CAASD,IAAI,CAACE,GAAL,CAASL,KAAT,EAAgBC,KAAhB,CAAT,EAAiCC,GAAjC,CAAP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K,EAAE,CACLL,MAAM,CAACM,SADF,EAEL;AACEC,MAAAA,QAAQ,EAAEhG,UAAU,KAAK,WAAf,GAA6B,UAA7B,GAA0C,UADtD;AAEEiG,MAAAA,MAAM,EAAEjG,UAAU,KAAK,MAAf,GAAwB,CAAC,CAAzB,GAA6B;AAFvC,KAFK,EAMLkF,mBANK,EAOLnF,WAPK;AAHT,KAaGS,mBAAmB,EAbtB,CA7BF,CATF,CADF,CADF;AA2DD;;AAED,MAAMiF,MAAM,GAAGxE,wBAAWiF,MAAX,CAAkB;AAC/BH,EAAAA,SAAS,EAAE;AACTI,IAAAA,GAAG,EAAE,CADI;AAETC,IAAAA,MAAM,EAAE,CAFC;AAGTC,IAAAA,QAAQ,EAAE,MAHD;AAITrF,IAAAA,KAAK,EAAE5B;AAJE,GADoB;AAO/BwG,EAAAA,OAAO,EAAE;AACPU,IAAAA,IAAI,EAAE;AADC,GAPsB;AAU/BZ,EAAAA,IAAI,EAAE;AACJY,IAAAA,IAAI,EAAE,CADF;AAEJ,OAAGT,sBAASU,MAAT,CAAgB;AACjB;AACA;AACAC,MAAAA,GAAG,EAAE,IAHY;AAIjBC,MAAAA,OAAO,EAAE;AAAEC,QAAAA,QAAQ,EAAE;AAAZ;AAJQ,KAAhB;AAFC;AAVyB,CAAlB,CAAf","sourcesContent":["import * as React from 'react';\nimport {\n I18nManager,\n InteractionManager,\n Keyboard,\n Platform,\n StatusBar,\n StyleSheet,\n View,\n} from 'react-native';\nimport {\n PanGestureHandler,\n PanGestureHandlerGestureEvent,\n State as GestureState,\n} from 'react-native-gesture-handler';\nimport Animated, {\n interpolate,\n runOnJS,\n useAnimatedGestureHandler,\n useAnimatedStyle,\n useDerivedValue,\n useSharedValue,\n withSpring,\n} from 'react-native-reanimated';\n\nimport type { DrawerProps } from '../../types';\nimport DrawerProgressContext from '../../utils/DrawerProgressContext';\nimport Overlay from './Overlay';\n\nconst SWIPE_DISTANCE_MINIMUM = 5;\nconst DEFAULT_DRAWER_WIDTH = '80%';\n\nconst minmax = (value: number, start: number, end: number) => {\n 'worklet';\n\n return Math.min(Math.max(value, start), end);\n};\n\nexport default function Drawer({\n dimensions,\n drawerPosition,\n drawerStyle,\n drawerType,\n gestureHandlerProps,\n hideStatusBarOnOpen,\n keyboardDismissMode,\n onClose,\n onOpen,\n open,\n overlayStyle,\n renderDrawerContent,\n renderSceneContent,\n statusBarAnimation,\n swipeDistanceThreshold,\n swipeEdgeWidth,\n swipeEnabled,\n swipeVelocityThreshold,\n}: DrawerProps) {\n const getDrawerWidth = (): number => {\n const { width = DEFAULT_DRAWER_WIDTH } =\n StyleSheet.flatten(drawerStyle) || {};\n\n if (typeof width === 'string' && width.endsWith('%')) {\n // Try to calculate width if a percentage is given\n const percentage = Number(width.replace(/%$/, ''));\n\n if (Number.isFinite(percentage)) {\n return dimensions.width * (percentage / 100);\n }\n }\n\n return typeof width === 'number' ? width : 0;\n };\n\n const drawerWidth = getDrawerWidth();\n\n const isOpen = drawerType === 'permanent' ? true : open;\n const isRight = drawerPosition === 'right';\n\n const getDrawerTranslationX = React.useCallback(\n (open: boolean) => {\n 'worklet';\n\n if (drawerPosition === 'left') {\n return open ? 0 : -drawerWidth;\n }\n\n return open ? 0 : drawerWidth;\n },\n [drawerPosition, drawerWidth]\n );\n\n const hideStatusBar = React.useCallback(\n (hide: boolean) => {\n if (hideStatusBarOnOpen) {\n StatusBar.setHidden(hide, statusBarAnimation);\n }\n },\n [hideStatusBarOnOpen, statusBarAnimation]\n );\n\n React.useEffect(() => {\n hideStatusBar(isOpen);\n\n return () => hideStatusBar(false);\n }, [isOpen, hideStatusBarOnOpen, statusBarAnimation, hideStatusBar]);\n\n const interactionHandleRef = React.useRef<number | null>(null);\n\n const startInteraction = () => {\n interactionHandleRef.current = InteractionManager.createInteractionHandle();\n };\n\n const endInteraction = () => {\n if (interactionHandleRef.current != null) {\n InteractionManager.clearInteractionHandle(interactionHandleRef.current);\n interactionHandleRef.current = null;\n }\n };\n\n const hideKeyboard = () => {\n if (keyboardDismissMode === 'on-drag') {\n Keyboard.dismiss();\n }\n };\n\n const onGestureStart = () => {\n startInteraction();\n hideKeyboard();\n hideStatusBar(true);\n };\n\n const onGestureFinish = () => {\n endInteraction();\n };\n\n // FIXME: Currently hitSlop is broken when on Android when drawer is on right\n // https://github.com/software-mansion/react-native-gesture-handler/issues/569\n const hitSlop = isRight\n ? // Extend hitSlop to the side of the screen when drawer is closed\n // This lets the user drag the drawer from the side of the screen\n { right: 0, width: isOpen ? undefined : swipeEdgeWidth }\n : { left: 0, width: isOpen ? undefined : swipeEdgeWidth };\n\n const touchStartX = useSharedValue(0);\n const touchX = useSharedValue(0);\n const translationX = useSharedValue(getDrawerTranslationX(open));\n const gestureState = useSharedValue<GestureState>(GestureState.UNDETERMINED);\n\n const toggleDrawer = React.useCallback(\n (open: boolean, velocity?: number) => {\n 'worklet';\n\n const translateX = getDrawerTranslationX(open);\n\n touchStartX.value = 0;\n touchX.value = 0;\n translationX.value = withSpring(\n translateX,\n {\n velocity,\n stiffness: 1000,\n damping: 500,\n mass: 3,\n overshootClamping: true,\n restDisplacementThreshold: 0.01,\n restSpeedThreshold: 0.01,\n },\n () => {\n if (translationX.value === getDrawerTranslationX(true)) {\n runOnJS(onOpen)();\n } else if (translationX.value === getDrawerTranslationX(false)) {\n runOnJS(onClose)();\n }\n }\n );\n },\n [getDrawerTranslationX, onClose, onOpen, touchStartX, touchX, translationX]\n );\n\n React.useEffect(() => toggleDrawer(open), [open, toggleDrawer]);\n\n const onGestureEvent = useAnimatedGestureHandler<\n PanGestureHandlerGestureEvent,\n { startX: number }\n >({\n onStart: (event, ctx) => {\n ctx.startX = translationX.value;\n gestureState.value = event.state;\n touchStartX.value = event.x;\n\n runOnJS(onGestureStart)();\n },\n onActive: (event, ctx) => {\n touchX.value = event.x;\n translationX.value = ctx.startX + event.translationX;\n gestureState.value = event.state;\n },\n onEnd: (event) => {\n gestureState.value = event.state;\n\n const nextOpen =\n (Math.abs(event.translationX) > SWIPE_DISTANCE_MINIMUM &&\n Math.abs(event.translationX) > swipeVelocityThreshold) ||\n Math.abs(event.translationX) > swipeDistanceThreshold\n ? drawerPosition === 'left'\n ? // If swiped to right, open the drawer, otherwise close it\n (event.velocityX === 0 ? event.translationX : event.velocityX) > 0\n : // If swiped to left, open the drawer, otherwise close it\n (event.velocityX === 0 ? event.translationX : event.velocityX) < 0\n : open;\n\n toggleDrawer(nextOpen, event.velocityX);\n },\n onFinish: () => {\n runOnJS(onGestureFinish)();\n },\n });\n\n const translateX = useDerivedValue(() => {\n // Comment stolen from react-native-gesture-handler/DrawerLayout\n //\n // While closing the drawer when user starts gesture outside of its area (in greyed\n // out part of the window), we want the drawer to follow only once finger reaches the\n // edge of the drawer.\n // E.g. on the diagram below drawer is illustrate by X signs and the greyed out area by\n // dots. The touch gesture starts at '*' and moves left, touch path is indicated by\n // an arrow pointing left\n // 1) +---------------+ 2) +---------------+ 3) +---------------+ 4) +---------------+\n // |XXXXXXXX|......| |XXXXXXXX|......| |XXXXXXXX|......| |XXXXX|.........|\n // |XXXXXXXX|......| |XXXXXXXX|......| |XXXXXXXX|......| |XXXXX|.........|\n // |XXXXXXXX|......| |XXXXXXXX|......| |XXXXXXXX|......| |XXXXX|.........|\n // |XXXXXXXX|......| |XXXXXXXX|.<-*..| |XXXXXXXX|<--*..| |XXXXX|<-----*..|\n // |XXXXXXXX|......| |XXXXXXXX|......| |XXXXXXXX|......| |XXXXX|.........|\n // |XXXXXXXX|......| |XXXXXXXX|......| |XXXXXXXX|......| |XXXXX|.........|\n // |XXXXXXXX|......| |XXXXXXXX|......| |XXXXXXXX|......| |XXXXX|.........|\n // +---------------+ +---------------+ +---------------+ +---------------+\n //\n // For the above to work properly we define animated value that will keep start position\n // of the gesture. Then we use that value to calculate how much we need to subtract from\n // the translationX. If the gesture started on the greyed out area we take the distance from the\n // edge of the drawer to the start position. Otherwise we don't subtract at all and the\n // drawer be pulled back as soon as you start the pan.\n //\n // This is used only when drawerType is \"front\"\n const touchDistance =\n drawerType === 'front' && gestureState.value === GestureState.ACTIVE\n ? minmax(\n drawerPosition === 'left'\n ? touchStartX.value - drawerWidth\n : dimensions.width - drawerWidth - touchStartX.value,\n 0,\n dimensions.width\n )\n : 0;\n\n const translateX =\n drawerPosition === 'left'\n ? minmax(translationX.value + touchDistance, -drawerWidth, 0)\n : minmax(translationX.value - touchDistance, 0, drawerWidth);\n\n return translateX;\n });\n\n const drawerAnimatedStyle = useAnimatedStyle(() => {\n const distanceFromEdge = dimensions.width - drawerWidth;\n\n return {\n transform:\n drawerType === 'permanent'\n ? // Reanimated needs the property to be present, but it results in Browser bug\n // https://bugs.chromium.org/p/chromium/issues/detail?id=20574\n []\n : [\n {\n translateX:\n // The drawer stays in place when `drawerType` is `back`\n (drawerType === 'back' ? 0 : translateX.value) +\n (drawerPosition === 'left'\n ? I18nManager.isRTL\n ? -distanceFromEdge\n : 0\n : I18nManager.isRTL\n ? 0\n : distanceFromEdge),\n },\n ],\n };\n });\n\n const contentAnimatedStyle = useAnimatedStyle(() => {\n return {\n transform:\n drawerType === 'permanent'\n ? // Reanimated needs the property to be present, but it results in Browser bug\n // https://bugs.chromium.org/p/chromium/issues/detail?id=20574\n []\n : [\n {\n translateX:\n // The screen content stays in place when `drawerType` is `front`\n drawerType === 'front'\n ? 0\n : translateX.value +\n drawerWidth * (drawerPosition === 'left' ? 1 : -1),\n },\n ],\n };\n });\n\n const progress = useDerivedValue(() => {\n return drawerType === 'permanent'\n ? 1\n : interpolate(\n translateX.value,\n [getDrawerTranslationX(false), getDrawerTranslationX(true)],\n [0, 1]\n );\n });\n\n return (\n <DrawerProgressContext.Provider value={progress}>\n <PanGestureHandler\n activeOffsetX={[-SWIPE_DISTANCE_MINIMUM, SWIPE_DISTANCE_MINIMUM]}\n failOffsetY={[-SWIPE_DISTANCE_MINIMUM, SWIPE_DISTANCE_MINIMUM]}\n hitSlop={hitSlop}\n enabled={drawerType !== 'permanent' && swipeEnabled}\n onGestureEvent={onGestureEvent}\n {...gestureHandlerProps}\n >\n {/* Immediate child of gesture handler needs to be an Animated.View */}\n <Animated.View\n style={[\n styles.main,\n {\n flexDirection:\n drawerType === 'permanent' && !isRight ? 'row-reverse' : 'row',\n },\n ]}\n >\n <Animated.View style={[styles.content, contentAnimatedStyle]}>\n <View\n accessibilityElementsHidden={isOpen && drawerType !== 'permanent'}\n importantForAccessibility={\n isOpen && drawerType !== 'permanent'\n ? 'no-hide-descendants'\n : 'auto'\n }\n style={styles.content}\n >\n {renderSceneContent()}\n </View>\n {drawerType !== 'permanent' ? (\n <Overlay\n progress={progress}\n onPress={() => toggleDrawer(false)}\n style={overlayStyle}\n />\n ) : null}\n </Animated.View>\n <Animated.View\n accessibilityViewIsModal={isOpen && drawerType !== 'permanent'}\n removeClippedSubviews={Platform.OS !== 'ios'}\n style={[\n styles.container,\n {\n position: drawerType === 'permanent' ? 'relative' : 'absolute',\n zIndex: drawerType === 'back' ? -1 : 0,\n },\n drawerAnimatedStyle,\n drawerStyle as any,\n ]}\n >\n {renderDrawerContent()}\n </Animated.View>\n </Animated.View>\n </PanGestureHandler>\n </DrawerProgressContext.Provider>\n );\n}\n\nconst styles = StyleSheet.create({\n container: {\n top: 0,\n bottom: 0,\n maxWidth: '100%',\n width: DEFAULT_DRAWER_WIDTH,\n },\n content: {\n flex: 1,\n },\n main: {\n flex: 1,\n ...Platform.select({\n // FIXME: We need to hide `overflowX` on Web so the translated content doesn't show offscreen.\n // But adding `overflowX: 'hidden'` prevents content from collapsing the URL bar.\n web: null,\n default: { overflow: 'hidden' },\n }),\n },\n});\n"]}
|
|
@@ -4,7 +4,7 @@ import { getHeaderTitle, Header, SafeAreaProviderCompat, Screen } from '@react-n
|
|
|
4
4
|
import { DrawerActions, useTheme } from '@react-navigation/native';
|
|
5
5
|
import * as React from 'react';
|
|
6
6
|
import { BackHandler, I18nManager, Platform, StyleSheet, View } from 'react-native';
|
|
7
|
-
import
|
|
7
|
+
import * as Reanimated from 'react-native-reanimated';
|
|
8
8
|
import { useSafeAreaFrame } from 'react-native-safe-area-context';
|
|
9
9
|
import DrawerPositionContext from '../utils/DrawerPositionContext';
|
|
10
10
|
import DrawerStatusContext from '../utils/DrawerStatusContext';
|
|
@@ -36,7 +36,7 @@ const getDefaultDrawerWidth = _ref => {
|
|
|
36
36
|
const GestureHandlerWrapper = GestureHandlerRootView !== null && GestureHandlerRootView !== void 0 ? GestureHandlerRootView : View;
|
|
37
37
|
|
|
38
38
|
function DrawerViewBase(_ref2) {
|
|
39
|
-
var
|
|
39
|
+
var _Reanimated$isConfigu;
|
|
40
40
|
|
|
41
41
|
let {
|
|
42
42
|
state,
|
|
@@ -45,11 +45,9 @@ function DrawerViewBase(_ref2) {
|
|
|
45
45
|
defaultStatus,
|
|
46
46
|
drawerContent = props => /*#__PURE__*/React.createElement(DrawerContent, props),
|
|
47
47
|
detachInactiveScreens = Platform.OS === 'web' || Platform.OS === 'android' || Platform.OS === 'ios',
|
|
48
|
-
//
|
|
49
|
-
// @ts-expect-error
|
|
50
|
-
useLegacyImplementation = !global.nativeCallSyncHook || // Reanimated 2 is not configured
|
|
48
|
+
// Reanimated 2 is not configured
|
|
51
49
|
// @ts-expect-error: the type definitions are incomplete
|
|
52
|
-
!((
|
|
50
|
+
useLegacyImplementation = !((_Reanimated$isConfigu = Reanimated.isConfigured) !== null && _Reanimated$isConfigu !== void 0 && _Reanimated$isConfigu.call(Reanimated))
|
|
53
51
|
} = _ref2;
|
|
54
52
|
const Drawer = useLegacyImplementation ? require('./legacy/Drawer').default : require('./modern/Drawer').default;
|
|
55
53
|
const focusedRouteKey = state.routes[state.index].key;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["DrawerView.tsx"],"names":["getHeaderTitle","Header","SafeAreaProviderCompat","Screen","DrawerActions","useTheme","React","BackHandler","I18nManager","Platform","StyleSheet","View","Animated","useSafeAreaFrame","DrawerPositionContext","DrawerStatusContext","getDrawerStatusFromState","DrawerContent","DrawerToggleButton","GestureHandlerRootView","MaybeScreen","MaybeScreenContainer","getDefaultDrawerWidth","height","width","smallerAxisSize","Math","min","isLandscape","isTablet","appBarHeight","OS","maxWidth","GestureHandlerWrapper","DrawerViewBase","state","navigation","descriptors","defaultStatus","drawerContent","props","detachInactiveScreens","useLegacyImplementation","global","nativeCallSyncHook","isConfigured","Drawer","require","default","focusedRouteKey","routes","index","key","drawerHideStatusBarOnOpen","drawerPosition","isRTL","drawerStatusBarAnimation","drawerStyle","drawerType","select","ios","gestureHandlerProps","keyboardDismissMode","overlayColor","swipeEdgeWidth","swipeEnabled","swipeMinDistance","options","loaded","setLoaded","useState","includes","dimensions","colors","drawerStatus","handleDrawerOpen","useCallback","dispatch","openDrawer","target","handleDrawerClose","closeDrawer","useEffect","handleHardwareBack","isFocused","handleEscape","e","subscription","addEventListener","document","body","remove","removeEventListener","renderDrawerContent","renderSceneContent","styles","content","map","route","descriptor","lazy","unmountOnBlur","header","layout","name","headerLeft","sceneContainerStyle","absoluteFill","zIndex","headerShown","headerTransparent","headerStatusBarHeight","render","backgroundColor","card","borderRightColor","border","borderRightWidth","hairlineWidth","borderLeftColor","borderLeftWidth","DrawerView","rest","create","flex"],"mappings":";;AAAA,SACEA,cADF,EAEEC,MAFF,EAGEC,sBAHF,EAIEC,MAJF,QAKO,4BALP;AAMA,SACEC,aADF,EAKEC,QALF,QAMO,0BANP;AAOA,OAAO,KAAKC,KAAZ,MAAuB,OAAvB;AACA,SACEC,WADF,EAEEC,WAFF,EAGEC,QAHF,EAIEC,UAJF,EAKEC,IALF,QAMO,cANP;AAOA,OAAOC,QAAP,MAAqB,yBAArB;AACA,SAASC,gBAAT,QAAiC,gCAAjC;AAWA,OAAOC,qBAAP,MAAkC,gCAAlC;AACA,OAAOC,mBAAP,MAAgC,8BAAhC;AACA,OAAOC,wBAAP,MAAqC,mCAArC;AACA,OAAOC,aAAP,MAA0B,iBAA1B;AACA,OAAOC,kBAAP,MAA+B,sBAA/B;AACA,SAASC,sBAAT,QAAuC,kBA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CAAC2C,MAD1B;AAEEI,MAAAA,eAAe,EAAE9G,UAAU,CAAC4G;AAF9B,KANN,CALW,EAeX7D,WAfW,CAdf;AA+BE,IAAA,YAAY,EAAE;AAAEwD,MAAAA,eAAe,EAAElD;AAAnB,KA/BhB;AAgCE,IAAA,mBAAmB,EAAE8B,mBAhCvB;AAiCE,IAAA,kBAAkB,EAAEC,kBAjCtB;AAkCE,IAAA,UAAU,EAAEtB;AAlCd,IADF,CADF;AAwCD;;AAED,eAAe,SAASiD,UAAT,QAAoD;AAAA,MAAhC;AAAErF,IAAAA,UAAF;AAAc,OAAGsF;AAAjB,GAAgC;AACjE,sBACE,oBAAC,sBAAD,qBACE,oBAAC,qBAAD;AAAuB,IAAA,KAAK,EAAE3B,MAAM,CAACC;AAArC,kBACE,oBAAC,cAAD;AAAgB,IAAA,UAAU,EAAE5D;AAA5B,KAA4CsF,IAA5C,EADF,CADF,CADF;AAOD;AAED,MAAM3B,MAAM,GAAGrF,UAAU,CAACiH,MAAX,CAAkB;AAC/B3B,EAAAA,OAAO,EAAE;AACP4B,IAAAA,IAAI,EAAE;AADC;AADsB,CAAlB,CAAf","sourcesContent":["import {\n getHeaderTitle,\n Header,\n SafeAreaProviderCompat,\n Screen,\n} from '@react-navigation/elements';\nimport {\n DrawerActions,\n DrawerNavigationState,\n DrawerStatus,\n ParamListBase,\n useTheme,\n} from '@react-navigation/native';\nimport * as React from 'react';\nimport {\n BackHandler,\n I18nManager,\n Platform,\n StyleSheet,\n View,\n} from 'react-native';\nimport Animated from 'react-native-reanimated';\nimport { useSafeAreaFrame } from 'react-native-safe-area-context';\n\nimport type {\n DrawerContentComponentProps,\n DrawerDescriptorMap,\n DrawerHeaderProps,\n DrawerNavigationConfig,\n DrawerNavigationHelpers,\n DrawerNavigationProp,\n DrawerProps,\n} from '../types';\nimport DrawerPositionContext from '../utils/DrawerPositionContext';\nimport DrawerStatusContext from '../utils/DrawerStatusContext';\nimport getDrawerStatusFromState from '../utils/getDrawerStatusFromState';\nimport DrawerContent from './DrawerContent';\nimport DrawerToggleButton from './DrawerToggleButton';\nimport { GestureHandlerRootView } from './GestureHandler';\nimport { MaybeScreen, MaybeScreenContainer } from './ScreenFallback';\n\ntype Props = DrawerNavigationConfig & {\n defaultStatus: DrawerStatus;\n state: DrawerNavigationState<ParamListBase>;\n navigation: DrawerNavigationHelpers;\n descriptors: DrawerDescriptorMap;\n};\n\nconst getDefaultDrawerWidth = ({\n height,\n width,\n}: {\n height: number;\n width: number;\n}) => {\n /*\n * Default drawer width is screen width - header height\n * with a max width of 280 on mobile and 320 on tablet\n * https://material.io/components/navigation-drawer\n */\n const smallerAxisSize = Math.min(height, width);\n const isLandscape = width > height;\n const isTablet = smallerAxisSize >= 600;\n const appBarHeight = Platform.OS === 'ios' ? (isLandscape ? 32 : 44) : 56;\n const maxWidth = isTablet ? 320 : 280;\n\n return Math.min(smallerAxisSize - appBarHeight, maxWidth);\n};\n\nconst GestureHandlerWrapper = GestureHandlerRootView ?? View;\n\nfunction DrawerViewBase({\n state,\n navigation,\n descriptors,\n defaultStatus,\n drawerContent = (props: DrawerContentComponentProps) => (\n <DrawerContent {...props} />\n ),\n detachInactiveScreens = Platform.OS === 'web' ||\n Platform.OS === 'android' ||\n Platform.OS === 'ios',\n // Running in chrome debugger\n // @ts-expect-error\n useLegacyImplementation = !global.nativeCallSyncHook ||\n // Reanimated 2 is not configured\n // @ts-expect-error: the type definitions are incomplete\n !Animated.isConfigured?.(),\n}: Props) {\n const Drawer: React.ComponentType<DrawerProps> = useLegacyImplementation\n ? require('./legacy/Drawer').default\n : require('./modern/Drawer').default;\n\n const focusedRouteKey = state.routes[state.index].key;\n const {\n drawerHideStatusBarOnOpen = false,\n drawerPosition = I18nManager.isRTL ? 'right' : 'left',\n drawerStatusBarAnimation = 'slide',\n drawerStyle,\n drawerType = Platform.select({ ios: 'slide', default: 'front' }),\n gestureHandlerProps,\n keyboardDismissMode = 'on-drag',\n overlayColor = 'rgba(0, 0, 0, 0.5)',\n swipeEdgeWidth = 32,\n swipeEnabled = Platform.OS !== 'web' &&\n Platform.OS !== 'windows' &&\n Platform.OS !== 'macos',\n swipeMinDistance = 60,\n } = descriptors[focusedRouteKey].options;\n\n const [loaded, setLoaded] = React.useState([focusedRouteKey]);\n\n if (!loaded.includes(focusedRouteKey)) {\n setLoaded([...loaded, focusedRouteKey]);\n }\n\n const dimensions = useSafeAreaFrame();\n\n const { colors } = useTheme();\n\n const drawerStatus = getDrawerStatusFromState(state);\n\n const handleDrawerOpen = React.useCallback(() => {\n navigation.dispatch({\n ...DrawerActions.openDrawer(),\n target: state.key,\n });\n }, [navigation, state.key]);\n\n const handleDrawerClose = React.useCallback(() => {\n navigation.dispatch({\n ...DrawerActions.closeDrawer(),\n target: state.key,\n });\n }, [navigation, state.key]);\n\n React.useEffect(() => {\n if (drawerStatus === defaultStatus || drawerType === 'permanent') {\n return;\n }\n\n const handleHardwareBack = () => {\n // We shouldn't handle the back button if the parent screen isn't focused\n // This will avoid the drawer overriding event listeners from a focused screen\n if (!navigation.isFocused()) {\n return false;\n }\n\n if (defaultStatus === 'open') {\n handleDrawerOpen();\n } else {\n handleDrawerClose();\n }\n\n return true;\n };\n\n const handleEscape = (e: KeyboardEvent) => {\n if (e.key === 'Escape') {\n handleHardwareBack();\n }\n };\n\n // We only add the listeners when drawer opens\n // This way we can make sure that the listener is added as late as possible\n // This will make sure that our handler will run first when back button is pressed\n const subscription = BackHandler.addEventListener(\n 'hardwareBackPress',\n handleHardwareBack\n );\n\n if (Platform.OS === 'web') {\n document?.body?.addEventListener?.('keyup', handleEscape);\n }\n\n return () => {\n subscription.remove();\n\n if (Platform.OS === 'web') {\n document?.body?.removeEventListener?.('keyup', handleEscape);\n }\n };\n }, [\n defaultStatus,\n drawerStatus,\n drawerType,\n handleDrawerClose,\n handleDrawerOpen,\n navigation,\n ]);\n\n const renderDrawerContent = () => {\n return (\n <DrawerPositionContext.Provider value={drawerPosition}>\n {drawerContent({\n state: state,\n navigation: navigation,\n descriptors: descriptors,\n })}\n </DrawerPositionContext.Provider>\n );\n };\n\n const renderSceneContent = () => {\n return (\n <MaybeScreenContainer\n enabled={detachInactiveScreens}\n hasTwoStates\n style={styles.content}\n >\n {state.routes.map((route, index) => {\n const descriptor = descriptors[route.key];\n const { lazy = true, unmountOnBlur } = descriptor.options;\n const isFocused = state.index === index;\n\n if (unmountOnBlur && !isFocused) {\n return null;\n }\n\n if (lazy && !loaded.includes(route.key) && !isFocused) {\n // Don't render a lazy screen if we've never navigated to it\n return null;\n }\n\n const {\n header = ({ layout, options }: DrawerHeaderProps) => (\n <Header\n {...options}\n layout={layout}\n title={getHeaderTitle(options, route.name)}\n headerLeft={\n options.headerLeft ??\n ((props) => <DrawerToggleButton {...props} />)\n }\n />\n ),\n sceneContainerStyle,\n } = descriptor.options;\n\n return (\n <MaybeScreen\n key={route.key}\n style={[StyleSheet.absoluteFill, { zIndex: isFocused ? 0 : -1 }]}\n visible={isFocused}\n enabled={detachInactiveScreens}\n >\n <Screen\n focused={isFocused}\n route={descriptor.route}\n navigation={descriptor.navigation}\n headerShown={descriptor.options.headerShown}\n headerTransparent={descriptor.options.headerTransparent}\n headerStatusBarHeight={descriptor.options.headerStatusBarHeight}\n header={header({\n layout: dimensions,\n route: descriptor.route,\n navigation:\n descriptor.navigation as DrawerNavigationProp<ParamListBase>,\n options: descriptor.options,\n })}\n style={sceneContainerStyle}\n >\n {descriptor.render()}\n </Screen>\n </MaybeScreen>\n );\n })}\n </MaybeScreenContainer>\n );\n };\n\n return (\n <DrawerStatusContext.Provider value={drawerStatus}>\n <Drawer\n open={drawerStatus !== 'closed'}\n onOpen={handleDrawerOpen}\n onClose={handleDrawerClose}\n gestureHandlerProps={gestureHandlerProps}\n swipeEnabled={swipeEnabled}\n swipeEdgeWidth={swipeEdgeWidth}\n swipeVelocityThreshold={500}\n swipeDistanceThreshold={swipeMinDistance}\n hideStatusBarOnOpen={drawerHideStatusBarOnOpen}\n statusBarAnimation={drawerStatusBarAnimation}\n keyboardDismissMode={keyboardDismissMode}\n drawerType={drawerType}\n drawerPosition={drawerPosition}\n drawerStyle={[\n {\n width: getDefaultDrawerWidth(dimensions),\n backgroundColor: colors.card,\n },\n drawerType === 'permanent' &&\n (drawerPosition === 'left'\n ? {\n borderRightColor: colors.border,\n borderRightWidth: StyleSheet.hairlineWidth,\n }\n : {\n borderLeftColor: colors.border,\n borderLeftWidth: StyleSheet.hairlineWidth,\n }),\n drawerStyle,\n ]}\n overlayStyle={{ backgroundColor: overlayColor }}\n renderDrawerContent={renderDrawerContent}\n renderSceneContent={renderSceneContent}\n dimensions={dimensions}\n />\n </DrawerStatusContext.Provider>\n );\n}\n\nexport default function DrawerView({ navigation, ...rest }: Props) {\n return (\n <SafeAreaProviderCompat>\n <GestureHandlerWrapper style={styles.content}>\n <DrawerViewBase navigation={navigation} {...rest} />\n </GestureHandlerWrapper>\n </SafeAreaProviderCompat>\n );\n}\n\nconst styles = StyleSheet.create({\n content: {\n flex: 1,\n },\n});\n"]}
|
|
1
|
+
{"version":3,"sources":["DrawerView.tsx"],"names":["getHeaderTitle","Header","SafeAreaProviderCompat","Screen","DrawerActions","useTheme","React","BackHandler","I18nManager","Platform","StyleSheet","View","Reanimated","useSafeAreaFrame","DrawerPositionContext","DrawerStatusContext","getDrawerStatusFromState","DrawerContent","DrawerToggleButton","GestureHandlerRootView","MaybeScreen","MaybeScreenContainer","getDefaultDrawerWidth","height","width","smallerAxisSize","Math","min","isLandscape","isTablet","appBarHeight","OS","maxWidth","GestureHandlerWrapper","DrawerViewBase","state","navigation","descriptors","defaultStatus","drawerContent","props","detachInactiveScreens","useLegacyImplementation","isConfigured","Drawer","require","default","focusedRouteKey","routes","index","key","drawerHideStatusBarOnOpen","drawerPosition","isRTL","drawerStatusBarAnimation","drawerStyle","drawerType","select","ios","gestureHandlerProps","keyboardDismissMode","overlayColor","swipeEdgeWidth","swipeEnabled","swipeMinDistance","options","loaded","setLoaded","useState","includes","dimensions","colors","drawerStatus","handleDrawerOpen","useCallback","dispatch","openDrawer","target","handleDrawerClose","closeDrawer","useEffect","handleHardwareBack","isFocused","handleEscape","e","subscription","addEventListener","document","body","remove","removeEventListener","renderDrawerContent","renderSceneContent","styles","content","map","route","descriptor","lazy","unmountOnBlur","header","layout","name","headerLeft","sceneContainerStyle","absoluteFill","zIndex","headerShown","headerTransparent","headerStatusBarHeight","render","backgroundColor","card","borderRightColor","border","borderRightWidth","hairlineWidth","borderLeftColor","borderLeftWidth","DrawerView","rest","create","flex"],"mappings":";;AAAA,SACEA,cADF,EAEEC,MAFF,EAGEC,sBAHF,EAIEC,MAJF,QAKO,4BALP;AAMA,SACEC,aADF,EAKEC,QALF,QAMO,0BANP;AAOA,OAAO,KAAKC,KAAZ,MAAuB,OAAvB;AACA,SACEC,WADF,EAEEC,WAFF,EAGEC,QAHF,EAIEC,UAJF,EAKEC,IALF,QAMO,cANP;AAOA,OAAO,KAAKC,UAAZ,MAA4B,yBAA5B;AACA,SAASC,gBAAT,QAAiC,gCAAjC;AAWA,OAAOC,qBAAP,MAAkC,gCAAlC;AACA,OAAOC,mBAAP,MAAgC,8BAAhC;AACA,OAAOC,wBAAP,MAAqC,mCAArC;AACA,OAAOC,aAAP,MAA0B,iBAA1B;AACA,OAAOC,kBAAP,MAA+B,sBAA/B;AACA,SAASC,sBAAT,QAAuC,kBAAvC;AACA,SAASC,WAAT,EAAsBC,oBAAtB,QAAkD,kBAAlD;;AASA,MAAMC,qBAAqB,GAAG,QAMxB;AAAA,MANyB;AAC7BC,IAAAA,MAD6B;AAE7BC,IAAAA;AAF6B,GAMzB;;AACJ;AACF;AACA;AACA;AACA;AACE,QAAMC,eAAe,GAAGC,IAAI,CAACC,GAAL,CAASJ,MAAT,EAAiBC,KAAjB,CAAxB;AACA,QAAMI,WAAW,GAAGJ,KAAK,GAAGD,MAA5B;AACA,QAAMM,QAAQ,GAAGJ,eAAe,IAAI,GAApC;AACA,QAAMK,YAAY,GAAGrB,QAAQ,CAACsB,EAAT,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,KAAK,EAAE3B,MAAM,CAACC;AAArC,kBACE,oBAAC,cAAD;AAAgB,IAAA,UAAU,EAAE1D;AAA5B,KAA4CoF,IAA5C,EADF,CADF,CADF;AAOD;AAED,MAAM3B,MAAM,GAAGnF,UAAU,CAAC+G,MAAX,CAAkB;AAC/B3B,EAAAA,OAAO,EAAE;AACP4B,IAAAA,IAAI,EAAE;AADC;AADsB,CAAlB,CAAf","sourcesContent":["import {\n getHeaderTitle,\n Header,\n SafeAreaProviderCompat,\n Screen,\n} from '@react-navigation/elements';\nimport {\n DrawerActions,\n DrawerNavigationState,\n DrawerStatus,\n ParamListBase,\n useTheme,\n} from '@react-navigation/native';\nimport * as React from 'react';\nimport {\n BackHandler,\n I18nManager,\n Platform,\n StyleSheet,\n View,\n} from 'react-native';\nimport * as Reanimated from 'react-native-reanimated';\nimport { useSafeAreaFrame } from 'react-native-safe-area-context';\n\nimport type {\n DrawerContentComponentProps,\n DrawerDescriptorMap,\n DrawerHeaderProps,\n DrawerNavigationConfig,\n DrawerNavigationHelpers,\n DrawerNavigationProp,\n DrawerProps,\n} from '../types';\nimport DrawerPositionContext from '../utils/DrawerPositionContext';\nimport DrawerStatusContext from '../utils/DrawerStatusContext';\nimport getDrawerStatusFromState from '../utils/getDrawerStatusFromState';\nimport DrawerContent from './DrawerContent';\nimport DrawerToggleButton from './DrawerToggleButton';\nimport { GestureHandlerRootView } from './GestureHandler';\nimport { MaybeScreen, MaybeScreenContainer } from './ScreenFallback';\n\ntype Props = DrawerNavigationConfig & {\n defaultStatus: DrawerStatus;\n state: DrawerNavigationState<ParamListBase>;\n navigation: DrawerNavigationHelpers;\n descriptors: DrawerDescriptorMap;\n};\n\nconst getDefaultDrawerWidth = ({\n height,\n width,\n}: {\n height: number;\n width: number;\n}) => {\n /*\n * Default drawer width is screen width - header height\n * with a max width of 280 on mobile and 320 on tablet\n * https://material.io/components/navigation-drawer\n */\n const smallerAxisSize = Math.min(height, width);\n const isLandscape = width > height;\n const isTablet = smallerAxisSize >= 600;\n const appBarHeight = Platform.OS === 'ios' ? (isLandscape ? 32 : 44) : 56;\n const maxWidth = isTablet ? 320 : 280;\n\n return Math.min(smallerAxisSize - appBarHeight, maxWidth);\n};\n\nconst GestureHandlerWrapper = GestureHandlerRootView ?? View;\n\nfunction DrawerViewBase({\n state,\n navigation,\n descriptors,\n defaultStatus,\n drawerContent = (props: DrawerContentComponentProps) => (\n <DrawerContent {...props} />\n ),\n detachInactiveScreens = Platform.OS === 'web' ||\n Platform.OS === 'android' ||\n Platform.OS === 'ios',\n // Reanimated 2 is not configured\n // @ts-expect-error: the type definitions are incomplete\n useLegacyImplementation = !Reanimated.isConfigured?.(),\n}: Props) {\n const Drawer: React.ComponentType<DrawerProps> = useLegacyImplementation\n ? require('./legacy/Drawer').default\n : require('./modern/Drawer').default;\n\n const focusedRouteKey = state.routes[state.index].key;\n const {\n drawerHideStatusBarOnOpen = false,\n drawerPosition = I18nManager.isRTL ? 'right' : 'left',\n drawerStatusBarAnimation = 'slide',\n drawerStyle,\n drawerType = Platform.select({ ios: 'slide', default: 'front' }),\n gestureHandlerProps,\n keyboardDismissMode = 'on-drag',\n overlayColor = 'rgba(0, 0, 0, 0.5)',\n swipeEdgeWidth = 32,\n swipeEnabled = Platform.OS !== 'web' &&\n Platform.OS !== 'windows' &&\n Platform.OS !== 'macos',\n swipeMinDistance = 60,\n } = descriptors[focusedRouteKey].options;\n\n const [loaded, setLoaded] = React.useState([focusedRouteKey]);\n\n if (!loaded.includes(focusedRouteKey)) {\n setLoaded([...loaded, focusedRouteKey]);\n }\n\n const dimensions = useSafeAreaFrame();\n\n const { colors } = useTheme();\n\n const drawerStatus = getDrawerStatusFromState(state);\n\n const handleDrawerOpen = React.useCallback(() => {\n navigation.dispatch({\n ...DrawerActions.openDrawer(),\n target: state.key,\n });\n }, [navigation, state.key]);\n\n const handleDrawerClose = React.useCallback(() => {\n navigation.dispatch({\n ...DrawerActions.closeDrawer(),\n target: state.key,\n });\n }, [navigation, state.key]);\n\n React.useEffect(() => {\n if (drawerStatus === defaultStatus || drawerType === 'permanent') {\n return;\n }\n\n const handleHardwareBack = () => {\n // We shouldn't handle the back button if the parent screen isn't focused\n // This will avoid the drawer overriding event listeners from a focused screen\n if (!navigation.isFocused()) {\n return false;\n }\n\n if (defaultStatus === 'open') {\n handleDrawerOpen();\n } else {\n handleDrawerClose();\n }\n\n return true;\n };\n\n const handleEscape = (e: KeyboardEvent) => {\n if (e.key === 'Escape') {\n handleHardwareBack();\n }\n };\n\n // We only add the listeners when drawer opens\n // This way we can make sure that the listener is added as late as possible\n // This will make sure that our handler will run first when back button is pressed\n const subscription = BackHandler.addEventListener(\n 'hardwareBackPress',\n handleHardwareBack\n );\n\n if (Platform.OS === 'web') {\n document?.body?.addEventListener?.('keyup', handleEscape);\n }\n\n return () => {\n subscription.remove();\n\n if (Platform.OS === 'web') {\n document?.body?.removeEventListener?.('keyup', handleEscape);\n }\n };\n }, [\n defaultStatus,\n drawerStatus,\n drawerType,\n handleDrawerClose,\n handleDrawerOpen,\n navigation,\n ]);\n\n const renderDrawerContent = () => {\n return (\n <DrawerPositionContext.Provider value={drawerPosition}>\n {drawerContent({\n state: state,\n navigation: navigation,\n descriptors: descriptors,\n })}\n </DrawerPositionContext.Provider>\n );\n };\n\n const renderSceneContent = () => {\n return (\n <MaybeScreenContainer\n enabled={detachInactiveScreens}\n hasTwoStates\n style={styles.content}\n >\n {state.routes.map((route, index) => {\n const descriptor = descriptors[route.key];\n const { lazy = true, unmountOnBlur } = descriptor.options;\n const isFocused = state.index === index;\n\n if (unmountOnBlur && !isFocused) {\n return null;\n }\n\n if (lazy && !loaded.includes(route.key) && !isFocused) {\n // Don't render a lazy screen if we've never navigated to it\n return null;\n }\n\n const {\n header = ({ layout, options }: DrawerHeaderProps) => (\n <Header\n {...options}\n layout={layout}\n title={getHeaderTitle(options, route.name)}\n headerLeft={\n options.headerLeft ??\n ((props) => <DrawerToggleButton {...props} />)\n }\n />\n ),\n sceneContainerStyle,\n } = descriptor.options;\n\n return (\n <MaybeScreen\n key={route.key}\n style={[StyleSheet.absoluteFill, { zIndex: isFocused ? 0 : -1 }]}\n visible={isFocused}\n enabled={detachInactiveScreens}\n >\n <Screen\n focused={isFocused}\n route={descriptor.route}\n navigation={descriptor.navigation}\n headerShown={descriptor.options.headerShown}\n headerTransparent={descriptor.options.headerTransparent}\n headerStatusBarHeight={descriptor.options.headerStatusBarHeight}\n header={header({\n layout: dimensions,\n route: descriptor.route,\n navigation:\n descriptor.navigation as DrawerNavigationProp<ParamListBase>,\n options: descriptor.options,\n })}\n style={sceneContainerStyle}\n >\n {descriptor.render()}\n </Screen>\n </MaybeScreen>\n );\n })}\n </MaybeScreenContainer>\n );\n };\n\n return (\n <DrawerStatusContext.Provider value={drawerStatus}>\n <Drawer\n open={drawerStatus !== 'closed'}\n onOpen={handleDrawerOpen}\n onClose={handleDrawerClose}\n gestureHandlerProps={gestureHandlerProps}\n swipeEnabled={swipeEnabled}\n swipeEdgeWidth={swipeEdgeWidth}\n swipeVelocityThreshold={500}\n swipeDistanceThreshold={swipeMinDistance}\n hideStatusBarOnOpen={drawerHideStatusBarOnOpen}\n statusBarAnimation={drawerStatusBarAnimation}\n keyboardDismissMode={keyboardDismissMode}\n drawerType={drawerType}\n drawerPosition={drawerPosition}\n drawerStyle={[\n {\n width: getDefaultDrawerWidth(dimensions),\n backgroundColor: colors.card,\n },\n drawerType === 'permanent' &&\n (drawerPosition === 'left'\n ? {\n borderRightColor: colors.border,\n borderRightWidth: StyleSheet.hairlineWidth,\n }\n : {\n borderLeftColor: colors.border,\n borderLeftWidth: StyleSheet.hairlineWidth,\n }),\n drawerStyle,\n ]}\n overlayStyle={{ backgroundColor: overlayColor }}\n renderDrawerContent={renderDrawerContent}\n renderSceneContent={renderSceneContent}\n dimensions={dimensions}\n />\n </DrawerStatusContext.Provider>\n );\n}\n\nexport default function DrawerView({ navigation, ...rest }: Props) {\n return (\n <SafeAreaProviderCompat>\n <GestureHandlerWrapper style={styles.content}>\n <DrawerViewBase navigation={navigation} {...rest} />\n </GestureHandlerWrapper>\n </SafeAreaProviderCompat>\n );\n}\n\nconst styles = StyleSheet.create({\n content: {\n flex: 1,\n },\n});\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
2
|
|
|
3
3
|
import * as React from 'react';
|
|
4
|
-
import { InteractionManager, Keyboard, Platform, StatusBar, StyleSheet, View } from 'react-native';
|
|
4
|
+
import { I18nManager, InteractionManager, Keyboard, Platform, StatusBar, StyleSheet, View } from 'react-native';
|
|
5
5
|
import { PanGestureHandler, State as GestureState } from 'react-native-gesture-handler';
|
|
6
6
|
import Animated, { interpolate, runOnJS, useAnimatedGestureHandler, useAnimatedStyle, useDerivedValue, useSharedValue, withSpring } from 'react-native-reanimated';
|
|
7
7
|
import DrawerProgressContext from '../../utils/DrawerProgressContext';
|
|
@@ -100,7 +100,7 @@ export default function Drawer(_ref) {
|
|
|
100
100
|
hideStatusBar(true);
|
|
101
101
|
};
|
|
102
102
|
|
|
103
|
-
const
|
|
103
|
+
const onGestureFinish = () => {
|
|
104
104
|
endInteraction();
|
|
105
105
|
}; // FIXME: Currently hitSlop is broken when on Android when drawer is on right
|
|
106
106
|
// https://github.com/software-mansion/react-native-gesture-handler/issues/569
|
|
@@ -160,7 +160,9 @@ export default function Drawer(_ref) {
|
|
|
160
160
|
(event.velocityX === 0 ? event.translationX : event.velocityX) > 0 : // If swiped to left, open the drawer, otherwise close it
|
|
161
161
|
(event.velocityX === 0 ? event.translationX : event.velocityX) < 0 : open;
|
|
162
162
|
toggleDrawer(nextOpen, event.velocityX);
|
|
163
|
-
|
|
163
|
+
},
|
|
164
|
+
onFinish: () => {
|
|
165
|
+
runOnJS(onGestureFinish)();
|
|
164
166
|
}
|
|
165
167
|
});
|
|
166
168
|
const translateX = useDerivedValue(() => {
|
|
@@ -194,11 +196,13 @@ export default function Drawer(_ref) {
|
|
|
194
196
|
return translateX;
|
|
195
197
|
});
|
|
196
198
|
const drawerAnimatedStyle = useAnimatedStyle(() => {
|
|
199
|
+
const distanceFromEdge = dimensions.width - drawerWidth;
|
|
197
200
|
return {
|
|
198
201
|
transform: drawerType === 'permanent' ? // Reanimated needs the property to be present, but it results in Browser bug
|
|
199
202
|
// https://bugs.chromium.org/p/chromium/issues/detail?id=20574
|
|
200
203
|
[] : [{
|
|
201
|
-
translateX:
|
|
204
|
+
translateX: // The drawer stays in place when `drawerType` is `back`
|
|
205
|
+
(drawerType === 'back' ? 0 : translateX.value) + (drawerPosition === 'left' ? I18nManager.isRTL ? -distanceFromEdge : 0 : I18nManager.isRTL ? 0 : distanceFromEdge)
|
|
202
206
|
}]
|
|
203
207
|
};
|
|
204
208
|
});
|
|
@@ -207,7 +211,8 @@ export default function Drawer(_ref) {
|
|
|
207
211
|
transform: drawerType === 'permanent' ? // Reanimated needs the property to be present, but it results in Browser bug
|
|
208
212
|
// https://bugs.chromium.org/p/chromium/issues/detail?id=20574
|
|
209
213
|
[] : [{
|
|
210
|
-
translateX:
|
|
214
|
+
translateX: // The screen content stays in place when `drawerType` is `front`
|
|
215
|
+
drawerType === 'front' ? 0 : translateX.value + drawerWidth * (drawerPosition === 'left' ? 1 : -1)
|
|
211
216
|
}]
|
|
212
217
|
};
|
|
213
218
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["Drawer.tsx"],"names":["React","InteractionManager","Keyboard","Platform","StatusBar","StyleSheet","View","PanGestureHandler","State","GestureState","Animated","interpolate","runOnJS","useAnimatedGestureHandler","useAnimatedStyle","useDerivedValue","useSharedValue","withSpring","DrawerProgressContext","Overlay","SWIPE_DISTANCE_MINIMUM","DEFAULT_DRAWER_WIDTH","minmax","value","start","end","Math","min","max","Drawer","dimensions","drawerPosition","drawerStyle","drawerType","gestureHandlerProps","hideStatusBarOnOpen","keyboardDismissMode","onClose","onOpen","open","overlayStyle","renderDrawerContent","renderSceneContent","statusBarAnimation","swipeDistanceThreshold","swipeEdgeWidth","swipeEnabled","swipeVelocityThreshold","getDrawerWidth","width","flatten","endsWith","percentage","Number","replace","isFinite","drawerWidth","isOpen","isRight","getDrawerTranslationX","useCallback","hideStatusBar","hide","setHidden","useEffect","interactionHandleRef","useRef","startInteraction","current","createInteractionHandle","endInteraction","clearInteractionHandle","hideKeyboard","dismiss","onGestureStart","onGestureEnd","hitSlop","right","undefined","left","touchStartX","touchX","translationX","gestureState","UNDETERMINED","toggleDrawer","velocity","translateX","stiffness","damping","mass","overshootClamping","restDisplacementThreshold","restSpeedThreshold","onGestureEvent","onStart","event","ctx","startX","state","x","onActive","onEnd","nextOpen","abs","velocityX","touchDistance","ACTIVE","drawerAnimatedStyle","transform","contentAnimatedStyle","progress","styles","main","flexDirection","content","OS","container","position","zIndex","create","top","bottom","maxWidth","flex","select","web","default","overflow"],"mappings":";;AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,SACEC,kBADF,EAEEC,QAFF,EAGEC,QAHF,EAIEC,SAJF,EAKEC,UALF,EAMEC,IANF,QAOO,cAPP;AAQA,SACEC,iBADF,EAGEC,KAAK,IAAIC,YAHX,QAIO,8BAJP;AAKA,OAAOC,QAAP,IACEC,WADF,EAEEC,OAFF,EAGEC,yBAHF,EAIEC,gBAJF,EAKEC,eALF,EAMEC,cANF,EAOEC,UAPF,QAQO,yBARP;AAWA,OAAOC,qBAAP,MAAkC,mCAAlC;AACA,OAAOC,OAAP,MAAoB,WAApB;AAEA,MAAMC,sBAAsB,GAAG,CAA/B;AACA,MAAMC,oBAAoB,GAAG,KAA7B;;AAEA,MAAMC,MAAM,GAAG,CAACC,KAAD,EAAgBC,KAAhB,EAA+BC,GAA/B,KAA+C;AAC5D;;AAEA,SAAOC,IAAI,CAACC,GAAL,CAASD,IAAI,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,EAAE9B,QAAQ,CAACiH,EAAT,KAAgB,KAFzC;AAGE,IAAA,KAAK,EAAE,CACLJ,MAAM,CAACK,SADF,EAEL;AACEC,MAAAA,QAAQ,EAAErF,UAAU,KAAK,WAAf,GAA6B,UAA7B,GAA0C,UADtD;AAEEsF,MAAAA,MAAM,EAAEtF,UAAU,KAAK,MAAf,GAAwB,CAAC,CAAzB,GAA6B;AAFvC,KAFK,EAML2E,mBANK,EAOL5E,WAPK;AAHT,KAaGS,mBAAmB,EAbtB,CA7BF,CATF,CADF,CADF;AA2DD;AAED,MAAMuE,MAAM,GAAG3G,UAAU,CAACmH,MAAX,CAAkB;AAC/BH,EAAAA,SAAS,EAAE;AACTI,IAAAA,GAAG,EAAE,CADI;AAETC,IAAAA,MAAM,EAAE,CAFC;AAGTC,IAAAA,QAAQ,EAAE,MAHD;AAIT1E,IAAAA,KAAK,EAAE5B;AAJE,GADoB;AAO/B8F,EAAAA,OAAO,EAAE;AACPS,IAAAA,IAAI,EAAE;AADC,GAPsB;AAU/BX,EAAAA,IAAI,EAAE;AACJW,IAAAA,IAAI,EAAE,CADF;AAEJ,OAAGzH,QAAQ,CAAC0H,MAAT,CAAgB;AACjB;AACA;AACAC,MAAAA,GAAG,EAAE,IAHY;AAIjBC,MAAAA,OAAO,EAAE;AAAEC,QAAAA,QAAQ,EAAE;AAAZ;AAJQ,KAAhB;AAFC;AAVyB,CAAlB,CAAf","sourcesContent":["import * as React from 'react';\nimport {\n InteractionManager,\n Keyboard,\n Platform,\n StatusBar,\n StyleSheet,\n View,\n} from 'react-native';\nimport {\n PanGestureHandler,\n PanGestureHandlerGestureEvent,\n State as GestureState,\n} from 'react-native-gesture-handler';\nimport Animated, {\n interpolate,\n runOnJS,\n useAnimatedGestureHandler,\n useAnimatedStyle,\n useDerivedValue,\n useSharedValue,\n withSpring,\n} from 'react-native-reanimated';\n\nimport type { DrawerProps } from '../../types';\nimport DrawerProgressContext from '../../utils/DrawerProgressContext';\nimport Overlay from './Overlay';\n\nconst SWIPE_DISTANCE_MINIMUM = 5;\nconst DEFAULT_DRAWER_WIDTH = '80%';\n\nconst minmax = (value: number, start: number, end: number) => {\n 'worklet';\n\n return Math.min(Math.max(value, start), end);\n};\n\nexport default function Drawer({\n dimensions,\n drawerPosition,\n drawerStyle,\n drawerType,\n gestureHandlerProps,\n hideStatusBarOnOpen,\n keyboardDismissMode,\n onClose,\n onOpen,\n open,\n overlayStyle,\n renderDrawerContent,\n renderSceneContent,\n statusBarAnimation,\n swipeDistanceThreshold,\n swipeEdgeWidth,\n swipeEnabled,\n swipeVelocityThreshold,\n}: DrawerProps) {\n const getDrawerWidth = (): number => {\n const { width = DEFAULT_DRAWER_WIDTH } =\n StyleSheet.flatten(drawerStyle) || {};\n\n if (typeof width === 'string' && width.endsWith('%')) {\n // Try to calculate width if a percentage is given\n const percentage = Number(width.replace(/%$/, ''));\n\n if (Number.isFinite(percentage)) {\n return dimensions.width * (percentage / 100);\n }\n }\n\n return typeof width === 'number' ? width : 0;\n };\n\n const drawerWidth = getDrawerWidth();\n\n const isOpen = drawerType === 'permanent' ? true : open;\n const isRight = drawerPosition === 'right';\n\n const getDrawerTranslationX = React.useCallback(\n (open: boolean) => {\n 'worklet';\n\n if (drawerPosition === 'left') {\n return open ? 0 : -drawerWidth;\n }\n\n return open ? 0 : drawerWidth;\n },\n [drawerPosition, drawerWidth]\n );\n\n const hideStatusBar = React.useCallback(\n (hide: boolean) => {\n if (hideStatusBarOnOpen) {\n StatusBar.setHidden(hide, statusBarAnimation);\n }\n },\n [hideStatusBarOnOpen, statusBarAnimation]\n );\n\n React.useEffect(() => {\n hideStatusBar(isOpen);\n\n return () => hideStatusBar(false);\n }, [isOpen, hideStatusBarOnOpen, statusBarAnimation, hideStatusBar]);\n\n const interactionHandleRef = React.useRef<number | null>(null);\n\n const startInteraction = () => {\n interactionHandleRef.current = InteractionManager.createInteractionHandle();\n };\n\n const endInteraction = () => {\n if (interactionHandleRef.current != null) {\n InteractionManager.clearInteractionHandle(interactionHandleRef.current);\n interactionHandleRef.current = null;\n }\n };\n\n const hideKeyboard = () => {\n if (keyboardDismissMode === 'on-drag') {\n Keyboard.dismiss();\n }\n };\n\n const onGestureStart = () => {\n startInteraction();\n hideKeyboard();\n hideStatusBar(true);\n };\n\n const onGestureEnd = () => {\n endInteraction();\n };\n\n // FIXME: Currently hitSlop is broken when on Android when drawer is on right\n // https://github.com/software-mansion/react-native-gesture-handler/issues/569\n const hitSlop = isRight\n ? // Extend hitSlop to the side of the screen when drawer is closed\n // This lets the user drag the drawer from the side of the screen\n { right: 0, width: isOpen ? undefined : swipeEdgeWidth }\n : { left: 0, width: isOpen ? undefined : swipeEdgeWidth };\n\n const touchStartX = useSharedValue(0);\n const touchX = useSharedValue(0);\n const translationX = useSharedValue(getDrawerTranslationX(open));\n const gestureState = useSharedValue<GestureState>(GestureState.UNDETERMINED);\n\n const toggleDrawer = React.useCallback(\n (open: boolean, velocity?: number) => {\n 'worklet';\n\n const translateX = getDrawerTranslationX(open);\n\n touchStartX.value = 0;\n touchX.value = 0;\n translationX.value = withSpring(\n translateX,\n {\n velocity,\n stiffness: 1000,\n damping: 500,\n mass: 3,\n overshootClamping: true,\n restDisplacementThreshold: 0.01,\n restSpeedThreshold: 0.01,\n },\n () => {\n if (translationX.value === getDrawerTranslationX(true)) {\n runOnJS(onOpen)();\n } else if (translationX.value === getDrawerTranslationX(false)) {\n runOnJS(onClose)();\n }\n }\n );\n },\n [getDrawerTranslationX, onClose, onOpen, touchStartX, touchX, translationX]\n );\n\n React.useEffect(() => toggleDrawer(open), [open, toggleDrawer]);\n\n const onGestureEvent = useAnimatedGestureHandler<\n PanGestureHandlerGestureEvent,\n { startX: number }\n >({\n onStart: (event, ctx) => {\n ctx.startX = translationX.value;\n gestureState.value = event.state;\n touchStartX.value = event.x;\n\n runOnJS(onGestureStart)();\n },\n onActive: (event, ctx) => {\n touchX.value = event.x;\n translationX.value = ctx.startX + event.translationX;\n gestureState.value = event.state;\n },\n onEnd: (event) => {\n gestureState.value = event.state;\n\n const nextOpen =\n (Math.abs(event.translationX) > SWIPE_DISTANCE_MINIMUM &&\n Math.abs(event.translationX) > swipeVelocityThreshold) ||\n Math.abs(event.translationX) > swipeDistanceThreshold\n ? drawerPosition === 'left'\n ? // If swiped to right, open the drawer, otherwise close it\n (event.velocityX === 0 ? event.translationX : event.velocityX) > 0\n : // If swiped to left, open the drawer, otherwise close it\n (event.velocityX === 0 ? event.translationX : event.velocityX) < 0\n : open;\n\n toggleDrawer(nextOpen, event.velocityX);\n runOnJS(onGestureEnd)();\n },\n });\n\n const translateX = useDerivedValue(() => {\n // Comment stolen from react-native-gesture-handler/DrawerLayout\n //\n // While closing the drawer when user starts gesture outside of its area (in greyed\n // out part of the window), we want the drawer to follow only once finger reaches the\n // edge of the drawer.\n // E.g. on the diagram below drawer is illustrate by X signs and the greyed out area by\n // dots. The touch gesture starts at '*' and moves left, touch path is indicated by\n // an arrow pointing left\n // 1) +---------------+ 2) +---------------+ 3) +---------------+ 4) +---------------+\n // |XXXXXXXX|......| |XXXXXXXX|......| |XXXXXXXX|......| |XXXXX|.........|\n // |XXXXXXXX|......| |XXXXXXXX|......| |XXXXXXXX|......| |XXXXX|.........|\n // |XXXXXXXX|......| |XXXXXXXX|......| |XXXXXXXX|......| |XXXXX|.........|\n // |XXXXXXXX|......| |XXXXXXXX|.<-*..| |XXXXXXXX|<--*..| |XXXXX|<-----*..|\n // |XXXXXXXX|......| |XXXXXXXX|......| |XXXXXXXX|......| |XXXXX|.........|\n // |XXXXXXXX|......| |XXXXXXXX|......| |XXXXXXXX|......| |XXXXX|.........|\n // |XXXXXXXX|......| |XXXXXXXX|......| |XXXXXXXX|......| |XXXXX|.........|\n // +---------------+ +---------------+ +---------------+ +---------------+\n //\n // For the above to work properly we define animated value that will keep start position\n // of the gesture. Then we use that value to calculate how much we need to subtract from\n // the translationX. If the gesture started on the greyed out area we take the distance from the\n // edge of the drawer to the start position. Otherwise we don't subtract at all and the\n // drawer be pulled back as soon as you start the pan.\n //\n // This is used only when drawerType is \"front\"\n const touchDistance =\n drawerType === 'front' && gestureState.value === GestureState.ACTIVE\n ? minmax(\n drawerPosition === 'left'\n ? touchStartX.value - drawerWidth\n : dimensions.width - drawerWidth - touchStartX.value,\n 0,\n dimensions.width\n )\n : 0;\n\n const translateX =\n drawerPosition === 'left'\n ? minmax(translationX.value + touchDistance, -drawerWidth, 0)\n : minmax(translationX.value - touchDistance, 0, drawerWidth);\n\n return translateX;\n });\n\n const drawerAnimatedStyle = useAnimatedStyle(() => {\n return {\n transform:\n drawerType === 'permanent'\n ? // Reanimated needs the property to be present, but it results in Browser bug\n // https://bugs.chromium.org/p/chromium/issues/detail?id=20574\n []\n : [\n {\n translateX: drawerType === 'back' ? 0 : translateX.value,\n },\n ],\n };\n });\n\n const contentAnimatedStyle = useAnimatedStyle(() => {\n return {\n transform:\n drawerType === 'permanent'\n ? // Reanimated needs the property to be present, but it results in Browser bug\n // https://bugs.chromium.org/p/chromium/issues/detail?id=20574\n []\n : [\n {\n translateX:\n drawerType === 'front'\n ? 0\n : drawerPosition === 'left'\n ? drawerWidth + translateX.value\n : translateX.value - drawerWidth,\n },\n ],\n };\n });\n\n const progress = useDerivedValue(() => {\n return drawerType === 'permanent'\n ? 1\n : interpolate(\n translateX.value,\n [getDrawerTranslationX(false), getDrawerTranslationX(true)],\n [0, 1]\n );\n });\n\n return (\n <DrawerProgressContext.Provider value={progress}>\n <PanGestureHandler\n activeOffsetX={[-SWIPE_DISTANCE_MINIMUM, SWIPE_DISTANCE_MINIMUM]}\n failOffsetY={[-SWIPE_DISTANCE_MINIMUM, SWIPE_DISTANCE_MINIMUM]}\n hitSlop={hitSlop}\n enabled={drawerType !== 'permanent' && swipeEnabled}\n onGestureEvent={onGestureEvent}\n {...gestureHandlerProps}\n >\n {/* Immediate child of gesture handler needs to be an Animated.View */}\n <Animated.View\n style={[\n styles.main,\n {\n flexDirection:\n drawerType === 'permanent' && !isRight ? 'row-reverse' : 'row',\n },\n ]}\n >\n <Animated.View style={[styles.content, contentAnimatedStyle]}>\n <View\n accessibilityElementsHidden={isOpen && drawerType !== 'permanent'}\n importantForAccessibility={\n isOpen && drawerType !== 'permanent'\n ? 'no-hide-descendants'\n : 'auto'\n }\n style={styles.content}\n >\n {renderSceneContent()}\n </View>\n {drawerType !== 'permanent' ? (\n <Overlay\n progress={progress}\n onPress={() => toggleDrawer(false)}\n style={overlayStyle}\n />\n ) : null}\n </Animated.View>\n <Animated.View\n accessibilityViewIsModal={isOpen && drawerType !== 'permanent'}\n removeClippedSubviews={Platform.OS !== 'ios'}\n style={[\n styles.container,\n {\n position: drawerType === 'permanent' ? 'relative' : 'absolute',\n zIndex: drawerType === 'back' ? -1 : 0,\n },\n drawerAnimatedStyle,\n drawerStyle as any,\n ]}\n >\n {renderDrawerContent()}\n </Animated.View>\n </Animated.View>\n </PanGestureHandler>\n </DrawerProgressContext.Provider>\n );\n}\n\nconst styles = StyleSheet.create({\n container: {\n top: 0,\n bottom: 0,\n maxWidth: '100%',\n width: DEFAULT_DRAWER_WIDTH,\n },\n content: {\n flex: 1,\n },\n main: {\n flex: 1,\n ...Platform.select({\n // FIXME: We need to hide `overflowX` on Web so the translated content doesn't show offscreen.\n // But adding `overflowX: 'hidden'` prevents content from collapsing the URL bar.\n web: null,\n default: { overflow: 'hidden' },\n }),\n },\n});\n"]}
|
|
1
|
+
{"version":3,"sources":["Drawer.tsx"],"names":["React","I18nManager","InteractionManager","Keyboard","Platform","StatusBar","StyleSheet","View","PanGestureHandler","State","GestureState","Animated","interpolate","runOnJS","useAnimatedGestureHandler","useAnimatedStyle","useDerivedValue","useSharedValue","withSpring","DrawerProgressContext","Overlay","SWIPE_DISTANCE_MINIMUM","DEFAULT_DRAWER_WIDTH","minmax","value","start","end","Math","min","max","Drawer","dimensions","drawerPosition","drawerStyle","drawerType","gestureHandlerProps","hideStatusBarOnOpen","keyboardDismissMode","onClose","onOpen","open","overlayStyle","renderDrawerContent","renderSceneContent","statusBarAnimation","swipeDistanceThreshold","swipeEdgeWidth","swipeEnabled","swipeVelocityThreshold","getDrawerWidth","width","flatten","endsWith","percentage","Number","replace","isFinite","drawerWidth","isOpen","isRight","getDrawerTranslationX","useCallback","hideStatusBar","hide","setHidden","useEffect","interactionHandleRef","useRef","startInteraction","current","createInteractionHandle","endInteraction","clearInteractionHandle","hideKeyboard","dismiss","onGestureStart","onGestureFinish","hitSlop","right","undefined","left","touchStartX","touchX","translationX","gestureState","UNDETERMINED","toggleDrawer","velocity","translateX","stiffness","damping","mass","overshootClamping","restDisplacementThreshold","restSpeedThreshold","onGestureEvent","onStart","event","ctx","startX","state","x","onActive","onEnd","nextOpen","abs","velocityX","onFinish","touchDistance","ACTIVE","drawerAnimatedStyle","distanceFromEdge","transform","isRTL","contentAnimatedStyle","progress","styles","main","flexDirection","content","OS","container","position","zIndex","create","top","bottom","maxWidth","flex","select","web","default","overflow"],"mappings":";;AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,SACEC,WADF,EAEEC,kBAFF,EAGEC,QAHF,EAIEC,QAJF,EAKEC,SALF,EAMEC,UANF,EAOEC,IAPF,QAQO,cARP;AASA,SACEC,iBADF,EAGEC,KAAK,IAAIC,YAHX,QAIO,8BAJP;AAKA,OAAOC,QAAP,IACEC,WADF,EAEEC,OAFF,EAGEC,yBAHF,EAIEC,gBAJF,EAKEC,eALF,EAMEC,cANF,EAOEC,UAPF,QAQO,yBARP;AAWA,OAAOC,qBAAP,MAAkC,mCAAlC;AACA,OAAOC,OAAP,MAAoB,WAApB;AAEA,MAAMC,sBAAsB,GAAG,CAA/B;AACA,MAAMC,oBAAoB,GAAG,KAA7B;;AAEA,MAAMC,MAAM,GAAG,CAACC,KAAD,EAAgBC,KAAhB,EAA+BC,GAA/B,KAA+C;AAC5D;;AAEA,SAAOC,IAAI,CAACC,GAAL,CAASD,IAAI,CAACE,GAAL,CAASL,KAAT,EAAgBC,KAAhB,CAAT,EAAiCC,GAAjC,CAAP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OAAO,EAAE,MAAM7B,YAAY,CAAC,KAAD,CAF7B;AAGE,IAAA,KAAK,EAAE7C;AAHT,IADD,GAMG,IAlBN,CATF,eA6BE,oBAAC,QAAD,CAAU,IAAV;AACE,IAAA,wBAAwB,EAAEiB,MAAM,IAAIxB,UAAU,KAAK,WADrD;AAEE,IAAA,qBAAqB,EAAE9B,QAAQ,CAACoH,EAAT,KAAgB,KAFzC;AAGE,IAAA,KAAK,EAAE,CACLJ,MAAM,CAACK,SADF,EAEL;AACEC,MAAAA,QAAQ,EAAExF,UAAU,KAAK,WAAf,GAA6B,UAA7B,GAA0C,UADtD;AAEEyF,MAAAA,MAAM,EAAEzF,UAAU,KAAK,MAAf,GAAwB,CAAC,CAAzB,GAA6B;AAFvC,KAFK,EAML4E,mBANK,EAOL7E,WAPK;AAHT,KAaGS,mBAAmB,EAbtB,CA7BF,CATF,CADF,CADF;AA2DD;AAED,MAAM0E,MAAM,GAAG9G,UAAU,CAACsH,MAAX,CAAkB;AAC/BH,EAAAA,SAAS,EAAE;AACTI,IAAAA,GAAG,EAAE,CADI;AAETC,IAAAA,MAAM,EAAE,CAFC;AAGTC,IAAAA,QAAQ,EAAE,MAHD;AAIT7E,IAAAA,KAAK,EAAE5B;AAJE,GADoB;AAO/BiG,EAAAA,OAAO,EAAE;AACPS,IAAAA,IAAI,EAAE;AADC,GAPsB;AAU/BX,EAAAA,IAAI,EAAE;AACJW,IAAAA,IAAI,EAAE,CADF;AAEJ,OAAG5H,QAAQ,CAAC6H,MAAT,CAAgB;AACjB;AACA;AACAC,MAAAA,GAAG,EAAE,IAHY;AAIjBC,MAAAA,OAAO,EAAE;AAAEC,QAAAA,QAAQ,EAAE;AAAZ;AAJQ,KAAhB;AAFC;AAVyB,CAAlB,CAAf","sourcesContent":["import * as React from 'react';\nimport {\n I18nManager,\n InteractionManager,\n Keyboard,\n Platform,\n StatusBar,\n StyleSheet,\n View,\n} from 'react-native';\nimport {\n PanGestureHandler,\n PanGestureHandlerGestureEvent,\n State as GestureState,\n} from 'react-native-gesture-handler';\nimport Animated, {\n interpolate,\n runOnJS,\n useAnimatedGestureHandler,\n useAnimatedStyle,\n useDerivedValue,\n useSharedValue,\n withSpring,\n} from 'react-native-reanimated';\n\nimport type { DrawerProps } from '../../types';\nimport DrawerProgressContext from '../../utils/DrawerProgressContext';\nimport Overlay from './Overlay';\n\nconst SWIPE_DISTANCE_MINIMUM = 5;\nconst DEFAULT_DRAWER_WIDTH = '80%';\n\nconst minmax = (value: number, start: number, end: number) => {\n 'worklet';\n\n return Math.min(Math.max(value, start), end);\n};\n\nexport default function Drawer({\n dimensions,\n drawerPosition,\n drawerStyle,\n drawerType,\n gestureHandlerProps,\n hideStatusBarOnOpen,\n keyboardDismissMode,\n onClose,\n onOpen,\n open,\n overlayStyle,\n renderDrawerContent,\n renderSceneContent,\n statusBarAnimation,\n swipeDistanceThreshold,\n swipeEdgeWidth,\n swipeEnabled,\n swipeVelocityThreshold,\n}: DrawerProps) {\n const getDrawerWidth = (): number => {\n const { width = DEFAULT_DRAWER_WIDTH } =\n StyleSheet.flatten(drawerStyle) || {};\n\n if (typeof width === 'string' && width.endsWith('%')) {\n // Try to calculate width if a percentage is given\n const percentage = Number(width.replace(/%$/, ''));\n\n if (Number.isFinite(percentage)) {\n return dimensions.width * (percentage / 100);\n }\n }\n\n return typeof width === 'number' ? width : 0;\n };\n\n const drawerWidth = getDrawerWidth();\n\n const isOpen = drawerType === 'permanent' ? true : open;\n const isRight = drawerPosition === 'right';\n\n const getDrawerTranslationX = React.useCallback(\n (open: boolean) => {\n 'worklet';\n\n if (drawerPosition === 'left') {\n return open ? 0 : -drawerWidth;\n }\n\n return open ? 0 : drawerWidth;\n },\n [drawerPosition, drawerWidth]\n );\n\n const hideStatusBar = React.useCallback(\n (hide: boolean) => {\n if (hideStatusBarOnOpen) {\n StatusBar.setHidden(hide, statusBarAnimation);\n }\n },\n [hideStatusBarOnOpen, statusBarAnimation]\n );\n\n React.useEffect(() => {\n hideStatusBar(isOpen);\n\n return () => hideStatusBar(false);\n }, [isOpen, hideStatusBarOnOpen, statusBarAnimation, hideStatusBar]);\n\n const interactionHandleRef = React.useRef<number | null>(null);\n\n const startInteraction = () => {\n interactionHandleRef.current = InteractionManager.createInteractionHandle();\n };\n\n const endInteraction = () => {\n if (interactionHandleRef.current != null) {\n InteractionManager.clearInteractionHandle(interactionHandleRef.current);\n interactionHandleRef.current = null;\n }\n };\n\n const hideKeyboard = () => {\n if (keyboardDismissMode === 'on-drag') {\n Keyboard.dismiss();\n }\n };\n\n const onGestureStart = () => {\n startInteraction();\n hideKeyboard();\n hideStatusBar(true);\n };\n\n const onGestureFinish = () => {\n endInteraction();\n };\n\n // FIXME: Currently hitSlop is broken when on Android when drawer is on right\n // https://github.com/software-mansion/react-native-gesture-handler/issues/569\n const hitSlop = isRight\n ? // Extend hitSlop to the side of the screen when drawer is closed\n // This lets the user drag the drawer from the side of the screen\n { right: 0, width: isOpen ? undefined : swipeEdgeWidth }\n : { left: 0, width: isOpen ? undefined : swipeEdgeWidth };\n\n const touchStartX = useSharedValue(0);\n const touchX = useSharedValue(0);\n const translationX = useSharedValue(getDrawerTranslationX(open));\n const gestureState = useSharedValue<GestureState>(GestureState.UNDETERMINED);\n\n const toggleDrawer = React.useCallback(\n (open: boolean, velocity?: number) => {\n 'worklet';\n\n const translateX = getDrawerTranslationX(open);\n\n touchStartX.value = 0;\n touchX.value = 0;\n translationX.value = withSpring(\n translateX,\n {\n velocity,\n stiffness: 1000,\n damping: 500,\n mass: 3,\n overshootClamping: true,\n restDisplacementThreshold: 0.01,\n restSpeedThreshold: 0.01,\n },\n () => {\n if (translationX.value === getDrawerTranslationX(true)) {\n runOnJS(onOpen)();\n } else if (translationX.value === getDrawerTranslationX(false)) {\n runOnJS(onClose)();\n }\n }\n );\n },\n [getDrawerTranslationX, onClose, onOpen, touchStartX, touchX, translationX]\n );\n\n React.useEffect(() => toggleDrawer(open), [open, toggleDrawer]);\n\n const onGestureEvent = useAnimatedGestureHandler<\n PanGestureHandlerGestureEvent,\n { startX: number }\n >({\n onStart: (event, ctx) => {\n ctx.startX = translationX.value;\n gestureState.value = event.state;\n touchStartX.value = event.x;\n\n runOnJS(onGestureStart)();\n },\n onActive: (event, ctx) => {\n touchX.value = event.x;\n translationX.value = ctx.startX + event.translationX;\n gestureState.value = event.state;\n },\n onEnd: (event) => {\n gestureState.value = event.state;\n\n const nextOpen =\n (Math.abs(event.translationX) > SWIPE_DISTANCE_MINIMUM &&\n Math.abs(event.translationX) > swipeVelocityThreshold) ||\n Math.abs(event.translationX) > swipeDistanceThreshold\n ? drawerPosition === 'left'\n ? // If swiped to right, open the drawer, otherwise close it\n (event.velocityX === 0 ? event.translationX : event.velocityX) > 0\n : // If swiped to left, open the drawer, otherwise close it\n (event.velocityX === 0 ? event.translationX : event.velocityX) < 0\n : open;\n\n toggleDrawer(nextOpen, event.velocityX);\n },\n onFinish: () => {\n runOnJS(onGestureFinish)();\n },\n });\n\n const translateX = useDerivedValue(() => {\n // Comment stolen from react-native-gesture-handler/DrawerLayout\n //\n // While closing the drawer when user starts gesture outside of its area (in greyed\n // out part of the window), we want the drawer to follow only once finger reaches the\n // edge of the drawer.\n // E.g. on the diagram below drawer is illustrate by X signs and the greyed out area by\n // dots. The touch gesture starts at '*' and moves left, touch path is indicated by\n // an arrow pointing left\n // 1) +---------------+ 2) +---------------+ 3) +---------------+ 4) +---------------+\n // |XXXXXXXX|......| |XXXXXXXX|......| |XXXXXXXX|......| |XXXXX|.........|\n // |XXXXXXXX|......| |XXXXXXXX|......| |XXXXXXXX|......| |XXXXX|.........|\n // |XXXXXXXX|......| |XXXXXXXX|......| |XXXXXXXX|......| |XXXXX|.........|\n // |XXXXXXXX|......| |XXXXXXXX|.<-*..| |XXXXXXXX|<--*..| |XXXXX|<-----*..|\n // |XXXXXXXX|......| |XXXXXXXX|......| |XXXXXXXX|......| |XXXXX|.........|\n // |XXXXXXXX|......| |XXXXXXXX|......| |XXXXXXXX|......| |XXXXX|.........|\n // |XXXXXXXX|......| |XXXXXXXX|......| |XXXXXXXX|......| |XXXXX|.........|\n // +---------------+ +---------------+ +---------------+ +---------------+\n //\n // For the above to work properly we define animated value that will keep start position\n // of the gesture. Then we use that value to calculate how much we need to subtract from\n // the translationX. If the gesture started on the greyed out area we take the distance from the\n // edge of the drawer to the start position. Otherwise we don't subtract at all and the\n // drawer be pulled back as soon as you start the pan.\n //\n // This is used only when drawerType is \"front\"\n const touchDistance =\n drawerType === 'front' && gestureState.value === GestureState.ACTIVE\n ? minmax(\n drawerPosition === 'left'\n ? touchStartX.value - drawerWidth\n : dimensions.width - drawerWidth - touchStartX.value,\n 0,\n dimensions.width\n )\n : 0;\n\n const translateX =\n drawerPosition === 'left'\n ? minmax(translationX.value + touchDistance, -drawerWidth, 0)\n : minmax(translationX.value - touchDistance, 0, drawerWidth);\n\n return translateX;\n });\n\n const drawerAnimatedStyle = useAnimatedStyle(() => {\n const distanceFromEdge = dimensions.width - drawerWidth;\n\n return {\n transform:\n drawerType === 'permanent'\n ? // Reanimated needs the property to be present, but it results in Browser bug\n // https://bugs.chromium.org/p/chromium/issues/detail?id=20574\n []\n : [\n {\n translateX:\n // The drawer stays in place when `drawerType` is `back`\n (drawerType === 'back' ? 0 : translateX.value) +\n (drawerPosition === 'left'\n ? I18nManager.isRTL\n ? -distanceFromEdge\n : 0\n : I18nManager.isRTL\n ? 0\n : distanceFromEdge),\n },\n ],\n };\n });\n\n const contentAnimatedStyle = useAnimatedStyle(() => {\n return {\n transform:\n drawerType === 'permanent'\n ? // Reanimated needs the property to be present, but it results in Browser bug\n // https://bugs.chromium.org/p/chromium/issues/detail?id=20574\n []\n : [\n {\n translateX:\n // The screen content stays in place when `drawerType` is `front`\n drawerType === 'front'\n ? 0\n : translateX.value +\n drawerWidth * (drawerPosition === 'left' ? 1 : -1),\n },\n ],\n };\n });\n\n const progress = useDerivedValue(() => {\n return drawerType === 'permanent'\n ? 1\n : interpolate(\n translateX.value,\n [getDrawerTranslationX(false), getDrawerTranslationX(true)],\n [0, 1]\n );\n });\n\n return (\n <DrawerProgressContext.Provider value={progress}>\n <PanGestureHandler\n activeOffsetX={[-SWIPE_DISTANCE_MINIMUM, SWIPE_DISTANCE_MINIMUM]}\n failOffsetY={[-SWIPE_DISTANCE_MINIMUM, SWIPE_DISTANCE_MINIMUM]}\n hitSlop={hitSlop}\n enabled={drawerType !== 'permanent' && swipeEnabled}\n onGestureEvent={onGestureEvent}\n {...gestureHandlerProps}\n >\n {/* Immediate child of gesture handler needs to be an Animated.View */}\n <Animated.View\n style={[\n styles.main,\n {\n flexDirection:\n drawerType === 'permanent' && !isRight ? 'row-reverse' : 'row',\n },\n ]}\n >\n <Animated.View style={[styles.content, contentAnimatedStyle]}>\n <View\n accessibilityElementsHidden={isOpen && drawerType !== 'permanent'}\n importantForAccessibility={\n isOpen && drawerType !== 'permanent'\n ? 'no-hide-descendants'\n : 'auto'\n }\n style={styles.content}\n >\n {renderSceneContent()}\n </View>\n {drawerType !== 'permanent' ? (\n <Overlay\n progress={progress}\n onPress={() => toggleDrawer(false)}\n style={overlayStyle}\n />\n ) : null}\n </Animated.View>\n <Animated.View\n accessibilityViewIsModal={isOpen && drawerType !== 'permanent'}\n removeClippedSubviews={Platform.OS !== 'ios'}\n style={[\n styles.container,\n {\n position: drawerType === 'permanent' ? 'relative' : 'absolute',\n zIndex: drawerType === 'back' ? -1 : 0,\n },\n drawerAnimatedStyle,\n drawerStyle as any,\n ]}\n >\n {renderDrawerContent()}\n </Animated.View>\n </Animated.View>\n </PanGestureHandler>\n </DrawerProgressContext.Provider>\n );\n}\n\nconst styles = StyleSheet.create({\n container: {\n top: 0,\n bottom: 0,\n maxWidth: '100%',\n width: DEFAULT_DRAWER_WIDTH,\n },\n content: {\n flex: 1,\n },\n main: {\n flex: 1,\n ...Platform.select({\n // FIXME: We need to hide `overflowX` on Web so the translated content doesn't show offscreen.\n // But adding `overflowX: 'hidden'` prevents content from collapsing the URL bar.\n web: null,\n default: { overflow: 'hidden' },\n }),\n },\n});\n"]}
|
|
@@ -29,9 +29,7 @@ export declare type DrawerNavigationConfig = {
|
|
|
29
29
|
* The new implementation based on Reanimated 2 will perform better,
|
|
30
30
|
* but you need additional configuration and need to use Hermes with Flipper to debug.
|
|
31
31
|
*
|
|
32
|
-
* This defaults to `true`
|
|
33
|
-
* - Reanimated 2 is not configured
|
|
34
|
-
* - App is connected to Chrome debugger (Reanimated 2 cannot be used with Chrome debugger)
|
|
32
|
+
* This defaults to `true` if Reanimated 2 is not configured.
|
|
35
33
|
*
|
|
36
34
|
* Otherwise, it defaults to `false`
|
|
37
35
|
*/
|
|
@@ -124,6 +122,8 @@ export declare type DrawerNavigationOptions = HeaderOptions & {
|
|
|
124
122
|
* - `back`: The drawer is revealed behind the screen on swipe.
|
|
125
123
|
* - `slide`: Both the screen and the drawer slide on swipe to reveal the drawer.
|
|
126
124
|
* - `permanent`: A permanent drawer is shown as a sidebar.
|
|
125
|
+
*
|
|
126
|
+
* Defaults to `slide` on iOS and `front` on other platforms.
|
|
127
127
|
*/
|
|
128
128
|
drawerType?: 'front' | 'back' | 'slide' | 'permanent';
|
|
129
129
|
/**
|
|
@@ -143,14 +143,6 @@ export declare type DrawerNavigationOptions = HeaderOptions & {
|
|
|
143
143
|
* Style object for the component wrapping the screen content.
|
|
144
144
|
*/
|
|
145
145
|
sceneContainerStyle?: StyleProp<ViewStyle>;
|
|
146
|
-
/**
|
|
147
|
-
* Whether you can use gestures to open or close the drawer.
|
|
148
|
-
* Setting this to `false` disables swipe gestures as well as tap on overlay to close.
|
|
149
|
-
* See `swipeEnabled` to disable only the swipe gesture.
|
|
150
|
-
* Defaults to `true`.
|
|
151
|
-
* Not supported on Web.
|
|
152
|
-
*/
|
|
153
|
-
gestureEnabled?: boolean;
|
|
154
146
|
/**
|
|
155
147
|
* Props to pass to the underlying pan gesture handler.
|
|
156
148
|
* Not supported on Web.
|
|
@@ -6,7 +6,7 @@ declare const Overlay: React.ForwardRefExoticComponent<{
|
|
|
6
6
|
onLayout?: ((event: import("react-native").LayoutChangeEvent) => void) | Animated.Node<((event: import("react-native").LayoutChangeEvent) => void) | undefined> | undefined;
|
|
7
7
|
pointerEvents?: "none" | "auto" | "box-none" | "box-only" | Animated.Node<"none" | "auto" | "box-none" | "box-only" | undefined> | undefined;
|
|
8
8
|
removeClippedSubviews?: boolean | Animated.Node<boolean | undefined> | undefined;
|
|
9
|
-
style?: import("react-native").StyleProp<Animated.
|
|
9
|
+
style?: import("react-native").StyleProp<import("react-native").ViewStyle> | Animated.Node<import("react-native").StyleProp<import("react-native").ViewStyle>>;
|
|
10
10
|
testID?: string | Animated.Node<string | undefined> | undefined;
|
|
11
11
|
nativeID?: string | Animated.Node<string | undefined> | undefined;
|
|
12
12
|
collapsable?: boolean | Animated.Node<boolean | undefined> | undefined;
|
|
@@ -60,6 +60,8 @@ declare const Overlay: React.ForwardRefExoticComponent<{
|
|
|
60
60
|
onAccessibilityTap?: (() => void) | Animated.Node<(() => void) | undefined> | undefined;
|
|
61
61
|
onMagicTap?: (() => void) | Animated.Node<(() => void) | undefined> | undefined;
|
|
62
62
|
accessibilityIgnoresInvertColors?: boolean | Animated.Node<boolean | undefined> | undefined;
|
|
63
|
+
} & {
|
|
64
|
+
style?: import("react-native").StyleProp<Animated.AnimateStyle<import("react-native").StyleProp<import("react-native").ViewStyle>>>;
|
|
63
65
|
} & {
|
|
64
66
|
animatedProps?: Partial<Animated.AnimateProps<import("react-native").ViewProps>> | undefined;
|
|
65
67
|
layout?: import("react-native-reanimated").BaseAnimationBuilder | import("react-native-reanimated").LayoutAnimationFunction | typeof import("react-native-reanimated").BaseAnimationBuilder | undefined;
|
|
@@ -6,7 +6,7 @@ declare const Overlay: React.ForwardRefExoticComponent<{
|
|
|
6
6
|
onLayout?: ((event: import("react-native").LayoutChangeEvent) => void) | Animated.Node<((event: import("react-native").LayoutChangeEvent) => void) | undefined> | undefined;
|
|
7
7
|
pointerEvents?: "none" | "auto" | "box-none" | "box-only" | Animated.Node<"none" | "auto" | "box-none" | "box-only" | undefined> | undefined;
|
|
8
8
|
removeClippedSubviews?: boolean | Animated.Node<boolean | undefined> | undefined;
|
|
9
|
-
style?: import("react-native").StyleProp<Animated.
|
|
9
|
+
style?: import("react-native").StyleProp<import("react-native").ViewStyle> | Animated.Node<import("react-native").StyleProp<import("react-native").ViewStyle>>;
|
|
10
10
|
testID?: string | Animated.Node<string | undefined> | undefined;
|
|
11
11
|
nativeID?: string | Animated.Node<string | undefined> | undefined;
|
|
12
12
|
collapsable?: boolean | Animated.Node<boolean | undefined> | undefined;
|
|
@@ -60,6 +60,8 @@ declare const Overlay: React.ForwardRefExoticComponent<{
|
|
|
60
60
|
onAccessibilityTap?: (() => void) | Animated.Node<(() => void) | undefined> | undefined;
|
|
61
61
|
onMagicTap?: (() => void) | Animated.Node<(() => void) | undefined> | undefined;
|
|
62
62
|
accessibilityIgnoresInvertColors?: boolean | Animated.Node<boolean | undefined> | undefined;
|
|
63
|
+
} & {
|
|
64
|
+
style?: import("react-native").StyleProp<Animated.AnimateStyle<import("react-native").StyleProp<import("react-native").ViewStyle>>>;
|
|
63
65
|
} & {
|
|
64
66
|
animatedProps?: Partial<Animated.AnimateProps<import("react-native").ViewProps>> | undefined;
|
|
65
67
|
layout?: import("react-native-reanimated").BaseAnimationBuilder | import("react-native-reanimated").LayoutAnimationFunction | typeof import("react-native-reanimated").BaseAnimationBuilder | undefined;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-navigation/drawer",
|
|
3
3
|
"description": "Drawer navigator component with animated transitions and gesturess",
|
|
4
|
-
"version": "6.3.
|
|
4
|
+
"version": "6.3.3",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react-native-component",
|
|
7
7
|
"react-component",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"react-native": "~0.64.3",
|
|
56
56
|
"react-native-builder-bob": "^0.18.1",
|
|
57
57
|
"react-native-gesture-handler": "~2.2.0",
|
|
58
|
-
"react-native-reanimated": "~2.
|
|
58
|
+
"react-native-reanimated": "~2.4.1",
|
|
59
59
|
"react-native-safe-area-context": "3.3.2",
|
|
60
60
|
"react-native-screens": "~3.10.1",
|
|
61
61
|
"typescript": "^4.3.2"
|
|
@@ -83,5 +83,5 @@
|
|
|
83
83
|
]
|
|
84
84
|
]
|
|
85
85
|
},
|
|
86
|
-
"gitHead": "
|
|
86
|
+
"gitHead": "1e342f16627854bca6534e2aef149824c00c99c0"
|
|
87
87
|
}
|
package/src/types.tsx
CHANGED
|
@@ -40,9 +40,7 @@ export type DrawerNavigationConfig = {
|
|
|
40
40
|
* The new implementation based on Reanimated 2 will perform better,
|
|
41
41
|
* but you need additional configuration and need to use Hermes with Flipper to debug.
|
|
42
42
|
*
|
|
43
|
-
* This defaults to `true`
|
|
44
|
-
* - Reanimated 2 is not configured
|
|
45
|
-
* - App is connected to Chrome debugger (Reanimated 2 cannot be used with Chrome debugger)
|
|
43
|
+
* This defaults to `true` if Reanimated 2 is not configured.
|
|
46
44
|
*
|
|
47
45
|
* Otherwise, it defaults to `false`
|
|
48
46
|
*/
|
|
@@ -152,6 +150,8 @@ export type DrawerNavigationOptions = HeaderOptions & {
|
|
|
152
150
|
* - `back`: The drawer is revealed behind the screen on swipe.
|
|
153
151
|
* - `slide`: Both the screen and the drawer slide on swipe to reveal the drawer.
|
|
154
152
|
* - `permanent`: A permanent drawer is shown as a sidebar.
|
|
153
|
+
*
|
|
154
|
+
* Defaults to `slide` on iOS and `front` on other platforms.
|
|
155
155
|
*/
|
|
156
156
|
drawerType?: 'front' | 'back' | 'slide' | 'permanent';
|
|
157
157
|
|
|
@@ -176,15 +176,6 @@ export type DrawerNavigationOptions = HeaderOptions & {
|
|
|
176
176
|
*/
|
|
177
177
|
sceneContainerStyle?: StyleProp<ViewStyle>;
|
|
178
178
|
|
|
179
|
-
/**
|
|
180
|
-
* Whether you can use gestures to open or close the drawer.
|
|
181
|
-
* Setting this to `false` disables swipe gestures as well as tap on overlay to close.
|
|
182
|
-
* See `swipeEnabled` to disable only the swipe gesture.
|
|
183
|
-
* Defaults to `true`.
|
|
184
|
-
* Not supported on Web.
|
|
185
|
-
*/
|
|
186
|
-
gestureEnabled?: boolean;
|
|
187
|
-
|
|
188
179
|
/**
|
|
189
180
|
* Props to pass to the underlying pan gesture handler.
|
|
190
181
|
* Not supported on Web.
|
package/src/views/DrawerView.tsx
CHANGED
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
StyleSheet,
|
|
20
20
|
View,
|
|
21
21
|
} from 'react-native';
|
|
22
|
-
import
|
|
22
|
+
import * as Reanimated from 'react-native-reanimated';
|
|
23
23
|
import { useSafeAreaFrame } from 'react-native-safe-area-context';
|
|
24
24
|
|
|
25
25
|
import type {
|
|
@@ -80,12 +80,9 @@ function DrawerViewBase({
|
|
|
80
80
|
detachInactiveScreens = Platform.OS === 'web' ||
|
|
81
81
|
Platform.OS === 'android' ||
|
|
82
82
|
Platform.OS === 'ios',
|
|
83
|
-
//
|
|
84
|
-
// @ts-expect-error
|
|
85
|
-
useLegacyImplementation = !
|
|
86
|
-
// Reanimated 2 is not configured
|
|
87
|
-
// @ts-expect-error: the type definitions are incomplete
|
|
88
|
-
!Animated.isConfigured?.(),
|
|
83
|
+
// Reanimated 2 is not configured
|
|
84
|
+
// @ts-expect-error: the type definitions are incomplete
|
|
85
|
+
useLegacyImplementation = !Reanimated.isConfigured?.(),
|
|
89
86
|
}: Props) {
|
|
90
87
|
const Drawer: React.ComponentType<DrawerProps> = useLegacyImplementation
|
|
91
88
|
? require('./legacy/Drawer').default
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import {
|
|
3
|
+
I18nManager,
|
|
3
4
|
InteractionManager,
|
|
4
5
|
Keyboard,
|
|
5
6
|
Platform,
|
|
@@ -129,7 +130,7 @@ export default function Drawer({
|
|
|
129
130
|
hideStatusBar(true);
|
|
130
131
|
};
|
|
131
132
|
|
|
132
|
-
const
|
|
133
|
+
const onGestureFinish = () => {
|
|
133
134
|
endInteraction();
|
|
134
135
|
};
|
|
135
136
|
|
|
@@ -210,7 +211,9 @@ export default function Drawer({
|
|
|
210
211
|
: open;
|
|
211
212
|
|
|
212
213
|
toggleDrawer(nextOpen, event.velocityX);
|
|
213
|
-
|
|
214
|
+
},
|
|
215
|
+
onFinish: () => {
|
|
216
|
+
runOnJS(onGestureFinish)();
|
|
214
217
|
},
|
|
215
218
|
});
|
|
216
219
|
|
|
@@ -260,6 +263,8 @@ export default function Drawer({
|
|
|
260
263
|
});
|
|
261
264
|
|
|
262
265
|
const drawerAnimatedStyle = useAnimatedStyle(() => {
|
|
266
|
+
const distanceFromEdge = dimensions.width - drawerWidth;
|
|
267
|
+
|
|
263
268
|
return {
|
|
264
269
|
transform:
|
|
265
270
|
drawerType === 'permanent'
|
|
@@ -268,7 +273,16 @@ export default function Drawer({
|
|
|
268
273
|
[]
|
|
269
274
|
: [
|
|
270
275
|
{
|
|
271
|
-
translateX:
|
|
276
|
+
translateX:
|
|
277
|
+
// The drawer stays in place when `drawerType` is `back`
|
|
278
|
+
(drawerType === 'back' ? 0 : translateX.value) +
|
|
279
|
+
(drawerPosition === 'left'
|
|
280
|
+
? I18nManager.isRTL
|
|
281
|
+
? -distanceFromEdge
|
|
282
|
+
: 0
|
|
283
|
+
: I18nManager.isRTL
|
|
284
|
+
? 0
|
|
285
|
+
: distanceFromEdge),
|
|
272
286
|
},
|
|
273
287
|
],
|
|
274
288
|
};
|
|
@@ -284,11 +298,11 @@ export default function Drawer({
|
|
|
284
298
|
: [
|
|
285
299
|
{
|
|
286
300
|
translateX:
|
|
301
|
+
// The screen content stays in place when `drawerType` is `front`
|
|
287
302
|
drawerType === 'front'
|
|
288
303
|
? 0
|
|
289
|
-
:
|
|
290
|
-
|
|
291
|
-
: translateX.value - drawerWidth,
|
|
304
|
+
: translateX.value +
|
|
305
|
+
drawerWidth * (drawerPosition === 'left' ? 1 : -1),
|
|
292
306
|
},
|
|
293
307
|
],
|
|
294
308
|
};
|