Skip to content

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

add support for floating keyboard on iPad

ammarahm-ed8674d8ace8f6
diff --git a/apps/mobile/NotesnookShare.js b/apps/mobile/NotesnookShare.js
index ff3566e02..6d8c85dd3 100644
--- a/apps/mobile/NotesnookShare.js
+++ b/apps/mobile/NotesnookShare.js
@@ -1,4 +1,5 @@
import React, {Component, createRef} from 'react';
+import {Keyboard} from 'react-native';
import {
ActivityIndicator,
Appearance,
@@ -8,8 +9,8 @@ import {
Text,
TouchableOpacity,
View,
- ScrollView,
- TextInput
+ ScrollView,
+ TextInput,
} from 'react-native';
import {COLOR_SCHEME_DARK, COLOR_SCHEME_LIGHT} from './src/utils/Colors';
import {db} from './src/utils/DB';
@@ -34,6 +35,7 @@ export default class NotesnookShare extends Component {
? COLOR_SCHEME_DARK
: COLOR_SCHEME_LIGHT,
height: 0,
+ floating: false,
};
this.initialText = '';
this.textInputRef = createRef();
@@ -41,10 +43,14 @@ export default class NotesnookShare extends Component {
}
async componentDidMount() {
+ Keyboard.addListener(
+ 'keyboardWillChangeFrame',
+ this.onKeyboardWillChangeFrame,
+ );
try {
- ShareExtension = require("rn-extensions-share").default
- validator = require("validator").default
- linkPreview = require("link-preview-js")
+ ShareExtension = require('rn-extensions-share').default;
+ validator = require('validator').default;
+ linkPreview = require('link-preview-js');
const data = await ShareExtension.data();
let text;
let item = data[0];
@@ -52,8 +58,9 @@ export default class NotesnookShare extends Component {
text = item.value;
}
if (validator.isURL(text)) {
- linkPreview.getLinkPreview(text)
- .then((r) => {
+ linkPreview
+ .getLinkPreview(text)
+ .then(r => {
if (r?.siteName) {
this.setState({
title: r.siteName,
@@ -74,7 +81,7 @@ export default class NotesnookShare extends Component {
});
}
})
- .catch((e) => {
+ .catch(e => {
this.setState({
title: 'Web Link',
text: text,
@@ -94,6 +101,13 @@ export default class NotesnookShare extends Component {
}
}
+ componentWillUnmount() {
+ Keyboard.removeListener(
+ 'keyboardWillChangeFrame',
+ this.onKeyboardWillChangeFrame,
+ );
+ }
+
close = () => {
this.setState({
text: null,
@@ -174,6 +188,10 @@ export default class NotesnookShare extends Component {
</View>
);
+ onKeyboardWillChangeFrame = event => {
+ this.setState({floating: event.endCoordinates.width !== windowWidth});
+ };
+
render() {
return Platform.OS === 'ios' ? (
<View
@@ -202,7 +220,7 @@ export default class NotesnookShare extends Component {
</TouchableOpacity>
<KeyboardAvoidingView
- enabled={Platform.OS === 'ios'}
+ enabled={!this.state.floating && Platform.OS === 'ios'}
style={{
paddingVertical: 25,
backgroundColor: this.state.colors.bg,
@@ -255,7 +273,7 @@ export default class NotesnookShare extends Component {
}}
placeholderTextColor={this.state.colors.icon}
value={this.state.title}
- onChangeText={(v) => this.setState({title: v})}
+ onChangeText={v => this.setState({title: v})}
onSubmitEditing={() => {
this.textInputRef.current?.focus();
}}
@@ -297,7 +315,7 @@ export default class NotesnookShare extends Component {
paddingHorizontal: 12,
}}
placeholderTextColor={this.state.colors.icon}
- onChangeText={(v) => this.setState({text: v})}
+ onChangeText={v => this.setState({text: v})}
multiline={true}
value={this.state.text}
blurOnSubmit={false}
@@ -317,7 +335,7 @@ export default class NotesnookShare extends Component {
) : (
<Modal visible transparent>
<View
- onLayout={(event) => {
+ onLayout={event => {
console.log(event.nativeEvent.layout.height);
this.setState({
height: event.nativeEvent.layout.height,
@@ -393,7 +411,7 @@ export default class NotesnookShare extends Component {
}}
placeholderTextColor={this.state.colors.icon}
value={this.state.title}
- onChangeText={(v) => this.setState({title: v})}
+ onChangeText={v => this.setState({title: v})}
onSubmitEditing={() => {
this.textInputRef.current?.focus();
}}
@@ -432,7 +450,7 @@ export default class NotesnookShare extends Component {
paddingHorizontal: 12,
}}
placeholderTextColor={this.state.colors.icon}
- onChangeText={(v) => this.setState({text: v})}
+ onChangeText={v => this.setState({text: v})}
multiline={true}
value={this.state.text}
placeholder="Type your note here"
diff --git a/apps/mobile/src/components/AddNotebookDialog/index.js b/apps/mobile/src/components/AddNotebookDialog/index.js
index 7915222da..6f44fddf4 100644
--- a/apps/mobile/src/components/AddNotebookDialog/index.js
+++ b/apps/mobile/src/components/AddNotebookDialog/index.js
@@ -19,6 +19,7 @@ import {db} from '../../utils/DB';
import {ph, pv, SIZE} from '../../utils/SizeUtils';
import {sleep} from '../../utils/TimeUtils';
import {ActionIcon} from '../ActionIcon';
+import BaseDialog from '../Dialog/base-dialog';
import DialogButtons from '../Dialog/dialog-buttons';
import DialogHeader from '../Dialog/dialog-header';
import {updateEvent} from '../DialogManager/recievers';
@@ -103,7 +104,7 @@ export class AddNotebookDialog extends React.Component {
});
};
- onDelete = (index) => {
+ onDelete = index => {
let {topics} = this.state;
let prevTopics = topics;
refs = [];
@@ -264,154 +265,143 @@ export class AddNotebookDialog extends React.Component {
const {topics, visible, topicInputFocused} = this.state;
if (!visible) return null;
return (
- <Modal
- visible={true}
- transparent={true}
- animated
- animationType={DDS.isTab ? 'fade' : 'slide'}
+ <BaseDialog
onShow={async () => {
this.topicsToDelete = [];
await sleep(300);
this.titleRef?.focus();
}}
onRequestClose={this.close}>
- <SafeAreaView>
- <TextInput
- ref={this.hiddenInput}
- style={{
- width: 1,
- height: 1,
- opacity: 0,
- position: 'absolute',
+ <TextInput
+ ref={this.hiddenInput}
+ style={{
+ width: 1,
+ height: 1,
+ opacity: 0,
+ position: 'absolute',
+ }}
+ blurOnSubmit={false}
+ />
+
+ <View
+ style={[
+ styles.container,
+ {
+ backgroundColor: colors.bg,
+ },
+ ]}>
+ <DialogHeader
+ title={
+ toEdit && toEdit.dateCreated ? 'Edit Notebook' : 'New Notebook'
+ }
+ paragraph={
+ toEdit && toEdit.dateCreated
+ ? 'Edit your notebook'
+ : 'Add a new notebook'
+ }
+ />
+
+ <Input
+ fwdRef={ref => (this.titleRef = ref)}
+ testID={notesnook.ids.dialogs.notebook.inputs.title}
+ onChangeText={value => {
+ this.title = value;
}}
- blurOnSubmit={false}
+ placeholder="Enter a title"
+ onSubmit={() => {
+ this.descriptionRef.focus();
+ }}
+ returnKeyLabel="Next"
+ returnKeyType="next"
+ defaultValue={toEdit ? toEdit.title : null}
/>
- <KeyboardAvoidingView
- behavior={Platform.OS === 'ios' ? 'padding' : null}
- style={styles.wrapper}>
- <TouchableOpacity onPress={this.close} style={styles.overlay} />
- <View
- style={[
- styles.container,
- {
- backgroundColor: colors.bg,
- },
- ]}>
- <DialogHeader
- title={
- toEdit && toEdit.dateCreated
- ? 'Edit Notebook'
- : 'New Notebook'
- }
- paragraph={
- toEdit && toEdit.dateCreated
- ? 'Edit your notebook'
- : 'Add a new notebook'
- }
- />
- <Input
- fwdRef={(ref) => (this.titleRef = ref)}
- testID={notesnook.ids.dialogs.notebook.inputs.title}
- onChangeText={(value) => {
- this.title = value;
- }}
- placeholder="Enter a title"
- onSubmit={() => {
- this.descriptionRef.focus();
- }}
- returnKeyLabel="Next"
- returnKeyType="next"
- defaultValue={toEdit ? toEdit.title : null}
- />
+ <Input
+ fwdRef={ref => (this.descriptionRef = ref)}
+ testID={notesnook.ids.dialogs.notebook.inputs.description}
+ onChangeText={value => {
+ this.description = value;
+ }}
+ placeholder="Describe your notebook."
+ onSubmit={() => {
+ this.topicInputRef.current?.focus();
+ }}
+ returnKeyLabel="Next"
+ returnKeyType="next"
+ defaultValue={toEdit ? toEdit.description : null}
+ />
- <Input
- fwdRef={(ref) => (this.descriptionRef = ref)}
- testID={notesnook.ids.dialogs.notebook.inputs.description}
- onChangeText={(value) => {
- this.description = value;
- }}
- placeholder="Describe your notebook."
- onSubmit={() => {
- this.topicInputRef.current?.focus();
- }}
- returnKeyLabel="Next"
- returnKeyType="next"
- defaultValue={toEdit ? toEdit.description : null}
- />
+ <Input
+ fwdRef={this.topicInputRef}
+ testID={notesnook.ids.dialogs.notebook.inputs.topic}
+ onChangeText={value => {
+ this.currentInputValue = value;
+ if (this.prevItem !== null) {
+ refs[this.prevIndex].setNativeProps({
+ text: value,
+ style: {
+ borderBottomColor: colors.accent,
+ },
+ });
+ }
+ }}
+ returnKeyLabel="Done"
+ returnKeyType="done"
+ onSubmit={() => {
+ this.onSubmit();
+ }}
+ blurOnSubmit={false}
+ button={{
+ icon: this.state.editTopic ? 'check' : 'plus',
+ onPress: this.onSubmit,
+ color: topicInputFocused ? colors.accent : colors.icon,
+ }}
+ placeholder="Add a topic"
+ />
- <Input
- fwdRef={this.topicInputRef}
- testID={notesnook.ids.dialogs.notebook.inputs.topic}
- onChangeText={(value) => {
- this.currentInputValue = value;
- if (this.prevItem !== null) {
- refs[this.prevIndex].setNativeProps({
- text: value,
- style: {
- borderBottomColor: colors.accent,
- },
- });
- }
- }}
- returnKeyLabel="Done"
- returnKeyType="done"
- onSubmit={() => {
- this.onSubmit();
- }}
- blurOnSubmit={false}
- button={{
- icon: this.state.editTopic ? 'check' : 'plus',
- onPress: this.onSubmit,
- color: topicInputFocused ? colors.accent : colors.icon,
+ <FlatList
+ data={topics}
+ ref={ref => (this.listRef = ref)}
+ keyExtractor={(item, index) => item + index.toString()}
+ renderItem={({item, index}) => (
+ <TopicItem
+ item={item}
+ onPress={(item, index) => {
+ this.prevIndex = index;
+ this.prevItem = item;
+ this.topicInputRef.current?.setNativeProps({
+ text: item,
+ });
+ this.topicInputRef.current?.focus();
+ this.currentInputValue = item;
+ this.setState({
+ editTopic: true,
+ });
}}
- placeholder="Add a topic"
+ onDelete={this.onDelete}
+ index={index}
+ colors={colors}
/>
+ )}
+ />
- <FlatList
- data={topics}
- ref={(ref) => (this.listRef = ref)}
- keyExtractor={(item, index) => item + index.toString()}
- renderItem={({item, index}) => (
- <TopicItem
- item={item}
- onPress={(item, index) => {
- this.prevIndex = index;
- this.prevItem = item;
- this.topicInputRef.current?.setNativeProps({
- text: item,
- });
- this.topicInputRef.current?.focus();
- this.currentInputValue = item;
- this.setState({
- editTopic: true,
- });
- }}
- onDelete={this.onDelete}
- index={index}
- colors={colors}
- />
- )}
- />
+ <DialogButtons
+ negativeTitle="Cancel"
+ positiveTitle={toEdit && toEdit.dateCreated ? 'Save' : 'Add'}
+ onPressPositive={this.addNewNotebook}
+ onPressNegative={this.close}
+ loading={this.state.loading}
+ />
+ </View>
- <DialogButtons
- negativeTitle="Cancel"
- positiveTitle={toEdit && toEdit.dateCreated ? 'Save' : 'Add'}
- onPressPositive={this.addNewNotebook}
- onPressNegative={this.close}
- loading={this.state.loading}
- />
- </View>
- </KeyboardAvoidingView>
- <Toast context="local" />
- </SafeAreaView>
- </Modal>
+ <Toast context="local" />
+ </BaseDialog>
);
}
}
const TopicItem = ({item, index, colors, onPress, onDelete}) => {
- const topicRef = (ref) => (refs[index] = ref);
+ const topicRef = ref => (refs[index] = ref);
return (
<View
diff --git a/apps/mobile/src/components/Container/index.js b/apps/mobile/src/components/Container/index.js
index 84e2ce731..a75e7ca3d 100644
--- a/apps/mobile/src/components/Container/index.js
+++ b/apps/mobile/src/components/Container/index.js
@@ -3,14 +3,16 @@ import { KeyboardAvoidingView, Platform, SafeAreaView } from 'react-native';
import Animated from 'react-native-reanimated';
import { useTracked } from '../../provider';
import { ContainerScale } from '../../utils/Animations';
+import useIsFloatingKeyboard from '../../utils/use-is-floating-keyboard';
import SelectionHeader from '../SelectionHeader';
import { ContainerTopSection } from './ContainerTopSection';
const AnimatedView = Animated.createAnimatedComponent(SafeAreaView);
export const Container = ({children, root}) => {
const [state] = useTracked();
const {colors, } = state;
+ const floating = useIsFloatingKeyboard();
return (
- <KeyboardAvoidingView behavior="padding" enabled={Platform.OS === 'ios'}
+ <KeyboardAvoidingView behavior="padding" enabled={Platform.OS === 'ios' && !floating }
style={{
backgroundColor:colors.bg,
width:"100%",
diff --git a/apps/mobile/src/components/Dialog/BaseDialog.js b/apps/mobile/src/components/Dialog/BaseDialog.js
index b9c8aae3c..e199ff339 100644
--- a/apps/mobile/src/components/Dialog/BaseDialog.js
+++ b/apps/mobile/src/components/Dialog/BaseDialog.js
@@ -10,6 +10,7 @@ import {
View,
} from 'react-native';
import {useTracked} from '../../provider';
+import useIsFloatingKeyboard from '../../utils/use-is-floating-keyboard';
const BaseDialog = ({
visible,
@@ -20,10 +21,11 @@ const BaseDialog = ({
premium,
statusBarTranslucent = true,
transparent,
- centered=true
+ centered = true,
}) => {
const [state, dispatch] = useTracked();
const scaleValue = new Animated.Value(1);
+ const floating = useIsFloatingKeyboard();
return (
<Modal
@@ -39,21 +41,20 @@ const BaseDialog = ({
animationType={animation}
onRequestClose={onRequestClose}>
<SafeAreaView
- style={ {
+ style={{
backgroundColor: transparent
? 'transparent'
: state.colors.night
? 'rgba(255,255,255,0.15)'
: 'rgba(0,0,0,0.3)',
- }}
- >
+ }}>
<KeyboardAvoidingView
- behavior={Platform.OS === 'ios' ? 'padding' : null}
+ enabled={!floating && Platform.OS === 'ios'}
style={[
styles.backdrop,
{
- justifyContent:centered? "center" : "flex-start"
- }
+ justifyContent: centered ? 'center' : 'flex-start',
+ },
]}>
<TouchableOpacity
onPress={onRequestClose}
diff --git a/apps/mobile/src/components/SimpleList/index.js b/apps/mobile/src/components/SimpleList/index.js
index 662b22e41..3c6a85476 100644
--- a/apps/mobile/src/components/SimpleList/index.js
+++ b/apps/mobile/src/components/SimpleList/index.js
@@ -213,6 +213,7 @@ const SimpleList = ({
opacity: 0,
elevation: 0,
}}
+
tintColor={colors.accent}
colors={[colors.accent]}
progressViewOffset={150}
@@ -235,6 +236,8 @@ const SimpleList = ({
height: '100%',
backgroundColor: colors.bg,
width: '100%',
+ minHeight: 1,
+ minWidth: 1
};
return (
<>
@@ -251,6 +254,7 @@ const SimpleList = ({
dataProvider={dataProvider}
rowRenderer={_renderRow}
onScroll={_onScroll}
+
canChangeSize={true}
renderFooter={listData.length === 0 ? null : Footer}
scrollViewProps={scrollProps}
diff --git a/apps/mobile/src/utils/useIsFloatingKeyboard.js b/apps/mobile/src/utils/useIsFloatingKeyboard.js
new file mode 100644
index 000000000..ed80cc1c8
--- /dev/null
+++ b/apps/mobile/src/utils/useIsFloatingKeyboard.js
@@ -0,0 +1,23 @@
+import { useState, useEffect } from 'react';
+import { Keyboard, Dimensions } from 'react-native';
+
+const useIsFloatingKeyboard = () => {
+ const windowWidth = Dimensions.get('window').width;
+
+ const [floating, setFloating] = useState(false);
+
+ useEffect(() => {
+ const onKeyboardWillChangeFrame = (event) => {
+ setFloating(event.endCoordinates.width !== windowWidth);
+ };
+
+ Keyboard.addListener('keyboardWillChangeFrame', onKeyboardWillChangeFrame);
+ return () => {
+ Keyboard.removeListener('keyboardWillChangeFrame', onKeyboardWillChangeFrame);
+ };
+ }, [windowWidth]);
+
+ return floating;
+};
+
+export default useIsFloatingKeyboard
\ No newline at end of file
diff --git a/apps/mobile/src/views/Editor/EditorWrapper.js b/apps/mobile/src/views/Editor/EditorWrapper.js
index bf18b9843..e2ae81da3 100644
--- a/apps/mobile/src/views/Editor/EditorWrapper.js
+++ b/apps/mobile/src/views/Editor/EditorWrapper.js
@@ -11,6 +11,7 @@ import {DDS} from '../../services/DeviceDetection';
import {eSendEvent} from '../../services/EventManager';
import {eOnLoadNote} from '../../utils/Events';
import {editorRef} from '../../utils/Refs';
+import useIsFloatingKeyboard from '../../utils/use-is-floating-keyboard';
import EditorOverlay from './EditorOverlay';
let prevVal = 0;
let finalValue = 80;
@@ -89,7 +90,7 @@ export const EditorWrapper = ({dimensions}) => {
const [state] = useTracked();
const {colors, loading} = state;
const insets = useSafeAreaInsets();
-
+ const floating = useIsFloatingKeyboard();
return (
<View
@@ -122,8 +123,8 @@ export const EditorWrapper = ({dimensions}) => {
onHandlerStateChange={onHandlerStateChange}
onGestureEvent={onGestureEvent}>
<AnimatedKeyboardView
- behavior={Platform.OS === 'ios' ? "padding" : null}
-
+ behavior="padding"
+ enabled={!floating && Platform.OS === 'ios'}
style={{
transform: [
{
diff --git a/apps/mobile/src/views/Editor/Functions.js b/apps/mobile/src/views/Editor/Functions.js
index 17adf2407..5c780dc12 100644
--- a/apps/mobile/src/views/Editor/Functions.js
+++ b/apps/mobile/src/views/Editor/Functions.js
@@ -206,7 +206,9 @@ export const loadNote = async item => {
eSendEvent('loadingNote', item);
webviewInit = false;
editing.isFocused = false;
- eSendEvent('webviewreset');
+ setTimeout(() => {
+ eSendEvent('webviewreset');
+ },1)
InteractionManager.runAfterInteractions(async () => {
sendNoteEditedEvent({
id: id,