Skip to content

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

fix context menu

ammarahm-ed36959654f193
diff --git a/apps/mobile/index.mobile.js b/apps/mobile/index.mobile.js
index 1426bc828..65f86ce63 100644
--- a/apps/mobile/index.mobile.js
+++ b/apps/mobile/index.mobile.js
@@ -14,6 +14,8 @@ import {
} from './src/utils/Animations';
import Editor from './src/views/Editor';
import {NavigationStack} from "./src/navigation/Drawer";
+import ContextMenu from './src/components/ContextMenu';
+import { DummyText } from './src/components/DummyText';
const editorRef = createRef();
@@ -86,6 +88,8 @@ export const Initialize = () => {
</AnimatedScreenContainer>
</Animatable.View>
<Toast />
+ <ContextMenu />
+ <DummyText/>
<DialogManager colors={colors} />
</>
);
diff --git a/apps/mobile/src/components/Container/ContainerBottomButton.js b/apps/mobile/src/components/Container/ContainerBottomButton.js
index e14019912..a34b9bc6c 100644
--- a/apps/mobile/src/components/Container/ContainerBottomButton.js
+++ b/apps/mobile/src/components/Container/ContainerBottomButton.js
@@ -1,27 +1,37 @@
import React, {useEffect, useState} from 'react';
-import {Keyboard, Platform, Text, View} from 'react-native';
+import {Keyboard, Platform, Text, UIManager, View} from 'react-native';
import {useSafeAreaInsets} from 'react-native-safe-area-context';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import {useTracked} from '../../provider';
-import {getElevation} from '../../utils';
+import {getElevation, showContext} from '../../utils';
import {PressableButton} from '../PressableButton';
import {normalize, pv, SIZE, WEIGHT} from '../../utils/SizeUtils';
import {DDS} from '../../services/DeviceDetection';
+import {sleep} from '../../utils/TimeUtils';
+import Animated, {Easing} from 'react-native-reanimated';
+const translateY = new Animated.Value(0);
export const ContainerBottomButton = ({title, onPress, color}) => {
const [state] = useTracked();
const {colors} = state;
- const [buttonHide, setButtonHide] = useState(false);
const insets = useSafeAreaInsets();
- const onKeyboardHide = () => {
+ function animate(translate) {
+ Animated.timing(translateY, {
+ toValue: translate,
+ duration: 250,
+ easing: Easing.elastic(1),
+ }).start();
+ }
+
+ const onKeyboardHide = async () => {
if (DDS.isTab) return;
- setButtonHide(false);
+ animate(0);
};
- const onKeyboardShow = () => {
+ const onKeyboardShow = async () => {
if (DDS.isTab) return;
- setButtonHide(true);
+ animate(150);
};
useEffect(() => {
@@ -34,17 +44,18 @@ export const ContainerBottomButton = ({title, onPress, color}) => {
}, []);
return (
- <View
+ <Animated.View
style={{
- width: '100%',
- opacity: buttonHide ? 0 : 1,
position: 'absolute',
- paddingHorizontal: 12,
- bottom: Platform.OS === 'ios' ? insets.bottom - 10 : insets.bottom + 20,
+ right: 12,
+ bottom: Platform.OS === 'ios' ? insets.bottom - 10 : insets.bottom + 12,
zIndex: 10,
transform: [
{
- translateY: buttonHide ? 200 : 0,
+ translateY: translateY,
+ },
+ {
+ translateX: translateY,
},
],
}}>
@@ -55,34 +66,26 @@ export const ContainerBottomButton = ({title, onPress, color}) => {
customStyle={{
...getElevation(5),
}}
+ onLongPress={event => {
+ console.log(event)
+ showContext(event,title);
+ }}
onPress={onPress}>
<View
style={{
- justifyContent: 'flex-start',
alignItems: 'center',
- flexDirection: 'row',
+ justifyContent: 'center',
width: '100%',
- padding: pv,
- borderRadius: 5,
height: normalize(60),
+ width: normalize(60),
}}>
<Icon
name={title === 'Clear all trash' ? 'delete' : 'plus'}
color="white"
size={SIZE.xl}
/>
- <Text
- testID="container_bottom_btn_text"
- style={{
- fontSize: SIZE.md,
- color: 'white',
- fontFamily: WEIGHT.regular,
- textAlignVertical: 'center',
- }}>
- {' ' + title}
- </Text>
</View>
</PressableButton>
- </View>
+ </Animated.View>
);
};
diff --git a/apps/mobile/src/components/ContextMenu/index.js b/apps/mobile/src/components/ContextMenu/index.js
index 80e01c0c3..4ecf087df 100644
--- a/apps/mobile/src/components/ContextMenu/index.js
+++ b/apps/mobile/src/components/ContextMenu/index.js
@@ -2,8 +2,8 @@ import React, {useEffect, useState} from 'react';
import {Text, View} from 'react-native';
import {useTracked} from '../../provider';
import {eSubscribeEvent, eUnSubscribeEvent} from '../../services/EventManager';
-import { getElevation } from '../../utils';
-import {SIZE, WEIGHT} from "../../utils/SizeUtils";
+import {getElevation} from '../../utils';
+import {SIZE, WEIGHT} from '../../utils/SizeUtils';
let contextTimeout = null;
@@ -51,7 +51,7 @@ const ContextMenu = () => {
left: contextMenu.location.x,
top: contextMenu.location.y,
backgroundColor: colors.night ? colors.nav : 'black',
- paddingVertical: 5,
+ paddingVertical: 8,
paddingHorizontal: 12,
borderRadius: 5,
}}>
diff --git a/apps/mobile/src/components/DummyText/index.js b/apps/mobile/src/components/DummyText/index.js
new file mode 100644
index 000000000..516f7eead
--- /dev/null
+++ b/apps/mobile/src/components/DummyText/index.js
@@ -0,0 +1,24 @@
+import React, { createRef } from 'react';
+import {Text} from 'react-native';
+import {SIZE, WEIGHT} from '../../utils/SizeUtils';
+
+export const dummyRef = createRef();
+
+export const DummyText = () => {
+ return (
+ <Text
+ ref={dummyRef}
+ style={[
+ {
+ fontFamily: WEIGHT.regular,
+ fontSize: SIZE.sm,
+ position:"absolute",
+ right:-1000,
+ top:-1000
+ },
+ ]}>
+ a
+ </Text>
+ );
+};
+
diff --git a/apps/mobile/src/components/NoteItem/index.js b/apps/mobile/src/components/NoteItem/index.js
index 0ba42dfd6..457934f5c 100644
--- a/apps/mobile/src/components/NoteItem/index.js
+++ b/apps/mobile/src/components/NoteItem/index.js
@@ -5,6 +5,8 @@ import {ActionIcon} from '../ActionIcon';
import {ActionSheetEvent} from '../DialogManager/recievers';
import {timeSince} from '../../utils/TimeUtils';
import {ph, SIZE, WEIGHT} from '../../utils/SizeUtils';
+import Paragraph from '../Typography/Paragraph';
+import Heading from '../Typography/Heading';
const w = Dimensions.get('window').width;
const h = Dimensions.get('window').height;
@@ -71,150 +73,128 @@ export default class NoteItem extends React.Component {
]}>
<View
style={{
- paddingLeft: 0,
width: '92%',
+ paddingRight: 5,
}}>
- <Text
- numberOfLines={1}
- style={{
- color: colors.heading,
- fontSize: SIZE.md,
- fontFamily: WEIGHT.bold,
- maxWidth: '100%',
- }}>
+ <Heading numberOfLines={1} size={SIZE.md}>
{item.title.replace('\n', '')}
- </Text>
+ </Heading>
+
+ <Paragraph numberOfLines={2}>
+ {item.headline[item.headline.length - 1] === '\n'
+ ? item.headline.slice(0, item.headline.length - 1)
+ : item.headline}
+ </Paragraph>
+
<View
style={{
+ flexDirection: 'row',
justifyContent: 'flex-start',
- alignItems: 'flex-start',
+ alignItems: 'center',
width: '100%',
+ marginTop: 5,
}}>
- <Text
- numberOfLines={2}
- style={{
- fontSize: SIZE.xs + 1,
- color: colors.pri,
- fontFamily: WEIGHT.regular,
- width: '100%',
- maxWidth: '100%',
- paddingRight: ph,
- }}>
- {item.headline[item.headline.length - 1] === '\n'
- ? item.headline.slice(0, item.headline.length - 1)
- : item.headline}
- </Text>
-
- <View
- style={{
- flexDirection: 'row',
- justifyContent: 'flex-start',
- alignItems: 'center',
- width: '100%',
- marginTop: 5,
- }}>
- {!isTrash ? (
- <>
- {item.colors.length > 0 ? (
- <View
- style={{
- marginRight: 10,
- flexDirection: 'row',
- justifyContent: 'center',
- alignItems: 'center',
- }}>
- {item.colors.map((item) => (
- <View
- key={item}
- style={{
- width: SIZE.xs,
- height: SIZE.xs,
- borderRadius: 100,
- backgroundColor: item,
- marginRight: -4.5,
- }}
- />
- ))}
- </View>
- ) : null}
-
- {item.locked ? (
- <Icon
- style={{marginRight: 10}}
- name="lock"
- size={SIZE.xs}
- color={colors.icon}
- />
- ) : null}
-
- {item.favorite ? (
- <Icon
- style={{marginRight: 10}}
- name="star"
- size={SIZE.xs + 1}
- color="orange"
- />
- ) : null}
- <Text
+ {!isTrash ? (
+ <>
+ {item.colors.length > 0 ? (
+ <View
style={{
- color: colors.icon,
- fontSize: SIZE.xs - 1,
- textAlignVertical: 'center',
- fontFamily: WEIGHT.regular,
marginRight: 10,
+ flexDirection: 'row',
+ justifyContent: 'center',
+ alignItems: 'center',
}}>
- {timeSince(item.dateCreated)}
- </Text>
- </>
- ) : null}
+ {item.colors.map((item) => (
+ <View
+ key={item}
+ style={{
+ width: SIZE.xs,
+ height: SIZE.xs,
+ borderRadius: 100,
+ backgroundColor: item,
+ marginRight: -4.5,
+ }}
+ />
+ ))}
+ </View>
+ ) : null}
- {isTrash ? (
- <>
- <Text
- style={{
- color: colors.accent,
- fontSize: SIZE.xs - 1,
- textAlignVertical: 'center',
- fontFamily: WEIGHT.regular,
- }}>
- {item.itemType[0].toUpperCase() +
- item.itemType.slice(1) +
- ' '}
- </Text>
- <Text
- style={{
- color: colors.icon,
- fontSize: SIZE.xs - 1,
- textAlignVertical: 'center',
- fontFamily: WEIGHT.regular,
- }}>
- Deleted on{' '}
- {item && item.dateDeleted
- ? new Date(item.dateDeleted).toISOString().slice(0, 10)
- : null + ' '}
- </Text>
- </>
- ) : null}
+ {item.locked ? (
+ <Icon
+ style={{marginRight: 10}}
+ name="lock"
+ size={SIZE.xs}
+ color={colors.icon}
+ />
+ ) : null}
- {item.conflicted ? (
- <View
+ {item.favorite ? (
+ <Icon
+ style={{marginRight: 10}}
+ name="star"
+ size={SIZE.xs + 1}
+ color="orange"
+ />
+ ) : null}
+ <Text
style={{
- backgroundColor: colors.errorText,
- borderRadius: 2.5,
- paddingHorizontal: 4,
- position: 'absolute',
- right: 20,
+ color: colors.icon,
+ fontSize: SIZE.xs - 1,
+ textAlignVertical: 'center',
+ fontFamily: WEIGHT.regular,
+ marginRight: 10,
}}>
- <Text
- style={{
- fontSize: SIZE.xs - 1,
- color: 'white',
- }}>
- CONFLICTS
- </Text>
- </View>
- ) : null}
- </View>
+ {timeSince(item.dateCreated)}
+ </Text>
+ </>
+ ) : null}
+
+ {isTrash ? (
+ <>
+ <Text
+ style={{
+ color: colors.accent,
+ fontSize: SIZE.xs - 1,
+ textAlignVertical: 'center',
+ fontFamily: WEIGHT.regular,
+ }}>
+ {item.itemType[0].toUpperCase() +
+ item.itemType.slice(1) +
+ ' '}
+ </Text>
+ <Text
+ style={{
+ color: colors.icon,
+ fontSize: SIZE.xs - 1,
+ textAlignVertical: 'center',
+ fontFamily: WEIGHT.regular,
+ }}>
+ Deleted on{' '}
+ {item && item.dateDeleted
+ ? new Date(item.dateDeleted).toISOString().slice(0, 10)
+ : null + ' '}
+ </Text>
+ </>
+ ) : null}
+
+ {item.conflicted ? (
+ <View
+ style={{
+ backgroundColor: colors.errorText,
+ borderRadius: 2.5,
+ paddingHorizontal: 4,
+ position: 'absolute',
+ right: 20,
+ }}>
+ <Text
+ style={{
+ fontSize: SIZE.xs - 1,
+ color: 'white',
+ }}>
+ CONFLICTS
+ </Text>
+ </View>
+ ) : null}
</View>
</View>
diff --git a/apps/mobile/src/utils/SizeUtils.js b/apps/mobile/src/utils/SizeUtils.js
index abcf94569..c1b126f82 100644
--- a/apps/mobile/src/utils/SizeUtils.js
+++ b/apps/mobile/src/utils/SizeUtils.js
@@ -1,94 +1,94 @@
-import {Dimensions, PixelRatio, Platform} from "react-native";
-import {DDS} from "../services/DeviceDetection";
+import {Dimensions, PixelRatio, Platform} from 'react-native';
+import {DDS} from '../services/DeviceDetection';
export const scale = {
- fontScale: 1,
+ fontScale: 1,
};
let windowSize = Dimensions.get('window');
let adjustedWidth = windowSize.width * PixelRatio.get();
let adjustedHeight = windowSize.height * PixelRatio.get();
const pixelDensity = PixelRatio.get();
export const getDeviceSize = () => {
- let dpi = getDpi(pixelDensity);
- let deviceWidthInInches = adjustedWidth / dpi;
- let deviceHeightInInches = adjustedHeight / dpi;
- let diagonalSize = Math.sqrt(
- Math.pow(deviceWidthInInches, 2) + Math.pow(deviceHeightInInches, 2),
- );
- return diagonalSize;
+ let dpi = getDpi(pixelDensity);
+ let deviceWidthInInches = adjustedWidth / dpi;
+ let deviceHeightInInches = adjustedHeight / dpi;
+ let diagonalSize = Math.sqrt(
+ Math.pow(deviceWidthInInches, 2) + Math.pow(deviceHeightInInches, 2),
+ );
+ return diagonalSize;
};
const getDpi = (pd) => {
- return 160 * pd;
+ return 160 * pd;
};
const correction = (size, multiplier) => {
- let dSize = getDeviceSize();
- if (dSize >= 4 && dSize <= 5.3 && pixelDensity <= 3) {
- return size * 0.92;
- } else if (dSize > 5.3 && dSize < 7 && pixelDensity < 3 && !DDS.isTab) {
- if (Platform.OS === 'ios') {
- return size;
- }
- return size * 0.93;
- } else if (dSize <= 7 && pixelDensity >= 3 && !DDS.isTab) {
- return size * 0.98;
- } else if (dSize >= 6.5 && dSize <= 7.2 && DDS.isTab) {
- return size * multiplier;
- } else if (dSize > 7.2 && dSize <= 8.5 && DDS.isTab) {
- return size * (multiplier + 0.10);
- } else if (dSize > 8.5 && dSize <= 9.8 && DDS.isTab) {
- return size * (multiplier + 0.15);
- } else if (dSize > 9.8) {
- return size;
- } else {
- return size;
+ let dSize = getDeviceSize();
+ if (dSize >= 4 && dSize <= 5.3 && pixelDensity <= 3) {
+ return size * 0.92;
+ } else if (dSize > 5.3 && dSize < 7 && pixelDensity < 3 && !DDS.isTab) {
+ if (Platform.OS === 'ios') {
+ return size;
}
+ return size * 0.93;
+ } else if (dSize <= 7 && pixelDensity >= 3 && !DDS.isTab) {
+ return size * 0.98;
+ } else if (dSize >= 6.5 && dSize <= 7.2 && DDS.isTab) {
+ return size * multiplier;
+ } else if (dSize > 7.2 && dSize <= 8.5 && DDS.isTab) {
+ return size * (multiplier + 0.1);
+ } else if (dSize > 8.5 && dSize <= 9.8 && DDS.isTab) {
+ return size * (multiplier + 0.15);
+ } else if (dSize > 9.8) {
+ return size;
+ } else {
+ return size;
+ }
};
export const normalize = (size) => {
- let pd = pixelDensity;
- if (pd === 1 || pd < 1) {
- return correction(size, 0.82);
- } else if (pd > 1 && pd <= 1.5) {
- return correction(size, 0.7);
- } else if (pd > 1.5 && pd <= 2) {
- return correction(size, 0.9);
- } else if (pd > 2 && pd <= 3) {
- return correction(size, 0.93);
- } else if (pd > 3) {
- return correction(size, 1);
- }
+ let pd = pixelDensity;
+ if (pd === 1 || pd < 1) {
+ return correction(size, 0.82);
+ } else if (pd > 1 && pd <= 1.5) {
+ return correction(size, 0.7);
+ } else if (pd > 1.5 && pd <= 2) {
+ return correction(size, 0.9);
+ } else if (pd > 2 && pd <= 3) {
+ return correction(size, 0.93);
+ } else if (pd > 3) {
+ return correction(size, 1);
+ }
};
export const SIZE = {
- xxs: 9 * scale.fontScale,
- xs: 11 * scale.fontScale,
- sm: normalize(14) * scale.fontScale,
- md: normalize(16) * scale.fontScale,
- lg: normalize(21) * scale.fontScale,
- xl: normalize(24) * scale.fontScale,
- xxl: normalize(28) * scale.fontScale,
- xxxl: normalize(32) * scale.fontScale,
+ xxs: 9 * scale.fontScale,
+ xs: 11 * scale.fontScale,
+ sm: normalize(13) * scale.fontScale,
+ md: normalize(16) * scale.fontScale,
+ lg: normalize(21) * scale.fontScale,
+ xl: normalize(24) * scale.fontScale,
+ xxl: normalize(28) * scale.fontScale,
+ xxxl: normalize(32) * scale.fontScale,
};
export function updateSize() {
- SIZE.xxs = 9 * scale.fontScale;
- SIZE.xs = 11 * scale.fontScale;
- SIZE.sm = normalize(14) * scale.fontScale;
- SIZE.md = normalize(16) * scale.fontScale;
- SIZE.lg = normalize(21) * scale.fontScale;
- SIZE.xl = normalize(24) * scale.fontScale;
- SIZE.xxl = normalize(28) * scale.fontScale;
- SIZE.xxxl = normalize(32) * scale.fontScale;
- ph = normalize(10) * scale.fontScale;
- pv = normalize(10) * scale.fontScale;
+ SIZE.xxs = 9 * scale.fontScale;
+ SIZE.xs = 10 * scale.fontScale;
+ SIZE.sm = normalize(13) * scale.fontScale;
+ SIZE.md = normalize(16) * scale.fontScale;
+ SIZE.lg = normalize(21) * scale.fontScale;
+ SIZE.xl = normalize(24) * scale.fontScale;
+ SIZE.xxl = normalize(28) * scale.fontScale;
+ SIZE.xxxl = normalize(32) * scale.fontScale;
+ ph = normalize(10) * scale.fontScale;
+ pv = normalize(10) * scale.fontScale;
}
-export const br = 5; // border radius
-export var ph = normalize(10); // padding horizontal
-export var pv = normalize(10); // padding vertical
-export const opacity = 0.5; // active opacity
+export const br = 5; // border radius
+export var ph = normalize(10); // padding horizontal
+export var pv = normalize(10); // padding vertical
+export const opacity = 0.5; // active opacity
export const WEIGHT = {
- light: 'Poppins-Regular',
- regular: 'Poppins-Regular',
- medium: 'Poppins-Regular',
- semibold: 'Poppins-SemiBold',
- bold: 'Poppins-SemiBold',
-};
\ No newline at end of file
+ light: 'Poppins-Regular',
+ regular: 'Poppins-Regular',
+ medium: 'Poppins-Regular',
+ semibold: 'Poppins-SemiBold',
+ bold: 'Poppins-SemiBold',
+};
diff --git a/apps/mobile/src/utils/index.js b/apps/mobile/src/utils/index.js
index d24d112d1..ed4f62efd 100755
--- a/apps/mobile/src/utils/index.js
+++ b/apps/mobile/src/utils/index.js
@@ -2,10 +2,12 @@ import {Dimensions, Platform} from 'react-native';
import {eSendEvent} from '../services/EventManager';
import {updateEvent} from '../components/DialogManager/recievers';
import {Actions} from '../provider/Actions';
-import {MMKV} from "./MMKV";
+import {MMKV} from './mmkv';
import RNFetchBlob from 'rn-fetch-blob';
-import {defaultState} from "../provider/DefaultState";
-import { createRef } from 'react';
+import {defaultState} from '../provider/DefaultState';
+import {createRef} from 'react';
+import {dummyRef} from '../components/DummyText';
+import {SIZE} from './SizeUtils';
export async function setSetting(settings, name, value) {
let s = {...settings};
@@ -14,11 +16,10 @@ export async function setSetting(settings, name, value) {
updateEvent({type: Actions.SETTINGS, settings: s});
}
-
export const scrollRef = createRef();
export const dirs = RNFetchBlob.fs.dirs;
-export const ANDROID_PATH = dirs.SDCardDir + '/Notesnook/';
+export const ANDROID_PATH = dirs.SDCardDir + '/Notesnook/';
export const IOS_PATH = dirs.DocumentDir;
export const getElevation = (elevation) => {
@@ -32,17 +33,17 @@ export const getElevation = (elevation) => {
};
export const sortSettings = {
- sort:defaultState.settings.sort,
- sortOrder: defaultState.settings.sortOrder
-}
+ sort: defaultState.settings.sort,
+ sortOrder: defaultState.settings.sortOrder,
+};
export const SORT = {
default: null,
alphabetical: 'abc',
year: 'year',
week: 'week',
- month: 'month'
-}
+ month: 'month',
+};
export const editing = {
currentlyEditing: false,
@@ -62,12 +63,33 @@ export const history = {
};
export async function showContext(event, title) {
- eSendEvent('showContextMenu', {
- location: {
- x: event.nativeEvent.pageX + 50,
- y: event.nativeEvent.pageY - 10,
- },
- title: title,
+ console.log(event.nativeEvent);
+ event._targetInst.ref.current?.measureInWindow((x, y, w, h) => {
+ dummyRef.current.setNativeProps({
+ style: {
+ fontSize: SIZE.sm,
+ },
+ });
+ dummyRef.current?.measure((xt, yt, wt, ht) => {
+ let xVal;
+ let yVal;
+
+ if (x > dWidth / 50) {
+ xVal = x - (w + (wt * title.length - 40));
+ } else {
+ xVal = x + (w + (wt * title.length - 40));
+ }
+
+ yVal = y + h / 2 + 10;
+
+ eSendEvent('showContextMenu', {
+ location: {
+ x: xVal,
+ y: yVal,
+ },
+ title: title,
+ });
+ });
});
}
@@ -79,7 +101,6 @@ export const itemSkus = Platform.select({
android: ['com.streetwriters.notesnook.sub.mo'],
});
-
export const MenuItemsList = [
{
name: 'Home',
@@ -107,4 +128,3 @@ export const MenuItemsList = [
close: true,
},
];
-