Skip to content

Commit bb7fa92

Browse files
committed
refactor(mobile): enhance header components and layout
- Introduced `NavigationBlurEffectHeaderView` for improved header rendering in various settings screens. - Updated `SafeNavigationScrollView` to accept a `Header` prop for better layout flexibility. - Refactored existing screens to utilize the new header component, enhancing consistency across the app. - Adjusted styles for header text to improve visual hierarchy. Signed-off-by: Innei <tukon479@gmail.com>
1 parent cd024e4 commit bb7fa92

21 files changed

Lines changed: 258 additions & 179 deletions

apps/mobile/src/components/layouts/header/HeaderElements.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export const HeaderSubmitTextButton = ({
9090
)}
9191
<Text
9292
className={cn(
93-
"text-accent text-base font-semibold",
93+
"text-accent text-base font-bold",
9494
!isValid && "text-secondary-label",
9595
isLoading && "opacity-0",
9696
)}

apps/mobile/src/components/layouts/views/SafeNavigationScrollView.tsx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ type SafeNavigationScrollViewProps = Omit<ScrollViewProps, "onScroll"> & {
4343

4444
contentViewStyle?: StyleProp<ViewStyle>
4545
contentViewClassName?: string
46+
47+
Header?: React.ReactNode
4648
} & PropsWithChildren
4749

4850
export const SafeNavigationScrollView = forwardRef<ScrollView, SafeNavigationScrollViewProps>(
@@ -55,6 +57,7 @@ export const SafeNavigationScrollView = forwardRef<ScrollView, SafeNavigationScr
5557
reanimatedScrollY,
5658
contentViewClassName,
5759
contentViewStyle,
60+
Header,
5861
...props
5962
},
6063
forwardedRef,
@@ -95,6 +98,7 @@ export const SafeNavigationScrollView = forwardRef<ScrollView, SafeNavigationScr
9598
return (
9699
<NavigationHeaderHeightContext.Provider value={headerHeight}>
97100
<SetNavigationHeaderHeightContext.Provider value={setHeaderHeight}>
101+
{Header}
98102
<ReAnimatedScrollView
99103
ref={ref}
100104
onScroll={scrollHandler}
@@ -131,6 +135,35 @@ export const SafeNavigationScrollView = forwardRef<ScrollView, SafeNavigationScr
131135
},
132136
)
133137

