@momo-kits/foundation 0.169.16-beta.12 → 0.169.16-beta.13
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/Application/Components/HeaderAnimated.tsx +33 -9
- package/Application/Components/HeaderExtendHeader.tsx +26 -14
- package/Application/__tests__/headerLayout.test.ts +113 -0
- package/Application/headerLayout.ts +114 -30
- package/Application/types.header.ts +7 -1
- package/Layout/Screen.tsx +7 -3
- package/Layout/layoutMetrics.ts +2 -2
- package/Layout/screenContent.tsx +4 -10
- package/Layout/screenHeader.tsx +26 -31
- package/Layout/screenTypes.ts +3 -3
- package/Layout/useHeaderBarOptions.ts +54 -0
- package/package.json +1 -1
|
@@ -12,6 +12,8 @@ import { Colors } from '../../Consts';
|
|
|
12
12
|
import { useNormalizedSharedValue } from '../hooks';
|
|
13
13
|
import { HeaderBarMetrics, useHeaderLayout } from '../headerLayout';
|
|
14
14
|
|
|
15
|
+
const TRANSPARENT_ALPHA = '00';
|
|
16
|
+
|
|
15
17
|
const ASPECT_RATIOS: Record<
|
|
16
18
|
NonNullable<HeaderAnimatedProps['aspectRatio']>,
|
|
17
19
|
number
|
|
@@ -21,10 +23,30 @@ const ASPECT_RATIOS: Record<
|
|
|
21
23
|
'1/1': 1 / 1,
|
|
22
24
|
};
|
|
23
25
|
|
|
26
|
+
/**
|
|
27
|
+
* Side fill colors behind the centered banner: `gradientColors` (one color fills
|
|
28
|
+
* solid, as LinearGradient needs two), else `backgroundColor` fading to transparent.
|
|
29
|
+
*/
|
|
30
|
+
const getBannerGradientColors = (
|
|
31
|
+
gradientColors?: string[],
|
|
32
|
+
backgroundColor?: string,
|
|
33
|
+
) => {
|
|
34
|
+
if (gradientColors?.length === 1) {
|
|
35
|
+
return [gradientColors[0], gradientColors[0]];
|
|
36
|
+
}
|
|
37
|
+
if (gradientColors?.length) {
|
|
38
|
+
return gradientColors;
|
|
39
|
+
}
|
|
40
|
+
if (backgroundColor) {
|
|
41
|
+
return [backgroundColor, backgroundColor + TRANSPARENT_ALPHA];
|
|
42
|
+
}
|
|
43
|
+
return undefined;
|
|
44
|
+
};
|
|
45
|
+
|
|
24
46
|
/**
|
|
25
47
|
* Parallax header image (or `children`): stretches when pulled down and fades out
|
|
26
|
-
* as the content scrolls up. Wide windows and the iPhone Duo inner display
|
|
27
|
-
* it at phone size
|
|
48
|
+
* as the content scrolls up. Wide windows and the iPhone Duo inner display center
|
|
49
|
+
* it at phone size × 1.2 over the side gradient.
|
|
28
50
|
*/
|
|
29
51
|
const HeaderAnimated: React.FC<HeaderAnimatedProps> = ({
|
|
30
52
|
animatedValue,
|
|
@@ -32,11 +54,16 @@ const HeaderAnimated: React.FC<HeaderAnimatedProps> = ({
|
|
|
32
54
|
useScale = true,
|
|
33
55
|
aspectRatio = '16/9',
|
|
34
56
|
bannerBackgroundColor,
|
|
57
|
+
bannerGradientColors,
|
|
35
58
|
children,
|
|
36
59
|
}) => {
|
|
37
60
|
const sharedValue = useNormalizedSharedValue(animatedValue);
|
|
38
61
|
const { isBannerCentered, bannerWidth } = useHeaderLayout();
|
|
39
62
|
const ratio = ASPECT_RATIOS[aspectRatio];
|
|
63
|
+
const sideColors = getBannerGradientColors(
|
|
64
|
+
bannerGradientColors,
|
|
65
|
+
bannerBackgroundColor,
|
|
66
|
+
);
|
|
40
67
|
const animatedStyle = useAnimatedStyle(() => {
|
|
41
68
|
let scale = 1;
|
|
42
69
|
if (useScale) {
|
|
@@ -88,13 +115,10 @@ const HeaderAnimated: React.FC<HeaderAnimatedProps> = ({
|
|
|
88
115
|
<Animated.View
|
|
89
116
|
style={[styles.container, { height: bannerWidth / ratio }, animatedStyle]}
|
|
90
117
|
>
|
|
91
|
-
{
|
|
92
|
-
<LinearGradient
|
|
93
|
-
colors={[bannerBackgroundColor, bannerBackgroundColor + '00']}
|
|
94
|
-
style={StyleSheet.absoluteFill}
|
|
95
|
-
/>
|
|
118
|
+
{sideColors && (
|
|
119
|
+
<LinearGradient colors={sideColors} style={StyleSheet.absoluteFill} />
|
|
96
120
|
)}
|
|
97
|
-
<View style={styles.
|
|
121
|
+
<View style={styles.centeredBanner}>{content}</View>
|
|
98
122
|
</Animated.View>
|
|
99
123
|
);
|
|
100
124
|
};
|
|
@@ -110,7 +134,7 @@ const styles = StyleSheet.create({
|
|
|
110
134
|
alignSelf: 'center',
|
|
111
135
|
},
|
|
112
136
|
full: { width: '100%', height: '100%' },
|
|
113
|
-
|
|
137
|
+
centeredBanner: {
|
|
114
138
|
width: HeaderBarMetrics.bannerWidth,
|
|
115
139
|
height: '100%',
|
|
116
140
|
alignSelf: 'center',
|
|
@@ -17,7 +17,6 @@ import BackgroundImageView from './BackgroundImageView';
|
|
|
17
17
|
import { type AnimatedCompatValue } from '../utils';
|
|
18
18
|
import { useNormalizedSharedValue } from '../hooks';
|
|
19
19
|
import { useScreenLayout } from '../../Layout';
|
|
20
|
-
import { HeaderMetrics } from '../../Layout/utils';
|
|
21
20
|
import {
|
|
22
21
|
HeaderBarMetrics,
|
|
23
22
|
type HeaderContentLayout,
|
|
@@ -28,10 +27,14 @@ import { useHeaderRightWidth } from './useHeaderRightWidth';
|
|
|
28
27
|
const { buttonSize, pillWidth, sidePadding, titleGap } = HeaderBarMetrics;
|
|
29
28
|
const SCREEN_PADDING = sidePadding;
|
|
30
29
|
const TOOLKIT_WIDTH = pillWidth + sidePadding;
|
|
30
|
+
// the iPhone Duo side bar keeps the content search size: 36pt plus its 8pt margins
|
|
31
|
+
const DUO_SEARCH_ROW_HEIGHT = 52;
|
|
32
|
+
// the extended header without search grows this much past the bar until scrolled
|
|
33
|
+
const EXTENDED_HEIGHT_EXTRA = 52;
|
|
31
34
|
|
|
32
35
|
/**
|
|
33
36
|
* Extended header background: a gradient that collapses on scroll and, with
|
|
34
|
-
* `inputSearchProps`, a
|
|
37
|
+
* `inputSearchProps`, a window-wide search that slides into the bar beside back/toolkit.
|
|
35
38
|
*/
|
|
36
39
|
const HeaderExtendHeader: React.FC<{
|
|
37
40
|
headerType?: HeaderType;
|
|
@@ -44,6 +47,10 @@ const HeaderExtendHeader: React.FC<{
|
|
|
44
47
|
useShadowHeader?: boolean;
|
|
45
48
|
gradientColor?: string;
|
|
46
49
|
headerBackground?: string;
|
|
50
|
+
/**
|
|
51
|
+
* `stretch` keeps the collapsed search beside back and the right cluster in the
|
|
52
|
+
* 600pt frame; the expanded search row spans the window with either layout.
|
|
53
|
+
*/
|
|
47
54
|
contentLayout?: HeaderContentLayout;
|
|
48
55
|
}> = ({
|
|
49
56
|
headerType = 'default',
|
|
@@ -64,7 +71,7 @@ const HeaderExtendHeader: React.FC<{
|
|
|
64
71
|
const headerBackground = customBackground ?? theme.assets?.headerBackground;
|
|
65
72
|
const layout = useScreenLayout();
|
|
66
73
|
const headerLayout = useHeaderLayout(contentLayout);
|
|
67
|
-
//
|
|
74
|
+
// collapsed into the bar, the search follows back and the right cluster into the frame
|
|
68
75
|
const frameShift = headerLayout.frameInset - sidePadding;
|
|
69
76
|
|
|
70
77
|
const backLeft = buttonSize + sidePadding + titleGap;
|
|
@@ -73,22 +80,27 @@ const HeaderExtendHeader: React.FC<{
|
|
|
73
80
|
const measuredRightWidth = useHeaderRightWidth() ?? TOOLKIT_WIDTH;
|
|
74
81
|
const defaultRightWidth = layout.sideBar ? 0 : measuredRightWidth;
|
|
75
82
|
const headerRightWidth = customHeaderRightWidth ?? defaultRightWidth;
|
|
76
|
-
const contentLeft = layout.insetLeft + SCREEN_PADDING
|
|
77
|
-
const contentRight = layout.insetLeft + layout.contentWidth
|
|
83
|
+
const contentLeft = layout.insetLeft + SCREEN_PADDING;
|
|
84
|
+
const contentRight = layout.insetLeft + layout.contentWidth;
|
|
78
85
|
// collapsed on the status bar row, the search stays between its clusters
|
|
79
86
|
const clearanceLeft = layout.statusBarClearance?.left ?? 0;
|
|
80
87
|
const clearanceRight = layout.statusBarClearance?.right ?? 0;
|
|
81
|
-
const searchLeft = leftPosition + clearanceLeft
|
|
82
|
-
const collapsedLeft = layout.insetLeft + searchLeft;
|
|
83
|
-
const
|
|
88
|
+
const searchLeft = leftPosition + clearanceLeft;
|
|
89
|
+
const collapsedLeft = layout.insetLeft + searchLeft + frameShift;
|
|
90
|
+
const barRight = contentRight - clearanceRight - frameShift;
|
|
91
|
+
const collapsedRight = barRight - headerRightWidth;
|
|
84
92
|
const searchWidth = contentRight - contentLeft - SCREEN_PADDING;
|
|
85
93
|
const collapsedSearchWidth = collapsedRight - collapsedLeft - SCREEN_PADDING;
|
|
86
|
-
// a row taller than barHeight (iPhone Duo) centers the collapsed search on the title
|
|
87
|
-
const titleRowHeight = layout.headerHeight - layout.headerStatusBarHeight;
|
|
88
|
-
const collapsedRaise = (titleRowHeight - HeaderMetrics.barHeight) / 2;
|
|
89
|
-
|
|
90
94
|
// the iPhone Duo side bar keeps the content search size
|
|
91
95
|
const searchSize = layout.sideBar ? 'default' : 'header';
|
|
96
|
+
// expanded search row under the bar: the search plus its vertical margins
|
|
97
|
+
let searchRowHeight = HeaderBarMetrics.searchBarHeight;
|
|
98
|
+
if (layout.sideBar) {
|
|
99
|
+
searchRowHeight = DUO_SEARCH_ROW_HEIGHT;
|
|
100
|
+
}
|
|
101
|
+
// a row taller than the search row (iPhone Duo) centers the collapsed search on the title
|
|
102
|
+
const titleRowHeight = heightHeader - layout.headerStatusBarHeight;
|
|
103
|
+
const collapsedRaise = (titleRowHeight - searchRowHeight) / 2;
|
|
92
104
|
|
|
93
105
|
let useShadowHeader = useShadowHeaderProp;
|
|
94
106
|
if (inputSearchProps && Platform.OS === 'android') {
|
|
@@ -101,7 +113,7 @@ const HeaderExtendHeader: React.FC<{
|
|
|
101
113
|
height: interpolate(
|
|
102
114
|
sharedValue.value,
|
|
103
115
|
[0, 100],
|
|
104
|
-
[heightHeader +
|
|
116
|
+
[heightHeader + searchRowHeight, heightHeader],
|
|
105
117
|
Extrapolation.CLAMP,
|
|
106
118
|
),
|
|
107
119
|
}));
|
|
@@ -154,7 +166,7 @@ const HeaderExtendHeader: React.FC<{
|
|
|
154
166
|
height: interpolate(
|
|
155
167
|
sharedValue.value,
|
|
156
168
|
[0, 100],
|
|
157
|
-
[heightHeader +
|
|
169
|
+
[heightHeader + EXTENDED_HEIGHT_EXTRA, heightHeader],
|
|
158
170
|
Extrapolation.CLAMP,
|
|
159
171
|
),
|
|
160
172
|
}));
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getHeaderFrameOptions,
|
|
3
|
+
getHeaderLayout,
|
|
4
|
+
getSearchHeaderHeight,
|
|
5
|
+
HeaderBarMetrics,
|
|
6
|
+
} from '../headerLayout';
|
|
7
|
+
|
|
8
|
+
const PHONE = { width: 375, height: 812 };
|
|
9
|
+
const FOLD_INNER = { width: 760, height: 840 };
|
|
10
|
+
const DUO_INNER = { width: 932, height: 678 };
|
|
11
|
+
|
|
12
|
+
describe('getHeaderLayout', () => {
|
|
13
|
+
it('keeps the phone row at the bar edges with a full-width banner', () => {
|
|
14
|
+
const layout = getHeaderLayout({ ...PHONE, isDuo: false });
|
|
15
|
+
expect(layout.isWide).toBe(false);
|
|
16
|
+
expect(layout.isBannerCentered).toBe(false);
|
|
17
|
+
expect(layout.bannerScale).toBe(1);
|
|
18
|
+
expect(layout.frameInset).toBe(HeaderBarMetrics.sidePadding);
|
|
19
|
+
expect(layout.frameWidth).toBe(351);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('keeps the grid row at the bar edges on a 760 window', () => {
|
|
23
|
+
const layout = getHeaderLayout({ ...FOLD_INNER, isDuo: false });
|
|
24
|
+
expect(layout.isWide).toBe(true);
|
|
25
|
+
expect(layout.frameInset).toBe(HeaderBarMetrics.sidePadding);
|
|
26
|
+
expect(layout.frameWidth).toBe(736);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('centers the stretch row in the 600 frame on a 760 window', () => {
|
|
30
|
+
const input = { ...FOLD_INNER, isDuo: false };
|
|
31
|
+
const layout = getHeaderLayout({ ...input, contentLayout: 'stretch' });
|
|
32
|
+
expect(layout.frameInset).toBe(80);
|
|
33
|
+
expect(layout.frameWidth).toBe(600);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('scales the centered banner to 450 on a 760 window', () => {
|
|
37
|
+
const layout = getHeaderLayout({ ...FOLD_INNER, isDuo: false });
|
|
38
|
+
expect(layout.isBannerCentered).toBe(true);
|
|
39
|
+
expect(layout.bannerScale).toBe(1.2);
|
|
40
|
+
expect(layout.bannerWidth).toBe(450);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('centers the banner on the iPhone Duo inner display, without the frame', () => {
|
|
44
|
+
const input = { ...DUO_INNER, isDuo: true };
|
|
45
|
+
const layout = getHeaderLayout({ ...input, contentLayout: 'stretch' });
|
|
46
|
+
expect(layout.isWide).toBe(false);
|
|
47
|
+
expect(layout.isBannerCentered).toBe(true);
|
|
48
|
+
expect(layout.bannerScale).toBe(1.2);
|
|
49
|
+
expect(layout.frameInset).toBe(HeaderBarMetrics.sidePadding);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe('getSearchHeaderHeight', () => {
|
|
54
|
+
it('grows a 48 bar row to the 56 search row', () => {
|
|
55
|
+
expect(getSearchHeaderHeight(48 + 47, 47)).toBe(56 + 47);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('keeps a row taller than the search row', () => {
|
|
59
|
+
expect(getSearchHeaderHeight(72, 0)).toBe(72);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe('getHeaderFrameOptions', () => {
|
|
64
|
+
const NO_EDGE = { left: 0, right: 0 };
|
|
65
|
+
const DUO_EDGE = { left: 60, right: 90 };
|
|
66
|
+
const frameInput = (contentLayout?: 'grid' | 'stretch') => {
|
|
67
|
+
const layout = getHeaderLayout({
|
|
68
|
+
...FOLD_INNER,
|
|
69
|
+
isDuo: false,
|
|
70
|
+
contentLayout,
|
|
71
|
+
});
|
|
72
|
+
return { layout, isDuo: false, headerMargin: 0, edgePadding: NO_EDGE };
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
it('leaves the options alone when contentLayout is unset', () => {
|
|
76
|
+
expect(getHeaderFrameOptions(frameInput())).toBeUndefined();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('pulls the stretch row into the 600 frame on a 760 window', () => {
|
|
80
|
+
const options = getHeaderFrameOptions({
|
|
81
|
+
...frameInput('stretch'),
|
|
82
|
+
contentLayout: 'stretch',
|
|
83
|
+
});
|
|
84
|
+
expect(options?.headerLeftContainerStyle).toEqual({ paddingLeft: 68 });
|
|
85
|
+
expect(options?.headerRightContainerStyle).toEqual({ paddingRight: 68 });
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('resets grid to the bar edges, so a former stretch frame does not stay', () => {
|
|
89
|
+
const options = getHeaderFrameOptions({
|
|
90
|
+
...frameInput('grid'),
|
|
91
|
+
contentLayout: 'grid',
|
|
92
|
+
});
|
|
93
|
+
expect(options?.headerLeftContainerStyle).toEqual({ paddingLeft: 0 });
|
|
94
|
+
expect(options?.headerRightContainerStyle).toEqual({ paddingRight: 0 });
|
|
95
|
+
expect(options?.headerTitleContainerStyle).toMatchObject({
|
|
96
|
+
left: HeaderBarMetrics.titleGap,
|
|
97
|
+
});
|
|
98
|
+
expect(options?.headerTitleContainerStyle).not.toHaveProperty('maxWidth');
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('keeps the iPhone Duo status bar clearance with stretch', () => {
|
|
102
|
+
const layout = getHeaderLayout({ ...DUO_INNER, isDuo: true });
|
|
103
|
+
const options = getHeaderFrameOptions({
|
|
104
|
+
layout,
|
|
105
|
+
isDuo: true,
|
|
106
|
+
headerMargin: 0,
|
|
107
|
+
edgePadding: DUO_EDGE,
|
|
108
|
+
contentLayout: 'stretch',
|
|
109
|
+
});
|
|
110
|
+
expect(options?.headerLeftContainerStyle).toEqual({ paddingLeft: 60 });
|
|
111
|
+
expect(options?.headerRightContainerStyle).toEqual({ paddingRight: 90 });
|
|
112
|
+
});
|
|
113
|
+
});
|
|
@@ -2,14 +2,18 @@ import { useMemo } from 'react';
|
|
|
2
2
|
import { useWindowDimensions, type ViewStyle } from 'react-native';
|
|
3
3
|
import type { StackNavigationOptions } from '@react-navigation/stack';
|
|
4
4
|
import { Spacing } from '../Consts';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
getHeaderMargin,
|
|
7
|
+
getHeaderRowOptions,
|
|
8
|
+
useScreenLayout,
|
|
9
|
+
} from '../Layout/utils';
|
|
6
10
|
import { FOLDABLE_MIN_WIDTH } from './modalLayout';
|
|
7
11
|
import { isIPhoneDuo } from './utils';
|
|
8
12
|
|
|
9
13
|
// Top navigation spec, shared with the Compose / SwiftUI kits
|
|
10
14
|
const HEADER_FRAME_MAX_WIDTH = 600;
|
|
11
|
-
//
|
|
12
|
-
const
|
|
15
|
+
// banner image on wide windows and the iPhone Duo inner display: phone (375) × 1.2
|
|
16
|
+
const WIDE_BANNER_SCALE = 1.2;
|
|
13
17
|
|
|
14
18
|
/**
|
|
15
19
|
* Top navigation geometry on every device
|
|
@@ -17,10 +21,11 @@ const IS_STRETCH_FRAME_ENABLED = false;
|
|
|
17
21
|
* - pillWidth / pillHeight: help center | home capsule
|
|
18
22
|
* - clusterWidth: shortcut, gap and pill on the right of the bar
|
|
19
23
|
* - searchHeight: search field inside the header
|
|
24
|
+
* - searchBarHeight: header row holding the search, taller than the plain bar
|
|
20
25
|
* - titleGap: space between back and the title, and the title and the right cluster
|
|
21
26
|
* - sidePadding: bar edge to back and to the right cluster
|
|
22
27
|
* - gradientHeight: header gradient, kept at the phone height on wide windows
|
|
23
|
-
* - bannerWidth: animated banner image
|
|
28
|
+
* - bannerWidth: animated banner image on wide windows, centered (phone × 1.2)
|
|
24
29
|
*/
|
|
25
30
|
const HeaderBarMetrics = {
|
|
26
31
|
buttonSize: 32,
|
|
@@ -28,17 +33,17 @@ const HeaderBarMetrics = {
|
|
|
28
33
|
pillWidth: 72,
|
|
29
34
|
pillHeight: 32,
|
|
30
35
|
clusterWidth: 112,
|
|
31
|
-
searchHeight:
|
|
36
|
+
searchHeight: 40,
|
|
37
|
+
searchBarHeight: 56,
|
|
32
38
|
titleGap: Spacing.S,
|
|
33
39
|
sidePadding: Spacing.M,
|
|
34
40
|
gradientHeight: 154,
|
|
35
|
-
bannerWidth:
|
|
41
|
+
bannerWidth: 450,
|
|
36
42
|
};
|
|
37
43
|
|
|
38
44
|
/**
|
|
39
45
|
* `grid` keeps the header row at the bar edges, `stretch` centers it in a 600pt
|
|
40
|
-
* frame on wide windows
|
|
41
|
-
* bar always span the window.
|
|
46
|
+
* frame on wide windows. Background, status bar and the search always span the window.
|
|
42
47
|
*/
|
|
43
48
|
type HeaderContentLayout = 'grid' | 'stretch';
|
|
44
49
|
|
|
@@ -53,6 +58,10 @@ type HeaderLayout = typeof HeaderBarMetrics & {
|
|
|
53
58
|
* inner display, portrait and landscape.
|
|
54
59
|
*/
|
|
55
60
|
isBannerCentered: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Banner size against the phone banner: `WIDE_BANNER_SCALE` when centered, else 1.
|
|
63
|
+
*/
|
|
64
|
+
bannerScale: number;
|
|
56
65
|
/**
|
|
57
66
|
* Window edge to back and to the right cluster: `sidePadding`, or centering the
|
|
58
67
|
* row in the 600pt frame with `stretch` on a wide window.
|
|
@@ -71,6 +80,18 @@ type HeaderLayoutInput = {
|
|
|
71
80
|
contentLayout?: HeaderContentLayout;
|
|
72
81
|
};
|
|
73
82
|
|
|
83
|
+
type EdgePadding = { left: number; right: number };
|
|
84
|
+
|
|
85
|
+
type HeaderFrameInput = {
|
|
86
|
+
layout: HeaderLayout;
|
|
87
|
+
isDuo: boolean;
|
|
88
|
+
// side margin @react-navigation/elements already adds to the row
|
|
89
|
+
headerMargin: number;
|
|
90
|
+
// padding of the plain row containers: the iPhone Duo status bar clearance, else 0
|
|
91
|
+
edgePadding: EdgePadding;
|
|
92
|
+
contentLayout?: HeaderContentLayout;
|
|
93
|
+
};
|
|
94
|
+
|
|
74
95
|
/**
|
|
75
96
|
* Header geometry for a window, pure so it can be tested without a device.
|
|
76
97
|
*/
|
|
@@ -84,15 +105,19 @@ const getHeaderLayout = ({
|
|
|
84
105
|
const isLargeWindow = Math.min(width, height) >= FOLDABLE_MIN_WIDTH;
|
|
85
106
|
const isWide = !isDuo && isLargeWindow;
|
|
86
107
|
let frameInset = sidePadding;
|
|
87
|
-
|
|
88
|
-
if (isWide && isStretch) {
|
|
108
|
+
if (isWide && contentLayout === 'stretch') {
|
|
89
109
|
const centered = (width - HEADER_FRAME_MAX_WIDTH) / 2;
|
|
90
110
|
frameInset = Math.max(sidePadding, centered);
|
|
91
111
|
}
|
|
112
|
+
let bannerScale = 1;
|
|
113
|
+
if (isLargeWindow) {
|
|
114
|
+
bannerScale = WIDE_BANNER_SCALE;
|
|
115
|
+
}
|
|
92
116
|
return {
|
|
93
117
|
...HeaderBarMetrics,
|
|
94
118
|
isWide,
|
|
95
119
|
isBannerCentered: isLargeWindow,
|
|
120
|
+
bannerScale,
|
|
96
121
|
frameInset,
|
|
97
122
|
frameWidth: width - frameInset * 2,
|
|
98
123
|
};
|
|
@@ -117,6 +142,19 @@ const useHeaderLayout = (contentLayout?: HeaderContentLayout): HeaderLayout => {
|
|
|
117
142
|
}, [width, height, isDuo, contentLayout]);
|
|
118
143
|
};
|
|
119
144
|
|
|
145
|
+
/**
|
|
146
|
+
* Header height once the search sits in its row: the row grows to `searchBarHeight`,
|
|
147
|
+
* a taller row (iPhone landscape, iPhone Duo) keeps its height.
|
|
148
|
+
*/
|
|
149
|
+
const getSearchHeaderHeight = (
|
|
150
|
+
headerHeight: number,
|
|
151
|
+
statusBarHeight: number,
|
|
152
|
+
) => {
|
|
153
|
+
const rowHeight = headerHeight - statusBarHeight;
|
|
154
|
+
const { searchBarHeight } = HeaderBarMetrics;
|
|
155
|
+
return statusBarHeight + Math.max(rowHeight, searchBarHeight);
|
|
156
|
+
};
|
|
157
|
+
|
|
120
158
|
const TITLE_CONTAINER_RESET: ViewStyle = {
|
|
121
159
|
marginLeft: 0,
|
|
122
160
|
marginEnd: 0,
|
|
@@ -127,33 +165,77 @@ const TITLE_CONTAINER_RESET: ViewStyle = {
|
|
|
127
165
|
};
|
|
128
166
|
|
|
129
167
|
/**
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
|
|
168
|
+
* Container styles of the bar-edge row, set explicitly: options are merged, so a
|
|
169
|
+
* former `stretch` frame would otherwise stay after a layout switch or a fold.
|
|
170
|
+
*/
|
|
171
|
+
const getEdgeFrameOptions = (
|
|
172
|
+
edgePadding: EdgePadding,
|
|
173
|
+
): StackNavigationOptions => {
|
|
174
|
+
return {
|
|
175
|
+
headerLeftContainerStyle: { paddingLeft: edgePadding.left },
|
|
176
|
+
headerRightContainerStyle: { paddingRight: edgePadding.right },
|
|
177
|
+
headerTitleContainerStyle: {
|
|
178
|
+
...TITLE_CONTAINER_RESET,
|
|
179
|
+
left: HeaderBarMetrics.titleGap,
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* React Navigation container styles placing back, title and the right cluster for
|
|
186
|
+
* `contentLayout`: the 600pt frame with `stretch`, else the bar edges (also iPhone
|
|
187
|
+
* Duo). `undefined` when the screen leaves `contentLayout` unset.
|
|
188
|
+
*/
|
|
189
|
+
const getHeaderFrameOptions = ({
|
|
190
|
+
layout,
|
|
191
|
+
isDuo,
|
|
192
|
+
headerMargin,
|
|
193
|
+
edgePadding,
|
|
194
|
+
contentLayout,
|
|
195
|
+
}: HeaderFrameInput): StackNavigationOptions | undefined => {
|
|
196
|
+
if (!contentLayout) {
|
|
197
|
+
return undefined;
|
|
198
|
+
}
|
|
199
|
+
if (contentLayout !== 'stretch' || isDuo) {
|
|
200
|
+
return getEdgeFrameOptions(edgePadding);
|
|
201
|
+
}
|
|
202
|
+
// the header content row already sits this far in on large iOS windows
|
|
203
|
+
const shift = layout.frameInset - layout.sidePadding;
|
|
204
|
+
const containerShift = Math.max(0, shift - headerMargin);
|
|
205
|
+
return {
|
|
206
|
+
headerLeftContainerStyle: { paddingLeft: containerShift },
|
|
207
|
+
headerRightContainerStyle: { paddingRight: containerShift },
|
|
208
|
+
headerTitleContainerStyle: {
|
|
209
|
+
...TITLE_CONTAINER_RESET,
|
|
210
|
+
left: layout.titleGap,
|
|
211
|
+
maxWidth: getTitleBudget(layout),
|
|
212
|
+
},
|
|
213
|
+
};
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Container styles for `contentLayout` on the current window, re-computed on fold,
|
|
218
|
+
* unfold and rotation; see `getHeaderFrameOptions`.
|
|
133
219
|
*/
|
|
134
220
|
const useHeaderFrameOptions = (
|
|
135
221
|
contentLayout?: HeaderContentLayout,
|
|
136
222
|
): StackNavigationOptions | undefined => {
|
|
137
223
|
const layout = useHeaderLayout(contentLayout);
|
|
138
|
-
const
|
|
224
|
+
const screenLayout = useScreenLayout();
|
|
225
|
+
const rowOptions = getHeaderRowOptions(screenLayout);
|
|
226
|
+
const edgeLeft = rowOptions.headerLeftContainerStyle?.paddingLeft ?? 0;
|
|
227
|
+
const edgeRight = rowOptions.headerRightContainerStyle?.paddingRight ?? 0;
|
|
228
|
+
const headerMargin = getHeaderMargin(screenLayout.width);
|
|
139
229
|
const isDuo = isIPhoneDuo();
|
|
140
230
|
return useMemo(() => {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
headerRightContainerStyle: { paddingRight: containerShift },
|
|
150
|
-
headerTitleContainerStyle: {
|
|
151
|
-
...TITLE_CONTAINER_RESET,
|
|
152
|
-
left: layout.titleGap,
|
|
153
|
-
maxWidth: getTitleBudget(layout),
|
|
154
|
-
},
|
|
155
|
-
};
|
|
156
|
-
}, [contentLayout, isDuo, layout, width]);
|
|
231
|
+
return getHeaderFrameOptions({
|
|
232
|
+
layout,
|
|
233
|
+
isDuo,
|
|
234
|
+
headerMargin,
|
|
235
|
+
edgePadding: { left: edgeLeft, right: edgeRight },
|
|
236
|
+
contentLayout,
|
|
237
|
+
});
|
|
238
|
+
}, [contentLayout, isDuo, layout, headerMargin, edgeLeft, edgeRight]);
|
|
157
239
|
};
|
|
158
240
|
|
|
159
241
|
export type { HeaderContentLayout, HeaderLayout };
|
|
@@ -162,7 +244,9 @@ export {
|
|
|
162
244
|
HeaderBarMetrics,
|
|
163
245
|
HEADER_FRAME_MAX_WIDTH,
|
|
164
246
|
TITLE_CONTAINER_RESET,
|
|
247
|
+
getHeaderFrameOptions,
|
|
165
248
|
getHeaderLayout,
|
|
249
|
+
getSearchHeaderHeight,
|
|
166
250
|
getTitleBudget,
|
|
167
251
|
useHeaderLayout,
|
|
168
252
|
useHeaderFrameOptions,
|
|
@@ -99,10 +99,16 @@ export interface HeaderAnimatedProps extends ViewProps {
|
|
|
99
99
|
useScale?: boolean;
|
|
100
100
|
aspectRatio?: '16/9' | '3/2' | '1/1';
|
|
101
101
|
/**
|
|
102
|
-
* Optional. On wide windows the image
|
|
102
|
+
* Optional. On wide windows the image is centered at phone width × 1.2; this
|
|
103
103
|
* color fills the sides and fades to transparent downward. No fill when unset.
|
|
104
|
+
* `bannerGradientColors` wins when both are set.
|
|
104
105
|
*/
|
|
105
106
|
bannerBackgroundColor?: string;
|
|
107
|
+
/**
|
|
108
|
+
* Optional. Side fill behind the centered banner on wide windows, from the top
|
|
109
|
+
* color to the bottom one: `[start, end]`. A single color fills solid.
|
|
110
|
+
*/
|
|
111
|
+
bannerGradientColors?: string[];
|
|
106
112
|
}
|
|
107
113
|
|
|
108
114
|
export type AnimatedHeader = {
|
package/Layout/Screen.tsx
CHANGED
|
@@ -28,7 +28,8 @@ import { useScreenLayout } from './utils';
|
|
|
28
28
|
import { HeaderExtendHeader } from '../Application';
|
|
29
29
|
import { DuoScrollGradient } from '../Application/Components/DuoGlassBackground';
|
|
30
30
|
import { BottomTabInsetContext } from '../Application/BottomTab/BottomTabInset';
|
|
31
|
-
import {
|
|
31
|
+
import { useHeaderLayout } from '../Application/headerLayout';
|
|
32
|
+
import { ANIMATED_BANNER_HEIGHT, ScreenProps } from './screenTypes';
|
|
32
33
|
import { renderAnimatedHeader, renderContent } from './screenContent';
|
|
33
34
|
import { createScrollHandlers } from './screenScroll';
|
|
34
35
|
import { ScreenFooter } from './screenFooter';
|
|
@@ -78,6 +79,9 @@ const Screen = forwardRef(
|
|
|
78
79
|
const insets = useSafeAreaInsets();
|
|
79
80
|
const frame = useSafeAreaFrame();
|
|
80
81
|
const heightHeader = useHeaderHeight();
|
|
82
|
+
const { bannerScale } = useHeaderLayout(contentLayout);
|
|
83
|
+
// the banner grows with its image on wide windows, the content keeps its overlap
|
|
84
|
+
const bannerBottom = ANIMATED_BANNER_HEIGHT * bannerScale + layoutOffset;
|
|
81
85
|
|
|
82
86
|
const animatedValue = useRef<Animated.Value>(
|
|
83
87
|
customAnimatedValue ?? new Animated.Value(0),
|
|
@@ -144,7 +148,7 @@ const Screen = forwardRef(
|
|
|
144
148
|
useShadowHeader,
|
|
145
149
|
gradientColor,
|
|
146
150
|
headerBackground,
|
|
147
|
-
|
|
151
|
+
bannerBottom,
|
|
148
152
|
contentLayout,
|
|
149
153
|
});
|
|
150
154
|
|
|
@@ -279,7 +283,7 @@ const Screen = forwardRef(
|
|
|
279
283
|
>
|
|
280
284
|
{renderAnimatedHeader(
|
|
281
285
|
animatedHeader,
|
|
282
|
-
|
|
286
|
+
bannerBottom,
|
|
283
287
|
animatedValue.current,
|
|
284
288
|
sharedValue,
|
|
285
289
|
)}
|
package/Layout/layoutMetrics.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** Header geometry. */
|
|
2
2
|
export const HeaderMetrics = {
|
|
3
|
-
/** Navigation bar row below the status bar. */
|
|
4
|
-
barHeight:
|
|
3
|
+
/** Navigation bar row below the status bar; a search row is taller (searchBarHeight). */
|
|
4
|
+
barHeight: 48,
|
|
5
5
|
/** Header never shorter than this on iPhone (landscape, iPhone Duo). */
|
|
6
6
|
iPhoneMinHeight: 72,
|
|
7
7
|
/** A smaller top inset means the status bar is not on the top edge. */
|
package/Layout/screenContent.tsx
CHANGED
|
@@ -3,7 +3,6 @@ import { Animated, View } from 'react-native';
|
|
|
3
3
|
import { Spacing } from '../Consts';
|
|
4
4
|
import styles from './styles';
|
|
5
5
|
import { validateChildren } from './utils';
|
|
6
|
-
import { ANIMATED_BANNER_HEIGHT } from './screenTypes';
|
|
7
6
|
import { AnimatedHeader } from '../Application/types';
|
|
8
7
|
|
|
9
8
|
type ContentInset = { insetLeft: number; insetRight: number };
|
|
@@ -65,23 +64,18 @@ export const renderContent = (content: any, layout: ContentInset): any => {
|
|
|
65
64
|
};
|
|
66
65
|
|
|
67
66
|
/**
|
|
68
|
-
* Animated banner from `animatedHeader.component`, clipped
|
|
69
|
-
* `layoutOffset
|
|
67
|
+
* Animated banner from `animatedHeader.component`, clipped at `bannerBottom` (banner
|
|
68
|
+
* height plus `layoutOffset`). Nothing without a component.
|
|
70
69
|
*/
|
|
71
70
|
export const renderAnimatedHeader = (
|
|
72
71
|
animatedHeader: AnimatedHeader | undefined,
|
|
73
|
-
|
|
72
|
+
bannerBottom: number,
|
|
74
73
|
animatedValue: Animated.Value,
|
|
75
74
|
sharedValue: any,
|
|
76
75
|
) => {
|
|
77
76
|
if (typeof animatedHeader?.component === 'function') {
|
|
78
77
|
return (
|
|
79
|
-
<View
|
|
80
|
-
style={[
|
|
81
|
-
styles.screenBanner,
|
|
82
|
-
{ maxHeight: ANIMATED_BANNER_HEIGHT + layoutOffset },
|
|
83
|
-
]}
|
|
84
|
-
>
|
|
78
|
+
<View style={[styles.screenBanner, { maxHeight: bannerBottom }]}>
|
|
85
79
|
{animatedHeader?.component({
|
|
86
80
|
animatedValue,
|
|
87
81
|
sharedValue,
|
package/Layout/screenHeader.tsx
CHANGED
|
@@ -13,13 +13,9 @@ import {
|
|
|
13
13
|
SearchHeader,
|
|
14
14
|
} from '../Application';
|
|
15
15
|
import { DuoGlassBackground } from '../Application/Components/DuoGlassBackground';
|
|
16
|
-
import {
|
|
17
|
-
type HeaderContentLayout,
|
|
18
|
-
useHeaderFrameOptions,
|
|
19
|
-
useHeaderLayout,
|
|
20
|
-
} from '../Application/headerLayout';
|
|
16
|
+
import { type HeaderContentLayout } from '../Application/headerLayout';
|
|
21
17
|
import { getHeaderMargin } from './utils';
|
|
22
|
-
import {
|
|
18
|
+
import { useHeaderBarOptions } from './useHeaderBarOptions';
|
|
23
19
|
import { HeaderType } from './types';
|
|
24
20
|
|
|
25
21
|
type ScreenHeaderParams = {
|
|
@@ -34,18 +30,20 @@ type ScreenHeaderParams = {
|
|
|
34
30
|
useShadowHeader: boolean;
|
|
35
31
|
gradientColor?: string;
|
|
36
32
|
headerBackground?: string;
|
|
37
|
-
|
|
33
|
+
bannerBottom: number;
|
|
38
34
|
contentLayout?: HeaderContentLayout;
|
|
39
35
|
};
|
|
40
36
|
|
|
41
37
|
/**
|
|
42
38
|
* Transparent header for an `inputSearchProps` Screen: its title fades out over the
|
|
43
|
-
* first 50pt of scroll while the search collapses into the bar.
|
|
39
|
+
* first 50pt of scroll while the search collapses into the bar (`searchTitleOptions`).
|
|
44
40
|
*/
|
|
45
41
|
const getSearchTitleOptions = (
|
|
46
42
|
sharedValue: SharedValue<number>,
|
|
43
|
+
searchTitleOptions: StackNavigationOptions,
|
|
47
44
|
): StackNavigationOptions => {
|
|
48
45
|
return {
|
|
46
|
+
...searchTitleOptions,
|
|
49
47
|
headerShown: true,
|
|
50
48
|
headerTransparent: true,
|
|
51
49
|
headerBackground: () => null,
|
|
@@ -79,14 +77,14 @@ export const useScreenHeader = ({
|
|
|
79
77
|
useShadowHeader,
|
|
80
78
|
gradientColor,
|
|
81
79
|
headerBackground,
|
|
82
|
-
|
|
80
|
+
bannerBottom,
|
|
83
81
|
contentLayout,
|
|
84
82
|
}: ScreenHeaderParams) => {
|
|
85
83
|
const currentTint = useRef<string | undefined>(undefined);
|
|
86
84
|
const appliedHeaderMode = useRef<string | undefined>(undefined);
|
|
87
85
|
const searchHeaderParams = useRef<SearchHeaderProps | undefined>(undefined);
|
|
88
|
-
const
|
|
89
|
-
const
|
|
86
|
+
const headerBarOptions = useHeaderBarOptions(layout, contentLayout);
|
|
87
|
+
const { barOptions, searchTitleOptions, searchOptions } = headerBarOptions;
|
|
90
88
|
|
|
91
89
|
// keepTitle leaves a title the screen set itself when the same type is re-applied
|
|
92
90
|
const setHeaderType = useCallback(
|
|
@@ -115,7 +113,7 @@ export const useScreenHeader = ({
|
|
|
115
113
|
headerTitle: (props: any) => <HeaderTitle {...props} />,
|
|
116
114
|
};
|
|
117
115
|
if (inputSearchProps) {
|
|
118
|
-
options = getSearchTitleOptions(sharedValue);
|
|
116
|
+
options = getSearchTitleOptions(sharedValue, searchTitleOptions);
|
|
119
117
|
}
|
|
120
118
|
break;
|
|
121
119
|
|
|
@@ -149,7 +147,7 @@ export const useScreenHeader = ({
|
|
|
149
147
|
headerTitle: (props: any) => <HeaderTitle {...props} />,
|
|
150
148
|
};
|
|
151
149
|
if (inputSearchProps) {
|
|
152
|
-
options = getSearchTitleOptions(sharedValue);
|
|
150
|
+
options = getSearchTitleOptions(sharedValue, searchTitleOptions);
|
|
153
151
|
}
|
|
154
152
|
}
|
|
155
153
|
|
|
@@ -159,7 +157,7 @@ export const useScreenHeader = ({
|
|
|
159
157
|
|
|
160
158
|
navigation?.instance?.setOptions({
|
|
161
159
|
header: undefined,
|
|
162
|
-
...
|
|
160
|
+
...barOptions,
|
|
163
161
|
...options,
|
|
164
162
|
});
|
|
165
163
|
},
|
|
@@ -172,7 +170,8 @@ export const useScreenHeader = ({
|
|
|
172
170
|
useShadowHeader,
|
|
173
171
|
hasSideBar,
|
|
174
172
|
quickReturnOptions,
|
|
175
|
-
|
|
173
|
+
barOptions,
|
|
174
|
+
searchTitleOptions,
|
|
176
175
|
],
|
|
177
176
|
);
|
|
178
177
|
|
|
@@ -193,7 +192,7 @@ export const useScreenHeader = ({
|
|
|
193
192
|
return (
|
|
194
193
|
<DuoGlassBackground
|
|
195
194
|
animatedValue={sharedValue}
|
|
196
|
-
bannerBottom={
|
|
195
|
+
bannerBottom={bannerBottom}
|
|
197
196
|
/>
|
|
198
197
|
);
|
|
199
198
|
}
|
|
@@ -220,7 +219,7 @@ export const useScreenHeader = ({
|
|
|
220
219
|
};
|
|
221
220
|
}
|
|
222
221
|
|
|
223
|
-
navigation?.instance?.setOptions({ ...
|
|
222
|
+
navigation?.instance?.setOptions({ ...barOptions, ...options });
|
|
224
223
|
},
|
|
225
224
|
[
|
|
226
225
|
gradientColor,
|
|
@@ -229,24 +228,20 @@ export const useScreenHeader = ({
|
|
|
229
228
|
sharedValue,
|
|
230
229
|
useShadowHeader,
|
|
231
230
|
hasSideBar,
|
|
232
|
-
|
|
231
|
+
bannerBottom,
|
|
233
232
|
quickReturnOptions,
|
|
234
|
-
|
|
233
|
+
barOptions,
|
|
235
234
|
],
|
|
236
235
|
);
|
|
237
236
|
|
|
238
237
|
const setAnimatedSearch = useCallback(() => {
|
|
239
|
-
const options = getSearchTitleOptions(sharedValue);
|
|
240
|
-
navigation?.instance?.setOptions({
|
|
241
|
-
|
|
242
|
-
...frameOptions,
|
|
243
|
-
...options,
|
|
244
|
-
});
|
|
245
|
-
}, [navigation?.instance, sharedValue, frameOptions]);
|
|
238
|
+
const options = getSearchTitleOptions(sharedValue, searchTitleOptions);
|
|
239
|
+
navigation?.instance?.setOptions({ header: undefined, ...options });
|
|
240
|
+
}, [navigation?.instance, sharedValue, searchTitleOptions]);
|
|
246
241
|
|
|
247
|
-
// the search field spans the content
|
|
248
|
-
//
|
|
249
|
-
let searchWidth =
|
|
242
|
+
// the search field spans the content, clear of the side bar and status bar
|
|
243
|
+
// clusters; kept as numbers so the setter below stays stable
|
|
244
|
+
let searchWidth = layout.width - Spacing.M * 2;
|
|
250
245
|
let searchLeft = Spacing.M;
|
|
251
246
|
if (layout.sideBar) {
|
|
252
247
|
searchWidth = layout.contentWidth - Spacing.M * 2;
|
|
@@ -265,7 +260,7 @@ export const useScreenHeader = ({
|
|
|
265
260
|
(params: SearchHeaderProps) => {
|
|
266
261
|
searchHeaderParams.current = params;
|
|
267
262
|
const options: StackNavigationOptions = {
|
|
268
|
-
...
|
|
263
|
+
...searchOptions,
|
|
269
264
|
headerRight: undefined,
|
|
270
265
|
headerTitleContainerStyle: {
|
|
271
266
|
width: searchWidth,
|
|
@@ -291,7 +286,7 @@ export const useScreenHeader = ({
|
|
|
291
286
|
|
|
292
287
|
navigation?.instance?.setOptions(options);
|
|
293
288
|
},
|
|
294
|
-
[navigation?.instance, sharedValue,
|
|
289
|
+
[navigation?.instance, sharedValue, searchOptions, searchWidth, searchLeft],
|
|
295
290
|
);
|
|
296
291
|
|
|
297
292
|
useEffect(() => {
|
package/Layout/screenTypes.ts
CHANGED
|
@@ -83,9 +83,9 @@ export interface ScreenProps extends ViewProps {
|
|
|
83
83
|
headerRightWidth?: 0 | 84 | 124 | number;
|
|
84
84
|
|
|
85
85
|
/**
|
|
86
|
-
* Optional. `stretch` centers back, title
|
|
87
|
-
*
|
|
88
|
-
*
|
|
86
|
+
* Optional. `stretch` centers back, title and the right cluster of the header in a
|
|
87
|
+
* 600pt frame on wide windows (foldable inner display, tablet); the background,
|
|
88
|
+
* status bar and a search header stay full width. Defaults to `grid`.
|
|
89
89
|
*/
|
|
90
90
|
contentLayout?: HeaderContentLayout;
|
|
91
91
|
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import type { StackNavigationOptions } from '@react-navigation/stack';
|
|
3
|
+
import {
|
|
4
|
+
getSearchHeaderHeight,
|
|
5
|
+
type HeaderContentLayout,
|
|
6
|
+
useHeaderFrameOptions,
|
|
7
|
+
} from '../Application/headerLayout';
|
|
8
|
+
import type { ScreenLayout } from './layoutTypes';
|
|
9
|
+
|
|
10
|
+
type HeaderBarOptions = {
|
|
11
|
+
barOptions: StackNavigationOptions;
|
|
12
|
+
searchTitleOptions: StackNavigationOptions;
|
|
13
|
+
searchOptions: StackNavigationOptions;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Header row options for the Screen setters: the plain bar and the taller title row
|
|
18
|
+
* above an `inputSearchProps` search, both in the `contentLayout` frame, and the
|
|
19
|
+
* search header row, which spans the window and leaves the frame.
|
|
20
|
+
*/
|
|
21
|
+
const useHeaderBarOptions = (
|
|
22
|
+
layout: ScreenLayout,
|
|
23
|
+
contentLayout?: HeaderContentLayout,
|
|
24
|
+
): HeaderBarOptions => {
|
|
25
|
+
const frameOptions = useHeaderFrameOptions(contentLayout);
|
|
26
|
+
// the search header fills the bar, so it keeps the bar-edge row with either layout
|
|
27
|
+
let searchLayout: HeaderContentLayout | undefined;
|
|
28
|
+
if (contentLayout) {
|
|
29
|
+
searchLayout = 'grid';
|
|
30
|
+
}
|
|
31
|
+
const edgeOptions = useHeaderFrameOptions(searchLayout);
|
|
32
|
+
const { headerHeight, headerStatusBarHeight } = layout;
|
|
33
|
+
const searchHeight = getSearchHeaderHeight(
|
|
34
|
+
headerHeight,
|
|
35
|
+
headerStatusBarHeight,
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
// the height is re-applied on every header type, so a former search row does not stay
|
|
39
|
+
const barOptions = useMemo((): StackNavigationOptions => {
|
|
40
|
+
return { ...frameOptions, headerStyle: { height: headerHeight } };
|
|
41
|
+
}, [frameOptions, headerHeight]);
|
|
42
|
+
|
|
43
|
+
const searchTitleOptions = useMemo((): StackNavigationOptions => {
|
|
44
|
+
return { ...frameOptions, headerStyle: { height: searchHeight } };
|
|
45
|
+
}, [frameOptions, searchHeight]);
|
|
46
|
+
|
|
47
|
+
const searchOptions = useMemo((): StackNavigationOptions => {
|
|
48
|
+
return { ...edgeOptions, headerStyle: { height: searchHeight } };
|
|
49
|
+
}, [edgeOptions, searchHeight]);
|
|
50
|
+
|
|
51
|
+
return { barOptions, searchTitleOptions, searchOptions };
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export { useHeaderBarOptions };
|