1- import type { ReactNode } from "react" ;
1+ import { useState , type ReactNode } from "react" ;
22import { Pressable , View } from "react-native" ;
33import { useSafeAreaInsets } from "react-native-safe-area-context" ;
44
55import { SymbolView , type AppSymbolName } from "./AppSymbol" ;
66import { AppText as Text } from "./AppText" ;
77import { cn } from "../lib/cn" ;
8+ import { useAppearancePreferences } from "../features/settings/appearance/AppearancePreferencesProvider" ;
9+ import { MaterialIconButton } from "./MaterialIconButton" ;
10+ import { AndroidAnchoredMenu } from "./AndroidAnchoredMenu" ;
11+ import { useScaledTextRole } from "../features/settings/appearance/useScaledTextRole" ;
812
913export interface AndroidHeaderAction {
1014 readonly accessibilityLabel : string ;
@@ -19,6 +23,8 @@ export function AndroidHeaderIconButton(props: {
1923 readonly onPress ?: ( ) => void ;
2024 readonly disabled ?: boolean ;
2125} ) {
26+ const { materialYouStyleLayoutActive } = useAppearancePreferences ( ) ;
27+ if ( materialYouStyleLayoutActive ) return < MaterialIconButton { ...props } /> ;
2228 return (
2329 < Pressable
2430 accessibilityLabel = { props . accessibilityLabel }
@@ -51,48 +57,89 @@ export function AndroidScreenHeader(props: {
5157 readonly hideBottomBorder ?: boolean ;
5258} ) {
5359 const insets = useSafeAreaInsets ( ) ;
60+ const titleTypography = useScaledTextRole ( "title" ) ;
61+ const subtitleTypography = useScaledTextRole ( "label" ) ;
62+ const { materialYouStyleLayoutActive } = useAppearancePreferences ( ) ;
63+ const [ headerWidth , setHeaderWidth ] = useState ( 0 ) ;
64+ const actions = props . actions ?? [ ] ;
65+ const directCount =
66+ materialYouStyleLayoutActive && actions . length > 2
67+ ? headerWidth >= 600
68+ ? 3
69+ : 1
70+ : actions . length ;
71+ const visibleActions = actions . slice ( 0 , directCount ) ;
72+ const overflowActions = actions . slice ( directCount ) ;
5473
5574 return (
5675 < View
57- className = "border-b border-header-border bg-header px-3 pb-2.5"
76+ onLayout = { ( event ) => setHeaderWidth ( event . nativeEvent . layout . width ) }
77+ className = {
78+ materialYouStyleLayoutActive
79+ ? "border-b border-header-border bg-header px-2 pb-2"
80+ : "border-b border-header-border bg-header px-3 pb-2.5"
81+ }
5882 style = { {
5983 paddingTop : props . embedded ? 8 : Math . max ( insets . top , 12 ) ,
6084 borderBottomWidth : props . hideBottomBorder ? 0 : undefined ,
6185 } }
6286 >
63- < View className = "min-h-12 flex-row items-center gap-2" >
87+ < View
88+ className = {
89+ materialYouStyleLayoutActive
90+ ? "min-h-14 flex-row items-center gap-1"
91+ : "min-h-12 flex-row items-center gap-2"
92+ }
93+ >
6494 { props . onBack ? (
65- < Pressable
66- accessibilityLabel = "Navigate up"
67- accessibilityRole = "button"
68- hitSlop = { 8 }
69- onPress = { props . onBack }
70- className = "-mr-2 size-11 items-center justify-center"
71- >
72- < SymbolView
73- name = "chevron.left"
74- size = { 24 }
75- tintColorClassName = { "accent-foreground" }
76- type = "monochrome"
95+ materialYouStyleLayoutActive ? (
96+ < MaterialIconButton
97+ accessibilityLabel = "Navigate up"
98+ icon = "arrow.left"
99+ onPress = { props . onBack }
77100 />
78- </ Pressable >
101+ ) : (
102+ < Pressable
103+ accessibilityLabel = "Navigate up"
104+ accessibilityRole = "button"
105+ hitSlop = { 8 }
106+ onPress = { props . onBack }
107+ className = "-mr-2 size-11 items-center justify-center"
108+ >
109+ < SymbolView
110+ name = "chevron.left"
111+ size = { 24 }
112+ tintColorClassName = { "accent-foreground" }
113+ type = "monochrome"
114+ />
115+ </ Pressable >
116+ )
79117 ) : null }
80118
81119 < View className = { cn ( "min-w-0 flex-1" , ! props . onBack && "pl-1" ) } >
82- < Text numberOfLines = { 1 } className = "text-lg font-t3-bold text-foreground" >
120+ < Text
121+ numberOfLines = { 1 }
122+ style = { materialYouStyleLayoutActive ? titleTypography : undefined }
123+ className = {
124+ materialYouStyleLayoutActive
125+ ? "text-foreground"
126+ : "text-lg font-t3-bold text-foreground"
127+ }
128+ >
83129 { props . title }
84130 </ Text >
85131 { props . subtitle ? (
86132 < Text
87133 numberOfLines = { 1 }
134+ style = { materialYouStyleLayoutActive ? subtitleTypography : undefined }
88135 className = "mt-px text-[13px] font-t3-medium text-foreground-muted"
89136 >
90137 { props . subtitle }
91138 </ Text >
92139 ) : null }
93140 </ View >
94141
95- { props . actions ? .map ( ( action ) => (
142+ { visibleActions . map ( ( action ) => (
96143 < AndroidHeaderIconButton
97144 key = { action . accessibilityLabel }
98145 accessibilityLabel = { action . accessibilityLabel }
@@ -101,6 +148,26 @@ export function AndroidScreenHeader(props: {
101148 onPress = { action . onPress }
102149 />
103150 ) ) }
151+ { overflowActions . length > 0 ? (
152+ < AndroidAnchoredMenu
153+ actions = { overflowActions . map ( ( action , index ) => ( {
154+ id : String ( index ) ,
155+ title : action . accessibilityLabel ,
156+ attributes : { disabled : Boolean ( action . disabled ) } ,
157+ } ) ) }
158+ onPressAction = { ( { nativeEvent } ) =>
159+ overflowActions [ Number ( nativeEvent . event ) ] ?. onPress ( )
160+ }
161+ >
162+ { ( open ) => (
163+ < MaterialIconButton
164+ accessibilityLabel = "More actions"
165+ icon = "ellipsis"
166+ onPress = { open }
167+ />
168+ ) }
169+ </ AndroidAnchoredMenu >
170+ ) : null }
104171 { props . trailing }
105172 </ View >
106173 </ View >
0 commit comments