Skip to content

Commit

Permalink
refactor: move drawer roundness to drawer navigator
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Mar 11, 2024
1 parent d0b5489 commit 6e84eea
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 34 deletions.
15 changes: 14 additions & 1 deletion packages/drawer/src/views/DrawerView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ type Props = DrawerNavigationConfig & {
descriptors: DrawerDescriptorMap;
};

const DRAWER_BORDER_RADIUS = 16;

function DrawerViewBase({
state,
navigation,
Expand All @@ -62,7 +64,7 @@ function DrawerViewBase({
drawerPosition = direction === 'rtl' ? 'right' : 'left',
drawerStatusBarAnimation,
drawerStyle,
drawerType,
drawerType = Platform.select({ ios: 'slide', default: 'front' }),
gestureHandlerProps,
keyboardDismissMode,
overlayColor = 'rgba(0, 0, 0, 0.5)',
Expand Down Expand Up @@ -298,6 +300,17 @@ function DrawerViewBase({
borderStartColor: colors.border,
borderStartWidth: StyleSheet.hairlineWidth,
}),

drawerType === 'front' &&
(drawerPosition === 'left'
? {
borderTopRightRadius: DRAWER_BORDER_RADIUS,
borderBottomRightRadius: DRAWER_BORDER_RADIUS,
}
: {
borderTopLeftRadius: DRAWER_BORDER_RADIUS,
borderBottomLeftRadius: DRAWER_BORDER_RADIUS,
}),
drawerStyle,
]}
overlayStyle={{ backgroundColor: overlayColor }}
Expand Down
18 changes: 1 addition & 17 deletions packages/react-native-drawer-layout/src/views/Drawer.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ const SWIPE_MIN_OFFSET = 5;
const SWIPE_MIN_DISTANCE = 60;
const SWIPE_MIN_VELOCITY = 500;

const DRAWER_BORDER_RADIUS = 16;

const minmax = (value: number, start: number, end: number) => {
'worklet';

Expand All @@ -48,7 +46,7 @@ export function Drawer({
layout: customLayout,
drawerPosition = I18nManager.getConstants().isRTL ? 'right' : 'left',
drawerStyle,
drawerType = Platform.select({ ios: 'slide', default: 'front' }),
drawerType = 'front',
gestureHandlerProps,
hideStatusBarOnOpen = false,
keyboardDismissMode = 'on-drag',
Expand Down Expand Up @@ -153,19 +151,6 @@ export function Drawer({
{ right: 0, width: isOpen ? undefined : swipeEdgeWidth }
: { left: 0, width: isOpen ? undefined : swipeEdgeWidth };

const borderRadiiStyle =
drawerType !== 'permanent'
? isRight
? {
borderTopLeftRadius: DRAWER_BORDER_RADIUS,
borderBottomLeftRadius: DRAWER_BORDER_RADIUS,
}
: {
borderTopRightRadius: DRAWER_BORDER_RADIUS,
borderBottomRightRadius: DRAWER_BORDER_RADIUS,
}
: null;

const touchStartX = useSharedValue(0);
const touchX = useSharedValue(0);
const translationX = useSharedValue(getDrawerTranslationX(open));
Expand Down Expand Up @@ -427,7 +412,6 @@ export function Drawer({
drawerType === 'permanent' ? 'relative' : 'absolute',
zIndex: drawerType === 'back' ? -1 : 0,
},
borderRadiiStyle,
drawerAnimatedStyle,
drawerStyle,
]}
Expand Down
16 changes: 0 additions & 16 deletions packages/react-native-drawer-layout/src/views/Drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import { getDrawerWidth } from '../utils/getDrawerWidth';
import { useFakeSharedValue } from '../utils/useFakeSharedValue';
import { Overlay } from './Overlay';

const DRAWER_BORDER_RADIUS = 16;

export function Drawer({
layout: customLayout,
drawerPosition = 'left',
Expand Down Expand Up @@ -58,19 +56,6 @@ export function Drawer({
const isOpen = drawerType === 'permanent' ? true : open;
const isRight = drawerPosition === 'right';

const borderRadiiStyle =
drawerType !== 'permanent'
? isRight
? {
borderTopLeftRadius: DRAWER_BORDER_RADIUS,
borderBottomLeftRadius: DRAWER_BORDER_RADIUS,
}
: {
borderTopRightRadius: DRAWER_BORDER_RADIUS,
borderBottomRightRadius: DRAWER_BORDER_RADIUS,
}
: null;

const drawerAnimatedStyle =
drawerType !== 'permanent'
? {
Expand Down Expand Up @@ -151,7 +136,6 @@ export function Drawer({
position: drawerType === 'permanent' ? 'relative' : 'absolute',
zIndex: drawerType === 'back' ? -1 : 0,
},
borderRadiiStyle,
drawerAnimatedStyle,
drawerStyle,
]}
Expand Down

0 comments on commit 6e84eea

Please sign in to comment.