Skip to content

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

fix quick note widget and extension on ios

ammarahm-ed02e58cb9577d
diff --git a/apps/mobile/QuickNoteIOS.js b/apps/mobile/QuickNoteIOS.js
deleted file mode 100644
index 0ba071955..000000000
--- a/apps/mobile/QuickNoteIOS.js
+++ /dev/null
@@ -1,131 +0,0 @@
-import React, {Component, createRef} from 'react';
-import {
- ActivityIndicator,
- Appearance,
- KeyboardAvoidingView,
- Platform,
- SafeAreaView,
- Text,
- TouchableOpacity,
- View
-} from 'react-native';
-import {TextInput} from 'react-native-gesture-handler';
-import SplashScreen from 'react-native-splash-screen';
-import ShareExtension from 'rn-extensions-share';
-import NotesnookShare from './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;
-export default class QuickNoteIOS extends Component {
- constructor(props, context) {
- super(props, context);
- this.state = {
- isOpen: true,
- text: '',
- title: '',
- loading: false,
- loadingIntent: false,
- colors:
- Appearance.getColorScheme() === 'dark'
- ? COLOR_SCHEME_DARK
- : COLOR_SCHEME_LIGHT,
- height: 0
- };
- this.initialText = '';
- this.textInputRef = createRef();
- this.titleInputRef = createRef();
- }
-
- componentDidMount() {
- SplashScreen.hide();
- sleep(300).then(r => {
- this.textInputRef.current?.focus();
- });
- }
-
- close = () => {
- ShareExtension.openURL('ShareMedia://MainApp');
- };
-
- onPress = async () => {
- this.titleInputRef.current?.blur();
- this.textInputRef.current?.blur();
- this.setState({
- loading: true
- });
-
- let tag = `<p>${this.state.text}</p>`;
-
- let add = async () => {
- await db.notes.add({
- title: this.state.title,
- content: {
- type: 'tiny',
- data: tag
- },
- id: null
- });
- };
- if (db && db.notes) {
- await add();
- } else {
- await db.init();
- await add();
- }
- await Storage.write('notesAddedFromIntent', 'added');
- await sleep(500);
- this.close();
- };
-
- saveBtn = () => (
- <View
- style={{
- paddingHorizontal: 12
- }}>
- <TouchableOpacity
- onPress={this.onPress}
- activeOpacity={0.8}
- style={{
- backgroundColor: this.state.colors.accent,
- width: '100%',
- height: 50,
- borderRadius: 5,
- justifyContent: 'center',
- alignItems: 'center',
- flexDirection: 'row'
- }}>
- {this.state.loading && (
- <ActivityIndicator color={this.state.colors.light} />
- )}
-
- <Text
- style={{
- fontSize: 18,
- fontWeight: 'bold',
- color: this.state.colors.light,
- marginLeft: this.state.loading ? 10 : 0
- }}>
- Save Note
- </Text>
- </TouchableOpacity>
- </View>
- );
-
- render() {
- return (
- <SafeAreaView
- style={{
- width: '100%',
- height: '100%',
- justifyContent: 'flex-start',
- backgroundColor: this.state.colors.nav
- }}>
- <NotesnookShare quicknote={true} />
- </SafeAreaView>
- );
- }
-}
diff --git a/apps/mobile/index.js b/apps/mobile/index.js
index 3bc0023df..f61e4293e 100644
--- a/apps/mobile/index.js
+++ b/apps/mobile/index.js
@@ -5,6 +5,7 @@ import {name as appName} from './app.json';
import {enableScreens} from 'react-native-screens';
import Notifications from './src/services/Notifications';
import jsdom from 'jsdom-jscore-rn';
+import {SafeAreaProvider} from 'react-native-safe-area-context';
global.HTMLParser = jsdom.html();
global.Buffer = require('buffer').Buffer;
enableScreens(true);
@@ -12,7 +13,7 @@ enableScreens(true);
let Provider;
let App;
let NotesnookShare;
-Notifications.init()
+Notifications.init();
let QuickNoteIOS;
const AppProvider = () => {
@@ -20,20 +21,31 @@ const AppProvider = () => {
App = require('./App').default;
return (
<Provider>
- <App />
+ <App />
</Provider>
);
};
AppRegistry.registerComponent(appName, () => AppProvider);
-AppRegistry.registerComponent('NotesnookShare', () => {
+const ShareProvider = () => {
NotesnookShare = require('./share/index').default;
- return NotesnookShare;
-})
+ return (
+ <SafeAreaProvider>
+ <NotesnookShare quicknote={false} />
+ </SafeAreaProvider>
+ );
+};
+
+AppRegistry.registerComponent('NotesnookShare', () => ShareProvider);
-AppRegistry.registerComponent('QuickNoteIOS', () => {
- QuickNoteIOS = require("./QuickNoteIOS").default
- return QuickNoteIOS;
-})
+const QuickNoteProvider = () => {
+ QuickNoteIOS = require('./share/quicknote').default;
+ return (
+ <SafeAreaProvider>
+ <QuickNoteIOS />
+ </SafeAreaProvider>
+ );
+};
+AppRegistry.registerComponent('QuickNoteIOS', () => QuickNoteProvider);
diff --git a/apps/mobile/share/index.js b/apps/mobile/share/index.js
index ff79b9f6b..b72a51ab7 100644
--- a/apps/mobile/share/index.js
+++ b/apps/mobile/share/index.js
@@ -20,6 +20,7 @@ import Animated, {
timing,
useValue
} from 'react-native-reanimated';
+import {useSafeAreaInsets} from 'react-native-safe-area-context';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import WebView from 'react-native-webview';
import ShareExtension from 'rn-extensions-share';
@@ -31,6 +32,7 @@ import {
} from '../src/services/EventManager';
import {getElevation} from '../src/utils';
import {db} from '../src/utils/database';
+import {SIZE} from '../src/utils/SizeUtils';
import Storage from '../src/utils/storage';
import {sleep} from '../src/utils/TimeUtils';
import {Search} from './search';
@@ -133,9 +135,7 @@ const NotesnookShare = ({quicknote = false}) => {
const webviewRef = useRef();
const opacity = useValue(0);
const translate = useValue(1000);
- const insets = {
- top: Platform.OS === 'ios' ? 30 : 0
- };
+ const insets = useSafeAreaInsets();
const prevAnimation = useRef(null);
const [showSearch, setShowSearch] = useState(false);
@@ -379,32 +379,65 @@ const NotesnookShare = ({quicknote = false}) => {
style={{
width: width > 500 ? 500 : width,
height: height,
- justifyContent: quicknote ? 'center' : 'flex-end',
+ justifyContent: quicknote ? 'flex-start' : 'flex-end',
opacity: Platform.OS !== 'ios' ? opacity : 1
}}>
{quicknote && !showSearch ? (
- <Button
- type="action"
- icon="close"
- iconColor={colors.pri}
- onPress={() => {
- if (showSearch) {
- console.log('hide search');
- setShowSearch(false);
- animate(1, 0);
- } else {
- close();
- }
- }}
+ <View
style={{
- position: 'absolute',
- left: 12,
- top: 6,
- width: 50,
- height: 50
- }}
- iconSize={25}
- />
+ width: '100%',
+ backgroundColor: colors.bg,
+ height: 50 + insets.top,
+ paddingTop: insets.top,
+ ...getElevation(1),
+ marginTop: -insets.top,
+ flexDirection: 'row',
+ alignItems: 'center',
+ justifyContent: 'space-between'
+ }}>
+ <Button
+ type="action"
+ icon="close"
+ iconColor={colors.pri}
+ onPress={() => {
+ if (showSearch) {
+ console.log('hide search');
+ setShowSearch(false);
+ animate(1, 0);
+ } else {
+ close();
+ }
+ }}
+ style={{
+ width: 50,
+ height: 50,
+ marginBottom: 0
+ }}
+ iconSize={25}
+ />
+
+ <Text
+ style={{
+ color: colors.pri,
+ fontSize: SIZE.md,
+ fontFamily:"OpenSans-Regular"
+ }}>
+ Quick note
+ </Text>
+
+ <Button
+ type="action"
+ icon="check"
+ iconColor={colors.accent}
+ onPress={onPress}
+ style={{
+ width: 50,
+ height: 50,
+ marginBottom: 0
+ }}
+ iconSize={25}
+ />
+ </View>
) : (
<TouchableOpacity
activeOpacity={1}
@@ -436,6 +469,7 @@ const NotesnookShare = ({quicknote = false}) => {
{showSearch && (
<Search
+ quicknote={quicknote}
getKeyboardHeight={() => keyboardHeight.current}
close={() => {
setShowSearch(false);
@@ -542,7 +576,7 @@ const NotesnookShare = ({quicknote = false}) => {
marginTop: 10,
minHeight: 100,
borderRadius: 10,
- ...getElevation(5),
+ ...getElevation(quicknote ? 1 : 5),
backgroundColor: colors.bg
}}>
<View
@@ -644,27 +678,9 @@ const NotesnookShare = ({quicknote = false}) => {
</View>
</View>
- {quicknote && (
- <Button
- color={colors.accent}
- onPress={onPress}
- iconSize={18}
- iconColor={colors.light}
- textColor={colors.light}
- title="Save note"
- textStyle={{
- marginLeft: 5,
- fontFamily: 'OpenSans-SemiBold'
- }}
- style={{
- marginTop: 10
- }}
- />
- )}
-
<View
style={{
- height: Platform.OS === 'ios' ? 60 : 40
+ height: Platform.OS === 'ios' ? 100 : 40
}}
/>
</View>
@@ -684,7 +700,8 @@ const Button = ({
iconSize = 22,
type = 'button',
iconColor = 'gray',
- textColor = 'white'
+ textColor = 'white',
+ fontSize = 18
}) => {
const types = {
action: {
@@ -754,7 +771,7 @@ const Button = ({
<Text
style={[
{
- fontSize: 18,
+ fontSize: fontSize || 18,
fontFamily: 'OpenSans-Regular',
color: textColor,
marginLeft: loading ? 10 : 0
diff --git a/apps/mobile/share/quick-note.js b/apps/mobile/share/quick-note.js
new file mode 100644
index 000000000..dcbc3f5f0
--- /dev/null
+++ b/apps/mobile/share/quick-note.js
@@ -0,0 +1,36 @@
+import React, {Component} from 'react';
+import {Appearance, SafeAreaView} from 'react-native';
+import SplashScreen from 'react-native-splash-screen';
+import NotesnookShare from './index';
+import {COLOR_SCHEME_DARK, COLOR_SCHEME_LIGHT} from '../src/utils/Colors';
+
+export default class QuickNoteIOS extends Component {
+ constructor(props, context) {
+ super(props, context);
+ this.state = {
+ colors:
+ Appearance.getColorScheme() === 'dark'
+ ? COLOR_SCHEME_DARK
+ : COLOR_SCHEME_LIGHT,
+ height: 0
+ };
+ }
+
+ componentDidMount() {
+ SplashScreen.hide();
+ }
+
+ render() {
+ return (
+ <SafeAreaView
+ style={{
+ width: '100%',
+ height: '100%',
+ justifyContent: 'flex-start',
+ backgroundColor: this.state.colors.nav
+ }}>
+ <NotesnookShare quicknote={true} />
+ </SafeAreaView>
+ );
+ }
+}
diff --git a/apps/mobile/share/search.js b/apps/mobile/share/search.js
index 60699a83c..8939e4d17 100644
--- a/apps/mobile/share/search.js
+++ b/apps/mobile/share/search.js
@@ -9,12 +9,13 @@ import {
useWindowDimensions,
View
} from 'react-native';
+import {useSafeAreaInsets} from 'react-native-safe-area-context';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import {getElevation} from '../src/utils';
import {db} from '../src/utils/database';
import {useShareStore} from './store';
-export const Search = ({close, getKeyboardHeight}) => {
+export const Search = ({close, getKeyboardHeight, quicknote}) => {
const colors = useShareStore(state => state.colors);
const setAppendNote = useShareStore(state => state.setAppendNote);
const [results, setResults] = useState([]);
@@ -24,6 +25,7 @@ export const Search = ({close, getKeyboardHeight}) => {
const notes = useRef(null);
const timer = useRef(null);
const inputRef = useRef();
+ const insets = useSafeAreaInsets();
const onSelectItem = async item => {
setAppendNote(item);
@@ -84,18 +86,26 @@ export const Search = ({close, getKeyboardHeight}) => {
</TouchableOpacity>
);
+ let extra = quicknote
+ ? {
+ marginTop: -insets.top,
+ paddingTop: insets.top
+ }
+ : {};
return (
<View
style={{
position: 'absolute',
- top:Platform.OS === "android" ? 20 : 0,
+ top: Platform.OS === 'android' ? 20 : 0,
backgroundColor: colors.bg,
- borderRadius: 10,
- width: '95%',
+ borderRadius: quicknote ? 0 : 10,
+ width: quicknote ? '100%' : '95%',
minHeight: 50,
alignSelf: 'center',
+ overflow:"hidden",
zIndex: 999,
- ...getElevation(5)
+ ...getElevation(quicknote ? 1 : 5),
+ ...extra
}}>
<View
style={{
@@ -105,7 +115,7 @@ export const Search = ({close, getKeyboardHeight}) => {
alignItems: 'center',
paddingHorizontal: 12,
marginBottom: 10,
- height:50
+ height: 50
}}>
<TextInput
ref={inputRef}
@@ -138,8 +148,8 @@ export const Search = ({close, getKeyboardHeight}) => {
style={{
maxHeight: height - getKeyboardHeight()
}}
- keyboardShouldPersistTaps="always"
- keyboardDismissMode="none"
+ keyboardShouldPersistTaps="always"
+ keyboardDismissMode="none"
keyExtractor={item => item.id}
renderItem={renderItem}
ListEmptyComponent={
@@ -152,7 +162,8 @@ export const Search = ({close, getKeyboardHeight}) => {
}}>
<Text
style={{
- fontFamily: 'OpenSans-Regular'
+ fontFamily: 'OpenSans-Regular',
+ color: colors.icon
}}>
Search for a note to append to it.
</Text>