138+
export const NavigationBlurEffectHeaderView = ({
139+
headerHideableBottom,
140+
headerHideableBottomHeight,
141+
headerTitleAbsolute,
142+
...props
143+
}: InternalNavigationHeaderProps & {
144+
blurThreshold?: number
145+
headerHideableBottom?: () => React.ReactNode
146+
headerHideableBottomHeight?: number
147+
headerTitleAbsolute?: boolean
148+
}) => {
149+
const hideableBottom = headerHideableBottom?.()
150+
return (
151+
<View className="absolute inset-x-0 top-0 z-[99]">
152+
<InternalNavigationHeader
153+
title={props.title}
154+
headerRight={props.headerRight}
155+
headerLeft={props.headerLeft}
156+
hideableBottom={hideableBottom}
157+
hideableBottomHeight={headerHideableBottomHeight}
158+
headerTitleAbsolute={headerTitleAbsolute}
159+
headerTitle={props.headerTitle}
160+
promptBeforeLeave={props.promptBeforeLeave}
161+
isLoading={props.isLoading}
162+
/>
163+
</View>
164+
)
165+
}
166+
134167
export const NavigationBlurEffectHeader = ({
135168
headerHideableBottom,
136169
headerHideableBottomHeight,

apps/mobile/src/lib/navigation/WrappedScreenItem.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { isUndefined } from "es-toolkit/compat"
22
import type { PrimitiveAtom } from "jotai"
33
import { atom, useAtomValue, useSetAtom } from "jotai"
44
import type { FC, ReactNode } from "react"
5-
import { memo, useCallback, useContext, useMemo } from "react"
5+
import { memo, useCallback, useContext, useMemo, useRef } from "react"
66
import type { NativeSyntheticEvent } from "react-native"
77
import { StyleSheet, View } from "react-native"
88
import { useSharedValue } from "react-native-reanimated"
@@ -124,6 +124,9 @@ export const WrappedScreenItem: FC<
124124
},
125125
[navigation, screenId],
126126
)
127+
128+
const ref = useRef<View>(null)
129+
127130
return (
128131
<ScreenItemContext.Provider value={ctxValue}>
129132
<ScreenOptionsContext.Provider value={screenOptionsCtxValue}>
@@ -133,8 +136,10 @@ export const WrappedScreenItem: FC<
133136
...defaultHeaderConfig,
134137
...headerConfig,
135138
}}
139+
nativeID=""
136140
key={screenId}
137141
screenId={screenId}
142+
ref={ref}
138143
stackPresentation={stackPresentation}
139144
style={[
140145
StyleSheet.absoluteFill,

apps/mobile/src/modules/feed/FollowFeed.tsx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,19 +128,20 @@ function FollowImpl(props: { feedId: string }) {
128128
className="bg-system-grouped-background"
129129
contentViewClassName="gap-y-4 mt-2"
130130
contentContainerStyle={{ paddingBottom: insets.bottom }}
131+
Header={
132+
<NavigationBlurEffectHeader
133+
title={`${isSubscribed ? "Edit" : "Follow"} - ${feed?.title}`}
134+
headerRight={
135+
<HeaderSubmitTextButton
136+
isValid={isValid}
137+
onPress={form.handleSubmit(submit)}
138+
isLoading={isLoading}
139+
label={isSubscribed ? "Save" : "Follow"}
140+
/>
141+
}
142+
/>
143+
}
131144
>
132-
<NavigationBlurEffectHeader
133-
title={`${isSubscribed ? "Edit" : "Follow"} - ${feed?.title}`}
134-
headerRight={
135-
<HeaderSubmitTextButton
136-
isValid={isValid}
137-
onPress={form.handleSubmit(submit)}
138-
isLoading={isLoading}
139-
label={isSubscribed ? "Save" : "Follow"}
140-
/>
141-
}
142-
/>
143-
144145
{/* Group 1 */}
145146
<GroupedInsetListCard className="px-5 py-4">
146147
<View className="flex flex-row gap-4">

apps/mobile/src/modules/settings/routes/2FASetting.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { OtpInputRef } from "react-native-otp-entry"
55
import { OtpInput } from "react-native-otp-entry"
66

77
import {
8-
NavigationBlurEffectHeader,
8+
NavigationBlurEffectHeaderView,
99
SafeNavigationScrollView,
1010
} from "@/src/components/layouts/views/SafeNavigationScrollView"
1111
import { QRCode } from "@/src/components/ui/qrcode/QRCode"
@@ -45,9 +45,7 @@ export const TwoFASetting: NavigationControllerView<{ totpURI: string }> = ({ to
4545

4646
return (
4747
<KeyboardAvoidingView behavior="padding">
48-
<SafeNavigationScrollView>
49-
<NavigationBlurEffectHeader title="Setting 2FA" />
50-
48+
<SafeNavigationScrollView Header={<NavigationBlurEffectHeaderView title="Setting 2FA" />}>
5149
<View className="my-8 items-center justify-center">
5250
<QRCode
5351
data={totpURI}

apps/mobile/src/modules/settings/routes/About.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Linking, Text, View } from "react-native"
44

55
import { Link } from "@/src/components/common/Link"
66
import {
7-
NavigationBlurEffectHeader,
7+
NavigationBlurEffectHeaderView,
88
SafeNavigationScrollView,
99
} from "@/src/components/layouts/views/SafeNavigationScrollView"
1010
import {
@@ -49,9 +49,11 @@ export const AboutScreen = () => {
4949
const appVersion = nativeApplicationVersion
5050

5151
return (
52-
<SafeNavigationScrollView className="bg-system-grouped-background" contentViewClassName="pt-6">
53-
<NavigationBlurEffectHeader title={t("titles.about")} />
54-
52+
<SafeNavigationScrollView
53+
Header={<NavigationBlurEffectHeaderView title={t("titles.about")} />}
54+
className="bg-system-grouped-background"
55+
contentViewClassName="pt-6"
56+
>
5557
<GroupedInsetListCard>
5658
<GroupedInsetListBaseCell className="flex-col py-6">
5759
<View className="flex-1 items-center justify-center">

apps/mobile/src/modules/settings/routes/Account.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { useTranslation } from "react-i18next"
66
import { Alert, Text, View } from "react-native"
77

88
import {
9-
NavigationBlurEffectHeader,
9+
NavigationBlurEffectHeaderView,
1010
SafeNavigationScrollView,
1111
} from "@/src/components/layouts/views/SafeNavigationScrollView"
1212
import { GroupedInsetListCardItemStyle } from "@/src/components/ui/grouped/GroupedInsetListCardItemStyle"
@@ -70,9 +70,10 @@ const useAccount = () => {
7070
export const AccountScreen = () => {
7171
const { t } = useTranslation("settings")
7272
return (
73-
<SafeNavigationScrollView className="bg-system-grouped-background">
74-
<NavigationBlurEffectHeader title={t("titles.account")} />
75-
73+
<SafeNavigationScrollView
74+
className="bg-system-grouped-background"
75+
Header={<NavigationBlurEffectHeaderView title={t("titles.account")} />}
76+
>
7677
<AuthenticationSection />
7778

7879
<SecuritySection />

apps/mobile/src/modules/settings/routes/Actions.tsx

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { useColors } from "react-native-uikit-colors"
88
import { SwipeableGroupProvider, SwipeableItem } from "@/src/components/common/SwipeableItem"
99
import { HeaderSubmitTextButton } from "@/src/components/layouts/header/HeaderElements"
1010
import {
11-
NavigationBlurEffectHeader,
11+
NavigationBlurEffectHeaderView,
1212
SafeNavigationScrollView,
1313
} from "@/src/components/layouts/views/SafeNavigationScrollView"
1414
import {
@@ -39,18 +39,22 @@ export const ActionsScreen = () => {
3939
const isDirty = useIsActionDataDirty()
4040

4141
return (
42-
<SafeNavigationScrollView nestedScrollEnabled className="bg-system-grouped-background">
43-
<NavigationBlurEffectHeader
44-
title={t("titles.actions")}
45-
headerRight={useCallback(
46-
() => (
47-
<SaveRuleButton disabled={!isDirty} />
48-
),
49-
[isDirty],
50-
)}
51-
promptBeforeLeave={isDirty}
52-
/>
53-
42+
<SafeNavigationScrollView
43+
Header={
44+
<NavigationBlurEffectHeaderView
45+
title={t("titles.actions")}
46+
headerRight={useCallback(
47+
() => (
48+
<SaveRuleButton disabled={!isDirty} />
49+
),
50+
[isDirty],
51+
)}
52+
promptBeforeLeave={isDirty}
53+
/>
54+
}
55+
nestedScrollEnabled
56+
className="bg-system-grouped-background"
57+
>
5458
<View className="mt-6">
5559
<GroupedInsetListCard>
5660
<GroupedInformationCell

apps/mobile/src/modules/settings/routes/Appearance.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useColorScheme, View } from "react-native"
44

55
import { setUISetting, useUISettingKey } from "@/src/atoms/settings/ui"
66
import {
7-
NavigationBlurEffectHeader,
7+
NavigationBlurEffectHeaderView,
88
SafeNavigationScrollView,
99
} from "@/src/components/layouts/views/SafeNavigationScrollView"
1010
import { Select } from "@/src/components/ui/form/Select"
@@ -29,10 +29,11 @@ export const AppearanceScreen = () => {
2929
const hideRecentReader = useUISettingKey("hideRecentReader")
3030

3131
return (
32-
<SafeNavigationScrollView className="bg-system-grouped-background">
33-
<NavigationBlurEffectHeader title={t("appearance.title")} />
34-
35-
<GroupedInsetListSectionHeader label={t("appearance.subscriptions")} />
32+
<SafeNavigationScrollView
33+
className="bg-system-grouped-background"
34+
Header={<NavigationBlurEffectHeaderView title={t("appearance.title")} />}
35+
>
36+
<GroupedInsetListSectionHeader label={t("appearance.subscriptions")} marginSize="small" />
3637
<GroupedInsetListCard>
3738
<GroupedInsetListCell
3839
label={t("appearance.show_unread_count.label")}

apps/mobile/src/modules/settings/routes/Data.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Alert } from "react-native"
44

55
import { setDataSetting, useDataSettingKey } from "@/src/atoms/settings/data"
66
import {
7-
NavigationBlurEffectHeader,
7+
NavigationBlurEffectHeaderView,
88
SafeNavigationScrollView,
99
} from "@/src/components/layouts/views/SafeNavigationScrollView"
1010
import {
@@ -23,10 +23,11 @@ export const DataScreen = () => {
2323
const { t } = useTranslation("settings")
2424
const sendAnonymousData = useDataSettingKey("sendAnonymousData")
2525
return (
26-
<SafeNavigationScrollView className="bg-system-grouped-background">
27-
<NavigationBlurEffectHeader title={t("titles.data_control")} />
28-
29-
<GroupedInsetListSectionHeader label={t("general.privacy")} />
26+
<SafeNavigationScrollView
27+
className="bg-system-grouped-background"
28+
Header={<NavigationBlurEffectHeaderView title={t("titles.data_control")} />}
29+
>
30+
<GroupedInsetListSectionHeader label={t("general.privacy")} marginSize="small" />
3031

3132
<GroupedInsetListCard>
3233
<GroupedInsetListCell

0 commit comments

Comments
 (0)