@oxy.so/bloom 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/docs/page-header.mdx +101 -0
- package/lib/commonjs/index.js +128 -116
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/index.web.js +128 -116
- package/lib/commonjs/index.web.js.map +1 -1
- package/lib/commonjs/page-header/PageHeader.js +286 -0
- package/lib/commonjs/page-header/PageHeader.js.map +1 -0
- package/lib/commonjs/page-header/index.js +13 -0
- package/lib/commonjs/page-header/index.js.map +1 -0
- package/lib/commonjs/page-header/types.js +6 -0
- package/lib/commonjs/page-header/types.js.map +1 -0
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/index.web.js +1 -0
- package/lib/module/index.web.js.map +1 -1
- package/lib/module/page-header/PageHeader.js +281 -0
- package/lib/module/page-header/PageHeader.js.map +1 -0
- package/lib/module/page-header/index.js +4 -0
- package/lib/module/page-header/index.js.map +1 -0
- package/lib/module/page-header/types.js +4 -0
- package/lib/module/page-header/types.js.map +1 -0
- package/lib/typescript/commonjs/index.d.ts +1 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/index.web.d.ts +1 -0
- package/lib/typescript/commonjs/index.web.d.ts.map +1 -1
- package/lib/typescript/commonjs/page-header/PageHeader.d.ts +6 -0
- package/lib/typescript/commonjs/page-header/PageHeader.d.ts.map +1 -0
- package/lib/typescript/commonjs/page-header/index.d.ts +3 -0
- package/lib/typescript/commonjs/page-header/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/page-header/types.d.ts +55 -0
- package/lib/typescript/commonjs/page-header/types.d.ts.map +1 -0
- package/lib/typescript/module/index.d.ts +1 -0
- package/lib/typescript/module/index.d.ts.map +1 -1
- package/lib/typescript/module/index.web.d.ts +1 -0
- package/lib/typescript/module/index.web.d.ts.map +1 -1
- package/lib/typescript/module/page-header/PageHeader.d.ts +6 -0
- package/lib/typescript/module/page-header/PageHeader.d.ts.map +1 -0
- package/lib/typescript/module/page-header/index.d.ts +3 -0
- package/lib/typescript/module/page-header/index.d.ts.map +1 -0
- package/lib/typescript/module/page-header/types.d.ts +55 -0
- package/lib/typescript/module/page-header/types.d.ts.map +1 -0
- package/package.json +15 -1
- package/src/index.ts +1 -0
- package/src/index.web.ts +1 -0
- package/src/page-header/PageHeader.tsx +319 -0
- package/src/page-header/index.ts +3 -0
- package/src/page-header/types.ts +62 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { StyleProp, ViewStyle } from 'react-native';
|
|
3
|
+
import type { SharedValue } from 'react-native-reanimated';
|
|
4
|
+
/** Where the title sits: after the back button, or centred on the bar. */
|
|
5
|
+
export type PageHeaderTitleAlign = 'start' | 'center';
|
|
6
|
+
/**
|
|
7
|
+
* The bottom separator: `auto` fades it in once the page has scrolled past
|
|
8
|
+
* `scrollThreshold`, `always` draws it at rest, `none` never draws it.
|
|
9
|
+
*/
|
|
10
|
+
export type PageHeaderBorder = 'auto' | 'always' | 'none';
|
|
11
|
+
export interface PageHeaderProps {
|
|
12
|
+
/** A string renders as the heading; a node renders as-is (and owns its own semantics). */
|
|
13
|
+
title?: ReactNode;
|
|
14
|
+
/** A string renders as a secondary line under the title; a node renders as-is. */
|
|
15
|
+
subtitle?: ReactNode;
|
|
16
|
+
/** Default `start`. */
|
|
17
|
+
titleAlign?: PageHeaderTitleAlign;
|
|
18
|
+
/** The title's heading level. Default 1. */
|
|
19
|
+
headingLevel?: 1 | 2 | 3 | 4 | 5 | 6;
|
|
20
|
+
/**
|
|
21
|
+
* Renders the back button and is called when it is pressed. The header is
|
|
22
|
+
* router-agnostic: pass `router.back`, or your app's safe-back helper.
|
|
23
|
+
*/
|
|
24
|
+
onBack?: () => void;
|
|
25
|
+
/** The back button's accessible name. Default "Back". */
|
|
26
|
+
backLabel?: string;
|
|
27
|
+
/** Rendered after the back button, before the title (an avatar, a logo). */
|
|
28
|
+
leading?: ReactNode;
|
|
29
|
+
/** Rendered at the end of the bar, 10 apart — typically Bloom `Button`s. */
|
|
30
|
+
actions?: ReactNode;
|
|
31
|
+
/** Default `auto`. */
|
|
32
|
+
border?: PageHeaderBorder;
|
|
33
|
+
/**
|
|
34
|
+
* The bar's background, shadow and title fade in with scroll instead of
|
|
35
|
+
* showing at rest — for a header over media. The back button and actions
|
|
36
|
+
* stay visible (their own fill reads over any image).
|
|
37
|
+
*/
|
|
38
|
+
transparent?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* The scroll offset driving `border="auto"`, `transparent` and the shadow.
|
|
41
|
+
* Pass it from a Reanimated scroll handler on native or for any scroll
|
|
42
|
+
* container. Omitted on web, the header follows `window.scrollY`; omitted on
|
|
43
|
+
* native, the header stays at rest.
|
|
44
|
+
*/
|
|
45
|
+
scrollY?: SharedValue<number>;
|
|
46
|
+
/** The offset (px) over which border, background and shadow fade in. Default 20. */
|
|
47
|
+
scrollThreshold?: number;
|
|
48
|
+
/** Web only: pin the bar to the top of its scroll container. Default true. */
|
|
49
|
+
sticky?: boolean;
|
|
50
|
+
/** Pad the top by the safe-area inset. Default true on native, false on web. */
|
|
51
|
+
safeArea?: boolean;
|
|
52
|
+
style?: StyleProp<ViewStyle>;
|
|
53
|
+
testID?: string;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/page-header/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAE3D,0EAA0E;AAC1E,MAAM,MAAM,oBAAoB,GAAG,OAAO,GAAG,QAAQ,CAAC;AAEtD;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,CAAC;AAE1D,MAAM,WAAW,eAAe;IAC9B,0FAA0F;IAC1F,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,kFAAkF;IAClF,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,uBAAuB;IACvB,UAAU,CAAC,EAAE,oBAAoB,CAAC;IAClC,4CAA4C;IAC5C,YAAY,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAErC;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB,yDAAyD;IACzD,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,4EAA4E;IAC5E,OAAO,CAAC,EAAE,SAAS,CAAC;IACpB,4EAA4E;IAC5E,OAAO,CAAC,EAAE,SAAS,CAAC;IAEpB,sBAAsB;IACtB,MAAM,CAAC,EAAE,gBAAgB,CAAC;IAC1B;;;;OAIG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;;;OAKG;IACH,OAAO,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC9B,oFAAoF;IACpF,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB,8EAA8E;IAC9E,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,gFAAgF;IAChF,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oxy.so/bloom",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"packageManager": "bun@1.3.14",
|
|
5
5
|
"description": "Bloom UI — Oxy ecosystem component library for React Native + Expo + Web",
|
|
6
6
|
"main": "lib/commonjs/index.js",
|
|
@@ -590,6 +590,20 @@
|
|
|
590
590
|
"default": "./lib/commonjs/app-shell/index.js"
|
|
591
591
|
}
|
|
592
592
|
},
|
|
593
|
+
"./page-header": {
|
|
594
|
+
"react-native": {
|
|
595
|
+
"types": "./lib/typescript/module/page-header/index.d.ts",
|
|
596
|
+
"default": "./src/page-header/index.ts"
|
|
597
|
+
},
|
|
598
|
+
"import": {
|
|
599
|
+
"types": "./lib/typescript/module/page-header/index.d.ts",
|
|
600
|
+
"default": "./lib/module/page-header/index.js"
|
|
601
|
+
},
|
|
602
|
+
"require": {
|
|
603
|
+
"types": "./lib/typescript/commonjs/page-header/index.d.ts",
|
|
604
|
+
"default": "./lib/commonjs/page-header/index.js"
|
|
605
|
+
}
|
|
606
|
+
},
|
|
593
607
|
"./notification-center": {
|
|
594
608
|
"react-native": {
|
|
595
609
|
"types": "./lib/typescript/module/notification-center/index.d.ts",
|
package/src/index.ts
CHANGED
|
@@ -187,6 +187,7 @@ export * from './important-alerts-card';
|
|
|
187
187
|
export * from './patient-info-card';
|
|
188
188
|
export * from './sidebar';
|
|
189
189
|
export * from './app-shell';
|
|
190
|
+
export * from './page-header';
|
|
190
191
|
export * from './notification-center';
|
|
191
192
|
export * from './theme-toggle';
|
|
192
193
|
export * from './settings-modal';
|
package/src/index.web.ts
CHANGED
|
@@ -192,6 +192,7 @@ export * from './important-alerts-card';
|
|
|
192
192
|
export * from './patient-info-card';
|
|
193
193
|
export * from './sidebar';
|
|
194
194
|
export * from './app-shell';
|
|
195
|
+
export * from './page-header';
|
|
195
196
|
export * from './notification-center';
|
|
196
197
|
export * from './theme-toggle';
|
|
197
198
|
export * from './settings-modal';
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import React, { memo, useContext, useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Platform,
|
|
4
|
+
StyleSheet,
|
|
5
|
+
View,
|
|
6
|
+
useWindowDimensions,
|
|
7
|
+
type LayoutChangeEvent,
|
|
8
|
+
} from 'react-native';
|
|
9
|
+
import Animated, {
|
|
10
|
+
Extrapolation,
|
|
11
|
+
interpolate,
|
|
12
|
+
useAnimatedStyle,
|
|
13
|
+
useSharedValue,
|
|
14
|
+
} from 'react-native-reanimated';
|
|
15
|
+
import { SafeAreaInsetsContext } from 'react-native-safe-area-context';
|
|
16
|
+
|
|
17
|
+
import { Button } from '../button';
|
|
18
|
+
import { BUTTON_SHADOW, mixColor, resolveButtonRamps } from '../button/shared';
|
|
19
|
+
import { RiArrowLeftLine } from '../icons/remix';
|
|
20
|
+
import { BREAKPOINTS } from '../styles/breakpoints';
|
|
21
|
+
import { WEB_POSITION_STICKY, type WebCssStyle } from '../styles/web-view-style';
|
|
22
|
+
import { Z_INDEX } from '../styles/z-index';
|
|
23
|
+
import { useTheme } from '../theme/use-theme';
|
|
24
|
+
import { Text } from '../typography';
|
|
25
|
+
import type { PageHeaderProps } from './types';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* `PageHeader`: a screen's top bar — back button, title (+ subtitle), leading
|
|
29
|
+
* node and actions, composed from the vocabulary Bloom's template headers and
|
|
30
|
+
* the settings modal's compact header use:
|
|
31
|
+
*
|
|
32
|
+
* bar min-height 56, side inset 16 (below `sm`) / 24, gap 8
|
|
33
|
+
* back secondary medium icon button (36, pill, shadow-xs), RiArrowLeftLine 20
|
|
34
|
+
* start group gap 6 (template header `gap-1.5`)
|
|
35
|
+
* title headline-medium, text-primary, px 4 (template `px-1`), one line
|
|
36
|
+
* subtitle body-2-regular, text-secondary (neutral-500), one line
|
|
37
|
+
* actions gap 10 (template `gap-2.5`)
|
|
38
|
+
* background background/full — card / dark neutral-925
|
|
39
|
+
* separator 1px separator-border — neutral-200 / dark neutral-800
|
|
40
|
+
* shadow shadow-xs, fading in with scroll
|
|
41
|
+
*
|
|
42
|
+
* Scroll-linked, not timed: border (`auto`), background (`transparent`) and
|
|
43
|
+
* shadow (and, when `transparent`, the title) interpolate over `[0, scrollThreshold]` of `scrollY` — the caller's
|
|
44
|
+
* shared value, else `window.scrollY` on web. No press scale.
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
const BAR_HEIGHT = 56;
|
|
48
|
+
const INSET_COMPACT = 16;
|
|
49
|
+
const INSET_WIDE = 24;
|
|
50
|
+
const START_GAP = 6;
|
|
51
|
+
const ROW_GAP = 8;
|
|
52
|
+
const ACTIONS_GAP = 10;
|
|
53
|
+
const TITLE_PADDING = 4;
|
|
54
|
+
const DEFAULT_THRESHOLD = 20;
|
|
55
|
+
|
|
56
|
+
const NO_INSETS = { top: 0, right: 0, bottom: 0, left: 0 };
|
|
57
|
+
|
|
58
|
+
function PageHeaderComponent({
|
|
59
|
+
title,
|
|
60
|
+
subtitle,
|
|
61
|
+
titleAlign = 'start',
|
|
62
|
+
headingLevel = 1,
|
|
63
|
+
onBack,
|
|
64
|
+
backLabel = 'Back',
|
|
65
|
+
leading,
|
|
66
|
+
actions,
|
|
67
|
+
border = 'auto',
|
|
68
|
+
transparent = false,
|
|
69
|
+
scrollY: externalScrollY,
|
|
70
|
+
scrollThreshold = DEFAULT_THRESHOLD,
|
|
71
|
+
sticky = true,
|
|
72
|
+
safeArea,
|
|
73
|
+
style,
|
|
74
|
+
testID,
|
|
75
|
+
}: PageHeaderProps) {
|
|
76
|
+
const isWeb = Platform.OS === 'web';
|
|
77
|
+
const theme = useTheme();
|
|
78
|
+
const { width } = useWindowDimensions();
|
|
79
|
+
const insets = useContext(SafeAreaInsetsContext) ?? NO_INSETS;
|
|
80
|
+
const padTop = (safeArea ?? !isWeb) ? insets.top : 0;
|
|
81
|
+
const sideInset = width >= BREAKPOINTS.sm ? INSET_WIDE : INSET_COMPACT;
|
|
82
|
+
|
|
83
|
+
const paint = useMemo(() => {
|
|
84
|
+
const { neutral } = resolveButtonRamps(theme);
|
|
85
|
+
return theme.isDark
|
|
86
|
+
? {
|
|
87
|
+
background: mixColor(neutral[900], neutral[950], 0.4),
|
|
88
|
+
separator: neutral[800],
|
|
89
|
+
textSecondary: neutral[500],
|
|
90
|
+
shadow: BUTTON_SHADOW.dark,
|
|
91
|
+
}
|
|
92
|
+
: {
|
|
93
|
+
background: theme.colors.card,
|
|
94
|
+
separator: neutral[200],
|
|
95
|
+
textSecondary: neutral[500],
|
|
96
|
+
shadow: BUTTON_SHADOW.light,
|
|
97
|
+
};
|
|
98
|
+
}, [theme]);
|
|
99
|
+
|
|
100
|
+
const internalScrollY = useSharedValue(0);
|
|
101
|
+
const scrollY = externalScrollY ?? internalScrollY;
|
|
102
|
+
|
|
103
|
+
// Web fallback: the document is the scroll owner, as in the fleet headers.
|
|
104
|
+
useEffect(() => {
|
|
105
|
+
if (!isWeb || externalScrollY || typeof window === 'undefined') return undefined;
|
|
106
|
+
const onScroll = () => {
|
|
107
|
+
internalScrollY.value = window.scrollY;
|
|
108
|
+
};
|
|
109
|
+
onScroll();
|
|
110
|
+
window.addEventListener('scroll', onScroll, { passive: true });
|
|
111
|
+
return () => window.removeEventListener('scroll', onScroll);
|
|
112
|
+
}, [isWeb, externalScrollY, internalScrollY]);
|
|
113
|
+
|
|
114
|
+
const threshold = Math.max(1, scrollThreshold);
|
|
115
|
+
|
|
116
|
+
const shadowStyle = useAnimatedStyle(() => ({
|
|
117
|
+
opacity: interpolate(scrollY.value, [0, threshold], [0, 1], Extrapolation.CLAMP),
|
|
118
|
+
}), [scrollY, threshold]);
|
|
119
|
+
|
|
120
|
+
const backgroundStyle = useAnimatedStyle(() => ({
|
|
121
|
+
opacity: transparent
|
|
122
|
+
? interpolate(scrollY.value, [0, threshold], [0, 1], Extrapolation.CLAMP)
|
|
123
|
+
: 1,
|
|
124
|
+
}), [scrollY, threshold, transparent]);
|
|
125
|
+
|
|
126
|
+
// Over media the title would sit on the photo; it arrives with the bar.
|
|
127
|
+
const titleStyle = useAnimatedStyle(() => ({
|
|
128
|
+
opacity: transparent
|
|
129
|
+
? interpolate(scrollY.value, [0, threshold], [0, 1], Extrapolation.CLAMP)
|
|
130
|
+
: 1,
|
|
131
|
+
}), [scrollY, threshold, transparent]);
|
|
132
|
+
|
|
133
|
+
const borderStyle = useAnimatedStyle(() => ({
|
|
134
|
+
opacity:
|
|
135
|
+
border === 'always'
|
|
136
|
+
? 1
|
|
137
|
+
: border === 'none'
|
|
138
|
+
? 0
|
|
139
|
+
: interpolate(scrollY.value, [0, threshold], [0, 1], Extrapolation.CLAMP),
|
|
140
|
+
}), [scrollY, threshold, border]);
|
|
141
|
+
|
|
142
|
+
// Centred title: inset it by the wider side so it sits on the bar's centre
|
|
143
|
+
// whatever the two sides hold.
|
|
144
|
+
const [startWidth, setStartWidth] = useState(0);
|
|
145
|
+
const [endWidth, setEndWidth] = useState(0);
|
|
146
|
+
const centered = titleAlign === 'center';
|
|
147
|
+
const onStartLayout = (e: LayoutChangeEvent) => setStartWidth(e.nativeEvent.layout.width);
|
|
148
|
+
const onEndLayout = (e: LayoutChangeEvent) => setEndWidth(e.nativeEvent.layout.width);
|
|
149
|
+
const centerInset = Math.max(startWidth, endWidth) + ROW_GAP;
|
|
150
|
+
|
|
151
|
+
const titleBlock =
|
|
152
|
+
title != null || subtitle != null ? (
|
|
153
|
+
<Animated.View
|
|
154
|
+
style={[
|
|
155
|
+
styles.titleBlock,
|
|
156
|
+
centered ? styles.titleBlockCentered : styles.titleBlockStart,
|
|
157
|
+
titleStyle,
|
|
158
|
+
]}
|
|
159
|
+
testID={testID ? `${testID}-title-block` : undefined}
|
|
160
|
+
>
|
|
161
|
+
{typeof title === 'string' || typeof title === 'number' ? (
|
|
162
|
+
<Text
|
|
163
|
+
role="heading"
|
|
164
|
+
aria-level={headingLevel}
|
|
165
|
+
variant="headline-medium"
|
|
166
|
+
numberOfLines={1}
|
|
167
|
+
style={{ color: theme.colors.text, textAlign: centered ? 'center' : 'left' }}
|
|
168
|
+
testID={testID ? `${testID}-title` : undefined}
|
|
169
|
+
>
|
|
170
|
+
{title}
|
|
171
|
+
</Text>
|
|
172
|
+
) : (
|
|
173
|
+
title
|
|
174
|
+
)}
|
|
175
|
+
{typeof subtitle === 'string' || typeof subtitle === 'number' ? (
|
|
176
|
+
<Text
|
|
177
|
+
variant="body-2-regular"
|
|
178
|
+
numberOfLines={1}
|
|
179
|
+
style={{ color: paint.textSecondary, textAlign: centered ? 'center' : 'left' }}
|
|
180
|
+
testID={testID ? `${testID}-subtitle` : undefined}
|
|
181
|
+
>
|
|
182
|
+
{subtitle}
|
|
183
|
+
</Text>
|
|
184
|
+
) : (
|
|
185
|
+
subtitle
|
|
186
|
+
)}
|
|
187
|
+
</Animated.View>
|
|
188
|
+
) : null;
|
|
189
|
+
|
|
190
|
+
const containerWeb: WebCssStyle | null =
|
|
191
|
+
isWeb && sticky ? { position: WEB_POSITION_STICKY, top: 0, zIndex: Z_INDEX.floating } : null;
|
|
192
|
+
|
|
193
|
+
return (
|
|
194
|
+
<View
|
|
195
|
+
testID={testID}
|
|
196
|
+
style={[styles.container, { paddingTop: padTop }, containerWeb, style]}
|
|
197
|
+
>
|
|
198
|
+
<Animated.View
|
|
199
|
+
pointerEvents="none"
|
|
200
|
+
style={[StyleSheet.absoluteFill, { boxShadow: paint.shadow }, shadowStyle]}
|
|
201
|
+
testID={testID ? `${testID}-shadow` : undefined}
|
|
202
|
+
/>
|
|
203
|
+
<Animated.View
|
|
204
|
+
pointerEvents="none"
|
|
205
|
+
style={[StyleSheet.absoluteFill, { backgroundColor: paint.background }, backgroundStyle]}
|
|
206
|
+
testID={testID ? `${testID}-background` : undefined}
|
|
207
|
+
/>
|
|
208
|
+
<Animated.View
|
|
209
|
+
pointerEvents="none"
|
|
210
|
+
style={[styles.border, { backgroundColor: paint.separator }, borderStyle]}
|
|
211
|
+
testID={testID ? `${testID}-border` : undefined}
|
|
212
|
+
/>
|
|
213
|
+
<View
|
|
214
|
+
style={[styles.bar, { paddingLeft: sideInset, paddingRight: sideInset }]}
|
|
215
|
+
testID={testID ? `${testID}-bar` : undefined}
|
|
216
|
+
>
|
|
217
|
+
<View
|
|
218
|
+
style={[styles.start, !centered && styles.startFill]}
|
|
219
|
+
onLayout={centered ? onStartLayout : undefined}
|
|
220
|
+
testID={testID ? `${testID}-start` : undefined}
|
|
221
|
+
>
|
|
222
|
+
{onBack ? (
|
|
223
|
+
<Button
|
|
224
|
+
variant="secondary"
|
|
225
|
+
size="medium"
|
|
226
|
+
iconOnly
|
|
227
|
+
leadingIcon={RiArrowLeftLine}
|
|
228
|
+
accessibilityLabel={backLabel}
|
|
229
|
+
onPress={onBack}
|
|
230
|
+
testID={testID ? `${testID}-back` : undefined}
|
|
231
|
+
/>
|
|
232
|
+
) : null}
|
|
233
|
+
{leading}
|
|
234
|
+
{centered ? null : titleBlock}
|
|
235
|
+
</View>
|
|
236
|
+
{centered ? <View style={styles.spacer} /> : null}
|
|
237
|
+
{actions ? (
|
|
238
|
+
<View
|
|
239
|
+
style={styles.actions}
|
|
240
|
+
onLayout={centered ? onEndLayout : undefined}
|
|
241
|
+
testID={testID ? `${testID}-actions` : undefined}
|
|
242
|
+
>
|
|
243
|
+
{actions}
|
|
244
|
+
</View>
|
|
245
|
+
) : null}
|
|
246
|
+
{centered && titleBlock ? (
|
|
247
|
+
<View
|
|
248
|
+
pointerEvents="box-none"
|
|
249
|
+
style={[styles.centerSlot, { left: sideInset + centerInset, right: sideInset + centerInset }]}
|
|
250
|
+
testID={testID ? `${testID}-center` : undefined}
|
|
251
|
+
>
|
|
252
|
+
{titleBlock}
|
|
253
|
+
</View>
|
|
254
|
+
) : null}
|
|
255
|
+
</View>
|
|
256
|
+
</View>
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const styles = StyleSheet.create({
|
|
261
|
+
container: {
|
|
262
|
+
width: '100%',
|
|
263
|
+
position: 'relative',
|
|
264
|
+
},
|
|
265
|
+
border: {
|
|
266
|
+
position: 'absolute',
|
|
267
|
+
left: 0,
|
|
268
|
+
right: 0,
|
|
269
|
+
bottom: 0,
|
|
270
|
+
height: 1,
|
|
271
|
+
},
|
|
272
|
+
bar: {
|
|
273
|
+
minHeight: BAR_HEIGHT,
|
|
274
|
+
flexDirection: 'row',
|
|
275
|
+
alignItems: 'center',
|
|
276
|
+
gap: ROW_GAP,
|
|
277
|
+
paddingTop: 8,
|
|
278
|
+
paddingBottom: 8,
|
|
279
|
+
},
|
|
280
|
+
start: {
|
|
281
|
+
flexDirection: 'row',
|
|
282
|
+
alignItems: 'center',
|
|
283
|
+
gap: START_GAP,
|
|
284
|
+
minWidth: 0,
|
|
285
|
+
},
|
|
286
|
+
startFill: {
|
|
287
|
+
flex: 1,
|
|
288
|
+
},
|
|
289
|
+
spacer: {
|
|
290
|
+
flex: 1,
|
|
291
|
+
},
|
|
292
|
+
titleBlock: {
|
|
293
|
+
minWidth: 0,
|
|
294
|
+
paddingLeft: TITLE_PADDING,
|
|
295
|
+
paddingRight: TITLE_PADDING,
|
|
296
|
+
},
|
|
297
|
+
titleBlockStart: {
|
|
298
|
+
flex: 1,
|
|
299
|
+
},
|
|
300
|
+
titleBlockCentered: {
|
|
301
|
+
alignItems: 'center',
|
|
302
|
+
},
|
|
303
|
+
centerSlot: {
|
|
304
|
+
position: 'absolute',
|
|
305
|
+
top: 0,
|
|
306
|
+
bottom: 0,
|
|
307
|
+
justifyContent: 'center',
|
|
308
|
+
},
|
|
309
|
+
actions: {
|
|
310
|
+
flexDirection: 'row',
|
|
311
|
+
alignItems: 'center',
|
|
312
|
+
justifyContent: 'flex-end',
|
|
313
|
+
gap: ACTIONS_GAP,
|
|
314
|
+
flexShrink: 0,
|
|
315
|
+
},
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
export const PageHeader = memo(PageHeaderComponent);
|
|
319
|
+
PageHeader.displayName = 'PageHeader';
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { StyleProp, ViewStyle } from 'react-native';
|
|
3
|
+
import type { SharedValue } from 'react-native-reanimated';
|
|
4
|
+
|
|
5
|
+
/** Where the title sits: after the back button, or centred on the bar. */
|
|
6
|
+
export type PageHeaderTitleAlign = 'start' | 'center';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The bottom separator: `auto` fades it in once the page has scrolled past
|
|
10
|
+
* `scrollThreshold`, `always` draws it at rest, `none` never draws it.
|
|
11
|
+
*/
|
|
12
|
+
export type PageHeaderBorder = 'auto' | 'always' | 'none';
|
|
13
|
+
|
|
14
|
+
export interface PageHeaderProps {
|
|
15
|
+
/** A string renders as the heading; a node renders as-is (and owns its own semantics). */
|
|
16
|
+
title?: ReactNode;
|
|
17
|
+
/** A string renders as a secondary line under the title; a node renders as-is. */
|
|
18
|
+
subtitle?: ReactNode;
|
|
19
|
+
/** Default `start`. */
|
|
20
|
+
titleAlign?: PageHeaderTitleAlign;
|
|
21
|
+
/** The title's heading level. Default 1. */
|
|
22
|
+
headingLevel?: 1 | 2 | 3 | 4 | 5 | 6;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Renders the back button and is called when it is pressed. The header is
|
|
26
|
+
* router-agnostic: pass `router.back`, or your app's safe-back helper.
|
|
27
|
+
*/
|
|
28
|
+
onBack?: () => void;
|
|
29
|
+
/** The back button's accessible name. Default "Back". */
|
|
30
|
+
backLabel?: string;
|
|
31
|
+
|
|
32
|
+
/** Rendered after the back button, before the title (an avatar, a logo). */
|
|
33
|
+
leading?: ReactNode;
|
|
34
|
+
/** Rendered at the end of the bar, 10 apart — typically Bloom `Button`s. */
|
|
35
|
+
actions?: ReactNode;
|
|
36
|
+
|
|
37
|
+
/** Default `auto`. */
|
|
38
|
+
border?: PageHeaderBorder;
|
|
39
|
+
/**
|
|
40
|
+
* The bar's background, shadow and title fade in with scroll instead of
|
|
41
|
+
* showing at rest — for a header over media. The back button and actions
|
|
42
|
+
* stay visible (their own fill reads over any image).
|
|
43
|
+
*/
|
|
44
|
+
transparent?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* The scroll offset driving `border="auto"`, `transparent` and the shadow.
|
|
47
|
+
* Pass it from a Reanimated scroll handler on native or for any scroll
|
|
48
|
+
* container. Omitted on web, the header follows `window.scrollY`; omitted on
|
|
49
|
+
* native, the header stays at rest.
|
|
50
|
+
*/
|
|
51
|
+
scrollY?: SharedValue<number>;
|
|
52
|
+
/** The offset (px) over which border, background and shadow fade in. Default 20. */
|
|
53
|
+
scrollThreshold?: number;
|
|
54
|
+
|
|
55
|
+
/** Web only: pin the bar to the top of its scroll container. Default true. */
|
|
56
|
+
sticky?: boolean;
|
|
57
|
+
/** Pad the top by the safe-area inset. Default true on native, false on web. */
|
|
58
|
+
safeArea?: boolean;
|
|
59
|
+
|
|
60
|
+
style?: StyleProp<ViewStyle>;
|
|
61
|
+
testID?: string;
|
|
62
|
+
}
|