fix backhandler is not removed when move away from editor

This commit is contained in:
ammarahm-ed
2021-02-27 12:21:25 +05:00
parent dfda1a2f86
commit 4838778178
2 changed files with 28 additions and 9 deletions

View File

@@ -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);
}

View File

@@ -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) {