feat(mobile): add add feed button to discover header

Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
Innei
2025-02-24 19:47:15 +08:00
parent 5e53dd4927
commit 1d62245f4b
3 changed files with 64 additions and 74 deletions
+59 -68
View File
@@ -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 = () => {
}}
>
<BlurEffect />
<View style={styles.header}>
<View style={[styles.header, styles.discoverHeader]}>
<PlaceholerSearchBar />
{/* Right actions group */}
<View className="ml-2">
<AddFeedButton />
</View>
</View>
<TabBar
@@ -104,7 +105,7 @@ const PlaceholerSearchBar = () => {
className="absolute inset-0 flex flex-row items-center justify-center"
pointerEvents="none"
>
<Search3CuteReIcon color={labelColor} height={18} width={18} />
<Search2CuteReIcon color={labelColor} height={18} width={18} />
<Text className="text-secondary-label ml-1" style={styles.searchPlaceholderText}>
Search
</Text>
@@ -146,9 +147,9 @@ const SearchInput = () => {
const setSearchValue = useSetAtom(searchValueAtom)
const inputRef = useRef<TextInput>(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 (
<View style={styles.searchbar} className="bg-tertiary-system-fill">
{focusOrHasValue && (
<Animated.View
style={{
opacity: placeholderOpacityValue,
}}
className="absolute inset-y-0 left-3 flex flex-row items-center justify-center"
>
<Animated.View style={placeholderAnimatedStyle}>
<Search2CuteReIcon color={placeholderTextColor} height={18} width={18} />
{!searchValue && !tempSearchValue && (
<Text className="text-secondary-label ml-2" style={styles.searchPlaceholderText}>
@@ -244,14 +238,7 @@ const SearchInput = () => {
}}
/>
<Animated.View
style={{
opacity: skeletonOpacityValue,
transform: [{ translateX: skeletonTranslateXValue }],
}}
className="absolute inset-0 flex flex-row items-center justify-center"
pointerEvents="none"
>
<Animated.View style={skeletonAnimatedStyle} pointerEvents="none">
<Search2CuteReIcon color={placeholderTextColor} height={18} width={18} />
<Text className="text-secondary-label ml-1" style={styles.searchPlaceholderText}>
Search
@@ -271,6 +258,10 @@ const styles = StyleSheet.create({
position: "relative",
},
discoverHeader: {
marginRight: 0,
},
searchbar: {
flex: 1,
display: "flex",
@@ -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 () => (
<HomeRightAction>
<HomeSharedRightAction>
{view === FeedViewType.Pictures && <HideNoMediaActionButton />}
</HomeRightAction>
</HomeSharedRightAction>
)
if (isFeed)
return () => (
+2 -3
View File
@@ -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}
<AddFeedButton />
</View>
)
}
@@ -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)