Skip to content

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

refactor navigation

ammarahm-ed984ee44fe469
diff --git a/apps/mobile/src/navigation/NavigatorStack.js b/apps/mobile/src/navigation/NavigatorStack.js
index 9d301c38b..a23c3e14f 100644
--- a/apps/mobile/src/navigation/NavigatorStack.js
+++ b/apps/mobile/src/navigation/NavigatorStack.js
@@ -4,6 +4,7 @@ import * as React from 'react';
import {Animated} from 'react-native';
import Container from '../components/Container';
import {updateEvent} from '../components/DialogManager/recievers';
+import { useTracked } from '../provider';
import {Actions} from '../provider/Actions';
import {eSendEvent} from '../services/EventManager';
import Navigation from '../services/Navigation';
@@ -29,7 +30,6 @@ const forFade = ({current}) => ({
});
const forSlide = ({current, next, inverted, layouts: {screen}}) => {
-
const progress = Animated.add(
current.progress.interpolate({
inputRange: [0, 1],
@@ -75,20 +75,23 @@ const screenOptionsForAnimation = {
export const NavigatorStack = React.memo(
() => {
-
+ const [state, dispatch] = useTracked();
+ const settings = state.settings;
+
+ const onStateChange = React.useCallback(() => {
+ dispatch({type: Actions.SELECTION_MODE, enabled: false});
+ dispatch({type: Actions.CLEAR_SELECTION});
+ eSendEvent('navigate');
+ });
return (
<Container root={true}>
<NavigationContainer
- onStateChange={() => {
- updateEvent({type: Actions.SELECTION_MODE, enabled: false});
- updateEvent({type: Actions.CLEAR_SELECTION});
- eSendEvent('navigate');
- }}
+ onStateChange={onStateChange}
independent={true}
ref={rootNavigatorRef}>
<Stack.Navigator
- initialRouteName={SettingsService.get().homepage}
+ initialRouteName={settings.homepage}
screenOptions={{
headerShown: false,
animationEnabled: false,
diff --git a/apps/mobile/src/services/Navigation.js b/apps/mobile/src/services/Navigation.js
index 9ba42fb20..f2fbd3504 100755
--- a/apps/mobile/src/services/Navigation.js
+++ b/apps/mobile/src/services/Navigation.js
@@ -1,6 +1,7 @@
import {DrawerActions, StackActions} from '@react-navigation/native';
import {updateEvent} from '../components/DialogManager/recievers';
import {Actions} from '../provider/Actions';
+import {eOnNewTopicAdded, refreshNotesPage} from '../utils/Events';
import {rootNavigatorRef, sideMenuRef} from '../utils/Refs';
import {eSendEvent} from './EventManager';
import SettingsService from './SettingsService';
@@ -9,9 +10,22 @@ let currentScreen = 'Notes';
let headerState = {
heading: 'Notes',
color: null,
- verticalMenu:true,
- currentScreen:'Notes'
+ verticalMenu: true,
+ currentScreen: 'Notes',
};
+
+const routeNames = {
+ Notes: 'Notes',
+ Notebooks: 'Notebooks',
+ Notebook: 'Notebook',
+ NotesPage: 'NotesPage',
+ Tags: 'Tags',
+ Favorites: 'favorites',
+ Trash: 'Trash',
+};
+
+let routesToUpdate = [];
+
function getCurrentScreen() {
return currentScreen;
}
@@ -20,6 +34,42 @@ function getHeaderState() {
return headerState;
}
+function clearRouteFromUpdates(routeName) {
+ if (routesToUpdate.indexOf(routeName) === -1) {
+ routesToUpdate = routesToUpdate.slice(routesToUpdate.indexOf(routeName), 1);
+ }
+}
+
+function routeNeedsUpdate(routeName, callback) {
+ if (routesToUpdate.indexOf(routeName) > -1) {
+ clearRouteFromUpdates(routeName);
+ callback();
+ }
+}
+
+function setRoutesToUpdate(routes) {
+ if (routes.indexOf(currentScreen) > -1) {
+ console.log('updating', currentScreen);
+ if (
+ currentScreen === routeNames.NotesPage &&
+ currentScreen === routeNames.Notebook
+ ) {
+ eSendEvent(
+ currentScreen === routeNames.NotesPage
+ ? refreshNotesPage
+ : eOnNewTopicAdded,
+ );
+ } else {
+ updateEvent({type: Actions[currentScreen.toUpperCase()]});
+ }
+ routes = routes.slice(routes.indexOf(currentScreen), 1);
+ }
+ routesToUpdate = routesToUpdate.concat(routes);
+ routesToUpdate.filter(function (item, pos) {
+ return routesToUpdate.indexOf(item) == pos;
+ });
+}
+
/**
* @typedef {Object} screenParams
* @property {string} heading
@@ -58,19 +108,6 @@ function setHeaderState(name, params, item) {
if (headerState) {
eSendEvent('onHeaderStateChange', headerState);
}
-
- /* if (name) {
- updateEvent({
- type: Actions.CURRENT_SCREEN,
- screen: name.toLowerCase(),
- });
- }
- if (params) {
- updateEvent({
- type: Actions.HEADER_STATE,
- state: params.menu,
- });
- } */
}
function goBack() {
@@ -120,4 +157,7 @@ export default {
replace,
popToTop,
getHeaderState,
+ setRoutesToUpdate,
+ routeNeedsUpdate,
+ routeNames,
};
diff --git a/apps/mobile/src/views/Favorites/index.js b/apps/mobile/src/views/Favorites/index.js
index 86b861d6d..97b3fd7db 100644
--- a/apps/mobile/src/views/Favorites/index.js
+++ b/apps/mobile/src/views/Favorites/index.js
@@ -1,5 +1,4 @@
import React, {useCallback, useEffect} from 'react';
-import {InteractionManager} from 'react-native';
import {Placeholder} from '../../components/ListPlaceholders';
import SimpleList from '../../components/SimpleList';
import {useTracked} from '../../provider';
@@ -8,20 +7,27 @@ import {DDS} from '../../services/DeviceDetection';
import {eSendEvent} from '../../services/EventManager';
import Navigation from '../../services/Navigation';
import SearchService from '../../services/SearchService';
+import { InteractionManager } from '../../utils';
import {eScrollEvent} from '../../utils/Events';
export const Favorites = ({route, navigation}) => {
const [state, dispatch] = useTracked();
const favorites = state.favorites;
const [localLoad, setLocalLoad] = React.useState(true);
const {loading} = state;
-
let pageIsLoaded = false;
- const onFocus = useCallback(() => {
+ let ranAfterInteractions = false;
+
+ const runAfterInteractions = () => {
InteractionManager.runAfterInteractions(() => {
if (localLoad) {
setLocalLoad(false);
}
+
+ Navigation.routeNeedsUpdate('Favorites',() => {
+ dispatch({type:Actions.FAVORITES})
+ })
+
eSendEvent(eScrollEvent, {name: 'Favorites', type: 'in'});
updateSearch();
if (DDS.isLargeTablet()) {
@@ -32,7 +38,15 @@ export const Favorites = ({route, navigation}) => {
},
});
}
+ ranAfterInteractions = false;
});
+ };
+
+ const onFocus = useCallback(() => {
+ if (!ranAfterInteractions) {
+ ranAfterInteractions = true;
+ runAfterInteractions();
+ }
if (!pageIsLoaded) {
pageIsLoaded = true;
@@ -51,9 +65,14 @@ export const Favorites = ({route, navigation}) => {
}, []);
useEffect(() => {
+ if (!ranAfterInteractions) {
+ ranAfterInteractions = true;
+ runAfterInteractions();
+ }
navigation.addListener('focus', onFocus);
return () => {
pageIsLoaded = false;
+ ranAfterInteractions = false;
eSendEvent(eScrollEvent, {name: 'Notebooks', type: 'back'});
navigation.removeListener('focus', onFocus);
};
@@ -70,13 +89,13 @@ export const Favorites = ({route, navigation}) => {
placeholder: 'Search in favorites',
data: favorites,
type: 'notes',
- title:"Favorites"
+ title: 'Favorites',
});
};
return (
<SimpleList
- data={favorites}
+ listData={favorites}
type="notes"
refreshCallback={() => {
dispatch({type: Actions.FAVORITES});
diff --git a/apps/mobile/src/views/Folders/index.js b/apps/mobile/src/views/Folders/index.js
index c58cf1f22..8e781c06f 100644
--- a/apps/mobile/src/views/Folders/index.js
+++ b/apps/mobile/src/views/Folders/index.js
@@ -10,30 +10,22 @@ import SearchService from '../../services/SearchService';
import {eScrollEvent} from '../../utils/Events';
import Navigation from '../../services/Navigation';
import {DDS} from '../../services/DeviceDetection';
-import {InteractionManager} from 'react-native';
export const Folders = ({route, navigation}) => {
const [state, dispatch] = useTracked();
const notebooks = state.notebooks;
const [loading, setLoading] = useState(true);
let pageIsLoaded = false;
+ let ranAfterInteractions = false;
+ const InteractionManager = {
+ runAfterInteractions:(func) => setTimeout(func,300)
+ }
const onFocus = useCallback(() => {
- InteractionManager.runAfterInteractions(() => {
- if (loading) {
- setLoading(false);
- }
- eSendEvent(eScrollEvent, {name: 'Notebooks', type: 'in'});
- updateSearch();
- if (DDS.isLargeTablet()) {
- dispatch({
- type: Actions.CONTAINER_BOTTOM_BUTTON,
- state: {
- onPress: _onPressBottomButton,
- },
- });
- }
- });
+ if (!ranAfterInteractions) {
+ ranAfterInteractions = true;
+ runAfterInteractions();
+ }
if (!pageIsLoaded) {
pageIsLoaded = true;
@@ -49,11 +41,41 @@ export const Folders = ({route, navigation}) => {
id: 'notebooks_navigation',
},
);
+
}, []);
+ const runAfterInteractions = () => {
+ InteractionManager.runAfterInteractions(() => {
+ if (loading) {
+ setLoading(false);
+ }
+ Navigation.routeNeedsUpdate('Notebooks',() => {
+ dispatch({type:Actions.NOTEBOOKS})
+ })
+
+ eSendEvent(eScrollEvent, {name: 'Notebooks', type: 'in'});
+ updateSearch();
+ if (DDS.isLargeTablet()) {
+ dispatch({
+ type: Actions.CONTAINER_BOTTOM_BUTTON,
+ state: {
+ onPress: _onPressBottomButton,
+ },
+ });
+ }
+ ranAfterInteractions = false;
+ });
+ };
+
useEffect(() => {
+ if (!ranAfterInteractions) {
+ ranAfterInteractions = true;
+ runAfterInteractions();
+ }
+
navigation.addListener('focus', onFocus);
return () => {
+ ranAfterInteractions = false;
pageIsLoaded = false;
navigation.removeListener('focus', onFocus);
eSendEvent(eScrollEvent, {name: 'Notebooks', type: 'back'});
@@ -71,7 +93,7 @@ export const Folders = ({route, navigation}) => {
placeholder: 'Type a keyword to search in notebooks',
data: notebooks,
type: 'notebooks',
- title:"Notebooks"
+ title: 'Notebooks',
});
};
@@ -80,7 +102,7 @@ export const Folders = ({route, navigation}) => {
return (
<>
<SimpleList
- data={notebooks}
+ listData={notebooks}
type="notebooks"
focused={() => navigation.isFocused()}
loading={loading}
diff --git a/apps/mobile/src/views/Home/index.js b/apps/mobile/src/views/Home/index.js
index e1eda3a5d..b4ac876e7 100755
--- a/apps/mobile/src/views/Home/index.js
+++ b/apps/mobile/src/views/Home/index.js
@@ -1,6 +1,5 @@
import React, {useCallback, useEffect, useState} from 'react';
-import { AsyncStorage } from 'react-native';
-import {InteractionManager} from 'react-native';
+import {AsyncStorage} from 'react-native';
import {ContainerBottomButton} from '../../components/Container/ContainerBottomButton';
import SimpleList from '../../components/SimpleList';
import {useTracked} from '../../provider';
@@ -9,10 +8,11 @@ import {DDS} from '../../services/DeviceDetection';
import {eSendEvent} from '../../services/EventManager';
import Navigation from '../../services/Navigation';
import SearchService from '../../services/SearchService';
-import {scrollRef} from '../../utils';
+import {InteractionManager, scrollRef} from '../../utils';
import {db} from '../../utils/DB';
import {eOnLoadNote, eScrollEvent} from '../../utils/Events';
import {tabBarRef} from '../../utils/Refs';
+import Storage from '../../utils/storage';
export const Home = ({route, navigation}) => {
const [state, dispatch] = useTracked();
@@ -20,26 +20,13 @@ export const Home = ({route, navigation}) => {
const [localLoad, setLocalLoad] = useState(true);
const notes = state.notes;
let pageIsLoaded = false;
+ let ranAfterInteractions = false;
const onFocus = useCallback(() => {
- InteractionManager.runAfterInteractions(() => {
- if (localLoad) {
- setLocalLoad(false);
- }
-
- updateSearch();
- eSendEvent(eScrollEvent, {name: 'Notes', type: 'in'});
-
- if (DDS.isLargeTablet()) {
- dispatch({
- type: Actions.CONTAINER_BOTTOM_BUTTON,
- state: {
- onPress: _onPressBottomButton,
- },
- });
- }
- });
-
+ if (!ranAfterInteractions) {
+ ranAfterInteractions = true;
+ runAfterInteractions();
+ }
if (!pageIsLoaded) {
pageIsLoaded = true;
return;
@@ -59,17 +46,49 @@ export const Home = ({route, navigation}) => {
const onBlur = useCallback(() => {}, []);
+ const runAfterInteractions = () => {
+ InteractionManager.runAfterInteractions(() => {
+ if (localLoad) {
+ setLocalLoad(false);
+ }
+
+ updateSearch();
+ eSendEvent(eScrollEvent, {name: 'Notes', type: 'in'});
+
+ Navigation.routeNeedsUpdate('Notes', () => {
+ console.log('updating notes as requested');
+ dispatch({type: Actions.NOTES});
+ });
+
+ if (DDS.isLargeTablet()) {
+ dispatch({
+ type: Actions.CONTAINER_BOTTOM_BUTTON,
+ state: {
+ onPress: _onPressBottomButton,
+ },
+ });
+ }
+ ranAfterInteractions = false;
+ });
+ };
+
useEffect(() => {
+ if (!ranAfterInteractions) {
+ ranAfterInteractions = true;
+ runAfterInteractions();
+ }
+
navigation.addListener('focus', onFocus);
navigation.addListener('blur', onBlur);
return () => {
pageIsLoaded = false;
+ ranAfterInteractions = false;
eSendEvent(eScrollEvent, {name: 'Notes', type: 'back'});
navigation.removeListener('focus', onFocus);
navigation.removeListener('blur', onBlur);
};
}, []);
-
+
useEffect(() => {
if (navigation.isFocused()) {
updateSearch();
@@ -86,7 +105,6 @@ export const Home = ({route, navigation}) => {
};
const _onPressBottomButton = async () => {
-
if (!DDS.isLargeTablet()) {
tabBarRef.current?.goToPage(1);
} else {
@@ -97,7 +115,7 @@ export const Home = ({route, navigation}) => {
return (
<>
<SimpleList
- data={notes}
+ listData={notes}
scrollRef={scrollRef}
type="notes"
isHome={true}
diff --git a/apps/mobile/src/views/Notebook/index.js b/apps/mobile/src/views/Notebook/index.js
index 93b4fd6d7..a6da80609 100644
--- a/apps/mobile/src/views/Notebook/index.js
+++ b/apps/mobile/src/views/Notebook/index.js
@@ -1,5 +1,4 @@
import React, {useEffect, useState} from 'react';
-import {InteractionManager} from 'react-native';
import {ContainerBottomButton} from '../../components/Container/ContainerBottomButton';
import SimpleList from '../../components/SimpleList';
import {
@@ -9,6 +8,7 @@ import {
} from '../../services/EventManager';
import Navigation from '../../services/Navigation';
import SearchService from '../../services/SearchService';
+import {InteractionManager} from '../../utils';
import {db} from '../../utils/DB';
import {
eOnNewTopicAdded,
@@ -22,28 +22,17 @@ export const Notebook = ({route, navigation}) => {
let params = route.params;
let pageIsLoaded = false;
- const onLoad = () => {
- InteractionManager.runAfterInteractions(() => {
- setTopics(db.notebooks.notebook(route.params.notebook.id).data.topics);
- });
- };
+ let ranAfterInteractions = false;
- useEffect(() => {
- onLoad();
- }, [route.params]);
-
- useEffect(() => {
- eSubscribeEvent(eOnNewTopicAdded, onLoad);
- return () => {
- eUnSubscribeEvent(eOnNewTopicAdded, onLoad);
- };
- }, []);
-
- const onFocus = async () => {
+ const runAfterInteractions = () => {
InteractionManager.runAfterInteractions(() => {
if (loading) {
setLoading(false);
}
+ Navigation.routeNeedsUpdate('Notebooks', () => {
+ onLoad();
+ });
+
eSendEvent(eScrollEvent, {name: params.title, type: 'in'});
if (route.params.menu) {
navigation.setOptions({
@@ -57,14 +46,37 @@ export const Notebook = ({route, navigation}) => {
});
}
updateSearch();
-
+ ranAfterInteractions = false;
});
-
+ };
+ const onLoad = () => {
+ InteractionManager.runAfterInteractions(() => {
+ setTopics(db.notebooks.notebook(route.params.notebook.id).data.topics);
+ });
+ };
+
+ useEffect(() => {
+ onLoad();
+ }, [route.params]);
+
+ useEffect(() => {
+ eSubscribeEvent(eOnNewTopicAdded, onLoad);
+ return () => {
+ eUnSubscribeEvent(eOnNewTopicAdded, onLoad);
+ };
+ }, []);
+
+ const onFocus = async () => {
+ if (!ranAfterInteractions) {
+ ranAfterInteractions = true;
+ runAfterInteractions();
+ }
+
if (!pageIsLoaded) {
pageIsLoaded = true;
return;
}
- Navigation.setHeaderState('notebooks', params, {
+ Navigation.setHeaderState('Notebooks', params, {
heading: params.title,
id: params.notebook.id,
type: 'notebook',
@@ -72,8 +84,14 @@ export const Notebook = ({route, navigation}) => {
};
useEffect(() => {
+ if (!ranAfterInteractions) {
+ ranAfterInteractions = true;
+ runAfterInteractions();
+ }
+
navigation.addListener('focus', onFocus);
return () => {
+ ranAfterInteractions = false;
eSendEvent(eScrollEvent, {name: params.title, type: 'back'});
navigation.removeListener('focus', onFocus);
};
@@ -90,7 +108,7 @@ export const Notebook = ({route, navigation}) => {
placeholder: `Search in "${params.title}"`,
data: topics,
type: 'topics',
- title:params.title
+ title: params.title,
});
};
@@ -102,7 +120,7 @@ export const Notebook = ({route, navigation}) => {
return (
<>
<SimpleList
- data={topics}
+ listData={topics}
type="topics"
refreshCallback={() => {
onLoad();
diff --git a/apps/mobile/src/views/Notes/index.js b/apps/mobile/src/views/Notes/index.js
index abb00bee1..75c498f54 100644
--- a/apps/mobile/src/views/Notes/index.js
+++ b/apps/mobile/src/views/Notes/index.js
@@ -1,5 +1,5 @@
import React, {useCallback, useEffect, useState} from 'react';
-import {InteractionManager, Platform} from 'react-native';
+import {Platform} from 'react-native';
import {ContainerBottomButton} from '../../components/Container/ContainerBottomButton';
import SimpleList from '../../components/SimpleList';
import {useTracked} from '../../provider';
@@ -12,7 +12,7 @@ import {
} from '../../services/EventManager';
import Navigation from '../../services/Navigation';
import SearchService from '../../services/SearchService';
-import {editing} from '../../utils';
+import {editing, InteractionManager} from '../../utils';
import {COLORS_NOTE} from '../../utils/Colors';
import {db} from '../../utils/DB';
import {eOnLoadNote, eScrollEvent, refreshNotesPage} from '../../utils/Events';
@@ -22,47 +22,22 @@ export const Notes = ({route, navigation}) => {
const [state, dispatch] = useTracked();
const {loading} = state;
const [localLoad, setLocalLoad] = useState(true);
-
const [notes, setNotes] = useState([]);
let params = route.params ? route.params : null;
let pageIsLoaded = false;
+ let ranAfterInteractions = false;
- useEffect(() => {
- eSubscribeEvent(refreshNotesPage, init);
-
- return () => {
- eUnSubscribeEvent(refreshNotesPage, init);
- editing.actionAfterFirstSave = {
- type: null,
- };
- };
- }, []);
-
- const setActionAfterFirstSave = () => {
- if (params.type === 'tag') {
- editing.actionAfterFirstSave = {
- type: 'tag',
- id: params.tag.id,
- };
- } else if (params.type === 'color') {
- editing.actionAfterFirstSave = {
- type: 'color',
- id: params.color.id,
- };
- } else {
- editing.actionAfterFirstSave = {
- type: 'topic',
- id: params.id,
- notebook: params.notebookId,
- };
- }
- };
-
- const init = (data) => {
+ const runAfterInteractions = (data) => {
InteractionManager.runAfterInteractions(() => {
if (localLoad) {
setLocalLoad(false);
}
+
+ Navigation.routeNeedsUpdate('NotesPage', () => {
+
+ init();
+ });
+
params = route.params;
if (data) {
params = data;
@@ -106,7 +81,51 @@ export const Notes = ({route, navigation}) => {
color: params.type == 'color' ? COLORS_NOTE[params.title] : null,
},
});
+ ranAfterInteractions = false;
});
+ };
+
+ useEffect(() => {
+ if (!ranAfterInteractions) {
+ ranAfterInteractions = true;
+ runAfterInteractions();
+ }
+ eSubscribeEvent(refreshNotesPage, init);
+ return () => {
+ ranAfterInteractions = false;
+ eUnSubscribeEvent(refreshNotesPage, init);
+ editing.actionAfterFirstSave = {
+ type: null,
+ };
+ };
+ }, []);
+
+ const setActionAfterFirstSave = () => {
+ if (params.type === 'tag') {
+ editing.actionAfterFirstSave = {
+ type: 'tag',
+ id: params.tag.id,
+ };
+ } else if (params.type === 'color') {
+ editing.actionAfterFirstSave = {
+ type: 'color',
+ id: params.color.id,
+ };
+ } else {
+ editing.actionAfterFirstSave = {
+ type: 'topic',
+ id: params.id,
+ notebook: params.notebookId,
+ };
+ }
+ };
+
+ const init = (data) => {
+ if (!ranAfterInteractions) {
+ console.log('focus');
+ ranAfterInteractions = true;
+ runAfterInteractions(data);
+ }
if (!pageIsLoaded) {
pageIsLoaded = true;
@@ -202,7 +221,7 @@ export const Notes = ({route, navigation}) => {
return (
<>
<SimpleList
- data={notes}
+ listData={notes}
type="notes"
refreshCallback={() => {
init();
diff --git a/apps/mobile/src/views/Search/index.js b/apps/mobile/src/views/Search/index.js
index 8958349a6..6d59aaf01 100644
--- a/apps/mobile/src/views/Search/index.js
+++ b/apps/mobile/src/views/Search/index.js
@@ -53,7 +53,7 @@ export const Search = ({route, navigation}) => {
return (
<>
<SimpleList
- data={searchResults}
+ listData={searchResults}
type="search"
focused={() => navigation.isFocused()}
placeholderText={`Notes you write appear here`}
diff --git a/apps/mobile/src/views/Settings/index.js b/apps/mobile/src/views/Settings/index.js
index 37c601a1f..22433fa34 100644
--- a/apps/mobile/src/views/Settings/index.js
+++ b/apps/mobile/src/views/Settings/index.js
@@ -128,9 +128,10 @@ export const Settings = ({navigation}) => {
navigation.addListener('focus', onFocus);
db.version()
.then((ver) => {
+ console.log(ver,"VERSION")
setVersion(ver);
})
- .catch(console.log);
+ .catch((e) => console.log(e,"VER"));
return () => {
pageIsLoaded = false;
@@ -154,7 +155,8 @@ export const Settings = ({navigation}) => {
{
name: 'Check for updates',
func: async () => {
- if (version?.mobile <= APP_VERSION) {
+ if (!version) return;
+ if (version.mobile <= APP_VERSION) {
ToastEvent.show('You are using the latest version', 'success');
return;
}
diff --git a/apps/mobile/src/views/Tags/index.js b/apps/mobile/src/views/Tags/index.js
index a881a080e..a6c00494a 100644
--- a/apps/mobile/src/views/Tags/index.js
+++ b/apps/mobile/src/views/Tags/index.js
@@ -1,5 +1,4 @@
import React, {useCallback, useEffect, useState} from 'react';
-import {InteractionManager} from 'react-native';
import {Placeholder} from '../../components/ListPlaceholders';
import SimpleList from '../../components/SimpleList';
import {useTracked} from '../../provider';
@@ -8,6 +7,7 @@ import {DDS} from '../../services/DeviceDetection';
import {eSendEvent} from '../../services/EventManager';
import Navigation from '../../services/Navigation';
import SearchService from '../../services/SearchService';
+import { InteractionManager } from '../../utils';
import {eScrollEvent} from '../../utils/Events';
export const Tags = ({route, navigation}) => {
@@ -16,11 +16,19 @@ export const Tags = ({route, navigation}) => {
const [loading, setLoading] = useState(true);
let pageIsLoaded = false;
- const onFocus = useCallback(() => {
+ let ranAfterInteractions = false;
+
+
+ const runAfterInteractions = () => {
InteractionManager.runAfterInteractions(() => {
if (loading) {
setLoading(false);
}
+
+ Navigation.routeNeedsUpdate('Tags',() => {
+ dispatch({type:Actions.TAGS})
+ })
+
eSendEvent(eScrollEvent, {name: 'Tags', type: 'in'});
if (DDS.isLargeTablet()) {
dispatch({
@@ -31,8 +39,19 @@ export const Tags = ({route, navigation}) => {
});
}
updateSearch();
+ ranAfterInteractions = false;
});
+
+ };
+
+ const onFocus = useCallback(() => {
+ if (!ranAfterInteractions) {
+
+ ranAfterInteractions = true;
+ runAfterInteractions();
+ }
+
if (!pageIsLoaded) {
pageIsLoaded = true;
return;
@@ -50,9 +69,14 @@ export const Tags = ({route, navigation}) => {
}, []);
useEffect(() => {
+ if (!ranAfterInteractions) {
+ ranAfterInteractions = true;
+ runAfterInteractions();
+ }
navigation.addListener('focus', onFocus);
return () => {
- pageIsLoaded = false;
+ pageIsLoaded = false;
+ ranAfterInteractions = false;
eSendEvent(eScrollEvent, {name: 'Tags', type: 'back'});
navigation.removeListener('focus', onFocus);
};
@@ -75,7 +99,7 @@ export const Tags = ({route, navigation}) => {
return (
<SimpleList
- data={tags}
+ listData={tags}
type="tags"
headerProps={{
heading: 'Tags',
diff --git a/apps/mobile/src/views/Trash/index.js b/apps/mobile/src/views/Trash/index.js
index 1c3272aa7..50310352c 100644
--- a/apps/mobile/src/views/Trash/index.js
+++ b/apps/mobile/src/views/Trash/index.js
@@ -1,5 +1,5 @@
import React, {useCallback, useEffect, useState} from 'react';
-import { InteractionManager } from 'react-native';
+
import {ContainerBottomButton} from '../../components/Container/ContainerBottomButton';
import {simpleDialogEvent} from '../../components/DialogManager/recievers';
import {TEMPLATE_EMPTY_TRASH} from '../../components/DialogManager/Templates';
@@ -11,6 +11,7 @@ import {DDS} from '../../services/DeviceDetection';
import {eSendEvent} from '../../services/EventManager';
import Navigation from '../../services/Navigation';
import SearchService from '../../services/SearchService';
+import {InteractionManager} from '../../utils';
import {eScrollEvent} from '../../utils/Events';
export const Trash = ({route, navigation}) => {
@@ -19,11 +20,18 @@ export const Trash = ({route, navigation}) => {
const [loading, setLoading] = useState(true);
let pageIsLoaded = false;
- const onFocus = useCallback(() => {
+ let ranAfterInteractions = false;
+
+ const runAfterInteractions = () => {
InteractionManager.runAfterInteractions(() => {
if (loading) {
setLoading(false);
}
+
+ Navigation.routeNeedsUpdate('Trash', () => {
+ dispatch({type: Actions.TRASH});
+ });
+
eSendEvent(eScrollEvent, {name: 'Trash', type: 'in'});
if (DDS.isLargeTablet()) {
dispatch({
@@ -34,7 +42,15 @@ export const Trash = ({route, navigation}) => {
});
}
updateSearch();
+ ranAfterInteractions = false;
});
+ };
+
+ const onFocus = useCallback(() => {
+ if (!ranAfterInteractions) {
+ ranAfterInteractions = true;
+ runAfterInteractions();
+ }
if (!pageIsLoaded) {
pageIsLoaded = true;
@@ -53,9 +69,14 @@ export const Trash = ({route, navigation}) => {
}, []);
useEffect(() => {
+ if (!ranAfterInteractions) {
+ ranAfterInteractions = true;
+ runAfterInteractions();
+ }
navigation.addListener('focus', onFocus);
return () => {
pageIsLoaded = false;
+ ranAfterInteractions = false;
eSendEvent(eScrollEvent, {name: 'Trash', type: 'back'});
navigation.removeListener('focus', onFocus);
};
@@ -72,7 +93,7 @@ export const Trash = ({route, navigation}) => {
placeholder: 'Search in trash',
data: trash,
type: 'trash',
- title: "Trash"
+ title: 'Trash',
});
};
@@ -81,7 +102,7 @@ export const Trash = ({route, navigation}) => {
return (
<>
<SimpleList
- data={trash}
+ listData={trash}
type="trash"
focused={() => navigation.isFocused()}
loading={loading}