Skip to content

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

fix header and search

ammarahm-ed9580bd063a4b
diff --git a/apps/mobile/src/components/Header/index.js b/apps/mobile/src/components/Header/index.js
index 0fc13e8d3..7b3973e1c 100644
--- a/apps/mobile/src/components/Header/index.js
+++ b/apps/mobile/src/components/Header/index.js
@@ -1,23 +1,61 @@
-import React from 'react';
+import React, { useEffect, useState } from 'react';
import {ActivityIndicator, Platform, StyleSheet, View} from 'react-native';
import * as Animatable from 'react-native-animatable';
import {useSafeAreaInsets} from 'react-native-safe-area-context';
import {useTracked} from '../../provider';
-import {eSendEvent} from '../../services/EventManager';
-import {useHideHeader} from '../../utils/Hooks';
+import {eSendEvent, eSubscribeEvent, eUnSubscribeEvent} from '../../services/EventManager';
import {dWidth} from '../../utils';
import {ActionIcon} from '../ActionIcon';
import {HeaderMenu} from './HeaderMenu';
import {HeaderTitle} from './HeaderTitle';
import {SIZE} from "../../utils/SizeUtils";
import {HeaderLeftMenu} from "./HeaderLeftMenu";
+import { eScrollEvent } from '../../utils/Events';
+let timeout = null;
export const Header = ({showSearch, root}) => {
const [state, ] = useTracked();
const {colors, syncing} = state;
-
const insets = useSafeAreaInsets();
- const hideHeader = useHideHeader();
+ const [hideHeader,setHideHeader] = useState(false);
+
+ const {
+ searchResults,
+ } = state;
+ let offsetY = 0;
+
+
+ const onScroll = (y) => {
+ if (searchResults.results.length > 0) return;
+ if (y < 30) {
+ setHideHeader(false);
+ offsetY = y;
+ }
+ if (y > offsetY) {
+ if (y - offsetY < 100) return;
+ clearTimeout(timeout);
+ timeout = null;
+ timeout = setTimeout(() => {
+ setHideHeader(true);
+ }, 300);
+ offsetY = y;
+ } else {
+ if (offsetY - y < 50) return;
+ clearTimeout(timeout);
+ timeout = null;
+ timeout = setTimeout(() => {
+ setHideHeader(false);
+ }, 300);
+ offsetY = y;
+ }
+ };
+
+ useEffect(() => {
+ eSubscribeEvent(eScrollEvent, onScroll);
+ return () => {
+ eUnSubscribeEvent(eScrollEvent, onScroll);
+ };
+ }, []);
return (
<View
diff --git a/apps/mobile/src/components/SearchInput/index.js b/apps/mobile/src/components/SearchInput/index.js
index f962ae314..3b20966cc 100644
--- a/apps/mobile/src/components/SearchInput/index.js
+++ b/apps/mobile/src/components/SearchInput/index.js
@@ -18,6 +18,34 @@ let searchResult = [];
let offsetY = 0;
let timeoutAnimate = null;
let animating = false;
+
+const _marginAnim = new Value(0);
+const _opacity = new Value(1);
+const _borderAnim = new Value(1.5);
+
+const animation = (margin, opacity, border) => {
+ if (animating) return;
+ animating = true;
+ timing(_marginAnim, {
+ toValue: margin,
+ duration: 230,
+ easing: Easing.inOut(Easing.ease),
+ }).start();
+ timing(_opacity, {
+ toValue: opacity,
+ duration: 250,
+ easing: Easing.inOut(Easing.ease),
+ }).start();
+ timing(_borderAnim, {
+ toValue: border,
+ duration: 270,
+ easing: Easing.inOut(Easing.ease),
+ }).start();
+ setTimeout(() => {
+ animating = false;
+ }, 500);
+};
+
export const Search = (props) => {
const [state, dispatch] = useTracked();
const {colors, searchResults} = state;
@@ -30,31 +58,7 @@ export const Search = (props) => {
color: null,
placeholder: 'Search all notes',
})
- const _marginAnim = new Value(0);
- const _opacity = new Value(1);
- const _borderAnim = new Value(1.5);
- const animation = (margin, opacity, border) => {
- if (animating) return;
- animating = true;
- timing(_marginAnim, {
- toValue: margin,
- duration: 230,
- easing: Easing.inOut(Easing.ease),
- }).start();
- timing(_opacity, {
- toValue: opacity,
- duration: 250,
- easing: Easing.inOut(Easing.ease),
- }).start();
- timing(_borderAnim, {
- toValue: border,
- duration: 270,
- easing: Easing.inOut(Easing.ease),
- }).start();
- setTimeout(() => {
- animating = false;
- }, 500);
- };
+
const onScroll = (y) => {
if (searchResults.results.length > 0) return;
@@ -96,12 +100,15 @@ export const Search = (props) => {
selection.type = searchState.type;
eSubscribeEvent(eScrollEvent, onScroll);
eSubscribeEvent('showSearch', () => {
+ console.log('show search');
+ animating = false;
animation(0, 1, 1.5);
});
eSubscribeEvent(eUpdateSearchState,updateSearchState)
return () => {
eUnSubscribeEvent(eScrollEvent, onScroll);
eUnSubscribeEvent('showSearch', () => {
+ animating = false;
animation(0, 1, 1.5);
});
eUnSubscribeEvent(eUpdateSearchState,updateSearchState)
diff --git a/apps/mobile/src/utils/Hooks.js b/apps/mobile/src/utils/Hooks.js
index a636841a2..c477c7f25 100644
--- a/apps/mobile/src/utils/Hooks.js
+++ b/apps/mobile/src/utils/Hooks.js
@@ -16,46 +16,3 @@ export function useForceUpdate() {
return update;
}
-export function useHideHeader() {
- const [hide,setHide] = useState(false);
- const [state, dispatch] = useTracked();
- const {
- searchResults,
- } = state;
- let offsetY = 0;
- let timeout = null;
-
- const onScroll = (y) => {
- if (searchResults.results.length > 0) return;
- if (y < 30) {
- setHide(false);
- offsetY = y;
- }
- if (y > offsetY) {
- if (y - offsetY < 100) return;
- clearTimeout(timeout);
- timeout = null;
- timeout = setTimeout(() => {
- setHide(true);
- }, 300);
- offsetY = y;
- } else {
- if (offsetY - y < 50) return;
- clearTimeout(timeout);
- timeout = null;
- timeout = setTimeout(() => {
- setHide(false);
- }, 300);
- offsetY = y;
- }
- };
-
- useEffect(() => {
- eSubscribeEvent(eScrollEvent, onScroll);
- return () => {
- eUnSubscribeEvent(eScrollEvent, onScroll);
- };
- }, []);
- return hide;
-
-}