Skip to content

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

hide searchInput with animation

ammarahm-edee8235474444
diff --git a/apps/mobile/src/components/SearchInput/index.js b/apps/mobile/src/components/SearchInput/index.js
index 7d57a8c19..72ac813c3 100644
--- a/apps/mobile/src/components/SearchInput/index.js
+++ b/apps/mobile/src/components/SearchInput/index.js
@@ -104,16 +104,23 @@ export const Search = (props) => {
selection.data = searchState.data;
selection.type = searchState.type;
eSubscribeEvent(eScrollEvent, onScroll);
- eSubscribeEvent('showSearch', () => {
- console.log('show search');
- animating = false;
+ eSubscribeEvent('showSearch', (hide) => {
+
+ if (hide) {
+ animation(-65, 0, 0);
+ return;
+ }
animation(0, 1, 1.5);
});
+
eSubscribeEvent(eUpdateSearchState, updateSearchState);
return () => {
eUnSubscribeEvent(eScrollEvent, onScroll);
- eUnSubscribeEvent('showSearch', () => {
- animating = false;
+ eUnSubscribeEvent('showSearch', (hide) => {
+ if (hide) {
+ animation(-65, 0, 0);
+ return;
+ }
animation(0, 1, 1.5);
});
eUnSubscribeEvent(eUpdateSearchState, updateSearchState);
@@ -188,7 +195,7 @@ export const Search = (props) => {
//setSearch(false);
};
- return searchState.data[0] && !searchState.noSearch ? (
+ return (
<Animated.View
style={{
opacity: _opacity,
@@ -208,10 +215,10 @@ export const Search = (props) => {
borderRadius: br,
height: '90%',
backgroundColor: focus
- ? searchState.color
? searchState.color
- : colors.shade
- : colors.nav,
+ ? searchState.color
+ : colors.shade
+ : colors.nav,
}}>
<TextInput
ref={inputRef}
@@ -251,7 +258,5 @@ export const Search = (props) => {
/>
</Animated.View>
</Animated.View>
- ) : (
- <></>
);
};
diff --git a/apps/mobile/src/views/Favorites/index.js b/apps/mobile/src/views/Favorites/index.js
index ec2efaa6c..25511f0da 100644
--- a/apps/mobile/src/views/Favorites/index.js
+++ b/apps/mobile/src/views/Favorites/index.js
@@ -23,13 +23,7 @@ export const Favorites = ({route, navigation}) => {
heading: "Favorites",
},
});
- eSendEvent(eUpdateSearchState,{
- placeholder: 'Search all favorites',
- data: favorites,
- noSearch: false,
- type: 'notes',
- color: null,
- })
+ updateSearch();
dispatch({
type: Actions.CURRENT_SCREEN,
@@ -45,9 +39,19 @@ export const Favorites = ({route, navigation}) => {
};
});
+
+
useEffect(() => {
if (navigation.isFocused()) {
+ updateSearch();
+ }
+ }, [favorites]);
+ const updateSearch = () => {
+ if (favorites.length === 0) {
+ eSendEvent('showSearch', true);
+ } else {
+
eSendEvent(eUpdateSearchState,{
placeholder: 'Search all favorites',
data: favorites,
@@ -56,7 +60,7 @@ export const Favorites = ({route, navigation}) => {
color: null,
})
}
- }, [favorites]);
+ };
return (
<SimpleList
diff --git a/apps/mobile/src/views/Folders/index.js b/apps/mobile/src/views/Folders/index.js
index ba61acabb..67fd87e07 100644
--- a/apps/mobile/src/views/Folders/index.js
+++ b/apps/mobile/src/views/Folders/index.js
@@ -6,8 +6,8 @@ import {NotebookItemWrapper} from '../../components/SimpleList/NotebookItemWrapp
import {useTracked} from '../../provider';
import {Actions} from '../../provider/Actions';
import {ContainerBottomButton} from '../../components/Container/ContainerBottomButton';
-import {eSendEvent} from "../../services/EventManager";
-import {eUpdateSearchState} from "../../utils/Events";
+import {eSendEvent} from '../../services/EventManager';
+import {eUpdateSearchState} from '../../utils/Events';
export const Folders = ({route, navigation}) => {
const [state, dispatch] = useTracked();
const {notebooks} = state;
@@ -20,25 +20,34 @@ export const Folders = ({route, navigation}) => {
dispatch({
type: Actions.HEADER_TEXT_STATE,
state: {
- heading: "Notebooks",
+ heading: 'Notebooks',
},
});
- eSendEvent(eUpdateSearchState,{
- placeholder: 'Search all notebooks',
- data: notebooks,
- noSearch: false,
- type: 'notebooks',
- color: null,
- },)
-
dispatch({type: Actions.NOTEBOOKS});
dispatch({
type: Actions.CURRENT_SCREEN,
screen: 'notebooks',
});
+ updateSearch();
+
}, [notebooks]);
+ const updateSearch = () => {
+ if (notebooks.length === 0) {
+ eSendEvent('showSearch', true);
+ } else {
+ eSendEvent(eUpdateSearchState, {
+ placeholder: 'Search all notebooks',
+ data: notebooks,
+ noSearch: false,
+ type: 'notebooks',
+ color: null,
+ });
+ }
+ }
+
+
useEffect(() => {
navigation.addListener('focus', onFocus);
return () => {
@@ -48,19 +57,13 @@ export const Folders = ({route, navigation}) => {
useEffect(() => {
if (navigation.isFocused()) {
- eSendEvent(eUpdateSearchState,{
- placeholder: 'Search all notebooks',
- data: notebooks,
- noSearch: false,
- type: 'notebooks',
- color: null,
- },)
+ updateSearch();
}
}, [notebooks]);
useEffect(() => {
- console.log('render folders');
- })
+ console.log('render folders');
+ });
const _onPressBottomButton = () => AddNotebookEvent();
diff --git a/apps/mobile/src/views/Home/index.js b/apps/mobile/src/views/Home/index.js
index dd2ec3eec..4bc19f84a 100755
--- a/apps/mobile/src/views/Home/index.js
+++ b/apps/mobile/src/views/Home/index.js
@@ -1,19 +1,18 @@
-import React, { createRef, useCallback, useEffect } from 'react';
-import { ContainerBottomButton } from '../../components/Container/ContainerBottomButton';
-import { Placeholder } from '../../components/ListPlaceholders';
+import React, {useCallback, useEffect} from 'react';
+import {ContainerBottomButton} from '../../components/Container/ContainerBottomButton';
+import {Placeholder} from '../../components/ListPlaceholders';
import SimpleList from '../../components/SimpleList';
-import { NoteItemWrapper } from '../../components/SimpleList/NoteItemWrapper';
-import { useTracked } from '../../provider';
-import { Actions } from '../../provider/Actions';
-import { DDS } from '../../services/DeviceDetection';
-import { eSendEvent } from '../../services/EventManager';
-import { scrollRef, sortSettings } from '../../utils';
-import { openEditorAnimation } from '../../utils/Animations';
+import {NoteItemWrapper} from '../../components/SimpleList/NoteItemWrapper';
+import {useTracked} from '../../provider';
+import {Actions} from '../../provider/Actions';
+import {DDS} from '../../services/DeviceDetection';
+import {eSendEvent} from '../../services/EventManager';
+import {scrollRef} from '../../utils';
+import {openEditorAnimation} from '../../utils/Animations';
import {
eOnLoadNote,
-
eScrollEvent,
- eUpdateSearchState
+ eUpdateSearchState,
} from '../../utils/Events';
export const Home = ({navigation}) => {
@@ -35,15 +34,9 @@ export const Home = ({navigation}) => {
type: Actions.HEADER_STATE,
state: true,
});
- eSendEvent(eUpdateSearchState, {
- placeholder: 'Search all notes',
- data: notes,
- noSearch: false,
- type: 'notes',
- color: null,
- });
+ updateSearch();
+
eSendEvent(eScrollEvent, 0);
- console.log(sortSettings);
dispatch({type: Actions.COLORS});
dispatch({type: Actions.NOTES});
}, [notes]);
@@ -61,11 +54,14 @@ export const Home = ({navigation}) => {
useEffect(() => {
if (navigation.isFocused()) {
- dispatch({
- type: Actions.HEADER_VERTICAL_MENU,
- state: notes.length > 0,
- });
+ updateSearch();
+ }
+ }, [notes]);
+ const updateSearch = () => {
+ if (notes.length === 0) {
+ eSendEvent('showSearch', true);
+ } else {
eSendEvent(eUpdateSearchState, {
placeholder: 'Search all notes',
data: notes,
@@ -74,7 +70,7 @@ export const Home = ({navigation}) => {
color: null,
});
}
- }, [notes]);
+ };
const _onPressBottomButton = async (event) => {
eSendEvent(eOnLoadNote, {type: 'new'});
@@ -109,5 +105,3 @@ export const Home = ({navigation}) => {
};
export default Home;
-
-
diff --git a/apps/mobile/src/views/Notebook/index.js b/apps/mobile/src/views/Notebook/index.js
index a9c2df05e..d98efc172 100644
--- a/apps/mobile/src/views/Notebook/index.js
+++ b/apps/mobile/src/views/Notebook/index.js
@@ -48,13 +48,7 @@ export const Notebook = ({route, navigation}) => {
},
});
- eSendEvent(eUpdateSearchState,{
- placeholder: `Search in "${params.title}"`,
- data: topics,
- noSearch: false,
- type: 'topics',
- color: null,
- })
+ updateSearch();
dispatch({
type: Actions.CURRENT_SCREEN,
@@ -69,8 +63,17 @@ export const Notebook = ({route, navigation}) => {
};
});
+
useEffect(() => {
if (navigation.isFocused()) {
+ updateSearch();
+ }
+ }, [topics]);
+
+ const updateSearch = () => {
+ if (topics.length === 0) {
+ eSendEvent('showSearch', true);
+ } else {
eSendEvent(eUpdateSearchState,{
placeholder: `Search in "${params.title}"`,
data: topics,
@@ -79,7 +82,9 @@ export const Notebook = ({route, navigation}) => {
color: null,
})
}
- }, [topics]);
+ };
+
+
const _onPressBottomButton = () => {
let n = route.params.notebook;
diff --git a/apps/mobile/src/views/Notes/index.js b/apps/mobile/src/views/Notes/index.js
index 3649c75e5..a2be20379 100644
--- a/apps/mobile/src/views/Notes/index.js
+++ b/apps/mobile/src/views/Notes/index.js
@@ -83,6 +83,7 @@ export const Notes = ({route, navigation}) => {
type: Actions.HEADER_STATE,
state: params.menu,
});
+ updateSearch();
dispatch({
type: Actions.HEADER_TEXT_STATE,
state: {
@@ -95,7 +96,6 @@ export const Notes = ({route, navigation}) => {
};
const onFocus = useCallback(() => {
-
init();
}, []);
@@ -117,18 +117,28 @@ export const Notes = ({route, navigation}) => {
useEffect(() => {
if (navigation.isFocused()) {
- eSendEvent(eUpdateSearchState,{
- placeholder: `Search in ${
- params.type === 'tag' ? '#' + params.title : params.title
- }`,
- data: notes,
- noSearch: false,
- type: 'notes',
- color: params.type === 'color' ? params.title : null,
- })
+ updateSearch();
}
}, [notes]);
+ const updateSearch = () => {
+ if (notes.length === 0) {
+ eSendEvent('showSearch', true);
+ } else {
+ eSendEvent(eUpdateSearchState,{
+ placeholder: `Search in ${
+ params.type === 'tag' ? '#' + params.title : params.title
+ }`,
+ data: notes,
+ noSearch: false,
+ type: 'notes',
+ color: params.type === 'color' ? params.title : null,
+ })
+ }
+ };
+
+
+
const _onPressBottomButton = useCallback(() => {
if (params.type === 'tag') {
editing.actionAfterFirstSave = {
diff --git a/apps/mobile/src/views/Settings/index.js b/apps/mobile/src/views/Settings/index.js
index 260ccdeff..561ae50c7 100644
--- a/apps/mobile/src/views/Settings/index.js
+++ b/apps/mobile/src/views/Settings/index.js
@@ -63,6 +63,7 @@ export const Settings = ({navigation}) => {
}
const onFocus = useCallback(() => {
+ eSendEvent('showSearch', true);
dispatch({
type: Actions.HEADER_STATE,
state: true,
@@ -84,8 +85,11 @@ export const Settings = ({navigation}) => {
type: '',
color: null,
});
+
}, []);
+
+
useEffect(() => {
navigation.addListener('focus', onFocus);
return () => {
diff --git a/apps/mobile/src/views/Tags/index.js b/apps/mobile/src/views/Tags/index.js
index 7c2eac12d..3d8591881 100644
--- a/apps/mobile/src/views/Tags/index.js
+++ b/apps/mobile/src/views/Tags/index.js
@@ -26,13 +26,7 @@ export const Tags = ({route, navigation}) => {
},
});
- eSendEvent(eUpdateSearchState, {
- placeholder: 'Search all tags',
- data: tags,
- noSearch: false,
- type: 'tags',
- color: null,
- });
+ updateSearch();
dispatch({type: Actions.TAGS});
dispatch({
type: Actions.CURRENT_SCREEN,
@@ -47,8 +41,18 @@ export const Tags = ({route, navigation}) => {
};
});
+
+
useEffect(() => {
if (navigation.isFocused()) {
+ updateSearch();
+ }
+ }, [tags]);
+
+ const updateSearch = () => {
+ if (tags.length === 0) {
+ eSendEvent('showSearch', true);
+ } else {
eSendEvent(eUpdateSearchState, {
placeholder: 'Search all tags',
data: tags,
@@ -57,7 +61,7 @@ export const Tags = ({route, navigation}) => {
color: null,
});
}
- }, [tags]);
+ };
return (
<SimpleList
diff --git a/apps/mobile/src/views/Trash/index.js b/apps/mobile/src/views/Trash/index.js
index 51e3ea6ba..82130bcb1 100644
--- a/apps/mobile/src/views/Trash/index.js
+++ b/apps/mobile/src/views/Trash/index.js
@@ -8,8 +8,8 @@ import {NotebookItemWrapper} from '../../components/SimpleList/NotebookItemWrapp
import {NoteItemWrapper} from '../../components/SimpleList/NoteItemWrapper';
import {useTracked} from '../../provider';
import {Actions} from '../../provider/Actions';
-import {eSendEvent} from "../../services/EventManager";
-import {eUpdateSearchState} from "../../utils/Events";
+import {eSendEvent} from '../../services/EventManager';
+import {eUpdateSearchState} from '../../utils/Events';
export const Trash = ({route, navigation}) => {
const [state, dispatch] = useTracked();
@@ -23,18 +23,11 @@ export const Trash = ({route, navigation}) => {
dispatch({
type: Actions.HEADER_TEXT_STATE,
state: {
- heading: "Trash",
+ heading: 'Trash',
},
});
- eSendEvent(eUpdateSearchState,{
- placeholder: 'Search all trash',
- data: trash,
- noSearch: false,
- type: 'trash',
- color: null,
- })
-
+ updateSearch();
dispatch({
type: Actions.TRASH,
});
@@ -53,17 +46,23 @@ export const Trash = ({route, navigation}) => {
useEffect(() => {
if (navigation.isFocused()) {
+ updateSearch();
+ }
+ }, [trash]);
- eSendEvent(eUpdateSearchState,{
+ const updateSearch = () => {
+ if (trash.length === 0) {
+ eSendEvent('showSearch', true);
+ } else {
+ eSendEvent(eUpdateSearchState, {
placeholder: 'Search all trash',
data: trash,
noSearch: false,
type: 'trash',
color: null,
- })
-
+ });
}
- }, [trash]);
+ };
const _onPressBottomButton = () => simpleDialogEvent(TEMPLATE_EMPTY_TRASH);