fix(mobile): put the profile button inline with the iOS screen title (#134)

This commit was merged in pull request #134.
This commit is contained in:
joshuafhiggins committed 2026-11-20 00:40:16 -05:00
1 parent dc30fb38f8
commit 5f2ce39b42
11 files changed
+109 -62

No files matched your search

+5 -12
View File
@@ -4,6 +4,7 @@ import { Stack } from "expo-router"
import { ProfileHeaderButton } from "@/components/profile-header-button" import { ProfileHeaderButton } from "@/components/profile-header-button"
import { import {
inlineTitleOptions, inlineTitleOptions,
showHeaderProfile,
tabStackScreenTitles, tabStackScreenTitles,
useStackScreenOptions, useStackScreenOptions,
} from "@/lib/navigation" } from "@/lib/navigation"
@@ -22,18 +23,10 @@ export default function HomeLayout() {
...baseOptions, ...baseOptions,
...inlineTitleOptions, ...inlineTitleOptions,
title: tabStackScreenTitles[route.name] ?? "Home", title: tabStackScreenTitles[route.name] ?? "Home",
headerRight: // iOS shows the profile button inline with the screen title instead.
route.name === "index" ? () => <ProfileHeaderButton /> : undefined, headerRight: showHeaderProfile(route.name)
unstable_headerRightItems: ? () => <ProfileHeaderButton />
route.name === "index" : undefined,
? () => [
{
type: "custom",
element: <ProfileHeaderButton />,
hidesSharedBackground: true,
},
]
: undefined,
})} })}
/> />
) )
+10 -2
View File
@@ -5,6 +5,7 @@ import Animated from "react-native-reanimated"
import { ContentCarousel } from "@/components/media-cards" import { ContentCarousel } from "@/components/media-cards"
import { HomeSkeleton } from "@/components/skeletons" import { HomeSkeleton } from "@/components/skeletons"
import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title" import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title"
import { ProfileHeaderButton } from "@/components/profile-header-button"
import { tabContentBottomInset } from "@/components/player" import { tabContentBottomInset } from "@/components/player"
import { useCachedPaginatedQuery } from "@/hooks/use-cached-query" import { useCachedPaginatedQuery } from "@/hooks/use-cached-query"
import { api } from "@otunes/convex/_generated/api" import { api } from "@otunes/convex/_generated/api"
@@ -56,7 +57,9 @@ export default function HomeScreen() {
(result) => result.status === "LoadingFirstPage" && !result.isCached (result) => result.status === "LoadingFirstPage" && !result.isCached
) )
if (isLoading) { if (isLoading) {
return <HomeSkeleton title="Home" /> return (
<HomeSkeleton title="Home" titleAccessory={<ProfileHeaderButton />} />
)
} }
const added = recentlyAdded.results.slice(0, CAROUSEL_ITEM_LIMIT) const added = recentlyAdded.results.slice(0, CAROUSEL_ITEM_LIMIT)
@@ -73,7 +76,12 @@ export default function HomeScreen() {
]} ]}
contentInsetAdjustmentBehavior="automatic" contentInsetAdjustmentBehavior="automatic"
> >
<ScreenTitle title="Home" scrollY={scrollY} style={styles.title} /> <ScreenTitle
title="Home"
scrollY={scrollY}
accessory={<ProfileHeaderButton />}
style={styles.title}
/>
<HomeCarousels recentlyAdded={added} recentlyPlayed={played} /> <HomeCarousels recentlyAdded={added} recentlyPlayed={played} />
</Animated.ScrollView> </Animated.ScrollView>
) )
@@ -5,6 +5,7 @@ import { Stack } from "expo-router"
import { ProfileHeaderButton } from "@/components/profile-header-button" import { ProfileHeaderButton } from "@/components/profile-header-button"
import { import {
inlineTitleOptions, inlineTitleOptions,
showHeaderProfile,
tabStackScreenTitles, tabStackScreenTitles,
useStackScreenOptions, useStackScreenOptions,
} from "@/lib/navigation" } from "@/lib/navigation"
@@ -26,18 +27,10 @@ export default function LibraryLayout() {
title: title:
tabStackScreenTitles[route.name] ?? tabStackScreenTitles[route.name] ??
(tabletLayout ? "Recently Added" : "Library"), (tabletLayout ? "Recently Added" : "Library"),
headerRight: // iOS shows the profile button inline with the screen title instead.
route.name === "index" ? () => <ProfileHeaderButton /> : undefined, headerRight: showHeaderProfile(route.name)
unstable_headerRightItems: ? () => <ProfileHeaderButton />
route.name === "index" : undefined,
? () => [
{
type: "custom",
element: <ProfileHeaderButton />,
hidesSharedBackground: true,
},
]
: undefined,
})} })}
/> />
) )
@@ -8,6 +8,7 @@ import { Ionicons } from "@expo/vector-icons"
import { MediaGridList } from "@/components/media-cards" import { MediaGridList } from "@/components/media-cards"
import { tabContentBottomInset } from "@/components/player" import { tabContentBottomInset } from "@/components/player"
import { MediaGridSkeleton } from "@/components/skeletons" import { MediaGridSkeleton } from "@/components/skeletons"
import { ProfileHeaderButton } from "@/components/profile-header-button"
import { useCachedPaginatedQuery } from "@/hooks/use-cached-query" import { useCachedPaginatedQuery } from "@/hooks/use-cached-query"
import { useAppNavigation } from "@/lib/app-navigation" import { useAppNavigation } from "@/lib/app-navigation"
import { api } from "@otunes/convex/_generated/api" import { api } from "@otunes/convex/_generated/api"
@@ -128,6 +129,7 @@ export default function LibraryScreen() {
return ( return (
<MediaGridSkeleton <MediaGridSkeleton
title={title} title={title}
titleAccessory={<ProfileHeaderButton />}
contentInset={false} contentInset={false}
header={listHeader} header={listHeader}
/> />
@@ -137,6 +139,7 @@ export default function LibraryScreen() {
return ( return (
<MediaGridList <MediaGridList
title={title} title={title}
titleAccessory={<ProfileHeaderButton />}
content={results} content={results}
paddingBottom={tabContentBottomInset} paddingBottom={tabContentBottomInset}
contentInset={false} contentInset={false}
@@ -4,6 +4,7 @@ import { Stack } from "expo-router"
import { ProfileHeaderButton } from "@/components/profile-header-button" import { ProfileHeaderButton } from "@/components/profile-header-button"
import { import {
inlineTitleOptions, inlineTitleOptions,
showHeaderProfile,
tabStackScreenTitles, tabStackScreenTitles,
useStackScreenOptions, useStackScreenOptions,
} from "@/lib/navigation" } from "@/lib/navigation"
@@ -22,18 +23,10 @@ export default function SearchLayout() {
...baseOptions, ...baseOptions,
...inlineTitleOptions, ...inlineTitleOptions,
title: tabStackScreenTitles[route.name] ?? "Search", title: tabStackScreenTitles[route.name] ?? "Search",
headerRight: // iOS shows the profile button inline with the screen title instead.
route.name === "index" ? () => <ProfileHeaderButton /> : undefined, headerRight: showHeaderProfile(route.name)
unstable_headerRightItems: ? () => <ProfileHeaderButton />
route.name === "index" : undefined,
? () => [
{
type: "custom",
element: <ProfileHeaderButton />,
hidesSharedBackground: true,
},
]
: undefined,
})} })}
/> />
) )
+5 -1
View File
@@ -7,7 +7,7 @@ import { MusicEntityView } from "@/components/music-entity-view"
import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title" import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title"
import { Link } from "expo-router" import { Link } from "expo-router"
import { Ionicons } from "@expo/vector-icons" import { Ionicons } from "@expo/vector-icons"
import { memo, useCallback, type ReactElement } from "react" import { memo, useCallback, type ReactElement, type ReactNode } from "react"
import { import {
FlatList, FlatList,
Platform, Platform,
@@ -302,6 +302,7 @@ export function MediaGridList({
ListHeaderComponent, ListHeaderComponent,
contentInset = true, contentInset = true,
title, title,
titleAccessory,
}: { }: {
content: MediaItem[] content: MediaItem[]
paddingBottom: number paddingBottom: number
@@ -310,6 +311,7 @@ export function MediaGridList({
contentInset?: boolean contentInset?: boolean
/** iOS `ScreenTitle` shown above the grid; it replaces the top inset. */ /** iOS `ScreenTitle` shown above the grid; it replaces the top inset. */
title?: string title?: string
titleAccessory?: ReactNode
}) { }) {
const tabletLayout = useTabletLayout() const tabletLayout = useTabletLayout()
const { columns, cardWidth, onLayout, horizontalPadding, gap } = const { columns, cardWidth, onLayout, horizontalPadding, gap } =
@@ -334,6 +336,7 @@ export function MediaGridList({
ListHeaderComponent={ListHeaderComponent} ListHeaderComponent={ListHeaderComponent}
contentInset={contentInset} contentInset={contentInset}
title={title} title={title}
titleAccessory={titleAccessory}
renderCard={renderTabletCard} renderCard={renderTabletCard}
/> />
) )
@@ -344,6 +347,7 @@ export function MediaGridList({
<ScreenTitle <ScreenTitle
title={title} title={title}
scrollY={scrollY} scrollY={scrollY}
accessory={titleAccessory}
// Inset grids already pad the whole list horizontally. // Inset grids already pad the whole list horizontally.
style={{ paddingHorizontal: contentInset ? 0 : horizontalPadding }} style={{ paddingHorizontal: contentInset ? 0 : horizontalPadding }}
/> />
+29 -16
View File
@@ -1,11 +1,12 @@
import { useHeaderHeight } from "expo-router/react-navigation" import { useHeaderHeight } from "expo-router/react-navigation"
import type { Component } from "react" import type { Component, ReactNode } from "react"
import { import {
Platform, Platform,
StyleSheet, StyleSheet,
Text,
type ScrollViewInstance, type ScrollViewInstance,
type StyleProp, type StyleProp,
type TextStyle, type ViewStyle,
} from "react-native" } from "react-native"
import Animated, { import Animated, {
useAnimatedRef, useAnimatedRef,
@@ -33,17 +34,20 @@ export function useScreenTitleScroll<
* iOS screen title rendered as the first item of a screen's scroll content, * iOS screen title rendered as the first item of a screen's scroll content,
* in place of the native large title (Apple Music style): it scrolls away * in place of the native large title (Apple Music style): it scrolls away
* with the content, never collapses into the bar, and stays put on * with the content, never collapses into the bar, and stays put on
* pull-down. Android keeps its native header title, so this renders nothing. * pull-down. `accessory` (e.g. the profile button) sits on the same row and
* scrolls with it. Android keeps its native header, so this renders nothing.
*/ */
export function ScreenTitle({ export function ScreenTitle({
title, title,
scrollY, scrollY,
accessory,
style, style,
}: { }: {
title: string title: string
/** From `useScreenTitleScroll`; omit for screens that never scroll. */ /** From `useScreenTitleScroll`; omit for screens that never scroll. */
scrollY?: SharedValue<number> scrollY?: SharedValue<number>
style?: StyleProp<TextStyle> accessory?: ReactNode
style?: StyleProp<ViewStyle>
}) { }) {
const colors = useThemeColors() const colors = useThemeColors()
// At rest the scroll offset is minus the automatic header inset, so any // At rest the scroll offset is minus the automatic header inset, so any
@@ -60,25 +64,34 @@ export function ScreenTitle({
if (Platform.OS !== "ios") return null if (Platform.OS !== "ios") return null
return ( return (
<Animated.Text <Animated.View style={[styles.row, style, pinStyle]}>
accessibilityRole="header" <Text
numberOfLines={2} accessibilityRole="header"
style={[styles.title, { color: colors.foreground }, style, pinStyle]} numberOfLines={2}
> style={[styles.title, { color: colors.foreground }]}
{title} >
</Animated.Text> {title}
</Text>
{accessory}
</Animated.View>
) )
} }
// Matches UIKit's large title metrics: 34pt bold in a 52pt tall area. // Matches UIKit's large title metrics: 34pt bold in a 52pt tall area.
const styles = StyleSheet.create({ const styles = StyleSheet.create({
title: { row: {
fontSize: 34, flexDirection: "row",
lineHeight: 41, alignItems: "center",
fontWeight: "700", gap: spacing.md,
letterSpacing: 0.37,
paddingHorizontal: spacing.lg, paddingHorizontal: spacing.lg,
paddingTop: 3, paddingTop: 3,
paddingBottom: 8, paddingBottom: 8,
}, },
title: {
flex: 1,
fontSize: 34,
lineHeight: 41,
fontWeight: "700",
letterSpacing: 0.37,
},
}) })
+12 -2
View File
@@ -9,6 +9,7 @@ import {
import Animated from "react-native-reanimated" import Animated from "react-native-reanimated"
import { ContentCarousel } from "@/components/media-cards" import { ContentCarousel } from "@/components/media-cards"
import { ProfileHeaderButton } from "@/components/profile-header-button"
import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title" import { ScreenTitle, useScreenTitleScroll } from "@/components/screen-title"
import type { MediaAction } from "@/components/media-context-menu" import type { MediaAction } from "@/components/media-context-menu"
import { tabContentBottomInset, SongListRow } from "@/components/player" import { tabContentBottomInset, SongListRow } from "@/components/player"
@@ -86,7 +87,12 @@ function SearchResultsBody({
) )
if (isSearching) { if (isSearching) {
return <SongListSkeleton title={title} /> return (
<SongListSkeleton
title={title}
titleAccessory={<ProfileHeaderButton />}
/>
)
} }
return ( return (
@@ -101,7 +107,11 @@ function SearchResultsBody({
keyboardShouldPersistTaps="handled" keyboardShouldPersistTaps="handled"
ListHeaderComponent={ ListHeaderComponent={
<> <>
<ScreenTitle title={title} scrollY={scrollY} /> <ScreenTitle
title={title}
scrollY={scrollY}
accessory={<ProfileHeaderButton />}
/>
{hasQuery && !hasResults ? ( {hasQuery && !hasResults ? (
<View style={styles.empty}> <View style={styles.empty}>
<Text <Text
+26 -5
View File
@@ -155,13 +155,15 @@ function SongRows({ rows, inset }: { rows: number; inset?: boolean }) {
export function SongListSkeleton({ export function SongListSkeleton({
rows = 10, rows = 10,
title, title,
titleAccessory,
}: { }: {
rows?: number rows?: number
title?: string title?: string
titleAccessory?: ReactNode
}) { }) {
return ( return (
<SkeletonScreen> <SkeletonScreen>
{title ? <ScreenTitle title={title} /> : null} {title ? <ScreenTitle title={title} accessory={titleAccessory} /> : null}
<SongRows rows={rows} /> <SongRows rows={rows} />
</SkeletonScreen> </SkeletonScreen>
) )
@@ -243,6 +245,7 @@ export function MediaGridSkeleton({
contentInset = true, contentInset = true,
header, header,
title, title,
titleAccessory,
}: { }: {
items?: number items?: number
contentInset?: boolean contentInset?: boolean
@@ -250,6 +253,7 @@ export function MediaGridSkeleton({
header?: ReactNode header?: ReactNode
/** The loaded list's `ScreenTitle`, which replaces its top inset. */ /** The loaded list's `ScreenTitle`, which replaces its top inset. */
title?: string title?: string
titleAccessory?: ReactNode
}) { }) {
return ( return (
<SkeletonScreen> <SkeletonScreen>
@@ -259,7 +263,7 @@ export function MediaGridSkeleton({
header={ header={
title ? ( title ? (
<> <>
<MediaGridTitle title={title} /> <MediaGridTitle title={title} accessory={titleAccessory} />
{header} {header}
</> </>
) : ( ) : (
@@ -271,11 +275,18 @@ export function MediaGridSkeleton({
) )
} }
function MediaGridTitle({ title }: { title: string }) { function MediaGridTitle({
title,
accessory,
}: {
title: string
accessory?: ReactNode
}) {
const { horizontalPadding } = useMediaGridLayout() const { horizontalPadding } = useMediaGridLayout()
return ( return (
<ScreenTitle <ScreenTitle
title={title} title={title}
accessory={accessory}
style={{ paddingHorizontal: horizontalPadding }} style={{ paddingHorizontal: horizontalPadding }}
/> />
) )
@@ -294,11 +305,21 @@ export function CarouselSkeleton() {
) )
} }
export function HomeSkeleton({ title }: { title: string }) { export function HomeSkeleton({
title,
titleAccessory,
}: {
title: string
titleAccessory?: ReactNode
}) {
return ( return (
<SkeletonScreen> <SkeletonScreen>
<View style={styles.home}> <View style={styles.home}>
<ScreenTitle title={title} style={styles.homeTitle} /> <ScreenTitle
title={title}
accessory={titleAccessory}
style={styles.homeTitle}
/>
<CarouselSkeleton /> <CarouselSkeleton />
<CarouselSkeleton /> <CarouselSkeleton />
</View> </View>
@@ -4,6 +4,7 @@ import {
useRef, useRef,
useState, useState,
type ReactElement, type ReactElement,
type ReactNode,
} from "react" } from "react"
import { import {
type ScrollViewInstance, type ScrollViewInstance,
@@ -31,6 +32,7 @@ type GridProps = {
contentInset?: boolean contentInset?: boolean
/** iOS `ScreenTitle` shown above the grid; it replaces the top inset. */ /** iOS `ScreenTitle` shown above the grid; it replaces the top inset. */
title?: string title?: string
titleAccessory?: ReactNode
renderCard: (item: MediaItem, width: number) => ReactElement renderCard: (item: MediaItem, width: number) => ReactElement
} }
@@ -45,6 +47,7 @@ export function TabletMediaGrid({
ListHeaderComponent, ListHeaderComponent,
contentInset = true, contentInset = true,
title, title,
titleAccessory,
renderCard, renderCard,
}: GridProps) { }: GridProps) {
const colors = useThemeColors() const colors = useThemeColors()
@@ -126,6 +129,7 @@ export function TabletMediaGrid({
<ScreenTitle <ScreenTitle
title={title} title={title}
scrollY={titleScrollY} scrollY={titleScrollY}
accessory={titleAccessory}
style={{ paddingHorizontal: horizontalPadding }} style={{ paddingHorizontal: horizontalPadding }}
/> />
) : null} ) : null}
+5
View File
@@ -24,6 +24,11 @@ export const tabStackScreenTitles: Record<string, string> = {
export const inlineTitleOptions: StackScreenOptions = export const inlineTitleOptions: StackScreenOptions =
Platform.OS === "ios" ? { headerTitleStyle: { color: "transparent" } } : {} Platform.OS === "ios" ? { headerTitleStyle: { color: "transparent" } } : {}
/** Tab roots show the profile button in the header, except on iOS where `ScreenTitle` holds it. */
export function showHeaderProfile(routeName: string) {
return routeName === "index" && Platform.OS !== "ios"
}
export function useStackScreenOptions( export function useStackScreenOptions(
overrides?: StackScreenOptions overrides?: StackScreenOptions
): StackScreenOptions { ): StackScreenOptions {