Skip to content

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

fix: sidemenu & ActionSheet bugs

ammarahm-ed8b6e4c648352
diff --git a/apps/mobile/App.js b/apps/mobile/App.js
index a9a776429..d6a555c56 100644
--- a/apps/mobile/App.js
+++ b/apps/mobile/App.js
@@ -43,13 +43,11 @@ const App = () => {
useEffect(() => {
DeviceEventEmitter.addListener('openSidebar', () => {
- DDS.isTab
- ? setSidebar(w * 0.3)
- : sideMenuRef.openMenu(!sideMenuRef.isOpen);
+ DDS.isTab ? setSidebar(w * 0.3) : sideMenuRef.openMenu(true);
});
DeviceEventEmitter.addListener('closeSidebar', () => {
- DDS.isTab ? setSidebar(0) : sideMenuRef.openMenu(!sideMenuRef.isOpen);
+ DDS.isTab ? setSidebar(0) : sideMenuRef.openMenu(false);
});
DeviceEventEmitter.addListener('disableGesture', () => {
sideMenuRef.setGestureEnabled(false);
@@ -60,10 +58,10 @@ const App = () => {
return () => {
DeviceEventEmitter.removeListener('openSidebar', () => {
- DDS.isTab ? setSidebar(0) : sideMenuRef.openMenu(!sideMenuRef.isOpen);
+ DDS.isTab ? setSidebar(0) : sideMenuRef.openMenu(true);
});
DeviceEventEmitter.removeListener('closeSidebar', () => {
- DDS.isTab ? setSidebar(0) : sideMenuRef.openMenu(!sideMenuRef.isOpen);
+ DDS.isTab ? setSidebar(0) : sideMenuRef.openMenu(false);
});
DeviceEventEmitter.removeListener('disableGesture', () => {
sideMenuRef.setGestureEnabled(false);
diff --git a/apps/mobile/src/components/ActionSheetComponent/index.js b/apps/mobile/src/components/ActionSheetComponent/index.js
index 0923eb629..4ab2d763f 100644
--- a/apps/mobile/src/components/ActionSheetComponent/index.js
+++ b/apps/mobile/src/components/ActionSheetComponent/index.js
@@ -37,10 +37,23 @@ export const ActionSheetComponent = ({
}) => {
const {colors, changeColorScheme} = useAppContext();
const [focused, setFocused] = useState(false);
- const [note, setNote] = useState(item ? item : {});
+ const [note, setNote] = useState({
+ colors: [],
+ tags: [],
+ pinned: false,
+ favorite: false,
+ locked: false,
+ content: {
+ text: '',
+ delta: {},
+ },
+ dateCreated: null,
+ });
useEffect(() => {
- setNote({...item});
+ if (item.dateCreated !== null) {
+ setNote({...item});
+ }
}, [item]);
let tagToAdd = null;
@@ -116,6 +129,7 @@ export const ActionSheetComponent = ({
};
const localRefresh = type => {
+ if (!note || !note.dateCreated) return;
let toAdd;
switch (type) {
case 'note': {
@@ -229,6 +243,7 @@ export const ActionSheetComponent = ({
name: 'Pin',
icon: 'tag',
func: () => {
+ if (!note.dateCreated) return;
db.pinItem(note.type, note.dateCreated);
localRefresh(item.type);
},
@@ -240,6 +255,7 @@ export const ActionSheetComponent = ({
name: 'Favorite',
icon: 'star',
func: () => {
+ if (!note.dateCreated) return;
db.favoriteItem(note.type, note.dateCreated);
localRefresh(item.type);
},
@@ -251,6 +267,7 @@ export const ActionSheetComponent = ({
name: 'Add to Vault',
icon: 'lock',
func: () => {
+ if (!note.dateCreated) return;
note.locked ? close('unlock') : close('lock');
},
close: true,
@@ -364,7 +381,7 @@ export const ActionSheetComponent = ({
justifyContent: 'center',
alignItems: 'center',
}}>
- {note.colors.includes(color) ? (
+ {note && note.colors && note.colors.includes(color) ? (
<Icon name="check" color="white" size={SIZE.lg} />
) : null}
</View>
@@ -386,45 +403,47 @@ export const ActionSheetComponent = ({
borderColor: focused ? colors.accent : colors.nav,
paddingVertical: 5,
}}>
- {note.tags.map(tag => (
- <TouchableOpacity
- key={tag}
- onPress={() => {
- let oldProps = {...note};
+ {note && note.tags
+ ? note.tags.map(tag => (
+ <TouchableOpacity
+ key={tag}
+ onPress={() => {
+ let oldProps = {...note};
- oldProps.tags.splice(oldProps.tags.indexOf(tag), 1);
- db.addNote({
- dateCreated: note.dateCreated,
- content: note.content,
- title: note.title,
- tags: oldProps.tags,
- });
- localRefresh(item.type);
- }}
- style={{
- flexDirection: 'row',
- justifyContent: 'flex-start',
- alignItems: 'center',
- margin: 1,
- paddingHorizontal: 5,
- paddingVertical: 2.5,
- }}>
- <Text
- style={{
- fontFamily: WEIGHT.regular,
- fontSize: SIZE.sm,
- color: colors.pri,
- }}>
- <Text
+ oldProps.tags.splice(oldProps.tags.indexOf(tag), 1);
+ db.addNote({
+ dateCreated: note.dateCreated,
+ content: note.content,
+ title: note.title,
+ tags: oldProps.tags,
+ });
+ localRefresh(item.type);
+ }}
style={{
- color: colors.accent,
+ flexDirection: 'row',
+ justifyContent: 'flex-start',
+ alignItems: 'center',
+ margin: 1,
+ paddingHorizontal: 5,
+ paddingVertical: 2.5,
}}>
- {tag.slice(0, 1)}
- </Text>
- {tag.slice(1)}
- </Text>
- </TouchableOpacity>
- ))}
+ <Text
+ style={{
+ fontFamily: WEIGHT.regular,
+ fontSize: SIZE.sm,
+ color: colors.pri,
+ }}>
+ <Text
+ style={{
+ color: colors.accent,
+ }}>
+ {tag.slice(0, 1)}
+ </Text>
+ {tag.slice(1)}
+ </Text>
+ </TouchableOpacity>
+ ))
+ : null}
<TextInput
style={{
backgroundColor: 'transparent',
diff --git a/apps/mobile/src/components/SideMenu/index.js b/apps/mobile/src/components/SideMenu/index.js
index 625f8a917..619251e23 100644
--- a/apps/mobile/src/components/SideMenu/index.js
+++ b/apps/mobile/src/components/SideMenu/index.js
@@ -7,10 +7,11 @@ import {
Dimensions,
Animated,
TouchableWithoutFeedback,
+ Easing,
} from 'react-native';
import PropTypes from 'prop-types';
import styles from './styles';
-
+import * as Animatable from 'react-native-animatable';
const deviceScreen = Dimensions.get('window');
const barrierForward = deviceScreen.width / 4;
@@ -26,6 +27,8 @@ export default class SideMenu extends React.Component {
this.isOpen = !!props.isOpen;
this.isGestureEnabled = true;
+ this.opacity = new Animated.Value(0);
+
const initialMenuPositionMultiplier =
props.menuPosition === 'right' ? -1 : 1;
const openOffsetMenuPercentage = props.openMenuOffset / deviceScreen.width;
@@ -105,7 +108,17 @@ export default class SideMenu extends React.Component {
if (this.isOpen) {
overlay = (
<TouchableWithoutFeedback onPress={() => this.openMenu(false)}>
- <View style={styles.overlay} />
+ <Animated.View
+ style={{
+ position: 'absolute',
+ top: 0,
+ left: 0,
+ bottom: 0,
+ right: 0,
+ backgroundColor: 'black',
+ opacity: this.opacity,
+ }}
+ />
</TouchableWithoutFeedback>
);
}
@@ -126,6 +139,14 @@ export default class SideMenu extends React.Component {
);
}
+ changeOpacity(opacity) {
+ Animated.timing(this.opacity, {
+ toValue: opacity,
+ duration: 400,
+ useNativeDriver: true,
+ }).start();
+ }
+
moveLeft(offset) {
const newOffset = this.menuPositionMultiplier() * offset;
@@ -187,7 +208,9 @@ export default class SideMenu extends React.Component {
openMenu(isOpen) {
const {hiddenMenuOffset, openMenuOffset} = this.state;
+ this.changeOpacity(isOpen ? 0.4 : 0);
this.moveLeft(isOpen ? openMenuOffset : hiddenMenuOffset);
+
this.isOpen = isOpen;
this.forceUpdate();
@@ -215,6 +238,7 @@ export default class SideMenu extends React.Component {
return (
<View style={styles.container} onLayout={this.onLayoutChange}>
{menu}
+
{this.getContentView()}
</View>
);
@@ -263,10 +287,11 @@ SideMenu.defaultProps = {
],
}),
animationFunction: (prop, value) =>
- Animated.spring(prop, {
+ Animated.timing(prop, {
toValue: value,
- friction: 8,
+ duration: 300,
useNativeDriver: true,
+ easing: Easing.elastic(0.5),
}),
isOpen: false,
diff --git a/apps/mobile/src/components/SideMenu/styles.js b/apps/mobile/src/components/SideMenu/styles.js
index 109a0dea5..d2012f8c5 100644
--- a/apps/mobile/src/components/SideMenu/styles.js
+++ b/apps/mobile/src/components/SideMenu/styles.js
@@ -28,6 +28,7 @@ export default StyleSheet.create({
},
overlay: {
...absoluteStretch,
- backgroundColor: 'transparent',
+ backgroundColor: 'black',
+ opacity: 0,
},
});
diff --git a/apps/mobile/src/components/header/index.js b/apps/mobile/src/components/header/index.js
index cbf76764f..a65d42743 100644
--- a/apps/mobile/src/components/header/index.js
+++ b/apps/mobile/src/components/header/index.js
@@ -7,6 +7,7 @@ import * as Animatable from 'react-native-animatable';
import NavigationService from '../../services/NavigationService';
import {DDS} from '../../../App';
import {useAppContext} from '../../provider/useAppContext';
+let isOpen = false;
export const Header = ({
heading,
canGoBack = true,
@@ -17,7 +18,6 @@ export const Header = ({
sendHeight = e => {},
}) => {
const {colors} = useAppContext();
- let isOpen = false;
return (
<Animatable.View
@@ -69,13 +69,7 @@ export const Header = ({
<TouchableOpacity
hitSlop={{top: 20, bottom: 20, left: 50, right: 40}}
onPress={() => {
- if (isOpen) {
- SideMenuEvent.close();
- isOpen = false;
- } else {
- SideMenuEvent.open();
- isOpen = true;
- }
+ SideMenuEvent.open();
}}
style={{
justifyContent: 'center',
diff --git a/apps/mobile/src/views/Editor/index.js b/apps/mobile/src/views/Editor/index.js
index 526b31848..6999fac69 100755
--- a/apps/mobile/src/views/Editor/index.js
+++ b/apps/mobile/src/views/Editor/index.js
@@ -310,7 +310,6 @@ const Editor = ({navigation}) => {
}, []);
useEffect(() => {
- SideMenuEvent.close();
SideMenuEvent.disable();
return () => {
DDS.isTab ? SideMenuEvent.open() : null;