Skip to content

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

fix navigation flow

ammarahm-ed4e3d5483dbef
diff --git a/apps/mobile/src/components/ActionIcon/index.js b/apps/mobile/src/components/ActionIcon/index.js
index 2078336dc..275064e91 100644
--- a/apps/mobile/src/components/ActionIcon/index.js
+++ b/apps/mobile/src/components/ActionIcon/index.js
@@ -18,6 +18,7 @@ export const ActionIcon = ({
bottom = 30,
testID,
disabled,
+ onLongPress
}) => {
const [state, dispatch] = useTracked();
const {colors} = state;
@@ -27,6 +28,7 @@ export const ActionIcon = ({
testID={testID}
onPress={onPress}
hitSlop={{top: top, left: left, right: right, bottom: bottom}}
+ onLongPress={onLongPress}
disabled={disabled}
type="gray"
customStyle={{
diff --git a/apps/mobile/src/components/Header/HeaderLeftMenu.js b/apps/mobile/src/components/Header/HeaderLeftMenu.js
index 810969aa3..04f8635ef 100644
--- a/apps/mobile/src/components/Header/HeaderLeftMenu.js
+++ b/apps/mobile/src/components/Header/HeaderLeftMenu.js
@@ -1,9 +1,10 @@
import React from 'react';
-import { notesnook } from '../../../e2e/test.ids';
-import { useTracked } from '../../provider';
+import {notesnook} from '../../../e2e/test.ids';
+import {useTracked} from '../../provider';
import Navigation from '../../services/Navigation';
-import { SIZE } from '../../utils/SizeUtils';
-import { ActionIcon } from '../ActionIcon';
+import SettingsService from '../../services/SettingsService';
+import {SIZE} from '../../utils/SizeUtils';
+import {ActionIcon} from '../ActionIcon';
export const HeaderLeftMenu = () => {
const [state] = useTracked();
@@ -11,7 +12,7 @@ export const HeaderLeftMenu = () => {
const onLeftButtonPress = () => {
if (headerMenuState) {
- Navigation.openDrawer()
+ Navigation.openDrawer();
return;
}
Navigation.goBack();
@@ -31,6 +32,10 @@ export const HeaderLeftMenu = () => {
marginRight: 25,
}}
onPress={onLeftButtonPress}
+ onLongPress={() => {
+ Navigation.popToTop();
+
+ }}
name={!headerMenuState ? 'arrow-left' : 'menu'}
size={SIZE.xxxl}
color={colors.pri}
diff --git a/apps/mobile/src/components/Input/index.js b/apps/mobile/src/components/Input/index.js
index 8fe076d56..72fd7a0dd 100644
--- a/apps/mobile/src/components/Input/index.js
+++ b/apps/mobile/src/components/Input/index.js
@@ -29,7 +29,7 @@ const Input = ({
marginBottom = 10,
button,
testID,
- defaultValue
+ defaultValue,
}) => {
const [state] = useTracked();
const colors = state.colors;
@@ -114,8 +114,8 @@ const Input = ({
<>
<View style={style}>
<TextInput
- ref={fwdRef}
- testID={testID}
+ ref={fwdRef}
+ testID={testID}
editable={!loading}
defaultValue={defaultValue}
autoCapitalize={autoCapitalize}
diff --git a/apps/mobile/src/components/SimpleList/NotebookItemWrapper.js b/apps/mobile/src/components/SimpleList/NotebookItemWrapper.js
index 8fee31b66..ea5333e77 100644
--- a/apps/mobile/src/components/SimpleList/NotebookItemWrapper.js
+++ b/apps/mobile/src/components/SimpleList/NotebookItemWrapper.js
@@ -5,6 +5,7 @@ import SelectionWrapper from '../../components/SelectionWrapper';
import {useTracked} from '../../provider';
import {Actions} from '../../provider/Actions';
import Navigation from '../../services/Navigation';
+import {rootNavigatorRef} from '../../utils/Refs';
export const NotebookItemWrapper = ({
item,
@@ -38,7 +39,7 @@ export const NotebookItemWrapper = ({
const onPress = () => {
if (selectionMode) {
console.log(item.title);
- onLongPress();
+ onLongPress();
return;
}
let routeName = isTopic ? 'NotesPage' : 'Notebook';
@@ -54,7 +55,7 @@ export const NotebookItemWrapper = ({
id: item.id,
type: item.type,
};
- Navigation.navigate(routeName, params, headerState);
+ Navigation.push(routeName, params, headerState);
};
return (
<SelectionWrapper
diff --git a/apps/mobile/src/services/Navigation.js b/apps/mobile/src/services/Navigation.js
index aef84bc6d..1718a5a5c 100755
--- a/apps/mobile/src/services/Navigation.js
+++ b/apps/mobile/src/services/Navigation.js
@@ -3,6 +3,7 @@ import {updateEvent} from '../components/DialogManager/recievers';
import {Actions} from '../provider/Actions';
import {rootNavigatorRef, sideMenuRef} from '../utils/Refs';
import {eSendEvent} from './EventManager';
+import SettingsService from './SettingsService';
let currentScreen = null;
@@ -65,8 +66,29 @@ function goBack() {
rootNavigatorRef.current?.goBack();
}
-function push(...args) {
- rootNavigatorRef.current?.dispatch(StackActions.push(...args));
+function push(name, params, item) {
+ currentScreen = name;
+ setHeaderState(name, params, item);
+ rootNavigatorRef.current?.dispatch(StackActions.push(name, params));
+}
+
+function replace(...args) {
+ rootNavigatorRef.current?.dispatch(StackActions.replace(...args));
+}
+
+function popToTop() {
+ rootNavigatorRef.current?.dispatch(StackActions.popToTop());
+ SettingsService.get().homepage;
+ setHeaderState(
+ SettingsService.get().homepage.toLowerCase(),
+ {
+ menu: true,
+ },
+ {
+ heading: SettingsService.get().homepage,
+ id: SettingsService.get().homepage.toLocaleLowerCase() + '_navigation',
+ },
+ );
}
function openDrawer() {
@@ -84,4 +106,6 @@ export default {
closeDrawer,
getCurrentScreen,
setHeaderState,
+ replace,
+ popToTop,
};
diff --git a/apps/mobile/src/views/Editor/EditorHeader.js b/apps/mobile/src/views/Editor/EditorHeader.js
index a8974ec26..5702dda42 100644
--- a/apps/mobile/src/views/Editor/EditorHeader.js
+++ b/apps/mobile/src/views/Editor/EditorHeader.js
@@ -17,6 +17,7 @@ import {
eUnSubscribeEvent,
ToastEvent,
} from '../../services/EventManager';
+import Navigation from '../../services/Navigation';
import {editing} from '../../utils';
import {exitEditorAnimation} from '../../utils/Animations';
import {
@@ -187,6 +188,10 @@ const EditorHeader = () => {
}}>
{DDS.isLargeTablet() && !fullscreen ? null : (
<ActionIcon
+ onLongPress={async () => {
+ await _onBackPress();
+ Navigation.popToTop();
+ }}
testID={notesnook.ids.default.header.buttons.back}
name="arrow-left"
color={colors.heading}
diff --git a/apps/mobile/src/views/Notebook/index.js b/apps/mobile/src/views/Notebook/index.js
index 02cde157d..6d69cdfa5 100644
--- a/apps/mobile/src/views/Notebook/index.js
+++ b/apps/mobile/src/views/Notebook/index.js
@@ -1,17 +1,21 @@
-import React, { useEffect, useState } from 'react';
-import { ContainerBottomButton } from '../../components/Container/ContainerBottomButton';
-import { AddTopicEvent } from '../../components/DialogManager/recievers';
+import React, {useEffect, useState} from 'react';
+import {ContainerBottomButton} from '../../components/Container/ContainerBottomButton';
+import {AddTopicEvent} from '../../components/DialogManager/recievers';
import SimpleList from '../../components/SimpleList';
-import { useTracked } from '../../provider';
+import {useTracked} from '../../provider';
import {
eSendEvent,
eSubscribeEvent,
- eUnSubscribeEvent
+ eUnSubscribeEvent,
} from '../../services/EventManager';
import Navigation from '../../services/Navigation';
import SearchService from '../../services/SearchService';
-import { db } from '../../utils/DB';
-import { eOnNewTopicAdded, eOpenAddTopicDialog, eScrollEvent } from '../../utils/Events';
+import {db} from '../../utils/DB';
+import {
+ eOnNewTopicAdded,
+ eOpenAddTopicDialog,
+ eScrollEvent,
+} from '../../utils/Events';
export const Notebook = ({route, navigation}) => {
const [, dispatch] = useTracked();
@@ -25,7 +29,6 @@ export const Notebook = ({route, navigation}) => {
useEffect(() => {
onLoad();
-
}, [route.params]);
useEffect(() => {
@@ -37,6 +40,17 @@ export const Notebook = ({route, navigation}) => {
const onFocus = async () => {
eSendEvent(eScrollEvent, {name: params.title, type: 'in'});
+ if (route.params.menu) {
+ navigation.setOptions({
+ animationEnabled: false,
+ gestureEnabled: false,
+ });
+ } else {
+ navigation.setOptions({
+ animationEnabled: true,
+ gestureEnabled: Platform.OS === 'ios',
+ });
+ }
updateSearch();
if (!pageIsLoaded) {
console.log('returning since page is not loaded');
@@ -74,7 +88,7 @@ export const Notebook = ({route, navigation}) => {
const _onPressBottomButton = () => {
let n = route.params.notebook;
- eSendEvent(eOpenAddTopicDialog,n.id)
+ eSendEvent(eOpenAddTopicDialog, n.id);
};
return (
diff --git a/apps/mobile/src/views/Notes/index.js b/apps/mobile/src/views/Notes/index.js
index 837735357..c4889e7c8 100644
--- a/apps/mobile/src/views/Notes/index.js
+++ b/apps/mobile/src/views/Notes/index.js
@@ -1,4 +1,5 @@
import React, {useCallback, useEffect, useState} from 'react';
+import { Platform } from 'react-native';
import {ContainerBottomButton} from '../../components/Container/ContainerBottomButton';
import SimpleList from '../../components/SimpleList';
import {NoteItemWrapper} from '../../components/SimpleList/NoteItemWrapper';
@@ -69,7 +70,7 @@ export const Notes = ({route, navigation}) => {
} else {
navigation.setOptions({
animationEnabled: true,
- gestureEnabled: true,
+ gestureEnabled: Platform.OS === "ios",
});
}
let allNotes = [];