Skip to content

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

fix backhandler is not removed when move away from editor

ammarahm-ed48387781785a
diff --git a/apps/mobile/initializer.root.js b/apps/mobile/initializer.root.js
index 0249559fa..431ef42b8 100644
--- a/apps/mobile/initializer.root.js
+++ b/apps/mobile/initializer.root.js
@@ -48,7 +48,7 @@ const onChangeTab = async (obj) => {
currentTab = 1;
activateKeepAwake();
eSendEvent('navigate');
-
+ eSendEvent(eClearEditor, 'addHandler');
if (!editing.currentlyEditing || !getNote()) {
eSendEvent(eOnLoadNote, {type: 'new'});
editing.currentlyEditing = true;
@@ -60,6 +60,7 @@ const onChangeTab = async (obj) => {
if (obj.from === 1) {
updateStatusBarColor();
deactivateKeepAwake();
+ eSendEvent(eClearEditor, 'removeHandler');
if (getNote()?.locked) {
eSendEvent(eClearEditor);
}
diff --git a/apps/mobile/src/views/Editor/EditorRoot.js b/apps/mobile/src/views/Editor/EditorRoot.js
index fc0fdc7f9..64f5ca788 100644
--- a/apps/mobile/src/views/Editor/EditorRoot.js
+++ b/apps/mobile/src/views/Editor/EditorRoot.js
@@ -28,7 +28,7 @@ import {
saveNote,
setIntent,
} from './Functions';
-import { toolbarRef } from './tiny/toolbar/constants';
+import {toolbarRef} from './tiny/toolbar/constants';
let handleBack;
let tapCount = 0;
@@ -67,7 +67,6 @@ const EditorRoot = () => {
await loadNote(item);
InteractionManager.runAfterInteractions(() => {
Keyboard.addListener('keyboardDidShow', () => {
-
if (!editing.movedAway) {
editing.isFocused = true;
}
@@ -82,7 +81,26 @@ const EditorRoot = () => {
});
};
- const onCallClear = async () => {
+ const onCallClear = async (value) => {
+ if (value === 'removeHandler') {
+ if (handleBack) {
+ handleBack.remove();
+ handleBack = null;
+ }
+ return;
+ }
+ if (value === 'addHandler') {
+ if (handleBack) {
+ handleBack.remove();
+ handleBack = null;
+ }
+
+ handleBack = BackHandler.addEventListener(
+ 'hardwareBackPress',
+ _onHardwareBackPress,
+ );
+ return;
+ }
if (editing.currentlyEditing) {
await _onBackPress();
}
@@ -96,12 +114,12 @@ const EditorRoot = () => {
};
const _onBackPress = async () => {
- eSendEvent("showTooltip");
+ eSendEvent('showTooltip');
toolbarRef.current?.scrollTo({
- x:0,
- y:0,
- animated:false
- })
+ x: 0,
+ y: 0,
+ animated: false,
+ });
editing.currentlyEditing = false;
if (DDS.isLargeTablet()) {
if (fullscreen) {