Merge pull request #8866 from streetwriters/feat-add-clear-button-search

Feat add clear button search
This commit is contained in:
Ammar Ahmed
2025-10-31 18:38:16 +05:00
committed by GitHub
5 changed files with 29 additions and 2 deletions

View File

@@ -19,7 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import { strings } from "@notesnook/intl"; import { strings } from "@notesnook/intl";
import { useThemeColors } from "@notesnook/theme"; import { useThemeColors } from "@notesnook/theme";
import React, { useRef } from "react"; import React, { useRef, useState } from "react";
import { View } from "react-native"; import { View } from "react-native";
import { TextInput } from "react-native-gesture-handler"; import { TextInput } from "react-native-gesture-handler";
import { IconButton } from "../../components/ui/icon-button"; import { IconButton } from "../../components/ui/icon-button";
@@ -36,6 +36,7 @@ export const SearchBar = ({
onChangeText: (value: string) => void; onChangeText: (value: string) => void;
loading?: boolean; loading?: boolean;
}) => { }) => {
const [clearButton, setClearButton] = useState(false);
const selectionMode = useSelectionStore((state) => state.selectionMode); const selectionMode = useSelectionStore((state) => state.selectionMode);
const isFocused = useNavigationStore( const isFocused = useNavigationStore(
(state) => state.focusedRouteId === "Search" (state) => state.focusedRouteId === "Search"
@@ -45,6 +46,7 @@ export const SearchBar = ({
const inputRef = useRef<TextInput>(null); const inputRef = useRef<TextInput>(null);
const _onChangeText = (value: string) => { const _onChangeText = (value: string) => {
onChangeText(value); onChangeText(value);
setClearButton(!!value);
}; };
return selectionMode && isFocused ? null : ( return selectionMode && isFocused ? null : (
@@ -100,6 +102,23 @@ export const SearchBar = ({
autoCorrect={false} autoCorrect={false}
placeholderTextColor={colors.primary.placeholder} placeholderTextColor={colors.primary.placeholder}
/> />
{clearButton ? (
<IconButton
name="close"
size={AppFontSize.xxl}
top={10}
testID="clear-search"
bottom={10}
onPress={() => {
inputRef.current?.clear();
onChangeText("");
setClearButton(false);
}}
color={colors.primary.paragraph}
type="plain"
/>
) : null}
</View> </View>
</View> </View>
); );

View File

@@ -1,5 +1,5 @@
import { execSync } from "child_process"; import { execSync } from "child_process";
//@ts-ignore
import { pathExists, ensureDir } from "fs-extra"; import { pathExists, ensureDir } from "fs-extra";
import { resolveConfig } from "detox/internals"; import { resolveConfig } from "detox/internals";

View File

@@ -28,6 +28,9 @@ describe("Search", () => {
.typeTextById("search-input", "Test") .typeTextById("search-input", "Test")
.wait(1000) .wait(1000)
.isVisibleByText("1") .isVisibleByText("1")
.waitAndTapById("clear-search")
.wait(2000)
.isNotVisibleByText("1")
.run(); .run();
}); });
}); });

View File

@@ -20,6 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import { expect as jestExpect } from "@jest/globals"; import { expect as jestExpect } from "@jest/globals";
import { device as _device, expect } from "detox"; import { device as _device, expect } from "detox";
import { readFileSync } from "fs"; import { readFileSync } from "fs";
//@ts-ignore
import { toMatchImageSnapshot } from "jest-image-snapshot"; import { toMatchImageSnapshot } from "jest-image-snapshot";
import type { RouteName } from "../../app/stores/use-navigation-store"; import type { RouteName } from "../../app/stores/use-navigation-store";
import { notesnook } from "../test.ids"; import { notesnook } from "../test.ids";

View File

@@ -104,6 +104,10 @@
"run-ios", "run-ios",
"build-ios", "build-ios",
"build-android", "build-android",
"build-android-debug",
"e2e-android-debug",
"e2e-android",
"e2e-ios",
"release-android", "release-android",
"release-android-bundle", "release-android-bundle",
"release-ios", "release-ios",