Skip to content

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

fix focusing editor after closing actionsheet

ammarahm-ed62986f126c3d
diff --git a/apps/mobile/android/app/src/main/assets/listeners.js b/apps/mobile/android/app/src/main/assets/listeners.js
index 975dea6f3..9f1c4d029 100644
--- a/apps/mobile/android/app/src/main/assets/listeners.js
+++ b/apps/mobile/android/app/src/main/assets/listeners.js
@@ -46,6 +46,15 @@ function attachTitleInputListeners() {
}
};
+ document.getElementById(titleInput).onfocus = function (evt) {
+ window.ReactNativeWebView.postMessage(
+ JSON.stringify({
+ type: 'focus',
+ value: 'title',
+ }),
+ );
+ };
+
document.getElementById(titleInput).onkeydown = function (evt) {
onTitleChange(evt);
};
@@ -101,6 +110,15 @@ function attachEditorListeners() {
titleInput = isTablet ? 'titleInput' : 'simpleTitleInput';
infoBar = isTablet ? '.info-bar' : '.info-bar-alt';
+ editor.on('selection-change', function () {
+ window.ReactNativeWebView.postMessage(
+ JSON.stringify({
+ type: 'focus',
+ value: 'editor',
+ }),
+ );
+ });
+
function isWhitespace(ch) {
let whiteSpace = false;
if (ch === ' ' || ch === '\t' || ch === '\n') {
@@ -115,9 +133,9 @@ function attachEditorListeners() {
editor.on('text-change', function (delta, oldDelta, source) {
var regex = /https?:\/\/[^\s]+$/;
- if (source === "custom") {
- return;
- }
+ if (source === 'custom') {
+ return;
+ }
if (
delta.ops.length === 2 &&
@@ -196,7 +214,6 @@ function attachMessageListener() {
}
switch (type) {
case 'reset': {
-
editor.history.clear();
editor.setText('', 'custom');
document.getElementById(titleInput).value = '';
@@ -210,7 +227,7 @@ function attachMessageListener() {
info.querySelector('#infosaved').innerText = '';
info.querySelector('#infowords').innerText = '';
autosize();
- editor.getModule("imageResize").hideOverlay();
+ editor.getModule('imageResize').hideOverlay();
break;
}
case 'keyboard':
diff --git a/apps/mobile/html/Web.bundle/site/listeners.js b/apps/mobile/html/Web.bundle/site/listeners.js
index 940e1ffa0..ea01510e9 100644
--- a/apps/mobile/html/Web.bundle/site/listeners.js
+++ b/apps/mobile/html/Web.bundle/site/listeners.js
@@ -46,6 +46,15 @@ function attachTitleInputListeners() {
}
};
+ document.getElementById(titleInput).onfocus = function (evt) {
+ window.ReactNativeWebView.postMessage(
+ JSON.stringify({
+ type: 'focus',
+ value: 'title',
+ }),
+ );
+ };
+
document.getElementById(titleInput).onkeydown = function (evt) {
onTitleChange(evt);
};
@@ -96,6 +105,8 @@ function autosize() {
}
}
+
+
function attachEditorListeners() {
/* editor.once('text-change', function () {
window.ReactNativeWebView.postMessage('loaded');
@@ -103,6 +114,15 @@ function attachEditorListeners() {
titleInput = isTablet ? 'titleInput' : 'simpleTitleInput';
infoBar = isTablet ? '.info-bar' : '.info-bar-alt';
+ editor.on('selection-change', function () {
+ window.ReactNativeWebView.postMessage(
+ JSON.stringify({
+ type: 'focus',
+ value: 'editor',
+ }),
+ );
+ });
+
function isWhitespace(ch) {
let whiteSpace = false;
if (ch === ' ' || ch === '\t' || ch === '\n') {
diff --git a/apps/mobile/initializer.root.js b/apps/mobile/initializer.root.js
index 00c374716..5e27f60c2 100644
--- a/apps/mobile/initializer.root.js
+++ b/apps/mobile/initializer.root.js
@@ -48,6 +48,7 @@ const onChangeTab = async (obj) => {
currentTab = 1;
activateKeepAwake();
eSendEvent('navigate');
+ editing.isFocused = false;
if (!editing.currentlyEditing || !getNote()) {
eSendEvent(eOnLoadNote, {type: 'new'});
editing.currentlyEditing = true;
diff --git a/apps/mobile/src/components/ActionSheetComponent/ActionSheetWrapper.js b/apps/mobile/src/components/ActionSheetComponent/ActionSheetWrapper.js
index 7dc4c6017..6f3807137 100644
--- a/apps/mobile/src/components/ActionSheetComponent/ActionSheetWrapper.js
+++ b/apps/mobile/src/components/ActionSheetComponent/ActionSheetWrapper.js
@@ -5,6 +5,8 @@ import {DDS} from '../../services/DeviceDetection';
import {hexToRGBA} from '../../utils/ColorUtils';
import ActionSheet from 'react-native-actions-sheet';
import {GetPremium} from './GetPremium';
+import { editing } from '../../utils';
+import { post } from '../../views/Editor/Functions';
const ActionSheetWrapper = ({
children,
@@ -37,6 +39,9 @@ const ActionSheetWrapper = ({
};
}, [colors.bg, gestureEnabled]);
+
+
+
return (
<ActionSheet
ref={fwdRef}
@@ -60,7 +65,20 @@ const ActionSheetWrapper = ({
offset={50}
/>
}
- onClose={onClose}>
+ onClose={() => {
+ if (editing.isFocused) {
+ post('blur');
+ if (editing.focusType == "editor") {
+ post('focusEditor');
+ } else {
+ post('focusTitle');
+ }
+ }
+
+ if (onClose) {
+ onClose()
+ }
+ } }>
{children}
</ActionSheet>
);
diff --git a/apps/mobile/src/components/ActionSheetComponent/GetPremium.js b/apps/mobile/src/components/ActionSheetComponent/GetPremium.js
index b3c002783..49a3fcd3c 100644
--- a/apps/mobile/src/components/ActionSheetComponent/GetPremium.js
+++ b/apps/mobile/src/components/ActionSheetComponent/GetPremium.js
@@ -9,8 +9,8 @@ import {
eSubscribeEvent,
eUnSubscribeEvent,
} from '../../services/EventManager';
-import {dWidth, getElevation} from '../../utils';
-import {eOpenPremiumDialog, eShowGetPremium} from '../../utils/Events';
+import {dWidth, editing, getElevation} from '../../utils';
+import {eCloseActionSheet, eOpenPremiumDialog, eShowGetPremium} from '../../utils/Events';
import {SIZE} from '../../utils/SizeUtils';
import {sleep} from '../../utils/TimeUtils';
import {post} from '../../views/Editor/Functions';
@@ -21,10 +21,10 @@ import Paragraph from '../Typography/Paragraph';
export const translatePrem = new Animated.Value(-dWidth * 5);
export const opacityPrem = new Animated.Value(0);
let timer = null;
-let currentMsg = {
+let currentMsg = {
title: '',
desc: '',
-}
+};
export const GetPremium = ({close, context = 'global', offset = 0}) => {
const [state, dispatch] = useTracked();
const {colors} = state;
@@ -39,8 +39,8 @@ export const GetPremium = ({close, context = 'global', offset = 0}) => {
currentMsg = {
title: '',
desc: '',
- }
- setMsg(currentMsg)
+ };
+ setMsg(currentMsg);
opacityPrem.setValue(0);
translatePrem.setValue(-dWidth * 5);
return;
@@ -56,7 +56,7 @@ export const GetPremium = ({close, context = 'global', offset = 0}) => {
currentMsg = {
title: event.title,
desc: event.desc,
- }
+ };
setMsg(currentMsg);
opacityPrem.setValue(1);
Animated.timing(translatePrem, {
@@ -74,8 +74,8 @@ export const GetPremium = ({close, context = 'global', offset = 0}) => {
currentMsg = {
title: '',
desc: '',
- }
- setMsg(currentMsg)
+ };
+ setMsg(currentMsg);
await sleep(200);
opacityPrem.setValue(0);
translatePrem.setValue(-dWidth * 5);
@@ -132,8 +132,14 @@ export const GetPremium = ({close, context = 'global', offset = 0}) => {
<Button
onPress={async () => {
open(null);
- post('blur');
- await sleep(500);
+ if (editing.isFocused) {
+ post('blur');
+ await sleep(300);
+ } else {
+ eSendEvent(eCloseActionSheet);
+ await sleep(300);
+
+ }
eSendEvent(eOpenPremiumDialog);
}}
width={80}