From ea1c666bcd0af51c2a27274a9f1237b94c3ed056 Mon Sep 17 00:00:00 2001 From: Innei Date: Mon, 24 Feb 2025 22:26:56 +0800 Subject: [PATCH] feat(mobile): enhance dialog system and UI interactions - Add new dialog library for flexible modal interactions - Implement AddFeedDialog with improved UX - Update Tabbar and Pressable components with smoother animations - Remove RootSiblingParent from main component - Upgrade react-native-uikit-colors to v0.3.8 - Introduce ScaleFadeRotateIn animation for consistent UI transitions Signed-off-by: Innei --- apps/mobile/package.json | 2 +- .../ui/datetime/RelativeDateTime.tsx | 2 +- .../components/ui/pressable/ItemPressable.tsx | 8 +- .../src/components/ui/tabbar/Tabbar.tsx | 14 +- .../ux/animations/ScaleFadeRotate.tsx | 40 ++++++ apps/mobile/src/lib/dialog.tsx | 126 ++++++++++++++++++ apps/mobile/src/main.tsx | 11 +- .../src/modules/dialogs/AddFeedDialog.tsx | 67 ++++++++++ apps/mobile/src/modules/screen/action.tsx | 116 ++++------------ apps/mobile/src/providers/index.tsx | 5 +- pnpm-lock.yaml | 26 +++- 11 files changed, 293 insertions(+), 124 deletions(-) create mode 100644 apps/mobile/src/components/ux/animations/ScaleFadeRotate.tsx create mode 100644 apps/mobile/src/lib/dialog.tsx create mode 100644 apps/mobile/src/modules/dialogs/AddFeedDialog.tsx diff --git a/apps/mobile/package.json b/apps/mobile/package.json index f0578b60a..acf7fe619 100644 --- a/apps/mobile/package.json +++ b/apps/mobile/package.json @@ -91,7 +91,7 @@ "react-native-sheet-transitions": "0.1.2", "react-native-svg": "15.11.1", "react-native-track-player": "4.1.1", - "react-native-uikit-colors": "0.2.0", + "react-native-uikit-colors": "0.3.8", "react-native-volume-manager": "2.0.8", "react-native-web": "0.19.13", "react-native-webview": "13.13.2", diff --git a/apps/mobile/src/components/ui/datetime/RelativeDateTime.tsx b/apps/mobile/src/components/ui/datetime/RelativeDateTime.tsx index 6fb66ffc1..70e49ce06 100644 --- a/apps/mobile/src/components/ui/datetime/RelativeDateTime.tsx +++ b/apps/mobile/src/components/ui/datetime/RelativeDateTime.tsx @@ -49,7 +49,7 @@ export const RelativeDateTime = ({ date, displayAbsoluteTimeAfterDay, dateFormatTemplate, - postfixText, + postfixText = "ago", ...props }: RelativeDateTimeProps) => { const [relative, setRelative] = useState(() => diff --git a/apps/mobile/src/components/ui/pressable/ItemPressable.tsx b/apps/mobile/src/components/ui/pressable/ItemPressable.tsx index 96e22e3f2..4aab7edf6 100644 --- a/apps/mobile/src/components/ui/pressable/ItemPressable.tsx +++ b/apps/mobile/src/components/ui/pressable/ItemPressable.tsx @@ -5,11 +5,14 @@ import { Fragment, memo, useEffect, useState } from "react" import type { PressableProps } from "react-native" import { StyleSheet } from "react-native" import Animated, { + cancelAnimation, interpolateColor, useAnimatedStyle, useSharedValue, + withSpring, } from "react-native-reanimated" +import { gentleSpringPreset } from "@/src/constants/spring" import { useColor } from "@/src/theme/colors" import { ReAnimatedPressable } from "../../common/AnimatedComponents" @@ -33,10 +36,11 @@ export const ItemPressable: FC = memo( const pressed = useSharedValue(0) useEffect(() => { + cancelAnimation(pressed) if (isPressing) { - pressed.value = 1 + pressed.value = withSpring(1, { duration: 0.2 }) } else { - pressed.value = 0 + pressed.value = withSpring(0, gentleSpringPreset) } }, [isPressing, pressed]) diff --git a/apps/mobile/src/components/ui/tabbar/Tabbar.tsx b/apps/mobile/src/components/ui/tabbar/Tabbar.tsx index 14cd69a4e..3883dc1ec 100644 --- a/apps/mobile/src/components/ui/tabbar/Tabbar.tsx +++ b/apps/mobile/src/components/ui/tabbar/Tabbar.tsx @@ -6,8 +6,6 @@ import { useContext, useEffect } from "react" import type { StyleProp, TextStyle } from "react-native" import { Platform, Pressable, StyleSheet, View } from "react-native" import Animated, { - FadeIn, - FadeOut, interpolateColor, useAnimatedStyle, useSharedValue, @@ -21,6 +19,7 @@ import { PlayerTabBar } from "@/src/modules/player/PlayerTabBar" import { accentColor, useColor } from "@/src/theme/colors" import { ThemedBlurView } from "../../common/ThemedBlurView" +import { ScaleFadeRotateIn } from "../../ux/animations/ScaleFadeRotate" import { Grid } from "../grid" import { BottomTabBarBackgroundContext } from "./contexts/BottomTabBarBackgroundContext" import { BottomTabBarVisibleContext } from "./contexts/BottomTabBarVisibleContext" @@ -148,11 +147,6 @@ export const Tabbar: FC = (props) => { ) } -const tabIconIconAnimations = { - in: FadeIn.springify(), - out: FadeOut.springify(), -} - const TextLabel = (props: { focused: boolean accessibilityLabel: string | undefined @@ -198,8 +192,7 @@ const TabIcon = ({ {focused && ( {renderIcon({ @@ -211,8 +204,7 @@ const TabIcon = ({ )} {!focused && ( {renderIcon({ diff --git a/apps/mobile/src/components/ux/animations/ScaleFadeRotate.tsx b/apps/mobile/src/components/ux/animations/ScaleFadeRotate.tsx new file mode 100644 index 000000000..2190111d6 --- /dev/null +++ b/apps/mobile/src/components/ux/animations/ScaleFadeRotate.tsx @@ -0,0 +1,40 @@ +import type { + BaseAnimationBuilder, + EntryExitAnimationFunction, + IEntryExitAnimationBuilder, +} from "react-native-reanimated" +import { ComplexAnimationBuilder, withSpring } from "react-native-reanimated" + +export class ScaleFadeRotateIn + extends ComplexAnimationBuilder + implements IEntryExitAnimationBuilder +{ + static presetName = "ScaleFadeRotateIn" + static override createInstance(this: T): InstanceType { + return new ScaleFadeRotateIn() as InstanceType + } + + override type = withSpring + + override build = (): EntryExitAnimationFunction => { + const [animation, config] = this.getAnimationAndConfig() + const callback = this.callbackV + const { initialValues } = this + + return () => { + "worklet" + return { + animations: { + opacity: animation(1, config), + transform: [{ scale: animation(1, config) }, { rotate: animation(0, config) }], + }, + initialValues: { + opacity: 0.8, + transform: [{ scale: 0.92 }, { rotate: 0.2 }], + ...initialValues, + }, + callback, + } as any + } + } +} diff --git a/apps/mobile/src/lib/dialog.tsx b/apps/mobile/src/lib/dialog.tsx new file mode 100644 index 000000000..118b9c49a --- /dev/null +++ b/apps/mobile/src/lib/dialog.tsx @@ -0,0 +1,126 @@ +import type { FC, ReactNode } from "react" +import { createContext, createElement, useContext } from "react" +import { Text, TouchableOpacity, View } from "react-native" +import Animated, { SlideInUp, SlideOutUp } from "react-native-reanimated" +import RootSiblings from "react-native-root-siblings" +import { useSafeAreaInsets } from "react-native-safe-area-context" +import { getColor } from "react-native-uikit-colors" + +import { FullWindowOverlay } from "../components/common/FullWindowOverlay" +import { Overlay } from "../components/ui/overlay/Overlay" +import { accentColor } from "../theme/colors" + +export interface DialogProps { + title?: string + content: ReactNode + variant?: "destructive" | "default" + onClose?: (ctx: Ctx & DialogContextType) => void + onConfirm?: (ctx: Ctx & DialogContextType) => void + cancelText?: string + confirmText?: string + + id: string +} + +const entering = SlideInUp.springify().damping(15).stiffness(100) +const exiting = SlideOutUp.duration(200) + +type DialogContextType = { + dismiss: () => void +} +const DialogContext = createContext(null) +export type DialogComponent = FC & + Omit, "content"> +class DialogStatic { + useDialogContext = () => { + return useContext(DialogContext) + } + + private currentStackedDialogs = new Set() + show(propsOrComponent: DialogProps | DialogComponent) { + const isExist = this.currentStackedDialogs.has(propsOrComponent.id) + if (isExist) { + return + } + const props = + "content" in propsOrComponent + ? propsOrComponent + : (propsOrComponent as unknown as DialogProps) + + const dismiss = () => this.destroy(props.id, siblings) + + const reactCtx = { dismiss } + + const mergeCtx = (ctx: Ctx) => ({ ...ctx, ...reactCtx }) + + const ctx = {} as Ctx + const children = + "content" in propsOrComponent + ? propsOrComponent.content + : createElement(propsOrComponent, { + dismiss, + ctx, + }) + + const handleClose = () => { + dismiss() + setTimeout(() => { + props.onClose?.(mergeCtx(ctx)) + }, 16) + } + const siblings = new RootSiblings( + ( + + + + + {children} + + + + + {props.cancelText ?? "Cancel"} + + + + { + props.onConfirm?.(mergeCtx(ctx)) + }} + > + + {props.confirmText ?? "Confirm"} + + + + + + ), + ) + + this.currentStackedDialogs.add(props.id) + return siblings + } + + destroy(id: string, siblings: RootSiblings) { + this.currentStackedDialogs.delete(id) + siblings.destroy() + } +} + +const SafeInsetTop = () => { + const insets = useSafeAreaInsets() + return +} +export const Dialog = new DialogStatic() diff --git a/apps/mobile/src/main.tsx b/apps/mobile/src/main.tsx index ab340ca67..cd68eb2e0 100644 --- a/apps/mobile/src/main.tsx +++ b/apps/mobile/src/main.tsx @@ -4,7 +4,6 @@ import { registerRootComponent } from "expo" import { Image } from "expo-image" import { App } from "expo-router/build/qualified-entry" import { cssInterop } from "nativewind" -import { RootSiblingParent } from "react-native-root-siblings" import { enableFreeze } from "react-native-screens" import { initializeApp } from "./initialize" @@ -14,12 +13,4 @@ cssInterop(Image, { className: "style" }) initializeApp() -const MApp = () => { - return ( - - - - ) -} - -registerRootComponent(MApp) +registerRootComponent(App) diff --git a/apps/mobile/src/modules/dialogs/AddFeedDialog.tsx b/apps/mobile/src/modules/dialogs/AddFeedDialog.tsx new file mode 100644 index 000000000..8837b0e43 --- /dev/null +++ b/apps/mobile/src/modules/dialogs/AddFeedDialog.tsx @@ -0,0 +1,67 @@ +import { router } from "expo-router" +import { Text, TextInput, View } from "react-native" +import { useColor } from "react-native-uikit-colors" + +import { LinkCuteReIcon } from "@/src/icons/link_cute_re" +import type { DialogComponent } from "@/src/lib/dialog" +import { accentColor } from "@/src/theme/colors" + +export const AddFeedDialog: DialogComponent<{ + url: string +}> = ({ dismiss, ctx }) => { + const label = useColor("label") + + const handleAdd = () => { + dismiss() + const value = ctx.url + if (!value) return + router.push({ + pathname: "/follow", + params: { + url: value, + type: "url", + }, + }) + } + + return ( + + + + + Enter Feed URL or RSSHub URL + + (ctx.url = text)} + autoFocus + enterKeyHint="done" + cursorColor={accentColor} + selectionColor={accentColor} + onSubmitEditing={handleAdd} + className="bg-system-background dark:bg-secondary-system-fill/30 text-text my-3 rounded-xl" + placeholder="https:// or rsshub://" + /> + + + ) +} + +AddFeedDialog.confirmText = "Add" +AddFeedDialog.cancelText = "Cancel" + +AddFeedDialog.onConfirm = (ctx) => { + const value = ctx.url + if (!value) return + ctx.dismiss() + + setTimeout(() => { + router.push({ + pathname: "/follow", + params: { + url: value, + type: "url", + }, + }) + }, 16) +} +AddFeedDialog.id = "add-feed-dialog" diff --git a/apps/mobile/src/modules/screen/action.tsx b/apps/mobile/src/modules/screen/action.tsx index ae5524fa0..530a39617 100644 --- a/apps/mobile/src/modules/screen/action.tsx +++ b/apps/mobile/src/modules/screen/action.tsx @@ -1,48 +1,47 @@ -import { Portal } from "@gorhom/portal" -import { router } from "expo-router" +import { cn } from "@follow/utils" import type { PropsWithChildren } from "react" -import { useRef, useState } from "react" -import { SafeAreaView, Text, TextInput, TouchableOpacity, View } from "react-native" -import Animated, { SlideInUp, SlideOutUp } from "react-native-reanimated" -import { useSafeAreaInsets } from "react-native-safe-area-context" +import { TouchableOpacity, View } from "react-native" import { setUISetting, useUISettingKey } from "@/src/atoms/settings/ui" import { UserAvatar } from "@/src/components/ui/avatar/UserAvatar" import { UIBarButton } from "@/src/components/ui/button/UIBarButton" -import { Overlay } from "@/src/components/ui/overlay/Overlay" import { AddCuteReIcon } from "@/src/icons/add_cute_re" -import { LinkCuteReIcon } from "@/src/icons/link_cute_re" +import { CheckCircleCuteReIcon } from "@/src/icons/check_circle_cute_re" import { PhotoAlbumCuteFiIcon } from "@/src/icons/photo_album_cute_fi" import { PhotoAlbumCuteReIcon } from "@/src/icons/photo_album_cute_re" +import { Dialog } from "@/src/lib/dialog" import { useWhoami } from "@/src/store/user/hooks" import { accentColor, useColor } from "@/src/theme/colors" -const useActionPadding = () => { - const insets = useSafeAreaInsets() - return { paddingLeft: insets.left + 12, paddingRight: insets.right + 12 } +import { AddFeedDialog } from "../dialogs/AddFeedDialog" + +const ActionGroup = ({ children, className }: PropsWithChildren<{ className?: string }>) => { + return ( + {children} + ) } export function HomeLeftAction() { - const insets = useActionPadding() const user = useWhoami() if (!user) return null return ( - - - + + + + + ) } export function HomeSharedRightAction(props: PropsWithChildren) { - const insets = useActionPadding() - return ( - + {props.children} - + } + /> + ) } @@ -69,82 +68,15 @@ export function HideNoMediaActionButton({ ) } export const AddFeedButton = () => { - const [isOpen, setIsOpen] = useState(false) - const label = useColor("label") - const handleClose = () => setIsOpen(false) - - const valueRef = useRef("") - const handleAdd = () => { - handleClose() - - const value = valueRef.current - if (!value) return - router.push({ - pathname: "/follow", - params: { - url: value, - type: "url", - }, - }) - } return ( <> } - onPress={() => setIsOpen((s) => !s)} + onPress={() => { + Dialog.show(AddFeedDialog) + }} /> - - - {isOpen && ( - <> - - - - - - - - - Enter Feed URL or RSSHub URL - - - (valueRef.current = text)} - autoFocus - enterKeyHint="done" - cursorColor={accentColor} - selectionColor={accentColor} - onSubmitEditing={handleAdd} - className="bg-system-background dark:bg-secondary-system-fill/30 text-text my-3 rounded-xl" - placeholder="https:// or rsshub://" - /> - - - - - Cancel - - - - Add - - - - - - )} - ) } diff --git a/apps/mobile/src/providers/index.tsx b/apps/mobile/src/providers/index.tsx index a71385b85..23766f8ec 100644 --- a/apps/mobile/src/providers/index.tsx +++ b/apps/mobile/src/providers/index.tsx @@ -10,6 +10,7 @@ import type { ReactNode } from "react" import { StyleSheet, View } from "react-native" import { GestureHandlerRootView } from "react-native-gesture-handler" import { KeyboardProvider } from "react-native-keyboard-controller" +import { RootSiblingParent } from "react-native-root-siblings" import { SheetProvider } from "react-native-sheet-transitions" import { PreviewImageProvider } from "../components/ui/image/PreviewPageProvider" @@ -36,7 +37,9 @@ export const RootProviders = ({ children }: { children: ReactNode }) => { - {children} + + {children} + diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 82a0ab7f8..5b4e067b1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -651,8 +651,8 @@ importers: specifier: 4.1.1 version: 4.1.1(patch_hash=ul2ym56izpf2mkfucn2nug6afu)(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5))(react@18.3.1) react-native-uikit-colors: - specifier: 0.2.0 - version: 0.2.0(fe3lmks7adwcuf5fbpjna3wt2m) + specifier: 0.3.8 + version: 0.3.8(fe3lmks7adwcuf5fbpjna3wt2m) react-native-volume-manager: specifier: 2.0.8 version: 2.0.8(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5))(react@18.3.1) @@ -5956,6 +5956,9 @@ packages: os: [darwin] hasBin: true + apple-uikit-colors@0.3.8: + resolution: {integrity: sha512-jnQNUMu2c6e2U/aTTNsR7m5JkrJXrTNC8cJwYFZ2Mb/EPIIzjPeqIPGYTcgpxTATyBHokQILAImJK9v0+6DNIA==} + application-config-path@0.1.1: resolution: {integrity: sha512-zy9cHePtMP0YhwG+CfHm0bgwdnga2X3gZexpdCwEj//dpb+TKajtiC8REEUJUSq6Ab4f9cgNy2l8ObXzCXFkEw==} @@ -12559,12 +12562,12 @@ packages: shaka-player: optional: true - react-native-uikit-colors@0.2.0: - resolution: {integrity: sha512-YYJHejX3JgmfGceo058fC8iFVhXdZtWjjqcb9lfSYVjYX29DnkcHmdjUGNLAK6M5R0/IFv9v7N2V2drpRKRVvA==} + react-native-uikit-colors@0.3.8: + resolution: {integrity: sha512-0iK5DZv4hOewbm8C8BNN+FCADukhyCjFZbEuabhwkrtXdeTPMFW6BzKEEtdSZ7Q23KSErgVgIC3wOXKXQGijtQ==} peerDependencies: nativewind: '>=4.1.0' react: '>=18.0.0' - react-native: npm:react-native@0.77.0 + react-native: '>=0.76.0' tailwindcss: '>=3.0.0' react-native-volume-manager@2.0.8: @@ -13778,6 +13781,9 @@ packages: peerDependencies: tailwindcss: ^2.0.0 || >=3.0.0 + tailwindcss-uikit-colors@0.3.8: + resolution: {integrity: sha512-MdP9XK5AF48H1XoyOt1XiEmJ5MM/3QYVuvsSmSJin5a/PWYnlw7bLVijXSZveGIbq2TpFqGpuRI+svdxhHK53A==} + tailwindcss@3.4.16: resolution: {integrity: sha512-TI4Cyx7gDiZ6r44ewaJmt0o6BrMCT5aK5e0rmJ/G9Xq3w7CX/5VXl/zIPEJZFUK5VEqwByyhqNPycPlvcK4ZNw==} engines: {node: '>=14.0.0'} @@ -21303,6 +21309,8 @@ snapshots: repeat-string: 1.6.1 optional: true + apple-uikit-colors@0.3.8: {} + application-config-path@0.1.1: {} aproba@2.0.0: {} @@ -29381,12 +29389,14 @@ snapshots: react: 18.3.1 react-native: 0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5) - react-native-uikit-colors@0.2.0(fe3lmks7adwcuf5fbpjna3wt2m): + react-native-uikit-colors@0.3.8(fe3lmks7adwcuf5fbpjna3wt2m): dependencies: + apple-uikit-colors: 0.3.8 nativewind: 4.1.23(react-native-reanimated@3.16.7(@babel/core@7.26.9)(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5))(react@18.3.1))(react-native-safe-area-context@5.2.0(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5))(react@18.3.1))(react-native-svg@15.11.1(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5))(react@18.3.1))(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5))(react@18.3.1)(tailwindcss@3.4.16(ts-node@10.9.2(@types/node@22.13.4)(typescript@5.7.3))) react: 18.3.1 react-native: 0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5) tailwindcss: 3.4.16(ts-node@10.9.2(@types/node@22.13.4)(typescript@5.7.3)) + tailwindcss-uikit-colors: 0.3.8 react-native-volume-manager@2.0.8(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5))(react@18.3.1): dependencies: @@ -30840,6 +30850,10 @@ snapshots: dependencies: tailwindcss: 3.4.16(ts-node@10.9.2(@types/node@22.13.4)(typescript@5.7.3)) + tailwindcss-uikit-colors@0.3.8: + dependencies: + apple-uikit-colors: 0.3.8 + tailwindcss@3.4.16(ts-node@10.9.2(@types/node@22.13.4)(typescript@5.7.3)): dependencies: '@alloc/quick-lru': 5.2.0