Skip to content

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

fix issues due to useCallback being used

ammarahm-edb4005314fffe
diff --git a/apps/mobile/src/components/Container/ContainerTopSection.js b/apps/mobile/src/components/Container/ContainerTopSection.js
index 816aaaabe..1f15d5bc1 100644
--- a/apps/mobile/src/components/Container/ContainerTopSection.js
+++ b/apps/mobile/src/components/Container/ContainerTopSection.js
@@ -8,12 +8,18 @@ export const ContainerTopSection = ({root}) => {
const [state, dispatch] = useTracked();
const {colors, selectionMode} = state;
const opacity = useValue(0);
+ const translateY = useValue(0);
useEffect(() => {
Animated.timing(opacity, {
duration: 100,
toValue: selectionMode ? 0 : 1,
easing: Easing.in(Easing.ease),
}).start();
+ Animated.timing(translateY, {
+ toValue: selectionMode ? -150 : 0,
+ duration: 100,
+ easing: Easing.in(Easing.ease),
+ }).start();
}, [selectionMode]);
return (
@@ -25,6 +31,12 @@ export const ContainerTopSection = ({root}) => {
display: 'flex',
width: '100%',
opacity: opacity,
+ overflow: 'hidden',
+ transform: [
+ {
+ translateY: translateY,
+ },
+ ],
}}>
<Header root={root} />
diff --git a/apps/mobile/src/components/Container/index.js b/apps/mobile/src/components/Container/index.js
index b4773665e..a0f613ca2 100644
--- a/apps/mobile/src/components/Container/index.js
+++ b/apps/mobile/src/components/Container/index.js
@@ -1,12 +1,10 @@
import React from 'react';
import {KeyboardAvoidingView, Platform, SafeAreaView} from 'react-native';
-import { useSafeAreaInsets} from 'react-native-safe-area-context';
+import {initialWindowMetrics} from 'react-native-safe-area-context';
import SelectionHeader from '../SelectionHeader';
import {ContainerTopSection} from './ContainerTopSection';
-export const Container = ({children,root}) => {
- const insets = useSafeAreaInsets();
-
+export const Container = ({children, root}) => {
return (
<KeyboardAvoidingView
behavior="padding"
@@ -14,7 +12,7 @@ export const Container = ({children,root}) => {
<SafeAreaView
style={{
height: '100%',
- paddingTop: insets.top,
+ paddingTop: initialWindowMetrics.insets.top,
}}>
<SelectionHeader />
<ContainerTopSection root={root} />
diff --git a/apps/mobile/src/components/SimpleList/index.js b/apps/mobile/src/components/SimpleList/index.js
index 0986eb340..dc353fcd6 100644
--- a/apps/mobile/src/components/SimpleList/index.js
+++ b/apps/mobile/src/components/SimpleList/index.js
@@ -1,7 +1,7 @@
-import React, {useEffect, useMemo, useState} from 'react';
+import React, {useCallback, useEffect, useMemo, useState} from 'react';
import {StyleSheet} from 'react-native';
import {Dimensions, Platform, RefreshControl, Text, View} from 'react-native';
-import {useSafeAreaInsets} from 'react-native-safe-area-context';
+import {initialWindowMetrics} from 'react-native-safe-area-context';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import {DataProvider, LayoutProvider, RecyclerListView} from 'recyclerlistview';
import {COLORS_NOTE, SIZE, WEIGHT} from '../../common/common';
@@ -40,7 +40,6 @@ const SimpleList = ({
return r1 !== r2;
}).cloneWithRows([]),
);
- const insets = useSafeAreaInsets();
const listData = data;
const dataType = type;
const _onScroll = (event) => {
@@ -50,16 +49,21 @@ const SimpleList = ({
};
useEffect(() => {
- console.log(focused());
+ loadData();
+ }, [listData]);
+
+ const loadData = useCallback(() => {
let mainData =
- searchResults.type === type && focused() && searchResults.results.length > 0
+ searchResults.type === type &&
+ focused() &&
+ searchResults.results.length > 0
? searchResults.results
: listData;
let d = [header, ...mainData];
/* for (var i = 0; i < 10000; i++) {
- d = [...d,...data];
- } */
+ d = [...d,...data];
+ } */
setDataProvider(
new DataProvider((r1, r2) => {
return r1 !== r2;
@@ -79,7 +83,7 @@ const SimpleList = ({
</Text>
);
- const _onRefresh = async () => {
+ const _onRefresh = useCallback(async () => {
if (Platform.OS === 'ios') {
dispatch({
type: ACTIONS.SYNCING,
@@ -118,7 +122,7 @@ const SimpleList = ({
}
dispatch({type: ACTIONS.ALL});
}
- };
+ }, []);
const _ListEmptyComponent = (
<View
@@ -156,7 +160,7 @@ const SimpleList = ({
break;
case 'header':
dim.width = width;
- dim.height = 25;
+ dim.height = 30;
break;
case 'MAIN_HEADER':
dim.width = width;
@@ -195,10 +199,10 @@ const SimpleList = ({
? 115
: 115 - 60
: listData[0] && !selectionMode
- ? 155 - insets.top
- : 155 - insets.top - 60,
+ ? 155 - initialWindowMetrics.insets.top
+ : 155 - initialWindowMetrics.insets.top - 60,
};
- }, []);
+ }, [selectionMode, listData]);
return !listData || listData.length === 0 ? (
_ListEmptyComponent