Skip to content

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

fix focus & scroll in editor ios

ammarahm-edede3c99f290f
diff --git a/apps/mobile/src/components/AppLoader/index.js b/apps/mobile/src/components/AppLoader/index.js
index 62e1d475f..1d8cf2a32 100644
--- a/apps/mobile/src/components/AppLoader/index.js
+++ b/apps/mobile/src/components/AppLoader/index.js
@@ -66,7 +66,7 @@ const AppLoader = ({onLoad}) => {
let askForRating = await MMKV.getItem('askForRating');
if (askForRating !== 'never' || askForRating !== 'completed') {
askForRating = JSON.parse(askForRating);
- if (askForRating.timestamp < Date.now()) {
+ if (askForRating?.timestamp < Date.now()) {
eSendEvent(eOpenRateDialog);
}
}
diff --git a/apps/mobile/src/views/Editor/EditorWrapper.js b/apps/mobile/src/views/Editor/EditorWrapper.js
index 3e2749778..b88f352ca 100644
--- a/apps/mobile/src/views/Editor/EditorWrapper.js
+++ b/apps/mobile/src/views/Editor/EditorWrapper.js
@@ -132,7 +132,8 @@ export const EditorWrapper = ({dimensions}) => {
onHandlerStateChange={onHandlerStateChange}
onGestureEvent={onGestureEvent}>
<AnimatedKeyboardView
- behavior={Platform.OS === 'ios' ? 'padding' : null}
+ behavior={Platform.OS === 'ios' ? "padding" : null}
+
style={{
transform: [
{
diff --git a/apps/mobile/src/views/Editor/index.js b/apps/mobile/src/views/Editor/index.js
index e3710ecea..c20c61c6d 100755
--- a/apps/mobile/src/views/Editor/index.js
+++ b/apps/mobile/src/views/Editor/index.js
@@ -12,7 +12,7 @@ import {
eUnSubscribeEvent,
} from '../../services/EventManager';
import {getCurrentColors} from '../../utils/Colors';
-import { normalize } from '../../utils/SizeUtils';
+import {normalize} from '../../utils/SizeUtils';
import {sleep} from '../../utils/TimeUtils';
import EditorHeader from './EditorHeader';
import {
@@ -49,8 +49,6 @@ const Editor = React.memo(
const {premiumUser} = state;
const [resetting, setResetting] = useState(false);
const insets = useSafeAreaInsets();
- const calculatedHeight =
- Dimensions.get('window').height - (insets.top + insets.bottom + normalize(50));
const onLoad = async () => {
await onWebViewLoad(premiumUser, getCurrentColors());
};
@@ -73,6 +71,8 @@ const Editor = React.memo(
};
}, []);
+ const CustomView = Platform.OS === 'ios' ? ScrollView : View;
+
return resetting ? null : (
<>
<TextInput
@@ -80,11 +80,26 @@ const Editor = React.memo(
style={{height: 1, padding: 0, width: 1, position: 'absolute'}}
blurOnSubmit={false}
/>
- <View
+
+ <CustomView
style={{
- height: calculatedHeight,
+ height: '100%',
+ width:"100%",
+ paddingBottom: Platform.OS === 'android' ? normalize(50) + 5 : null,
+
}}
- nestedScrollEnabled>
+ bounces={false}
+ bouncesZoom={false}
+ disableScrollViewPanResponder
+ keyboardDismissMode="none"
+ keyboardShouldPersistTaps="always"
+ showsVerticalScrollIndicator={false}
+ scrollEnabled={false}
+ nestedScrollEnabled
+ contentContainerStyle={{
+ width: '100%',
+ height: '100%',
+ }}>
<EditorHeader />
<WebView
testID={notesnook.ids.default.editor}
@@ -114,7 +129,7 @@ const Editor = React.memo(
autoManageStatusBarEnabled={false}
onMessage={_onMessage}
/>
- </View>
+ </CustomView>
<EditorToolbar />
</>
);
diff --git a/apps/mobile/src/views/Editor/tiny/tiny.js b/apps/mobile/src/views/Editor/tiny/tiny.js
index c700225e5..8b6fca607 100644
--- a/apps/mobile/src/views/Editor/tiny/tiny.js
+++ b/apps/mobile/src/views/Editor/tiny/tiny.js
@@ -1,3 +1,4 @@
+import {Platform} from 'react-native';
import {editing} from '../../../utils';
import {EditorWebView, getWebviewInit, post} from '../Functions';
@@ -11,16 +12,9 @@ document.activeElement.blur();
window.blur();
`;
-/**
- * window.scrollBy({
- top: 45,
- left: 0,
- behavior: 'smooth'
- })
- */
-
const keyboardStateChanged = `(() => {
-
+ let node = tinymce.activeEditor.selection.getNode();
+ node.scrollIntoView({behavior: "smooth", block: "end"});
})();
`;
const blur = `
@@ -57,9 +51,9 @@ const pre = `(() => {
} else {
tinymce.activeEditor.execCommand("mceInsertNewLine", false, { shiftKey: true });
}
-})();`
+})();`;
-const updateDateEdited = (value) => `
+const updateDateEdited = value => `
(() => {
info = document.querySelector(infoBar);
info.querySelector('#infodate').innerText = "${value}";
@@ -69,7 +63,7 @@ const updateDateEdited = (value) => `
})();
`;
-const updateSavingState = (value) => `
+const updateSavingState = value => `
(() => {
info = document.querySelector(infoBar);
info.querySelector('#infosaved').innerText = "${value}";
@@ -88,7 +82,7 @@ const focusTitle = `
document.getElementById("titleInput").focus();
`;
-const setTitle = (value) => `
+const setTitle = value => `
document.getElementById("titleInput").value = \`${value}\`;
autosize();
`;
@@ -97,7 +91,7 @@ const cacheRange = `current_selection_range = editor.selection.getRng();`;
const restoreRange = `editor.selection.setRng(current_selection_range);`;
const clearRange = `current_selection_range = null`;
-const toggleFormat = (format) => {
+const toggleFormat = format => {
let command = `
tinymce.activeEditor.execCommand(${format});
`;
@@ -112,7 +106,7 @@ const formatWithValue = (format, value) => {
return command;
};
-export const nomenu = (enabled) => `
+export const nomenu = enabled => `
(() => {
let isenabled = ${enabled};
let titleIn = document.getElementById('titlebar');
@@ -125,7 +119,7 @@ export const nomenu = (enabled) => `
}
})();
`;
-const updateTheme = (value) => `
+const updateTheme = value => `
(() => {
let v = ${value}
pageTheme.colors = v;
@@ -142,7 +136,7 @@ const notLoading = `
isLoading = false;
`;
-const html = (value) => post('html', value);
+const html = value => post('html', value);
const focusEditor = `
tinymce.activeEditor.focus();
@@ -178,7 +172,9 @@ tinymce.activeEditor.undoManager.clear();
const onKeyboardShow = () => {
if (!editing.movedAway) {
editing.isFocused = true;
- call(EditorWebView, keyboardStateChanged);
+ if (Platform.OS === 'ios') {
+ call(EditorWebView, keyboardStateChanged);
+ }
}
};
@@ -206,5 +202,5 @@ export default {
notLoading,
keyboardStateChanged,
onKeyboardShow,
- pre
+ pre,
};
diff --git a/apps/mobile/src/views/Editor/tiny/toolbar/index.js b/apps/mobile/src/views/Editor/tiny/toolbar/index.js
index 5fd382b4f..7104bacd8 100644
--- a/apps/mobile/src/views/Editor/tiny/toolbar/index.js
+++ b/apps/mobile/src/views/Editor/tiny/toolbar/index.js
@@ -1,4 +1,5 @@
import React, { useEffect } from 'react';
+import { Platform } from 'react-native';
import { ScrollView, View } from 'react-native';
import { useTracked } from '../../../../provider';
import { normalize } from '../../../../utils/SizeUtils';
@@ -26,6 +27,8 @@ const EditorToolbar = React.memo(
style={{
width: '100%',
minHeight: normalize(50),
+ position:Platform.OS === "android" ? "absolute" : "relative",
+ bottom:Platform.OS === "android" ? 0 : null
}}>
<Tooltip />
<ScrollView