Skip to content

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

mobile: Fix crash when leaving note after search (#2289)

Ammar Ahmedcd2ca94c3de4
diff --git a/apps/mobile/app/hooks/use-actions.js b/apps/mobile/app/hooks/use-actions.js
index 30f9d4801..aeec775ea 100644
--- a/apps/mobile/app/hooks/use-actions.js
+++ b/apps/mobile/app/hooks/use-actions.js
@@ -623,7 +623,7 @@ export const useActions = ({ close = () => null, item }) => {
id: "pin-to-notifications",
title:
notifPinned !== null
- ? "Unpin from Notifications"
+ ? "Unpin from notifications"
: "Pin to notifications",
icon: "message-badge-outline",
on: notifPinned !== null,
diff --git a/apps/mobile/app/screens/settings/home.tsx b/apps/mobile/app/screens/settings/home.tsx
index 2e8f32f4c..55f0c8e19 100644
--- a/apps/mobile/app/screens/settings/home.tsx
+++ b/apps/mobile/app/screens/settings/home.tsx
@@ -20,7 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import { NativeStackScreenProps } from "@react-navigation/native-stack";
import React, { useEffect, useState } from "react";
import { View } from "react-native";
-import Animated, { FadeInDown, FadeOutDown } from "react-native-reanimated";
+import Animated, { FadeInDown } from "react-native-reanimated";
import DelayLayout from "../../components/delay-layout";
import BaseDialog from "../../components/dialog/base-dialog";
import { ProgressBarComponent } from "../../components/ui/svg/lazy";
@@ -75,57 +75,55 @@ const Home = ({
return (
<DelayLayout delay={300} type="settings">
- <View>
- {loading && (
- //@ts-ignore // Migrate to typescript required.
- <BaseDialog animated={false} bounce={false} visible={true}>
+ {loading && (
+ //@ts-ignore // Migrate to typescript required.
+ <BaseDialog animated={false} bounce={false} visible={true}>
+ <View
+ style={{
+ width: "100%",
+ height: "100%",
+ backgroundColor: colors.bg,
+ justifyContent: "center",
+ alignItems: "center"
+ }}
+ >
+ <Heading color={colors.pri} size={SIZE.lg}>
+ Logging out
+ </Heading>
+ <Paragraph color={colors.icon}>
+ Please wait while we log out and clear app data.
+ </Paragraph>
<View
style={{
- width: "100%",
- height: "100%",
- backgroundColor: colors.bg,
- justifyContent: "center",
- alignItems: "center"
+ flexDirection: "row",
+ width: 100,
+ marginTop: 15
}}
>
- <Heading color={colors.pri} size={SIZE.lg}>
- Logging out
- </Heading>
- <Paragraph color={colors.icon}>
- Please wait while we log out and clear app data.
- </Paragraph>
- <View
- style={{
- flexDirection: "row",
- width: 100,
- marginTop: 15
- }}
- >
- <ProgressBarComponent
- height={5}
- width={100}
- animated={true}
- useNativeDriver
- indeterminate
- indeterminateAnimationDuration={2000}
- unfilledColor={colors.nav}
- color={colors.accent}
- borderWidth={0}
- />
- </View>
+ <ProgressBarComponent
+ height={5}
+ width={100}
+ animated={true}
+ useNativeDriver
+ indeterminate
+ indeterminateAnimationDuration={2000}
+ unfilledColor={colors.nav}
+ color={colors.accent}
+ borderWidth={0}
+ />
</View>
- </BaseDialog>
- )}
+ </View>
+ </BaseDialog>
+ )}
- <Animated.FlatList
- entering={FadeInDown}
- exiting={FadeOutDown}
- data={settingsGroups}
- keyExtractor={keyExtractor}
- ListFooterComponent={<View style={{ height: 200 }} />}
- renderItem={renderItem}
- />
- </View>
+ <Animated.FlatList
+ entering={FadeInDown}
+ data={settingsGroups}
+ windowSize={1}
+ keyExtractor={keyExtractor}
+ ListFooterComponent={<View style={{ height: 200 }} />}
+ renderItem={renderItem}
+ />
</DelayLayout>
);
};
diff --git a/apps/mobile/app/screens/settings/section-group.tsx b/apps/mobile/app/screens/settings/section-group.tsx
index dcbae2bf9..606e3d01b 100644
--- a/apps/mobile/app/screens/settings/section-group.tsx
+++ b/apps/mobile/app/screens/settings/section-group.tsx
@@ -42,12 +42,12 @@ export const SectionGroup = ({ item }: { item: SettingSection }) => {
color={colors.accent}
size={SIZE.xs}
>
- {item.name.toUpperCase()}
+ {(item.name as string).toUpperCase()}
</Heading>
) : null}
{item.sections?.map((item) => (
- <SectionItem key={item.name} item={item} />
+ <SectionItem key={item.name as string} item={item} />
))}
</View>
);
diff --git a/apps/mobile/app/screens/settings/trash-interval-selector.jsx b/apps/mobile/app/screens/settings/trash-interval-selector.jsx
index 383f9fcbe..6ab611707 100644
--- a/apps/mobile/app/screens/settings/trash-interval-selector.jsx
+++ b/apps/mobile/app/screens/settings/trash-interval-selector.jsx
@@ -87,7 +87,7 @@ export const TrashIntervalSelector = () => {
>
{[-1, 7, 30, 365].map((item) => (
<MenuItem
- key={item.name}
+ key={item.toString()}
onPress={async () => {
if (item === -1) {
await PremiumService.verify(() => {
diff --git a/apps/mobile/app/services/navigation.ts b/apps/mobile/app/services/navigation.ts
index b118f3490..f5821996a 100755
--- a/apps/mobile/app/services/navigation.ts
+++ b/apps/mobile/app/services/navigation.ts
@@ -35,6 +35,7 @@ import { eOnNewTopicAdded } from "../utils/events";
import { rootNavigatorRef, tabBarRef } from "../utils/global-refs";
import { eSendEvent } from "./event-manager";
import SettingsService from "./settings";
+import SearchService from "./search";
/**
* Routes that should be updated on focus
@@ -86,7 +87,8 @@ const routeUpdateFunctions: {
ColoredNotes: (params) => eSendEvent("ColoredNotes", params),
TopicNotes: (params) => eSendEvent("TopicNotes", params),
Monographs: (params) => eSendEvent("Monographs", params),
- Reminders: () => useReminderStore.getState().setReminders()
+ Reminders: () => useReminderStore.getState().setReminders(),
+ Search: () => SearchService.updateAndSearch()
};
function clearRouteFromQueue(routeName: RouteName) {
@@ -113,7 +115,7 @@ function queueRoutesForUpdate(...routesToUpdate: RouteName[]) {
: (Object.keys(routeNames) as (keyof RouteParams)[]);
const currentScreen = useNavigationStore.getState().currentScreen;
if (routes.indexOf(currentScreen.name) > -1) {
- routeUpdateFunctions[currentScreen.name]();
+ routeUpdateFunctions[currentScreen.name]?.();
clearRouteFromQueue(currentScreen.name);
// Remove focused screen from queue
routes.splice(routes.indexOf(currentScreen.name), 1);
@@ -129,7 +131,7 @@ function navigate<T extends RouteName>(
useNavigationStore.getState().update(screen, !!params?.canGoBack);
if (screen.name === "Notebook") routeUpdateFunctions["Notebook"](params);
if (screen.name.endsWith("Notes") && screen.name !== "Notes")
- routeUpdateFunctions[screen.name](params);
+ routeUpdateFunctions[screen.name]?.(params);
//@ts-ignore Not sure how to fix this for now ignore it.
rootNavigatorRef.current?.navigate<RouteName>(screen.name, params);
}
diff --git a/apps/mobile/app/services/search.js b/apps/mobile/app/services/search.js
index 6b5f827bb..44c7acc5e 100644
--- a/apps/mobile/app/services/search.js
+++ b/apps/mobile/app/services/search.js
@@ -26,7 +26,7 @@ let searchInformation = {
placeholder: "Search in all notes",
data: [],
type: "notes",
- get: () => null
+ get: () => []
};
let keyword = null;
diff --git a/apps/mobile/e2e/tests/note.e2e.js b/apps/mobile/e2e/tests/note.e2e.js
index 13d9ea1d2..9de2385e7 100644
--- a/apps/mobile/e2e/tests/note.e2e.js
+++ b/apps/mobile/e2e/tests/note.e2e.js
@@ -55,12 +55,13 @@ describe("NOTE TESTS", () => {
await prepare();
let note = await createNote();
await tapById(notesnook.listitem.menu);
- await tapById("icon-Favorite");
+ await tapById("icon-favorite");
await visibleById("icon-star");
await navigate("Favorites");
await visibleByText(note.body);
+ await sleep(500);
await tapById(notesnook.listitem.menu);
- await tapById("icon-Favorite");
+ await tapById("icon-favorite");
await expect(element(by.text(note.body))).not.toBeVisible();
await navigate("Notes");
});
@@ -69,11 +70,11 @@ describe("NOTE TESTS", () => {
await prepare();
await createNote();
await tapById(notesnook.listitem.menu);
- await tapById("icon-Pin");
+ await tapById("icon-pin");
await visibleByText("Pinned");
await visibleById("icon-pinned");
await tapById(notesnook.listitem.menu);
- await tapById("icon-Pin");
+ await tapById("icon-pin");
expect(element(by.id("icon-pinned"))).not.toBeVisible();
});
@@ -81,11 +82,12 @@ describe("NOTE TESTS", () => {
await prepare();
await createNote();
await tapById(notesnook.listitem.menu);
- await tapById("icon-PinToNotif");
- await visibleByText("Unpin from Notifications");
+ await tapById("icon-pin-to-notifications");
+ await visibleByText("Unpin from notifications");
+ await sleep(500);
+ await tapById("icon-pin-to-notifications");
await sleep(500);
- await tapById("icon-PinToNotif");
- await visibleByText("Pin to Notifications");
+ await visibleByText("Pin to notifications");
});
// it("Copy note", async () => {
@@ -100,7 +102,7 @@ describe("NOTE TESTS", () => {
await prepare();
await createNote();
await tapById(notesnook.listitem.menu);
- await tapById("icon-Export");
+ await tapById("icon-export");
await visibleByText("PDF");
});
@@ -122,7 +124,7 @@ describe("NOTE TESTS", () => {
await prepare();
await createNote();
await tapById(notesnook.listitem.menu);
- await tapById("icon-Delete");
+ await tapById("icon-delete");
await navigate("Trash");
await tapById(notesnook.listitem.menu);
await tapByText("Restore note");
diff --git a/apps/mobile/e2e/tests/search.e2e.js b/apps/mobile/e2e/tests/search.e2e.js
index 66224b0d3..013a7571c 100644
--- a/apps/mobile/e2e/tests/search.e2e.js
+++ b/apps/mobile/e2e/tests/search.e2e.js
@@ -17,13 +17,15 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+import { notesnook } from "../test.ids";
import {
tapById,
visibleByText,
createNote,
prepare,
elementById,
- sleep
+ sleep,
+ tapByText
} from "./utils";
describe("Search", () => {
@@ -34,6 +36,10 @@ describe("Search", () => {
await sleep(300);
await elementById("search-input").typeText("n");
await sleep(1000);
+ await tapByText(note.body);
+ await sleep(1000);
+ await device.pressBack();
+ await device.pressBack();
await visibleByText(note.body);
});
});