Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

change sideMenu to drawer-layout

ammarahm-ed47c85c5bd96e
diff --git a/apps/mobile/index.mobile.js b/apps/mobile/index.mobile.js
index fab2f8588..943242ed5 100644
--- a/apps/mobile/index.mobile.js
+++ b/apps/mobile/index.mobile.js
@@ -1,15 +1,15 @@
-import React, {createRef, useEffect} from 'react';
+import React, {createRef, useEffect, useState} from 'react';
import {Platform, StatusBar, View} from 'react-native';
import * as Animatable from 'react-native-animatable';
+import DrawerLayout from 'react-native-drawer-layout';
import Animated from 'react-native-reanimated';
import {Menu} from './src/components/Menu';
-import SideMenu from './src/components/SideMenu';
import {useTracked} from './src/provider';
+import {NavigationStack} from './src/services/Navigator';
import {EditorOpacity, EditorPosition} from './src/utils/animations';
import {sideMenuRef} from './src/utils/refs';
-import {DDS, w} from './src/utils/utils';
+import {DDS} from './src/utils/utils';
import Editor from './src/views/Editor';
-import {NavigationStack} from './src/services/Navigator';
const editorRef = createRef();
export const Initialize = () => {
@@ -23,6 +23,7 @@ export const Initialize = () => {
StatusBar.setBarStyle(colors.night ? 'light-content' : 'dark-content');
}
}, []);
+
return (
<Animatable.View
transition="backgroundColor"
@@ -33,23 +34,22 @@ export const Initialize = () => {
flexDirection: 'row',
backgroundColor: colors.bg,
}}>
- <SideMenu
+ <DrawerLayout
ref={sideMenuRef}
- bounceBackOnOverdraw={false}
- contentContainerStyle={{
+ style={{
opacity: 0,
backgroundColor: colors.bg,
}}
- menu={
+ keyboardDismissMode="ondrag"
+ drawerWidth={300}
+ useNativeAnimations={true}
+ renderNavigationView={() => (
<Menu
hide={false}
colors={colors}
- close={() =>
- sideMenuRef.current?.openMenu(!sideMenuRef.current?.isOpen)
- }
+ close={() => sideMenuRef.current?.closeDrawer()}
/>
- }
- openMenuOffset={w / 1.5}>
+ )}>
<View
style={{
width: DDS.isTab ? '70%' : '100%',
@@ -58,7 +58,7 @@ export const Initialize = () => {
}}>
<NavigationStack />
</View>
- </SideMenu>
+ </DrawerLayout>
<Animated.View
ref={editorRef}
diff --git a/apps/mobile/src/components/Menu/index.js b/apps/mobile/src/components/Menu/index.js
index e8d5cba0b..654f77fe7 100644
--- a/apps/mobile/src/components/Menu/index.js
+++ b/apps/mobile/src/components/Menu/index.js
@@ -35,6 +35,9 @@ import {
import NavigationService from '../../services/NavigationService';
import {db, DDS, hexToRGBA, timeSince, ToastEvent} from '../../utils/utils';
import {sideMenuOverlayRef} from '../../utils/refs';
+import {createAnimatableComponent} from 'react-native-animatable';
+
+const AnimatedSafeAreaView = createAnimatableComponent(SafeAreaView);
export const Menu = ({
close = () => {},
@@ -119,12 +122,14 @@ export const Menu = ({
];
return (
- <SafeAreaView
+ <AnimatedSafeAreaView
+ transition="backgroundColor"
+ duration={300}
style={{
height: '100%',
opacity: hide ? 0 : 1,
width: '100%',
- backgroundColor: 'transparent',
+ backgroundColor: colors.bg,
borderRightWidth: noTextMode ? 1 : 0,
borderRightColor: noTextMode ? colors.accent : 'transparent',
}}>
@@ -169,25 +174,6 @@ export const Menu = ({
) : null}
</View>
- {DDS.isTab ? null : (
- <View
- ref={sideMenuOverlayRef}
- style={{
- height: '100%',
- width: '100%',
- position: 'absolute',
- zIndex: 999,
- backgroundColor: colors.bg,
- display: 'flex',
- transform: [
- {
- translateX: 0,
- },
- ],
- }}
- />
- )}
-
<ScrollView
contentContainerStyle={{minHeight: '50%'}}
showsVerticalScrollIndicator={false}>
@@ -742,6 +728,6 @@ export const Menu = ({
</TouchableOpacity>
)}
</View>
- </SafeAreaView>
+ </AnimatedSafeAreaView>
);
};
diff --git a/apps/mobile/src/components/SideMenu/index.js b/apps/mobile/src/components/SideMenu/index.js
deleted file mode 100644
index 33e69546e..000000000
--- a/apps/mobile/src/components/SideMenu/index.js
+++ /dev/null
@@ -1,380 +0,0 @@
-// @flow
-
-import PropTypes from 'prop-types';
-import React from 'react';
-import {
- Animated,
- Dimensions,
- Easing,
- PanResponder,
- TouchableWithoutFeedback,
- View,
-} from 'react-native';
-import styles from './styles';
-import {sideMenuOverlayRef} from '../../utils/refs';
-const deviceScreen = Dimensions.get('window');
-const barrierForward = deviceScreen.width / 4;
-
-function shouldOpenMenu(dx) {
- return dx > barrierForward;
-}
-
-const gestures = {
- enabled: true,
-};
-
-export default class SideMenu extends React.Component {
- constructor(props) {
- super(props);
- this.state = {};
- this.prevLeft = 0;
- this.isOpen = !!props.isOpen;
- this.isGestureEnabled = true;
- this.overlay;
- this.opacity = new Animated.Value(0);
-
- const initialMenuPositionMultiplier =
- props.menuPosition === 'right' ? -1 : 1;
- const openOffsetMenuPercentage = props.openMenuOffset / deviceScreen.width;
- const hiddenMenuOffsetPercentage =
- props.hiddenMenuOffset / deviceScreen.width;
- const left = new Animated.Value(
- props.isOpen
- ? props.openMenuOffset * initialMenuPositionMultiplier
- : props.hiddenMenuOffset,
- );
-
- this.onLayoutChange = this.onLayoutChange.bind(this);
- this.onStartShouldSetResponderCapture = props.onStartShouldSetResponderCapture.bind(
- this,
- );
- this.onMoveShouldSetPanResponder = this.handleMoveShouldSetPanResponder.bind(
- this,
- );
- this.onPanResponderMove = this.handlePanResponderMove.bind(this);
- this.onPanResponderRelease = this.handlePanResponderEnd.bind(this);
- this.onPanResponderTerminate = this.handlePanResponderEnd.bind(this);
-
- this.state = {
- width: deviceScreen.width,
- height: deviceScreen.height,
- openOffsetMenuPercentage,
- openMenuOffset: deviceScreen.width * openOffsetMenuPercentage,
- hiddenMenuOffsetPercentage,
- hiddenMenuOffset: deviceScreen.width * hiddenMenuOffsetPercentage,
- left,
- };
-
- this.state.left.addListener(({value}) =>
- this.props.onSliding(
- Math.abs(
- (value - this.state.hiddenMenuOffset) /
- (this.state.openMenuOffset - this.state.hiddenMenuOffset),
- ),
- ),
- );
-
- this.responder = PanResponder.create({
- onStartShouldSetResponderCapture: this.onStartShouldSetResponderCapture,
- onMoveShouldSetPanResponder: this.onMoveShouldSetPanResponder,
- onPanResponderMove: this.onPanResponderMove,
- onPanResponderRelease: this.onPanResponderRelease,
- onPanResponderTerminate: this.onPanResponderTerminate,
- });
- }
-
- /* UNSAFE_componentWillReceiveProps(props) {
- if (
- typeof props.isOpen !== 'undefined' &&
- this.isOpen !== props.isOpen &&
- (props.autoClosing || this.isOpen === false)
- ) {
- this.openMenu(props.isOpen);
- }
- } */
-
- onLayoutChange(e) {
- const {width, height} = e.nativeEvent.layout;
- const openMenuOffset = width * this.state.openOffsetMenuPercentage;
- const hiddenMenuOffset = width * this.state.hiddenMenuOffsetPercentage;
- this.setState({width, height, openMenuOffset, hiddenMenuOffset});
- }
-
- /**
- * Get content view. This view will be rendered over menu
- * @return {React.Component}
- */
- getContentView() {
- //let overlay = null;
-
- const {width, height} = this.state;
- const ref = sideMenu => (this.sideMenu = sideMenu);
- const style = [
- styles.frontView,
- {width, height},
-
- this.props.animationStyle(this.state.left),
- ];
-
- return (
- <Animated.View style={style} ref={ref} {...this.responder.panHandlers}>
- {this.props.children}
-
- <TouchableWithoutFeedback onPress={() => this.openMenu(false)}>
- <Animated.View
- ref={ref => (this.overlay = ref)}
- onTouchStart={() => {}}
- style={{
- display: 'none',
- position: 'relative',
- top: 0,
- right: 0,
- left: 0,
- bottom: 0,
- backgroundColor: 'black',
- opacity: this.opacity,
- zIndex: 1,
- }}
- />
- </TouchableWithoutFeedback>
- </Animated.View>
- );
- }
-
- changeOpacity(opacity) {
- if (opacity === 0.5) {
- this.overlay.setNativeProps({
- style: {
- display: 'flex',
- position: 'absolute',
- zIndex: 1,
- },
- });
- }
- Animated.timing(this.opacity, {
- toValue: opacity,
- duration: 400,
- useNativeDriver: true,
- }).start(() => {
- if (opacity < 0.5) {
- this.overlay.setNativeProps({
- style: {
- display: 'none',
- position: 'relative',
- zIndex: -1,
- },
- });
- }
- });
- }
-
- moveLeft(offset) {
- const newOffset = this.menuPositionMultiplier() * offset;
-
- this.props.animationFunction(this.state.left, newOffset).start();
-
- this.prevLeft = newOffset;
- }
-
- menuPositionMultiplier() {
- return this.props.menuPosition === 'right' ? -1 : 1;
- }
-
- doAfterShow() {
- sideMenuOverlayRef.current?.setNativeProps({
- style: {
- display: 'none',
- position: 'relative',
- transform: [
- {
- translateX: -deviceScreen.width * 2,
- },
- ],
- },
- });
- }
-
- doAfterHide() {
- sideMenuOverlayRef.current?.setNativeProps({
- style: {
- display: 'flex',
- position: 'absolute',
- transform: [
- {
- translateX: 0,
- },
- ],
- },
- });
- }
-
- handlePanResponderMove(e, gestureState) {
- if (this.state.left.__getValue() * this.menuPositionMultiplier() >= 0) {
- let newLeft = this.prevLeft + gestureState.dx;
- this.overlay.setNativeProps({
- style: {
- display: 'flex',
- position: 'absolute',
- zIndex: 1,
- },
- });
- if (
- !this.props.bounceBackOnOverdraw &&
- Math.abs(newLeft) > this.state.openMenuOffset
- ) {
- newLeft = this.menuPositionMultiplier() * this.state.openMenuOffset;
- }
-
- let o = newLeft / this.props.openMenuOffset;
- this.opacity.setValue(o * 0.5);
- if (o > 0.1) {
- this.doAfterShow();
- } else {
- this.doAfterHide();
- }
- this.props.onMove(newLeft);
- this.state.left.setValue(newLeft);
- }
- }
-
- handlePanResponderEnd(e, gestureState) {
- const offsetLeft =
- this.menuPositionMultiplier() *
- (this.state.left.__getValue() + gestureState.dx);
-
- this.openMenu(shouldOpenMenu(offsetLeft));
- }
-
- handleMoveShouldSetPanResponder = (e, gestureState) => {
- if (gestures.enabled) {
- const x = Math.round(Math.abs(gestureState.dx));
- const y = Math.round(Math.abs(gestureState.dy));
-
- const touchMoved = x > this.props.toleranceX && y < this.props.toleranceY;
-
- if (this.isOpen) {
- this.doAfterShow();
- return touchMoved;
- }
-
- const withinEdgeHitWidth =
- this.props.menuPosition === 'right'
- ? gestureState.moveX > deviceScreen.width - this.props.edgeHitWidth
- : gestureState.moveX < this.props.edgeHitWidth;
-
- const swipingToOpen = this.menuPositionMultiplier() * gestureState.dx > 0;
-
- return withinEdgeHitWidth && touchMoved && swipingToOpen;
- }
-
- return false;
- };
-
- openMenu(isOpen) {
- const {hiddenMenuOffset, openMenuOffset} = this.state;
-
- if (isOpen) {
- this.doAfterShow();
- setTimeout(() => {
- if (this.isOpen) {
- this.doAfterShow();
- }
- }, 500);
- } else {
- setTimeout(() => {
- if (!this.isOpen) {
- this.doAfterHide();
- }
- }, 500);
- }
-
- this.changeOpacity(isOpen ? 0.5 : 0);
- this.moveLeft(isOpen ? openMenuOffset : hiddenMenuOffset);
-
- this.isOpen = isOpen;
-
- this.forceUpdate();
- this.props.onChange(isOpen);
- }
-
- setGestureEnabled(enabled) {
- gestures.enabled = enabled;
- }
-
- componentDidMount() {
- this.setGestureEnabled(true);
- }
-
- render() {
- const boundryStyle =
- this.props.menuPosition === 'right'
- ? {left: this.state.width - this.state.openMenuOffset}
- : {right: this.state.width - this.state.openMenuOffset};
-
- const menu = (
- <View style={[styles.menu, boundryStyle]}>{this.props.menu}</View>
- );
-
- return (
- <View style={[styles.container]} onLayout={this.onLayoutChange}>
- {menu}
-
- {this.getContentView()}
- </View>
- );
- }
-}
-
-SideMenu.propTypes = {
- edgeHitWidth: PropTypes.number,
- toleranceX: PropTypes.number,
- toleranceY: PropTypes.number,
- menuPosition: PropTypes.oneOf(['left', 'right']),
- onChange: PropTypes.func,
- onMove: PropTypes.func,
- children: PropTypes.node,
- menu: PropTypes.node,
- openMenuOffset: PropTypes.number,
- hiddenMenuOffset: PropTypes.number,
- animationStyle: PropTypes.func,
- disableGestures: PropTypes.oneOfType([PropTypes.func, PropTypes.bool]),
- animationFunction: PropTypes.func,
- onStartShouldSetResponderCapture: PropTypes.func,
- isOpen: PropTypes.bool,
- bounceBackOnOverdraw: PropTypes.bool,
- autoClosing: PropTypes.bool,
-};
-
-SideMenu.defaultProps = {
- toleranceY: 10,
- toleranceX: 10,
- edgeHitWidth: 60,
- children: null,
- menu: null,
- openMenuOffset: deviceScreen.width * (2 / 3),
- disableGestures: false,
- menuPosition: 'left',
- hiddenMenuOffset: 0,
- onMove: () => {},
- onStartShouldSetResponderCapture: () => true,
- onChange: () => {},
- onSliding: () => {},
- animationStyle: value => ({
- transform: [
- {
- translateX: value,
- },
- ],
- }),
- animationFunction: (prop, value) =>
- Animated.timing(prop, {
- toValue: value,
- duration: 300,
- useNativeDriver: true,
- easing: Easing.elastic(0.5),
- }),
- isOpen: false,
-
- bounceBackOnOverdraw: true,
- autoClosing: true,
-};
diff --git a/apps/mobile/src/components/SideMenu/styles.js b/apps/mobile/src/components/SideMenu/styles.js
deleted file mode 100644
index d2012f8c5..000000000
--- a/apps/mobile/src/components/SideMenu/styles.js
+++ /dev/null
@@ -1,34 +0,0 @@
-// @flow
-
-import {StyleSheet} from 'react-native';
-
-const absoluteStretch = {
- position: 'absolute',
- top: 0,
- left: 0,
- bottom: 0,
- right: 0,
-};
-
-export default StyleSheet.create({
- container: {
- ...absoluteStretch,
- justifyContent: 'center',
- },
- menu: {
- ...absoluteStretch,
- },
- frontView: {
- flex: 1,
- position: 'absolute',
- left: 0,
- top: 0,
- backgroundColor: 'transparent',
- overflow: 'hidden',
- },
- overlay: {
- ...absoluteStretch,
- backgroundColor: 'black',
- opacity: 0,
- },
-});
diff --git a/apps/mobile/src/components/header/index.js b/apps/mobile/src/components/header/index.js
index a4a948ef0..1b566cb77 100644
--- a/apps/mobile/src/components/header/index.js
+++ b/apps/mobile/src/components/header/index.js
@@ -132,7 +132,7 @@ export const Header = ({
<TouchableOpacity
hitSlop={{top: 20, bottom: 20, left: 50, right: 40}}
onPress={() => {
- sideMenuRef.current?.openMenu(true);
+ sideMenuRef.current?.openDrawer();
}}
style={{
justifyContent: 'center',
diff --git a/apps/mobile/src/provider/reducer.js b/apps/mobile/src/provider/reducer.js
index 9c523fc0f..15f395985 100644
--- a/apps/mobile/src/provider/reducer.js
+++ b/apps/mobile/src/provider/reducer.js
@@ -127,12 +127,6 @@ export const reducer = (state, action) => {
};
}
case ACTIONS.SELECTION_MODE: {
- if (action.enabled) {
- sideMenuRef.current?.setGestureEnabled(false);
- } else {
- sideMenuRef.current?.setGestureEnabled(true);
- }
-
return {
...state,
selectionMode: action.enabled,
@@ -152,9 +146,6 @@ export const reducer = (state, action) => {
selectedItems.push(action.item);
}
history.selectedItemsList = selectedItems;
- if (selectedItems.length === 0) {
- sideMenuRef.current?.setGestureEnabled(true);
- }
return {
...state,
selectedItemsList: selectedItems,
@@ -163,7 +154,6 @@ export const reducer = (state, action) => {
}
case ACTIONS.CLEAR_SELECTION: {
history.selectedItemsList = [];
- sideMenuRef.current?.setGestureEnabled(true);
return {
...state,
selectedItemsList: [],
diff --git a/apps/mobile/src/views/Editor/index.js b/apps/mobile/src/views/Editor/index.js
index e2dc1e359..69a4758f5 100755
--- a/apps/mobile/src/views/Editor/index.js
+++ b/apps/mobile/src/views/Editor/index.js
@@ -90,7 +90,6 @@ const Editor = ({noMenu}) => {
_onHardwareBackPress,
);
}
- noMenu ? null : sideMenuRef.current?.setGestureEnabled(false);
if (note && note.id) {
dispatch({type: ACTIONS.NOTES});
if (item && item.type === 'new') {
@@ -487,8 +486,6 @@ const Editor = ({noMenu}) => {
ToastEvent.show('Note Saved!', 'success');
}
await clearEditor();
- DDS.isTab ? sideMenuRef.current?.openMenu(true) : null;
- sideMenuRef.current?.setGestureEnabled(true);
if (handleBack) {
handleBack.remove();
handleBack = null;
diff --git a/apps/mobile/src/views/Home/index.js b/apps/mobile/src/views/Home/index.js
index 957242425..3b5e7dc29 100755
--- a/apps/mobile/src/views/Home/index.js
+++ b/apps/mobile/src/views/Home/index.js
@@ -86,8 +86,6 @@ export const Home = ({navigation}) => {
if (DDS.isTab) {
eSendEvent(eOnLoadNote, {type: 'new'});
} else {
- sideMenuRef.current?.openMenu(false);
- sideMenuRef.current?.setGestureEnabled(false);
eSendEvent(eOnLoadNote, {type: 'new'});
openEditorAnimation();
}
diff --git a/apps/mobile/src/views/Login/index.js b/apps/mobile/src/views/Login/index.js
index 24cf79093..a1325a207 100644
--- a/apps/mobile/src/views/Login/index.js
+++ b/apps/mobile/src/views/Login/index.js
@@ -38,10 +38,6 @@ export const Login = ({route, navigation}) => {
const isFocused = useIsFocused();
- useEffect(() => {
- eSendEvent(eCloseSideMenu);
- }, []);
-
const handleBackPress = () => {
return true;
};
diff --git a/apps/mobile/src/views/Notes/index.js b/apps/mobile/src/views/Notes/index.js
index 6bf01f5f1..eb2f225e5 100644
--- a/apps/mobile/src/views/Notes/index.js
+++ b/apps/mobile/src/views/Notes/index.js
@@ -157,8 +157,6 @@ export const Notes = ({route,navigation}) => {
if (DDS.isTab) {
eSendEvent(eOnLoadNote, {type: 'new'});
} else {
- sideMenuRef.current?.openMenu(false);
- sideMenuRef.current?.setGestureEnabled(false);
eSendEvent(eOnLoadNote, {type: 'new'});
openEditorAnimation();
}