feat(mobile): introduce HeaderSubmitTextButton and refactor header components
- Added HeaderSubmitTextButton for improved button functionality in headers. - Updated various screens to utilize HeaderSubmitTextButton instead of HeaderSubmitButton for better consistency. - Refactored header components to include new hooks and improve layout handling. - Enhanced styling of FakeNativeHeaderTitle for better visual hierarchy. These changes enhance the user interface and provide a more consistent experience across the application. Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
@@ -13,7 +13,7 @@ export function FakeNativeHeaderTitle({ style, ...rest }: Props) {
|
||||
accessibilityRole="header"
|
||||
aria-level="1"
|
||||
numberOfLines={1}
|
||||
className={"text-label font-bold"}
|
||||
className={"text-label font-semibold"}
|
||||
{...rest}
|
||||
style={[styles.title, style]}
|
||||
/>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { withOpacity } from "@follow/utils"
|
||||
import { cn, withOpacity } from "@follow/utils"
|
||||
import { useCallback } from "react"
|
||||
import { TouchableOpacity } from "react-native"
|
||||
import { Text, TouchableOpacity, View } from "react-native"
|
||||
|
||||
import { CheckLineIcon } from "@/src/icons/check_line"
|
||||
import { CloseCuteReIcon } from "@/src/icons/close_cute_re"
|
||||
@@ -24,6 +24,7 @@ const HeaderCloseButton = () => {
|
||||
const canDismiss = useCanDismiss()
|
||||
const isInModal = useScreenIsInSheetModal()
|
||||
const isSingleRouteInGroup = useIsSingleRouteInGroup()
|
||||
|
||||
const handlePress = useCallback(() => {
|
||||
if (canDismiss) {
|
||||
navigation.dismiss()
|
||||
@@ -67,6 +68,35 @@ export const HeaderSubmitButton = ({
|
||||
)
|
||||
}
|
||||
|
||||
export const HeaderSubmitTextButton = ({
|
||||
isValid,
|
||||
onPress,
|
||||
isLoading,
|
||||
label = "Submit",
|
||||
}: ModalHeaderSubmitButtonProps & {
|
||||
label?: string
|
||||
}) => {
|
||||
const labelColor = useColor("label")
|
||||
return (
|
||||
<UINavigationHeaderActionButton onPress={onPress} disabled={!isValid || isLoading}>
|
||||
{isLoading && (
|
||||
<View className="absolute inset-y-0 right-2 items-center justify-center">
|
||||
<RotateableLoading size={20} color={withOpacity(labelColor, 0.5)} />
|
||||
</View>
|
||||
)}
|
||||
<Text
|
||||
className={cn(
|
||||
"text-accent text-base font-semibold",
|
||||
!isValid && "text-secondary-label",
|
||||
isLoading && "opacity-0",
|
||||
)}
|
||||
>
|
||||
{label}
|
||||
</Text>
|
||||
</UINavigationHeaderActionButton>
|
||||
)
|
||||
}
|
||||
|
||||
export const HeaderCloseOnly = () => {
|
||||
return (
|
||||
<StackScreenHeaderPortal>
|
||||
|
||||
@@ -30,6 +30,7 @@ import { MingcuteLeftLineIcon } from "@/src/icons/mingcute_left_line"
|
||||
import {
|
||||
useCanBack,
|
||||
useCanDismiss,
|
||||
useIsTopRouteInGroup,
|
||||
useNavigation,
|
||||
useScreenIsInSheetModal,
|
||||
} from "@/src/lib/navigation/hooks"
|
||||
@@ -304,7 +305,6 @@ export const InternalNavigationHeader = ({
|
||||
)}
|
||||
</View>
|
||||
{/* Center */}
|
||||
|
||||
<Animated.View
|
||||
className="flex min-w-0 flex-1 shrink flex-row items-center justify-center truncate"
|
||||
pointerEvents={"box-none"}
|
||||
@@ -353,6 +353,11 @@ export const DefaultHeaderBackButton = ({
|
||||
}: NavigationHeaderButtonProps) => {
|
||||
const label = useColor("label")
|
||||
const navigation = useNavigation()
|
||||
|
||||
const isTopRouteInGroup = useIsTopRouteInGroup()
|
||||
|
||||
const showCloseIcon = canDismiss && isTopRouteInGroup
|
||||
|
||||
if (!canGoBack && !canDismiss) return null
|
||||
return (
|
||||
<UINavigationHeaderActionButton
|
||||
@@ -383,7 +388,7 @@ export const DefaultHeaderBackButton = ({
|
||||
}
|
||||
}}
|
||||
>
|
||||
{canGoBack ? (
|
||||
{!showCloseIcon ? (
|
||||
<MingcuteLeftLineIcon height={20} width={20} color={label} />
|
||||
) : (
|
||||
<CloseCuteReIcon height={20} width={20} color={label} />
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useTypeScriptHappyCallback } from "@follow/hooks"
|
||||
import { useSetAtom, useStore } from "jotai"
|
||||
import type { PropsWithChildren } from "react"
|
||||
import { forwardRef, useContext, useEffect, useState } from "react"
|
||||
import { forwardRef, useContext, useLayoutEffect, useState } from "react"
|
||||
import type { ScrollView, ScrollViewProps, StyleProp, ViewStyle } from "react-native"
|
||||
import { View } from "react-native"
|
||||
import type { SharedValue } from "react-native-reanimated"
|
||||
@@ -126,7 +126,7 @@ export const NavigationBlurEffectHeader = ({
|
||||
|
||||
const setSlot = useSetAtom(screenCtxValue.Slot)
|
||||
const store = useStore()
|
||||
useEffect(() => {
|
||||
useLayoutEffect(() => {
|
||||
setSlot({
|
||||
...store.get(screenCtxValue.Slot),
|
||||
header: (
|
||||
|
||||
@@ -72,3 +72,15 @@ export const useIsSingleRouteInGroup = () => {
|
||||
if (!routeGroup || routeGroup.length === 0) return false
|
||||
return routeGroup.length === 1
|
||||
}
|
||||
|
||||
export const useIsTopRouteInGroup = () => {
|
||||
const { screenId } = useContext(ScreenItemContext)
|
||||
|
||||
const routeGroups = useContext(GroupedNavigationRouteContext)
|
||||
if (!routeGroups) return false
|
||||
const routeGroup = routeGroups.find((group) => group.some((r) => r.id === screenId))
|
||||
|
||||
if (!routeGroup || routeGroup.length === 0) return false
|
||||
|
||||
return routeGroup.at(0)?.screenOptions?.id === screenId
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import { ActivityIndicator, Text, View } from "react-native"
|
||||
import { useSafeAreaInsets } from "react-native-safe-area-context"
|
||||
import { z } from "zod"
|
||||
|
||||
import { HeaderSubmitButton } from "@/src/components/layouts/header/HeaderElements"
|
||||
import { HeaderSubmitTextButton } from "@/src/components/layouts/header/HeaderElements"
|
||||
import {
|
||||
NavigationBlurEffectHeader,
|
||||
SafeNavigationScrollView,
|
||||
@@ -131,10 +131,11 @@ function FollowImpl(props: { feedId: string }) {
|
||||
<NavigationBlurEffectHeader
|
||||
title={`${isSubscribed ? "Edit" : "Follow"} - ${feed?.title}`}
|
||||
headerRight={
|
||||
<HeaderSubmitButton
|
||||
<HeaderSubmitTextButton
|
||||
isValid={isValid}
|
||||
onPress={form.handleSubmit(submit)}
|
||||
isLoading={isLoading}
|
||||
label={isSubscribed ? "Save" : "Follow"}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
|
||||
@@ -6,7 +6,7 @@ import { Controller, useForm } from "react-hook-form"
|
||||
import { ActivityIndicator, Alert, StyleSheet, Text, View } from "react-native"
|
||||
import { z } from "zod"
|
||||
|
||||
import { HeaderSubmitButton } from "@/src/components/layouts/header/HeaderElements"
|
||||
import { HeaderSubmitTextButton } from "@/src/components/layouts/header/HeaderElements"
|
||||
import {
|
||||
NavigationBlurEffectHeader,
|
||||
SafeNavigationScrollView,
|
||||
@@ -132,10 +132,11 @@ const Impl = (props: { id: string }) => {
|
||||
<NavigationBlurEffectHeader
|
||||
title={`${isSubscribed ? "Edit" : "Follow"} - ${list?.title}`}
|
||||
headerRight={
|
||||
<HeaderSubmitButton
|
||||
<HeaderSubmitTextButton
|
||||
isValid={isValid}
|
||||
onPress={form.handleSubmit(submit)}
|
||||
isLoading={isLoading}
|
||||
label={isSubscribed ? "Save" : "Follow"}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
import { useCallback } from "react"
|
||||
|
||||
import { getFetchErrorInfo } from "@/src/lib/error-parser"
|
||||
import { useNavigation } from "@/src/lib/navigation/hooks"
|
||||
import { toast } from "@/src/lib/toast"
|
||||
import { TwoFactorAuthScreen } from "@/src/screens/(modal)/2fa"
|
||||
import { useWhoami } from "@/src/store/user/hooks"
|
||||
|
||||
export const useTOTPModalWrapper = <T extends { TOTPCode?: string }>(
|
||||
callback: (input: T) => Promise<any>,
|
||||
options?: { force?: boolean },
|
||||
) => {
|
||||
const user = useWhoami()
|
||||
const navigation = useNavigation()
|
||||
return useCallback(
|
||||
async (input: T) => {
|
||||
const presentTOTPModal = () => {
|
||||
if (!user?.twoFactorEnabled) {
|
||||
toast.error("You need to enable two-factor authentication to perform this action.")
|
||||
|
||||
navigation.pushControllerView(TwoFactorAuthScreen)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// present({
|
||||
// title: t("profile.totp_code.title"),
|
||||
// content: ({ dismiss }) => {
|
||||
// return createElement(TOTPForm, {
|
||||
// async onSubmitMutationFn(values) {
|
||||
// await callback({
|
||||
// ...input,
|
||||
// TOTPCode: values.code,
|
||||
// })
|
||||
// dismiss()
|
||||
// },
|
||||
// })
|
||||
// },
|
||||
// })
|
||||
}
|
||||
|
||||
if (options?.force) {
|
||||
presentTOTPModal()
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await callback(input)
|
||||
} catch (error) {
|
||||
const { code } = getFetchErrorInfo(error as Error)
|
||||
if (code === 4008) {
|
||||
presentTOTPModal()
|
||||
}
|
||||
}
|
||||
},
|
||||
[callback, navigation, options?.force, user?.twoFactorEnabled],
|
||||
)
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
import { withOpacity } from "@follow/utils/src/color"
|
||||
import { useMutation } from "@tanstack/react-query"
|
||||
import type { FC } from "react"
|
||||
import { useCallback, useState } from "react"
|
||||
import { useState } from "react"
|
||||
import {
|
||||
ActivityIndicator,
|
||||
Text,
|
||||
@@ -11,13 +10,12 @@ import {
|
||||
} from "react-native"
|
||||
import { KeyboardController } from "react-native-keyboard-controller"
|
||||
|
||||
import { RotateableLoading } from "@/src/components/common/RotateableLoading"
|
||||
import { HeaderSubmitTextButton } from "@/src/components/layouts/header/HeaderElements"
|
||||
import {
|
||||
NavigationBlurEffectHeader,
|
||||
SafeNavigationScrollView,
|
||||
} from "@/src/components/layouts/views/SafeNavigationScrollView"
|
||||
import { UserAvatar } from "@/src/components/ui/avatar/UserAvatar"
|
||||
import { UIBarButton } from "@/src/components/ui/button/UIBarButton"
|
||||
import { PlainTextField } from "@/src/components/ui/form/TextField"
|
||||
import {
|
||||
GroupedInsetListCard,
|
||||
@@ -26,7 +24,6 @@ import {
|
||||
GroupedOutlineDescription,
|
||||
} from "@/src/components/ui/grouped/GroupedList"
|
||||
import { CheckCircleCuteReIcon } from "@/src/icons/check_circle_cute_re"
|
||||
import { CheckLineIcon } from "@/src/icons/check_line"
|
||||
import { CloseCircleFillIcon } from "@/src/icons/close_circle_fill"
|
||||
import { useNavigation } from "@/src/lib/navigation/hooks"
|
||||
import { toast } from "@/src/lib/toast"
|
||||
@@ -35,7 +32,7 @@ import { useWhoami } from "@/src/store/user/hooks"
|
||||
import type { MeModel } from "@/src/store/user/store"
|
||||
import { userSyncService } from "@/src/store/user/store"
|
||||
import type { UserProfileEditable } from "@/src/store/user/types"
|
||||
import { accentColor, useColor } from "@/src/theme/colors"
|
||||
import { accentColor } from "@/src/theme/colors"
|
||||
|
||||
import { setAvatar } from "../utils"
|
||||
|
||||
@@ -95,31 +92,21 @@ const ProfileForm: FC<{
|
||||
},
|
||||
})
|
||||
|
||||
const label = useColor("label")
|
||||
const headerRight = useCallback(
|
||||
() => (
|
||||
<UIBarButton
|
||||
label="Save"
|
||||
disabled={isPending || Object.keys(dirtyFields).length === 0}
|
||||
normalIcon={
|
||||
isPending ? (
|
||||
<RotateableLoading size={20} color={withOpacity(label, 0.5)} />
|
||||
) : (
|
||||
<CheckLineIcon height={20} width={20} />
|
||||
)
|
||||
}
|
||||
onPress={() => {
|
||||
updateProfile()
|
||||
}}
|
||||
/>
|
||||
),
|
||||
[dirtyFields, isPending, label, updateProfile],
|
||||
)
|
||||
|
||||
const navigation = useNavigation()
|
||||
return (
|
||||
<View className="mt-4">
|
||||
<NavigationBlurEffectHeader headerRight={headerRight} title="Edit Profile" />
|
||||
<NavigationBlurEffectHeader
|
||||
headerRight={
|
||||
<HeaderSubmitTextButton
|
||||
label="Save"
|
||||
isValid={isPending || Object.keys(dirtyFields).length === 0}
|
||||
onPress={() => {
|
||||
updateProfile()
|
||||
}}
|
||||
/>
|
||||
}
|
||||
title="Edit Profile"
|
||||
/>
|
||||
|
||||
<TouchableWithoutFeedback
|
||||
onPress={() => {
|
||||
|
||||
@@ -2,7 +2,7 @@ import { cn } from "@follow/utils"
|
||||
import { useMutation, useQuery } from "@tanstack/react-query"
|
||||
import dayjs from "dayjs"
|
||||
import { setStringAsync } from "expo-clipboard"
|
||||
import { Clipboard, Pressable, Text, View } from "react-native"
|
||||
import { Pressable, Text, View } from "react-native"
|
||||
|
||||
import { useServerConfigs } from "@/src/atoms/server-configs"
|
||||
import { UINavigationHeaderActionButton } from "@/src/components/layouts/header/NavigationHeader"
|
||||
@@ -53,7 +53,7 @@ export const InvitationsScreen: NavigationControllerView = () => {
|
||||
const { data: invitations, isLoading } = useInvitationsQuery()
|
||||
const limitation = useInvitationsLimitationQuery()
|
||||
const handleCopyCode = (code: string) => {
|
||||
Clipboard.setString(code)
|
||||
setStringAsync(code)
|
||||
toast.success("Copied to clipboard")
|
||||
}
|
||||
return (
|
||||
|
||||
@@ -2,7 +2,7 @@ import { useMutation } from "@tanstack/react-query"
|
||||
import { useMemo, useState } from "react"
|
||||
import { View } from "react-native"
|
||||
|
||||
import { HeaderSubmitButton } from "@/src/components/layouts/header/HeaderElements"
|
||||
import { HeaderSubmitTextButton } from "@/src/components/layouts/header/HeaderElements"
|
||||
import {
|
||||
NavigationBlurEffectHeader,
|
||||
SafeNavigationScrollView,
|
||||
@@ -50,7 +50,7 @@ export const EditEmailScreen: NavigationControllerView = () => {
|
||||
<NavigationBlurEffectHeader
|
||||
title="Edit Email"
|
||||
headerRight={
|
||||
<HeaderSubmitButton
|
||||
<HeaderSubmitTextButton
|
||||
isLoading={isPending}
|
||||
isValid={!!(email && newEmailIsValid && isDirty)}
|
||||
onPress={() => {
|
||||
|
||||
@@ -13,7 +13,7 @@ import { Controller, useForm } from "react-hook-form"
|
||||
import { KeyboardAvoidingView, Linking, Text, TouchableOpacity, View } from "react-native"
|
||||
import { z } from "zod"
|
||||
|
||||
import { HeaderSubmitButton } from "@/src/components/layouts/header/HeaderElements"
|
||||
import { HeaderSubmitTextButton } from "@/src/components/layouts/header/HeaderElements"
|
||||
import {
|
||||
NavigationBlurEffectHeader,
|
||||
SafeNavigationScrollView,
|
||||
@@ -339,5 +339,7 @@ const ModalHeaderSubmitButtonImpl = ({
|
||||
}
|
||||
})
|
||||
|
||||
return <HeaderSubmitButton isLoading={isLoading} isValid={isValid} onPress={submit} />
|
||||
return (
|
||||
<HeaderSubmitTextButton isLoading={isLoading} isValid={isValid} onPress={submit} label="Next" />
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user