diff --git a/apps/mobile/src/modules/discover/search.tsx b/apps/mobile/src/modules/discover/search.tsx index 93288076c..1e3796519 100644 --- a/apps/mobile/src/modules/discover/search.tsx +++ b/apps/mobile/src/modules/discover/search.tsx @@ -4,33 +4,29 @@ import { router } from "expo-router" import { useAtom, useAtomValue, useSetAtom } from "jotai" import type { FC } from "react" import { useContext, useEffect, useRef, useState } from "react" -import type { LayoutChangeEvent } from "react-native" -import { - Animated, +import type { Animated as RnAnimated, LayoutChangeEvent } from "react-native" +import { Pressable, StyleSheet, Text, TextInput, TouchableOpacity, View } from "react-native" +import Animated, { Easing, - Pressable, - StyleSheet, - Text, - TextInput, - TouchableOpacity, - useAnimatedValue, - View, -} from "react-native" + useAnimatedStyle, + useSharedValue, + withTiming, +} from "react-native-reanimated" import { useSafeAreaFrame, useSafeAreaInsets } from "react-native-safe-area-context" import { BlurEffect } from "@/src/components/common/BlurEffect" import { TabBar } from "@/src/components/ui/tabview/TabBar" import { Search2CuteReIcon } from "@/src/icons/search_2_cute_re" -import { Search3CuteReIcon } from "@/src/icons/search_3_cute_re" import { accentColor, useColor } from "@/src/theme/colors" +import { AddFeedButton } from "../screen/action" import { RSSHubCategoryCopyMap } from "./copy" import { useSearchPageContext } from "./ctx" import { DiscoverContext } from "./DiscoverContext" import { SearchTabBar } from "./SearchTabBar" export const SearchHeader: FC<{ - animatedX: Animated.Value + animatedX: RnAnimated.Value onLayout: (e: LayoutChangeEvent) => void }> = ({ animatedX, onLayout }) => { const frame = useSafeAreaFrame() @@ -72,8 +68,13 @@ const DiscoverHeaderImpl = () => { }} > - + + + {/* Right actions group */} + + + { className="absolute inset-0 flex flex-row items-center justify-center" pointerEvents="none" > - + Search @@ -146,9 +147,9 @@ const SearchInput = () => { const setSearchValue = useSetAtom(searchValueAtom) const inputRef = useRef(null) - const skeletonOpacityValue = useAnimatedValue(0) - const skeletonTranslateXValue = useAnimatedValue(0) - const placeholderOpacityValue = useAnimatedValue(1) + const skeletonOpacity = useSharedValue(0) + const skeletonTranslateX = useSharedValue(0) + const placeholderOpacity = useSharedValue(1) const [tempSearchValue, setTempSearchValue] = useState(searchValue) @@ -156,48 +157,46 @@ const SearchInput = () => { useEffect(() => { if (focusOrHasValue) { - Animated.timing(skeletonOpacityValue, { - toValue: 0, - duration: 100, - easing: Easing.ease, - useNativeDriver: true, - }).start() - Animated.timing(skeletonTranslateXValue, { - toValue: -150, + skeletonOpacity.value = withTiming(0, { duration: 100, easing: Easing.ease }) + skeletonTranslateX.value = withTiming(-150, { duration: 100, easing: Easing.inOut(Easing.ease), - useNativeDriver: true, - }).start() - - Animated.timing(placeholderOpacityValue, { - toValue: 1, - duration: 200, - easing: Easing.ease, - useNativeDriver: true, - }).start() + }) + placeholderOpacity.value = withTiming(1, { duration: 200, easing: Easing.ease }) } else { - Animated.timing(skeletonOpacityValue, { - toValue: 1, - duration: 100, - easing: Easing.ease, - useNativeDriver: true, - }).start() - - Animated.timing(skeletonTranslateXValue, { - toValue: 0, + skeletonOpacity.value = withTiming(1, { duration: 100, easing: Easing.ease }) + skeletonTranslateX.value = withTiming(0, { duration: 100, easing: Easing.inOut(Easing.ease), - useNativeDriver: true, - }).start() - - Animated.timing(placeholderOpacityValue, { - toValue: 0, - duration: 200, - easing: Easing.ease, - useNativeDriver: true, - }).start() + }) + placeholderOpacity.value = withTiming(0, { duration: 200, easing: Easing.ease }) } - }, [focusOrHasValue, skeletonOpacityValue, placeholderOpacityValue, skeletonTranslateXValue]) + }, [focusOrHasValue, placeholderOpacity, skeletonOpacity, skeletonTranslateX]) + + const skeletonAnimatedStyle = useAnimatedStyle(() => ({ + opacity: skeletonOpacity.value, + position: "absolute", + top: 0, + bottom: 0, + left: 0, + right: 0, + flexDirection: "row", + alignItems: "center", + justifyContent: "center", + transform: [{ translateX: skeletonTranslateX.value }], + })) + + const placeholderAnimatedStyle = useAnimatedStyle(() => ({ + opacity: placeholderOpacity.value, + + position: "absolute", + top: 0, + bottom: 0, + left: 12, + flexDirection: "row", + alignItems: "center", + justifyContent: "center", + })) useEffect(() => { if (!isFocused) { @@ -210,12 +209,7 @@ const SearchInput = () => { return ( {focusOrHasValue && ( - + {!searchValue && !tempSearchValue && ( @@ -244,14 +238,7 @@ const SearchInput = () => { }} /> - + Search @@ -271,6 +258,10 @@ const styles = StyleSheet.create({ position: "relative", }, + discoverHeader: { + marginRight: 0, + }, + searchbar: { flex: 1, display: "flex", diff --git a/apps/mobile/src/modules/screen/TimelineSelectorProvider.tsx b/apps/mobile/src/modules/screen/TimelineSelectorProvider.tsx index 63755e379..01b44df5c 100644 --- a/apps/mobile/src/modules/screen/TimelineSelectorProvider.tsx +++ b/apps/mobile/src/modules/screen/TimelineSelectorProvider.tsx @@ -14,7 +14,7 @@ import { getWebUrl } from "@/src/lib/env" import { HideNoMediaActionButton, HomeLeftAction, - HomeRightAction, + HomeSharedRightAction, } from "@/src/modules/screen/action" import { headerHideableBottomHeight } from "@/src/modules/screen/hooks/useHeaderHeight" import { TimelineViewSelector } from "@/src/modules/screen/TimelineViewSelector" @@ -43,9 +43,9 @@ export function TimelineSelectorProvider({ children }: { children: React.ReactNo headerRight={useMemo(() => { if (isTimeline) return () => ( - + {view === FeedViewType.Pictures && } - + ) if (isFeed) return () => ( diff --git a/apps/mobile/src/modules/screen/action.tsx b/apps/mobile/src/modules/screen/action.tsx index cad6e0473..ae5524fa0 100644 --- a/apps/mobile/src/modules/screen/action.tsx +++ b/apps/mobile/src/modules/screen/action.tsx @@ -33,7 +33,7 @@ export function HomeLeftAction() { ) } -export function HomeRightAction(props: PropsWithChildren) { +export function HomeSharedRightAction(props: PropsWithChildren) { const insets = useActionPadding() return ( @@ -42,7 +42,6 @@ export function HomeRightAction(props: PropsWithChildren) { style={{ paddingRight: insets.paddingRight }} > {props.children} - ) } @@ -69,7 +68,7 @@ export function HideNoMediaActionButton({ /> ) } -const AddFeedButton = () => { +export const AddFeedButton = () => { const [isOpen, setIsOpen] = useState(false) const label = useColor("label") const handleClose = () => setIsOpen(false)