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 <tukon479@gmail.com>
This commit is contained in:
Innei
2025-02-24 22:27:14 +08:00
parent a350991de2
commit ea1c666bcd
11 changed files with 293 additions and 124 deletions
+1 -1
View File
@@ -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",
@@ -49,7 +49,7 @@ export const RelativeDateTime = ({
date,
displayAbsoluteTimeAfterDay,
dateFormatTemplate,
postfixText,
postfixText = "ago",
...props
}: RelativeDateTimeProps) => {
const [relative, setRelative] = useState<string>(() =>
@@ -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<ItemPressableProps> = 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])
@@ -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<BottomTabBarProps> = (props) => {
)
}
const tabIconIconAnimations = {
in: FadeIn.springify(),
out: FadeOut.springify(),
}
const TextLabel = (props: {
focused: boolean
accessibilityLabel: string | undefined
@@ -198,8 +192,7 @@ const TabIcon = ({
<View style={styles.wrapperUikit}>
{focused && (
<Animated.View
entering={tabIconIconAnimations.in}
exiting={tabIconIconAnimations.out}
entering={ScaleFadeRotateIn}
style={[styles.icon, { opacity: activeOpacity }]}
>
{renderIcon({
@@ -211,8 +204,7 @@ const TabIcon = ({
)}
{!focused && (
<Animated.View
entering={tabIconIconAnimations.in}
exiting={tabIconIconAnimations.out}
entering={ScaleFadeRotateIn}
style={[styles.icon, { opacity: inactiveOpacity }]}
>
{renderIcon({
@@ -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<T extends typeof BaseAnimationBuilder>(this: T): InstanceType<T> {
return new ScaleFadeRotateIn() as InstanceType<T>
}
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
}
}
}
+126
View File
@@ -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<Ctx> {
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<DialogContextType | null>(null)
export type DialogComponent<Ctx = unknown> = FC<DialogContextType & { ctx: Ctx }> &
Omit<DialogProps<Ctx>, "content">
class DialogStatic {
useDialogContext = () => {
return useContext(DialogContext)
}
private currentStackedDialogs = new Set<string>()
show<Ctx>(propsOrComponent: DialogProps<Ctx> | DialogComponent<Ctx>) {
const isExist = this.currentStackedDialogs.has(propsOrComponent.id)
if (isExist) {
return
}
const props =
"content" in propsOrComponent
? propsOrComponent
: (propsOrComponent as unknown as DialogProps<Ctx>)
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(
(
<FullWindowOverlay>
<Overlay onPress={handleClose} />
<Animated.View
className="bg-secondary-system-background absolute inset-x-0 -top-8 pt-8"
entering={entering}
exiting={exiting}
>
<SafeInsetTop />
<DialogContext.Provider value={reactCtx}>{children}</DialogContext.Provider>
<View className="flex-row gap-4 px-6 pb-4">
<TouchableOpacity
className="bg-system-fill flex-1 items-center justify-center rounded-full px-6 py-3"
onPress={handleClose}
>
<Text className="text-label text-base font-medium">
{props.cancelText ?? "Cancel"}
</Text>
</TouchableOpacity>
<TouchableOpacity
className="flex-1 items-center justify-center rounded-full bg-accent px-6 py-3"
style={{
backgroundColor: props.variant === "destructive" ? getColor("red") : accentColor,
}}
onPress={() => {
props.onConfirm?.(mergeCtx(ctx))
}}
>
<Text className="text-label text-base font-semibold">
{props.confirmText ?? "Confirm"}
</Text>
</TouchableOpacity>
</View>
</Animated.View>
</FullWindowOverlay>
),
)
this.currentStackedDialogs.add(props.id)
return siblings
}
destroy(id: string, siblings: RootSiblings) {
this.currentStackedDialogs.delete(id)
siblings.destroy()
}
}
const SafeInsetTop = () => {
const insets = useSafeAreaInsets()
return <View style={{ height: insets.top }} />
}
export const Dialog = new DialogStatic()
+1 -10
View File
@@ -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 (
<RootSiblingParent>
<App />
</RootSiblingParent>
)
}
registerRootComponent(MApp)
registerRootComponent(App)
@@ -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 (
<View>
<View className="px-6 py-4">
<View className="flex-row items-center gap-2">
<LinkCuteReIcon color={label} height={20} width={20} />
<Text className="text-label text-base font-medium">Enter Feed URL or RSSHub URL</Text>
</View>
<TextInput
onChangeText={(text) => (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://"
/>
</View>
</View>
)
}
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"
+24 -92
View File
@@ -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 (
<View className={cn("flex flex-row items-center gap-2 px-[12px]", className)}>{children}</View>
)
}
export function HomeLeftAction() {
const insets = useActionPadding()
const user = useWhoami()
if (!user) return null
return (
<TouchableOpacity className="flex-row items-center" style={{ paddingLeft: insets.paddingLeft }}>
<UserAvatar image={user.image} name={user.name!} size={28} />
</TouchableOpacity>
<ActionGroup>
<TouchableOpacity>
<UserAvatar image={user.image} name={user.name!} size={28} />
</TouchableOpacity>
</ActionGroup>
)
}
export function HomeSharedRightAction(props: PropsWithChildren) {
const insets = useActionPadding()
return (
<View
className="-mr-2 flex-row items-center gap-2"
style={{ paddingRight: insets.paddingRight }}
>
<ActionGroup className="-mr-2">
{props.children}
</View>
<UIBarButton
label="Mark All as Read"
normalIcon={<CheckCircleCuteReIcon height={20} width={20} color={accentColor} />}
/>
</ActionGroup>
)
}
@@ -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 (
<>
<UIBarButton
label="Add Feed"
normalIcon={<AddCuteReIcon color={accentColor} />}
onPress={() => setIsOpen((s) => !s)}
onPress={() => {
Dialog.show(AddFeedDialog)
}}
/>
<Portal>
{isOpen && (
<>
<Overlay onPress={handleClose} />
<Animated.View
className="bg-secondary-system-background absolute inset-x-0 -top-8 pt-8"
entering={SlideInUp.springify().damping(15).stiffness(100)}
exiting={SlideOutUp.duration(200)}
>
<SafeAreaView className="bg-secondary-system-background">
<View className="mt-4 px-6 py-4">
<View className="flex-row items-center gap-2">
<LinkCuteReIcon color={label} height={20} width={20} />
<Text className="text-label text-base font-medium">
Enter Feed URL or RSSHub URL
</Text>
</View>
<TextInput
onChangeText={(text) => (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://"
/>
</View>
<View className="flex-row gap-4 px-6 pb-4">
<TouchableOpacity
className="bg-system-fill flex-1 items-center justify-center rounded-full px-6 py-3"
onPress={handleClose}
>
<Text className="text-label text-base font-medium">Cancel</Text>
</TouchableOpacity>
<TouchableOpacity
className="flex-1 items-center justify-center rounded-full bg-accent px-6 py-3"
onPress={handleAdd}
>
<Text className="text-label text-base font-semibold">Add</Text>
</TouchableOpacity>
</View>
</SafeAreaView>
</Animated.View>
</>
)}
</Portal>
</>
)
}
+4 -1
View File
@@ -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 }) => {
<SheetProvider>
<ActionSheetProvider>
<PreviewImageProvider>
<PortalProvider>{children}</PortalProvider>
<RootSiblingParent>
<PortalProvider>{children}</PortalProvider>
</RootSiblingParent>
</PreviewImageProvider>
</ActionSheetProvider>
</SheetProvider>
+20 -6
View File
@@ -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