Skip to content

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

update quick note widget item

ammarahm-ed8a11961a6de3
diff --git a/apps/mobile/QuickNoteIOS.js b/apps/mobile/QuickNoteIOS.js
index 9b8a6dc97..374193ca3 100644
--- a/apps/mobile/QuickNoteIOS.js
+++ b/apps/mobile/QuickNoteIOS.js
@@ -1,23 +1,18 @@
-import React, {Component, createRef} from 'react';
-import {SafeAreaView} from 'react-native';
+import React, { Component, createRef } from 'react';
import {
ActivityIndicator,
Appearance,
- KeyboardAvoidingView,
- Modal,
- Platform,
- Text,
+ KeyboardAvoidingView, Platform, SafeAreaView, Text,
TouchableOpacity,
- View,
+ View
} from 'react-native';
-import {ScrollView, TextInput} from 'react-native-gesture-handler';
+import { TextInput } from 'react-native-gesture-handler';
import SplashScreen from 'react-native-splash-screen';
-import {COLOR_SCHEME_DARK, COLOR_SCHEME_LIGHT} from './src/utils/Colors';
-import {db} from './src/utils/DB';
-import {SIZE} from './src/utils/SizeUtils';
-import Storage from './src/utils/storage';
-import {sleep} from './src/utils/TimeUtils';
import ShareExtension from 'rn-extensions-share';
+import { COLOR_SCHEME_DARK, COLOR_SCHEME_LIGHT } from './src/utils/Colors';
+import { db } from './src/utils/database';
+import Storage from './src/utils/storage';
+import { sleep } from './src/utils/TimeUtils';
let validator;
let linkPreview;
diff --git a/apps/mobile/share/index.js b/apps/mobile/share/index.js
index 31f612f8b..a5b045a2a 100644
--- a/apps/mobile/share/index.js
+++ b/apps/mobile/share/index.js
@@ -19,7 +19,10 @@ import WebView from 'react-native-webview';
import ShareExtension from 'rn-extensions-share';
import sanitize from 'sanitize-html';
import validator from 'validator';
+import {getElevation, showTooltip, TOOLTIP_POSITIONS} from '../src/utils';
import {COLOR_SCHEME_DARK, COLOR_SCHEME_LIGHT} from '../src/utils/Colors';
+import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
+import Clipboard from '@react-native-clipboard/clipboard';
import {db} from '../src/utils/database';
import {SIZE} from '../src/utils/SizeUtils';
import Storage from '../src/utils/storage';
@@ -70,6 +73,24 @@ let defaultNote = {
let editorContentValue = null;
+const modes = {
+ 1: {
+ type: 'text',
+ title: 'Plain text',
+ icon: 'card-text-outline'
+ },
+ 2: {
+ type: 'clip',
+ title: 'Web clip',
+ icon: 'web'
+ },
+ 3: {
+ type: 'link',
+ title: 'Link',
+ icon: 'link'
+ }
+};
+
const NotesnookShare = () => {
const [colors, setColors] = useState(
Appearance.getColorScheme() === 'dark'
@@ -80,6 +101,7 @@ const NotesnookShare = () => {
const [loadingIntent, setLoadingIntent] = useState(true);
const [loading, setLoading] = useState(false);
const [floating, setFloating] = useState(false);
+ const [quickNote, setQuickNote] = useState(false);
const [rawData, setRawData] = useState({
type: null,
value: null
@@ -93,8 +115,12 @@ const NotesnookShare = () => {
const insets = {
top: Platform.OS === 'ios' ? 30 : 0
};
+ const prevAnimation = useRef(null);
+ const [mode, setMode] = useState(1);
+ const [keyboard,setKeyboard] = useState(false);
const animate = (opacityV, translateV) => {
+ prevAnimation.current = translateV;
if (Platform.OS === 'ios') return;
timing(opacity, {
toValue: opacityV,
@@ -108,17 +134,29 @@ const NotesnookShare = () => {
}).start();
};
+ const onKeyboardDidShow = (event) => {
+ let kHeight = event.endCoordinates.height;
+ console.log('called')
+ translate.setValue(-kHeight/1.8);
+ }
+
+ const onKeyboardDidHide = () => {
+ translate.setValue(0);
+ }
+
useEffect(() => {
- Keyboard.addListener('keyboardWillChangeFrame', onKeyboardWillChangeFrame);
+ let keyboardWillChangeFrame = Keyboard.addListener('keyboardWillChangeFrame', onKeyboardWillChangeFrame);
+ let keyboardDidShow = Keyboard.addListener("keyboardDidShow", onKeyboardDidShow);
+ let keyboardDidHide = Keyboard.addListener("keyboardDidHide", onKeyboardDidHide);
return () => {
- Keyboard.removeListener(
- 'keyboardWillChangeFrame',
- onKeyboardWillChangeFrame
- );
+ keyboardWillChangeFrame?.remove();
+ keyboardDidShow?.remove();
+ keyboardDidHide?.remove();
};
- });
+ },[]);
const onKeyboardWillChangeFrame = event => {
+ console.log('keyboad change frame',event)
setFloating(event.endCoordinates.width !== width);
};
@@ -144,6 +182,15 @@ const NotesnookShare = () => {
return defaultNote;
});
const data = await ShareExtension.data();
+ console.log(data);
+ if (!data || data.length === 0) {
+ setRawData({
+ value: ''
+ });
+ setLoadingIntent(false);
+ setQuickNote(true);
+ return;
+ }
for (item of data) {
if (item.type === 'text') {
setRawData(item);
@@ -168,7 +215,7 @@ const NotesnookShare = () => {
useEffect(() => {
setNote(defaultNote);
loadData();
- sleep(300).then(() => {
+ sleep(50).then(() => {
animate(1, 0);
});
}, []);
@@ -237,7 +284,6 @@ const NotesnookShare = () => {
justifyContent: 'flex-end',
opacity: Platform.OS !== 'ios' ? opacity : 1
}}>
-
<TouchableOpacity
activeOpacity={1}
onPress={() => {
@@ -252,18 +298,21 @@ const NotesnookShare = () => {
style={{
width: '100%',
height: '100%',
- backgroundColor: 'rgba(0,0,0,0.01)'
+ backgroundColor: 'rgba(0,0,0,0)'
}}
/>
</TouchableOpacity>
<AnimatedKAV
enabled={!floating && Platform.OS === 'ios'}
+ onLayout={event => {
+ if (prevAnimation.current === 0) return;
+ console.log('setting value here');
+ translate.setValue(event.nativeEvent.layout.height + 30);
+ }}
style={{
paddingVertical: 25,
- backgroundColor: colors.bg,
- borderTopRightRadius: 10,
- borderTopLeftRadius: 10,
+ backgroundColor: 'transparent',
marginBottom: insets.top,
transform: [
{
@@ -272,17 +321,20 @@ const NotesnookShare = () => {
]
}}
behavior="padding">
+ {quickNote ? null : (
<View
- style={{
- width:50,
- height:6,
- borderRadius:100,
- backgroundColor:colors.nav,
- alignSelf:'center',
- position:'absolute',
- marginTop:15
- }}
+ style={{
+ width: 50,
+ height: 6,
+ borderRadius: 100,
+ backgroundColor: colors.nav,
+ alignSelf: 'center',
+ position: 'absolute',
+ marginTop: 15
+ }}
/>
+ )}
+
{loadingIntent ? (
<View
style={{
@@ -308,186 +360,281 @@ const NotesnookShare = () => {
style={{
maxHeight: '100%'
}}>
+ {quickNote ? null : (
+ <View
+ style={{
+ borderBottomWidth: 1,
+ borderBottomColor: colors.nav,
+ paddingHorizontal: 12
+ }}>
+ <TextInput
+ ref={titleInputRef}
+ style={{
+ fontSize: 25,
+ fontFamily:
+ Platform.OS === 'android' ? 'Roboto-Medium' : null,
+ fontWeight: Platform.OS === 'ios' ? '600' : null,
+ color: colors.pri,
+ flexGrow: 1,
+ maxWidth: '100%'
+ }}
+ placeholderTextColor={colors.icon}
+ defaultValue={note?.title}
+ onChangeText={v =>
+ setNote(_note => {
+ _note.title = v;
+ return _note;
+ })
+ }
+ onSubmitEditing={() => {
+ textInputRef.current?.focus();
+ }}
+ blurOnSubmit={false}
+ placeholder="Note title"
+ />
+ </View>
+ )}
+
+ {quickNote ? null : (
+ <View
+ style={{
+ flexDirection: 'row',
+ alignItems: 'center',
+ marginVertical: 10,
+ borderBottomWidth: 1,
+ borderBottomColor: colors.nav
+ }}>
+ {[
+ {
+ title: 'Plain text',
+ onPress: () => {
+ let html = validator.isURL(rawData.value)
+ ? makeHtmlFromUrl(rawData.value)
+ : makeHtmlFromPlainText(rawData.value);
+ setNote(note => {
+ note.content.data = html;
+ return note;
+ });
+ onLoad();
+ }
+ },
+ ...[
+ rawData?.value && validator.isURL(rawData.value)
+ ? {
+ title: 'Clip webpage',
+ onPress: async () => {
+ let html = await sanitizeHtml(rawData.value);
+ setNote(note => {
+ note.content.data = html;
+ return note;
+ });
+ onLoad();
+ }
+ }
+ : null
+ ]
+ ].map(
+ (item, index) =>
+ item && (
+ <Button
+ title={item.title}
+ color={colors.nav}
+ textStyle={{
+ color: colors.icon,
+ fontWeight: 'normal',
+ fontSize: 14,
+ fontFamily: null
+ }}
+ onPress={item.onPress}
+ style={{
+ borderWidth: 0.5,
+ borderRadius: 100,
+ borderColor: colors.icon,
+ height: 30,
+ marginRight: 10,
+ marginLeft: index === 0 ? 12 : 0,
+ paddingHorizontal: 12
+ }}
+ />
+ )
+ )}
+ </View>
+ )}
+
+ {quickNote ? null : (
+ <View
+ style={{
+ height: height * 0.25,
+ width: '100%'
+ }}>
+ <WebView
+ onLoad={onLoad}
+ ref={webviewRef}
+ style={{
+ width: '100%',
+ height: '100%',
+ backgroundColor: 'transparent'
+ }}
+ cacheMode="LOAD_DEFAULT"
+ domStorageEnabled={true}
+ scrollEnabled={true}
+ bounces={false}
+ allowFileAccess={true}
+ scalesPageToFit={true}
+ allowingReadAccessToURL={
+ Platform.OS === 'android' ? true : null
+ }
+ onShouldStartLoadWithRequest={onShouldStartLoadWithRequest}
+ allowFileAccessFromFileURLs={true}
+ allowUniversalAccessFromFileURLs={true}
+ originWhitelist={['*']}
+ javaScriptEnabled={true}
+ cacheEnabled={true}
+ source={
+ Platform.OS === 'ios'
+ ? {uri: sourceUri}
+ : {
+ uri: 'file:///android_asset/plaineditor.html',
+ baseUrl: 'file:///android_asset/'
+ }
+ }
+ />
+ </View>
+ )}
+
<View
style={{
- borderBottomWidth: 1,
- borderBottomColor: colors.nav,
+ width: '100%',
paddingHorizontal: 12
}}>
- <TextInput
- ref={titleInputRef}
+ <Button
+ color={colors.accent}
+ onPress={onPress}
+ loading={loading}
+ icon="check"
+ iconSize={25}
+ type="action"
style={{
- fontSize: 25,
- fontFamily:
- Platform.OS === 'android' ? 'Roboto-Medium' : null,
- fontWeight: Platform.OS === 'ios' ? '600' : null,
- color: colors.pri,
- flexGrow: 1,
- maxWidth: '100%'
- }}
- placeholderTextColor={colors.icon}
- defaultValue={note?.title}
- onChangeText={v =>
- setNote(_note => {
- _note.title = v;
- return _note;
- })
- }
- onSubmitEditing={() => {
- textInputRef.current?.focus();
+ position: 'absolute',
+ zIndex: 999,
+ ...getElevation(10),
+ right: 24,
+ bottom: -35
}}
- blurOnSubmit={false}
- placeholder="Note title"
/>
- </View>
- <View
- style={{
- flexDirection: 'row',
- alignItems: 'center',
- marginVertical: 10,
- borderBottomWidth: 1,
- borderBottomColor: colors.nav
- }}>
- {[
- {
- title: 'Plain text',
- onPress: () => {
- let html = validator.isURL(rawData.value)
- ? makeHtmlFromUrl(rawData.value)
- : makeHtmlFromPlainText(rawData.value);
- setNote(note => {
- note.content.data = html;
- return note;
- });
- onLoad();
+ <View
+ style={{
+ marginTop: 10,
+ minHeight: 100,
+ borderRadius: 10,
+ ...getElevation(5),
+ backgroundColor: colors.bg
+ }}>
+ <TextInput
+ ref={textInputRef}
+ style={{
+ fontSize: 16,
+ color: colors.pri,
+ fontFamily: 'OpenSans-Regular',
+ padding: 12,
+ width: '100%'
+ }}
+ placeholderTextColor={colors.icon}
+ onChangeText={v => (editorContentValue = v)}
+ multiline={true}
+ numberOfLines={quickNote ? 5 : 3}
+ textAlignVertical="top"
+ value={editorContentValue}
+ blurOnSubmit={false}
+ placeholder={
+ quickNote
+ ? 'Write something...'
+ : 'Add some additional notes here'
}
- },
- ...[
- validator.isURL(rawData.value)
- ? {
- title: 'Clip webpage',
- onPress: async () => {
- let html = await sanitizeHtml(rawData.value);
- setNote(note => {
- note.content.data = html;
- return note;
- });
- onLoad();
- }
+ />
+
+ <View
+ style={{
+ flexDirection: 'row',
+ paddingHorizontal: 12,
+ paddingRight: 80
+ }}>
+ <Button
+ color={colors.shade}
+ onPress={onPress}
+ loading={loading}
+ icon={modes[mode].icon}
+ onPress={async () => {
+ let _mode = modes[mode];
+ if (_mode.type === "text") {
+ setMode(2);
+ return;
+ }
+ if (_mode.type === "clip") {
+ setMode(1);
+ return
}
- : null
- ]
- ].map(
- (item, index) =>
- item && (
+
+ if (_mode.type == "link") {
+ setMode(3)
+ }
+ }}
+ title={modes[mode].title}
+ iconSize={18}
+ iconColor={colors.accent}
+ textStyle={{
+ fontSize: 12,
+ color: colors.accent,
+ marginLeft: 5
+ }}
+ style={{
+ marginRight: 10,
+ height: 30,
+ borderRadius: 100,
+ paddingHorizontal: 12,
+ marginTop: -2.5
+ }}
+ />
+
+ {Clipboard.hasString() ? (
<Button
- title={item.title}
color={colors.nav}
+ onPress={onPress}
+ loading={loading}
+ icon="clipboard"
+ onPress={async () => {
+ let text = await Clipboard.getString();
+ if (text) {
+ textInputRef.current?.setNativeProps({
+ text: text
+ });
+ editorContentValue = text;
+ }
+ }}
+ iconSize={18}
+ iconColor={colors.icon}
+ title="Paste"
textStyle={{
+ fontSize: 12,
color: colors.icon,
- fontWeight: 'normal',
- fontSize: 14,
- fontFamily:null
+ marginLeft: 5
}}
- onPress={item.onPress}
style={{
- borderWidth: 0.5,
- borderRadius: 100,
- borderColor: colors.icon,
+ marginRight: 15,
height: 30,
- marginRight: 10,
- marginLeft: index === 0 ? 12 : 0,
- paddingHorizontal: 12
+ borderRadius: 100,
+ paddingHorizontal: 6,
+ marginTop: -2.5
}}
/>
- )
- )}
- </View>
-
- <View
- style={{
- height: height * 0.25,
- width: '100%'
- }}>
- <WebView
- onLoad={onLoad}
- ref={webviewRef}
- style={{
- width: '100%',
- height: '100%',
- backgroundColor: 'transparent'
- }}
- cacheMode="LOAD_DEFAULT"
- domStorageEnabled={true}
- scrollEnabled={true}
- bounces={false}
- allowFileAccess={true}
- scalesPageToFit={true}
- allowingReadAccessToURL={
- Platform.OS === 'android' ? true : null
- }
- onShouldStartLoadWithRequest={onShouldStartLoadWithRequest}
- allowFileAccessFromFileURLs={true}
- allowUniversalAccessFromFileURLs={true}
- originWhitelist={['*']}
- javaScriptEnabled={true}
- cacheEnabled={true}
- source={
- Platform.OS === 'ios'
- ? {uri: sourceUri}
- : {
- uri: 'file:///android_asset/plaineditor.html',
- baseUrl: 'file:///android_asset/'
- }
- }
- />
- </View>
-
- <TextInput
- ref={textInputRef}
- style={{
- fontSize: 15,
- color: colors.pri,
- marginBottom: 10,
- width: '100%',
- maxHeight: '70%',
- padding: 12,
- backgroundColor: colors.nav,
- alignSelf: 'center',
- marginTop: 10,
- minHeight: 80,
- paddingTop: 12,
- paddingBottom: 12
- }}
- placeholderTextColor={colors.icon}
- onChangeText={v => (editorContentValue = v)}
- multiline={true}
- numberOfLines={3}
- textAlignVertical="top"
- value={editorContentValue}
- blurOnSubmit={false}
- placeholder="Add some additional notes here"
- />
-
- <View
- style={{
- paddingHorizontal: 12,
- }}>
-
- <Button
- title={loading ? 'Saving note' : 'Save note'}
- color={colors.accent}
- onPress={onPress}
- loading={loading}
- style={{
- width: '100%'
- }}
- />
+ ) : null}
+ </View>
+ </View>
</View>
<View
style={{
- height: 10
+ height: 40
}}
/>
</View>
@@ -498,7 +645,39 @@ const NotesnookShare = () => {
);
};
-const Button = ({title, onPress, color, loading, style, textStyle}) => {
+const Button = ({
+ title,
+ onPress,
+ color,
+ loading,
+ style,
+ textStyle,
+ icon,
+ iconSize = 1,
+ type = 'button',
+ iconColor
+}) => {
+ const types = {
+ action: {
+ width: 60,
+ height: 60,
+ borderRadius: 100,
+ minWidth: 0,
+ paddingHorizontal: 0
+ },
+ button: {
+ backgroundColor: color,
+ height: 50,
+ borderRadius: 5,
+ justifyContent: 'center',
+ alignItems: 'center',
+ flexDirection: 'row',
+ marginBottom: 10,
+ minWidth: 80,
+ paddingHorizontal: 20
+ }
+ };
+
return (
<TouchableOpacity
onPress={onPress}
@@ -515,23 +694,30 @@ const Button = ({title, onPress, color, loading, style, textStyle}) => {
minWidth: 80,
paddingHorizontal: 20
},
+ types[type],
style
]}>
{loading && <ActivityIndicator color="white" />}
- <Text
- style={[
- {
- fontSize: 18,
- fontFamily: Platform.OS === 'android' ? 'Roboto-Medium' : null,
- fontWeight: Platform.OS === 'ios' ? '600' : null,
- color: 'white',
- marginLeft: loading ? 10 : 0
- },
- textStyle
- ]}>
- {title}
- </Text>
+ {icon && (
+ <Icon name={icon} size={iconSize} color={iconColor || 'white'} />
+ )}
+
+ {title && (
+ <Text
+ style={[
+ {
+ fontSize: 18,
+ fontFamily: Platform.OS === 'android' ? 'Roboto-Medium' : null,
+ fontWeight: Platform.OS === 'ios' ? '600' : null,
+ color: 'white',
+ marginLeft: loading ? 10 : 0
+ },
+ textStyle
+ ]}>
+ {title}
+ </Text>
+ )}
</TouchableOpacity>
);
};