@momo-kits/foundation 0.169.17-beta.6 → 0.169.17-beta.7
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 +9 -33
- package/Application/Components/HeaderExtendHeader.tsx +18 -28
- package/Application/Components/SearchHeader.tsx +5 -7
- package/Application/headerLayout.ts +30 -114
- package/Application/types.header.ts +1 -7
- package/Input/InputSearch.tsx +10 -3
- package/Layout/FloatingButton.tsx +8 -1
- package/Layout/Screen.tsx +3 -7
- package/Layout/layoutMetrics.ts +2 -2
- package/Layout/screenContent.tsx +10 -4
- package/Layout/screenHeader.tsx +31 -26
- package/Layout/screenTypes.ts +3 -3
- package/package.json +1 -1
- package/Application/__tests__/headerLayout.test.ts +0 -113
- package/Layout/useHeaderBarOptions.ts +0 -54
|
@@ -12,8 +12,6 @@ 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
|
-
|
|
17
15
|
const ASPECT_RATIOS: Record<
|
|
18
16
|
NonNullable<HeaderAnimatedProps['aspectRatio']>,
|
|
19
17
|
number
|
|
@@ -23,30 +21,10 @@ const ASPECT_RATIOS: Record<
|
|
|
23
21
|
'1/1': 1 / 1,
|
|
24
22
|
};
|
|
25
23
|
|
|
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
|
-
|
|
46
24
|
/**
|
|
47
25
|
* Parallax header image (or `children`): stretches when pulled down and fades out
|
|
48
|
-
* as the content scrolls up. Wide windows and the iPhone Duo inner display
|
|
49
|
-
* it at phone size
|
|
26
|
+
* as the content scrolls up. Wide windows and the iPhone Duo inner display keep
|
|
27
|
+
* it at phone size, centered.
|
|
50
28
|
*/
|
|
51
29
|
const HeaderAnimated: React.FC<HeaderAnimatedProps> = ({
|
|
52
30
|
animatedValue,
|
|
@@ -54,16 +32,11 @@ const HeaderAnimated: React.FC<HeaderAnimatedProps> = ({
|
|
|
54
32
|
useScale = true,
|
|
55
33
|
aspectRatio = '16/9',
|
|
56
34
|
bannerBackgroundColor,
|
|
57
|
-
bannerGradientColors,
|
|
58
35
|
children,
|
|
59
36
|
}) => {
|
|
60
37
|
const sharedValue = useNormalizedSharedValue(animatedValue);
|
|
61
38
|
const { isBannerCentered, bannerWidth } = useHeaderLayout();
|
|
62
39
|
const ratio = ASPECT_RATIOS[aspectRatio];
|
|
63
|
-
const sideColors = getBannerGradientColors(
|
|
64
|
-
bannerGradientColors,
|
|
65
|
-
bannerBackgroundColor,
|
|
66
|
-
);
|
|
67
40
|
const animatedStyle = useAnimatedStyle(() => {
|
|
68
41
|
let scale = 1;
|
|
69
42
|
if (useScale) {
|
|
@@ -115,10 +88,13 @@ const HeaderAnimated: React.FC<HeaderAnimatedProps> = ({
|
|
|
115
88
|
<Animated.View
|
|
116
89
|
style={[styles.container, { height: bannerWidth / ratio }, animatedStyle]}
|
|
117
90
|
>
|
|
118
|
-
{
|
|
119
|
-
<LinearGradient
|
|
91
|
+
{!!bannerBackgroundColor && (
|
|
92
|
+
<LinearGradient
|
|
93
|
+
colors={[bannerBackgroundColor, bannerBackgroundColor + '00']}
|
|
94
|
+
style={StyleSheet.absoluteFill}
|
|
95
|
+
/>
|
|
120
96
|
)}
|
|
121
|
-
<View style={styles.
|
|
97
|
+
<View style={styles.phoneBanner}>{content}</View>
|
|
122
98
|
</Animated.View>
|
|
123
99
|
);
|
|
124
100
|
};
|
|
@@ -134,7 +110,7 @@ const styles = StyleSheet.create({
|
|
|
134
110
|
alignSelf: 'center',
|
|
135
111
|
},
|
|
136
112
|
full: { width: '100%', height: '100%' },
|
|
137
|
-
|
|
113
|
+
phoneBanner: {
|
|
138
114
|
width: HeaderBarMetrics.bannerWidth,
|
|
139
115
|
height: '100%',
|
|
140
116
|
alignSelf: 'center',
|
|
@@ -17,7 +17,7 @@ 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 {
|
|
20
|
+
import { HeaderMetrics } from '../../Layout/utils';
|
|
21
21
|
import {
|
|
22
22
|
HeaderBarMetrics,
|
|
23
23
|
type HeaderContentLayout,
|
|
@@ -28,12 +28,10 @@ import { useHeaderRightWidth } from './useHeaderRightWidth';
|
|
|
28
28
|
const { buttonSize, pillWidth, sidePadding, titleGap } = HeaderBarMetrics;
|
|
29
29
|
const SCREEN_PADDING = sidePadding;
|
|
30
30
|
const TOOLKIT_WIDTH = pillWidth + sidePadding;
|
|
31
|
-
// the extended header without search grows this much past the bar until scrolled
|
|
32
|
-
const EXTENDED_HEIGHT_EXTRA = 52;
|
|
33
31
|
|
|
34
32
|
/**
|
|
35
33
|
* Extended header background: a gradient that collapses on scroll and, with
|
|
36
|
-
* `inputSearchProps`, a
|
|
34
|
+
* `inputSearchProps`, a full-width search that slides into the bar beside back/toolkit.
|
|
37
35
|
*/
|
|
38
36
|
const HeaderExtendHeader: React.FC<{
|
|
39
37
|
headerType?: HeaderType;
|
|
@@ -46,10 +44,6 @@ const HeaderExtendHeader: React.FC<{
|
|
|
46
44
|
useShadowHeader?: boolean;
|
|
47
45
|
gradientColor?: string;
|
|
48
46
|
headerBackground?: string;
|
|
49
|
-
/**
|
|
50
|
-
* `stretch` keeps the collapsed search beside back and the right cluster in the
|
|
51
|
-
* 600pt frame; the expanded search row spans the window with either layout.
|
|
52
|
-
*/
|
|
53
47
|
contentLayout?: HeaderContentLayout;
|
|
54
48
|
}> = ({
|
|
55
49
|
headerType = 'default',
|
|
@@ -70,12 +64,8 @@ const HeaderExtendHeader: React.FC<{
|
|
|
70
64
|
const headerBackground = customBackground ?? theme.assets?.headerBackground;
|
|
71
65
|
const layout = useScreenLayout();
|
|
72
66
|
const headerLayout = useHeaderLayout(contentLayout);
|
|
73
|
-
//
|
|
74
|
-
|
|
75
|
-
let frameShift = headerLayout.frameInset - sidePadding;
|
|
76
|
-
if (!layout.sideBar) {
|
|
77
|
-
frameShift = Math.max(frameShift, getHeaderMargin(layout.width));
|
|
78
|
-
}
|
|
67
|
+
// the stretch frame pulls the search in from both bar edges
|
|
68
|
+
const frameShift = headerLayout.frameInset - sidePadding;
|
|
79
69
|
|
|
80
70
|
const backLeft = buttonSize + sidePadding + titleGap;
|
|
81
71
|
const defaultLeft = layout.sideBar ? SCREEN_PADDING : backLeft;
|
|
@@ -83,22 +73,22 @@ const HeaderExtendHeader: React.FC<{
|
|
|
83
73
|
const measuredRightWidth = useHeaderRightWidth() ?? TOOLKIT_WIDTH;
|
|
84
74
|
const defaultRightWidth = layout.sideBar ? 0 : measuredRightWidth;
|
|
85
75
|
const headerRightWidth = customHeaderRightWidth ?? defaultRightWidth;
|
|
86
|
-
const contentLeft = layout.insetLeft + SCREEN_PADDING;
|
|
87
|
-
const contentRight = layout.insetLeft + layout.contentWidth;
|
|
76
|
+
const contentLeft = layout.insetLeft + SCREEN_PADDING + frameShift;
|
|
77
|
+
const contentRight = layout.insetLeft + layout.contentWidth - frameShift;
|
|
88
78
|
// collapsed on the status bar row, the search stays between its clusters
|
|
89
79
|
const clearanceLeft = layout.statusBarClearance?.left ?? 0;
|
|
90
80
|
const clearanceRight = layout.statusBarClearance?.right ?? 0;
|
|
91
|
-
const searchLeft = leftPosition + clearanceLeft;
|
|
92
|
-
const collapsedLeft = layout.insetLeft + searchLeft
|
|
93
|
-
const
|
|
94
|
-
const collapsedRight = barRight - headerRightWidth;
|
|
81
|
+
const searchLeft = leftPosition + clearanceLeft + frameShift;
|
|
82
|
+
const collapsedLeft = layout.insetLeft + searchLeft;
|
|
83
|
+
const collapsedRight = contentRight - clearanceRight - headerRightWidth;
|
|
95
84
|
const searchWidth = contentRight - contentLeft - SCREEN_PADDING;
|
|
96
85
|
const collapsedSearchWidth = collapsedRight - collapsedLeft - SCREEN_PADDING;
|
|
97
|
-
//
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
+
// the iPhone Duo side bar keeps the content search size
|
|
91
|
+
const searchSize = layout.sideBar ? 'default' : 'header';
|
|
102
92
|
|
|
103
93
|
let useShadowHeader = useShadowHeaderProp;
|
|
104
94
|
if (inputSearchProps && Platform.OS === 'android') {
|
|
@@ -111,7 +101,7 @@ const HeaderExtendHeader: React.FC<{
|
|
|
111
101
|
height: interpolate(
|
|
112
102
|
sharedValue.value,
|
|
113
103
|
[0, 100],
|
|
114
|
-
[heightHeader +
|
|
104
|
+
[heightHeader + 52, heightHeader],
|
|
115
105
|
Extrapolation.CLAMP,
|
|
116
106
|
),
|
|
117
107
|
}));
|
|
@@ -164,7 +154,7 @@ const HeaderExtendHeader: React.FC<{
|
|
|
164
154
|
height: interpolate(
|
|
165
155
|
sharedValue.value,
|
|
166
156
|
[0, 100],
|
|
167
|
-
[heightHeader +
|
|
157
|
+
[heightHeader + 52, heightHeader],
|
|
168
158
|
Extrapolation.CLAMP,
|
|
169
159
|
),
|
|
170
160
|
}));
|
|
@@ -225,7 +215,7 @@ const HeaderExtendHeader: React.FC<{
|
|
|
225
215
|
<InputSearch
|
|
226
216
|
{...inputSearchProps}
|
|
227
217
|
ref={inputSearchRef}
|
|
228
|
-
size={
|
|
218
|
+
size={searchSize}
|
|
229
219
|
backgroundColor={'transparent'}
|
|
230
220
|
showButtonText={false}
|
|
231
221
|
/>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Colors, Radius, Spacing, Styles } from '../../Consts';
|
|
2
|
-
import { InputRef, InputSearch } from '../../Input';
|
|
2
|
+
import { InputRef, InputSearch, type InputSearchProps } from '../../Input';
|
|
3
3
|
import { StyleSheet, TouchableOpacity, View } from 'react-native';
|
|
4
4
|
import Animated, { useAnimatedStyle } from 'react-native-reanimated';
|
|
5
5
|
import React, { useContext } from 'react';
|
|
@@ -8,7 +8,6 @@ import { ApplicationContext, MiniAppContext } from '../../Context';
|
|
|
8
8
|
import { Text } from '../../Text';
|
|
9
9
|
import { useNormalizedSharedValue } from '../hooks';
|
|
10
10
|
import { useScreenLayout } from '../../Layout';
|
|
11
|
-
import { getHeaderMargin } from '../../Layout/utils';
|
|
12
11
|
import { HeaderBarMetrics } from '../headerLayout';
|
|
13
12
|
import { useHeaderRightWidth } from './useHeaderRightWidth';
|
|
14
13
|
|
|
@@ -37,8 +36,10 @@ const SearchHeader = React.forwardRef<InputRef, SearchHeaderProps>(
|
|
|
37
36
|
const context = useContext<any>(MiniAppContext);
|
|
38
37
|
const layout = useScreenLayout();
|
|
39
38
|
let defaultRightWidth = useHeaderRightWidth() ?? TOOLKIT_WIDTH;
|
|
39
|
+
let searchSize: InputSearchProps['size'] = 'header';
|
|
40
40
|
if (layout.sideBar) {
|
|
41
41
|
defaultRightWidth = DUO_TOOLKIT_WIDTH;
|
|
42
|
+
searchSize = 'default';
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
const sharedValue = useNormalizedSharedValue(animatedValue);
|
|
@@ -47,10 +48,7 @@ const SearchHeader = React.forwardRef<InputRef, SearchHeaderProps>(
|
|
|
47
48
|
const headerRightWidth = props?.headerRightWidth ?? defaultRightWidth;
|
|
48
49
|
|
|
49
50
|
// iPhone Duo side bar holds back: the search shares the content width with the buttons only
|
|
50
|
-
|
|
51
|
-
const headerMargin = getHeaderMargin(layout.width);
|
|
52
|
-
const rowWidth =
|
|
53
|
-
layout.width - leftPosition - sidePadding - headerMargin * 2;
|
|
51
|
+
const rowWidth = layout.width - leftPosition - sidePadding;
|
|
54
52
|
let searchMaxWidth = rowWidth - headerRightWidth;
|
|
55
53
|
if (layout.sideBar) {
|
|
56
54
|
searchMaxWidth = layout.contentWidth - Spacing.M * 2 - headerRightWidth;
|
|
@@ -120,7 +118,7 @@ const SearchHeader = React.forwardRef<InputRef, SearchHeaderProps>(
|
|
|
120
118
|
<InputSearch
|
|
121
119
|
ref={ref}
|
|
122
120
|
{...props}
|
|
123
|
-
size={
|
|
121
|
+
size={searchSize}
|
|
124
122
|
backgroundColor={'transparent'}
|
|
125
123
|
showButtonText={false}
|
|
126
124
|
/>
|
|
@@ -2,18 +2,14 @@ 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 {
|
|
6
|
-
getHeaderMargin,
|
|
7
|
-
getHeaderRowOptions,
|
|
8
|
-
useScreenLayout,
|
|
9
|
-
} from '../Layout/utils';
|
|
5
|
+
import { getHeaderMargin } from '../Layout/utils';
|
|
10
6
|
import { FOLDABLE_MIN_WIDTH } from './modalLayout';
|
|
11
7
|
import { isIPhoneDuo } from './utils';
|
|
12
8
|
|
|
13
9
|
// Top navigation spec, shared with the Compose / SwiftUI kits
|
|
14
10
|
const HEADER_FRAME_MAX_WIDTH = 600;
|
|
15
|
-
//
|
|
16
|
-
const
|
|
11
|
+
// stretch frame on hold until design confirms it: `stretch` lays out like `grid`
|
|
12
|
+
const IS_STRETCH_FRAME_ENABLED = false;
|
|
17
13
|
|
|
18
14
|
/**
|
|
19
15
|
* Top navigation geometry on every device
|
|
@@ -21,11 +17,10 @@ const WIDE_BANNER_SCALE = 1.2;
|
|
|
21
17
|
* - pillWidth / pillHeight: help center | home capsule
|
|
22
18
|
* - clusterWidth: shortcut, gap and pill on the right of the bar
|
|
23
19
|
* - searchHeight: search field inside the header
|
|
24
|
-
* - searchBarHeight: header row holding the search, taller than the plain bar
|
|
25
20
|
* - titleGap: space between back and the title, and the title and the right cluster
|
|
26
21
|
* - sidePadding: bar edge to back and to the right cluster
|
|
27
22
|
* - gradientHeight: header gradient, kept at the phone height on wide windows
|
|
28
|
-
* - bannerWidth: animated banner image
|
|
23
|
+
* - bannerWidth: animated banner image, kept at the phone width on wide windows
|
|
29
24
|
*/
|
|
30
25
|
const HeaderBarMetrics = {
|
|
31
26
|
buttonSize: 32,
|
|
@@ -33,17 +28,17 @@ const HeaderBarMetrics = {
|
|
|
33
28
|
pillWidth: 72,
|
|
34
29
|
pillHeight: 32,
|
|
35
30
|
clusterWidth: 112,
|
|
36
|
-
searchHeight:
|
|
37
|
-
searchBarHeight: 56,
|
|
31
|
+
searchHeight: 32,
|
|
38
32
|
titleGap: Spacing.S,
|
|
39
33
|
sidePadding: Spacing.M,
|
|
40
34
|
gradientHeight: 154,
|
|
41
|
-
bannerWidth:
|
|
35
|
+
bannerWidth: 375,
|
|
42
36
|
};
|
|
43
37
|
|
|
44
38
|
/**
|
|
45
39
|
* `grid` keeps the header row at the bar edges, `stretch` centers it in a 600pt
|
|
46
|
-
* frame on wide windows
|
|
40
|
+
* frame on wide windows (on hold: same as `grid` for now). Background and status
|
|
41
|
+
* bar always span the window.
|
|
47
42
|
*/
|
|
48
43
|
type HeaderContentLayout = 'grid' | 'stretch';
|
|
49
44
|
|
|
@@ -58,10 +53,6 @@ type HeaderLayout = typeof HeaderBarMetrics & {
|
|
|
58
53
|
* inner display, portrait and landscape.
|
|
59
54
|
*/
|
|
60
55
|
isBannerCentered: boolean;
|
|
61
|
-
/**
|
|
62
|
-
* Banner size against the phone banner: `WIDE_BANNER_SCALE` when centered, else 1.
|
|
63
|
-
*/
|
|
64
|
-
bannerScale: number;
|
|
65
56
|
/**
|
|
66
57
|
* Window edge to back and to the right cluster: `sidePadding`, or centering the
|
|
67
58
|
* row in the 600pt frame with `stretch` on a wide window.
|
|
@@ -80,18 +71,6 @@ type HeaderLayoutInput = {
|
|
|
80
71
|
contentLayout?: HeaderContentLayout;
|
|
81
72
|
};
|
|
82
73
|
|
|
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
|
-
|
|
95
74
|
/**
|
|
96
75
|
* Header geometry for a window, pure so it can be tested without a device.
|
|
97
76
|
*/
|
|
@@ -105,19 +84,15 @@ const getHeaderLayout = ({
|
|
|
105
84
|
const isLargeWindow = Math.min(width, height) >= FOLDABLE_MIN_WIDTH;
|
|
106
85
|
const isWide = !isDuo && isLargeWindow;
|
|
107
86
|
let frameInset = sidePadding;
|
|
108
|
-
|
|
87
|
+
const isStretch = IS_STRETCH_FRAME_ENABLED && contentLayout === 'stretch';
|
|
88
|
+
if (isWide && isStretch) {
|
|
109
89
|
const centered = (width - HEADER_FRAME_MAX_WIDTH) / 2;
|
|
110
90
|
frameInset = Math.max(sidePadding, centered);
|
|
111
91
|
}
|
|
112
|
-
let bannerScale = 1;
|
|
113
|
-
if (isLargeWindow) {
|
|
114
|
-
bannerScale = WIDE_BANNER_SCALE;
|
|
115
|
-
}
|
|
116
92
|
return {
|
|
117
93
|
...HeaderBarMetrics,
|
|
118
94
|
isWide,
|
|
119
95
|
isBannerCentered: isLargeWindow,
|
|
120
|
-
bannerScale,
|
|
121
96
|
frameInset,
|
|
122
97
|
frameWidth: width - frameInset * 2,
|
|
123
98
|
};
|
|
@@ -142,19 +117,6 @@ const useHeaderLayout = (contentLayout?: HeaderContentLayout): HeaderLayout => {
|
|
|
142
117
|
}, [width, height, isDuo, contentLayout]);
|
|
143
118
|
};
|
|
144
119
|
|
|
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
|
-
|
|
158
120
|
const TITLE_CONTAINER_RESET: ViewStyle = {
|
|
159
121
|
marginLeft: 0,
|
|
160
122
|
marginEnd: 0,
|
|
@@ -165,77 +127,33 @@ const TITLE_CONTAINER_RESET: ViewStyle = {
|
|
|
165
127
|
};
|
|
166
128
|
|
|
167
129
|
/**
|
|
168
|
-
*
|
|
169
|
-
*
|
|
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`.
|
|
130
|
+
* React Navigation container styles that keep back, title and the right cluster
|
|
131
|
+
* in the `stretch` frame. `undefined` for `grid`, and on iPhone Duo, which keeps
|
|
132
|
+
* its own header row.
|
|
219
133
|
*/
|
|
220
134
|
const useHeaderFrameOptions = (
|
|
221
135
|
contentLayout?: HeaderContentLayout,
|
|
222
136
|
): StackNavigationOptions | undefined => {
|
|
223
137
|
const layout = useHeaderLayout(contentLayout);
|
|
224
|
-
const
|
|
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);
|
|
138
|
+
const { width } = useWindowDimensions();
|
|
229
139
|
const isDuo = isIPhoneDuo();
|
|
230
140
|
return useMemo(() => {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
141
|
+
if (!IS_STRETCH_FRAME_ENABLED || contentLayout !== 'stretch' || isDuo) {
|
|
142
|
+
return undefined;
|
|
143
|
+
}
|
|
144
|
+
// the header content row already sits this far in on large iOS windows
|
|
145
|
+
const shift = layout.frameInset - layout.sidePadding;
|
|
146
|
+
const containerShift = Math.max(0, shift - getHeaderMargin(width));
|
|
147
|
+
return {
|
|
148
|
+
headerLeftContainerStyle: { paddingLeft: containerShift },
|
|
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]);
|
|
239
157
|
};
|
|
240
158
|
|
|
241
159
|
export type { HeaderContentLayout, HeaderLayout };
|
|
@@ -244,9 +162,7 @@ export {
|
|
|
244
162
|
HeaderBarMetrics,
|
|
245
163
|
HEADER_FRAME_MAX_WIDTH,
|
|
246
164
|
TITLE_CONTAINER_RESET,
|
|
247
|
-
getHeaderFrameOptions,
|
|
248
165
|
getHeaderLayout,
|
|
249
|
-
getSearchHeaderHeight,
|
|
250
166
|
getTitleBudget,
|
|
251
167
|
useHeaderLayout,
|
|
252
168
|
useHeaderFrameOptions,
|
|
@@ -99,16 +99,10 @@ 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 keeps its phone width, centered; this
|
|
103
103
|
* color fills the sides and fades to transparent downward. No fill when unset.
|
|
104
|
-
* `bannerGradientColors` wins when both are set.
|
|
105
104
|
*/
|
|
106
105
|
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[];
|
|
112
106
|
}
|
|
113
107
|
|
|
114
108
|
export type AnimatedHeader = {
|
package/Input/InputSearch.tsx
CHANGED
|
@@ -33,6 +33,7 @@ const SEARCH_ICON_SIZE = 24;
|
|
|
33
33
|
/**
|
|
34
34
|
* Search field with search icon, clear icon, optional trailing icon and a
|
|
35
35
|
* cancel button; with `typingData` it shows an animated placeholder instead.
|
|
36
|
+
* Deprecated `icon*` props fall back into the `trailing*` ones.
|
|
36
37
|
*/
|
|
37
38
|
const InputSearch: ForwardRefRenderFunction<InputRef, InputSearchProps> = (
|
|
38
39
|
{
|
|
@@ -40,9 +41,12 @@ const InputSearch: ForwardRefRenderFunction<InputRef, InputSearchProps> = (
|
|
|
40
41
|
onFocus,
|
|
41
42
|
onBlur,
|
|
42
43
|
value,
|
|
43
|
-
trailing,
|
|
44
|
-
trailingColor,
|
|
45
|
-
onPressTrailing,
|
|
44
|
+
trailing: trailingProp,
|
|
45
|
+
trailingColor: trailingColorProp,
|
|
46
|
+
onPressTrailing: onPressTrailingProp,
|
|
47
|
+
icon,
|
|
48
|
+
iconColor,
|
|
49
|
+
onPressIcon,
|
|
46
50
|
onChangeText,
|
|
47
51
|
buttonText = 'Hủy',
|
|
48
52
|
showButtonText = true,
|
|
@@ -59,6 +63,9 @@ const InputSearch: ForwardRefRenderFunction<InputRef, InputSearchProps> = (
|
|
|
59
63
|
ref,
|
|
60
64
|
) => {
|
|
61
65
|
const { theme } = useContext(ApplicationContext);
|
|
66
|
+
const trailing = trailingProp ?? icon;
|
|
67
|
+
const trailingColor = trailingColorProp ?? iconColor;
|
|
68
|
+
const onPressTrailing = onPressTrailingProp ?? onPressIcon;
|
|
62
69
|
const context = useContext<any>(MiniAppContext);
|
|
63
70
|
const scaledFontSize = useScaleSize(INPUT_FONT_SIZE);
|
|
64
71
|
const searchFontFamily = exportFontFamily('regular');
|
|
@@ -75,6 +75,12 @@ export const FloatingButton: React.FC<FloatingButtonProps> = ({
|
|
|
75
75
|
opacityAnimated.value = withTiming(1, { duration: ANIMATION_DURATION });
|
|
76
76
|
}, [label, opacityAnimated]);
|
|
77
77
|
|
|
78
|
+
// Re-measure the expanded width when the label or its scaled size changes.
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
if (lastDirection.value === 'down') return;
|
|
81
|
+
widthAnimated.value = null;
|
|
82
|
+
}, [label, scaledFontSize, lastDirection, widthAnimated]);
|
|
83
|
+
|
|
78
84
|
useAnimatedReaction(
|
|
79
85
|
() => sharedValue.value,
|
|
80
86
|
value => {
|
|
@@ -115,7 +121,8 @@ export const FloatingButton: React.FC<FloatingButtonProps> = ({
|
|
|
115
121
|
);
|
|
116
122
|
|
|
117
123
|
const containerStyle = useAnimatedStyle(() => ({
|
|
118
|
-
width
|
|
124
|
+
// 'auto' (not undefined) so Reanimated drops the old width and re-lays out.
|
|
125
|
+
width: widthAnimated.value ?? 'auto',
|
|
119
126
|
}));
|
|
120
127
|
|
|
121
128
|
const labelStyle = useAnimatedStyle(() => ({
|
package/Layout/Screen.tsx
CHANGED
|
@@ -28,8 +28,7 @@ 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 {
|
|
32
|
-
import { ANIMATED_BANNER_HEIGHT, ScreenProps } from './screenTypes';
|
|
31
|
+
import { ScreenProps } from './screenTypes';
|
|
33
32
|
import { renderAnimatedHeader, renderContent } from './screenContent';
|
|
34
33
|
import { createScrollHandlers } from './screenScroll';
|
|
35
34
|
import { ScreenFooter } from './screenFooter';
|
|
@@ -79,9 +78,6 @@ const Screen = forwardRef(
|
|
|
79
78
|
const insets = useSafeAreaInsets();
|
|
80
79
|
const frame = useSafeAreaFrame();
|
|
81
80
|
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;
|
|
85
81
|
|
|
86
82
|
const animatedValue = useRef<Animated.Value>(
|
|
87
83
|
customAnimatedValue ?? new Animated.Value(0),
|
|
@@ -148,7 +144,7 @@ const Screen = forwardRef(
|
|
|
148
144
|
useShadowHeader,
|
|
149
145
|
gradientColor,
|
|
150
146
|
headerBackground,
|
|
151
|
-
|
|
147
|
+
layoutOffset,
|
|
152
148
|
contentLayout,
|
|
153
149
|
});
|
|
154
150
|
|
|
@@ -283,7 +279,7 @@ const Screen = forwardRef(
|
|
|
283
279
|
>
|
|
284
280
|
{renderAnimatedHeader(
|
|
285
281
|
animatedHeader,
|
|
286
|
-
|
|
282
|
+
layoutOffset,
|
|
287
283
|
animatedValue.current,
|
|
288
284
|
sharedValue,
|
|
289
285
|
)}
|
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. */
|
|
4
|
+
barHeight: 52,
|
|
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,6 +3,7 @@ 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';
|
|
6
7
|
import { AnimatedHeader } from '../Application/types';
|
|
7
8
|
|
|
8
9
|
type ContentInset = { insetLeft: number; insetRight: number };
|
|
@@ -64,18 +65,23 @@ export const renderContent = (content: any, layout: ContentInset): any => {
|
|
|
64
65
|
};
|
|
65
66
|
|
|
66
67
|
/**
|
|
67
|
-
* Animated banner from `animatedHeader.component`, clipped
|
|
68
|
-
*
|
|
68
|
+
* Animated banner from `animatedHeader.component`, clipped to the banner height plus
|
|
69
|
+
* `layoutOffset`. Nothing without a component.
|
|
69
70
|
*/
|
|
70
71
|
export const renderAnimatedHeader = (
|
|
71
72
|
animatedHeader: AnimatedHeader | undefined,
|
|
72
|
-
|
|
73
|
+
layoutOffset: number,
|
|
73
74
|
animatedValue: Animated.Value,
|
|
74
75
|
sharedValue: any,
|
|
75
76
|
) => {
|
|
76
77
|
if (typeof animatedHeader?.component === 'function') {
|
|
77
78
|
return (
|
|
78
|
-
<View
|
|
79
|
+
<View
|
|
80
|
+
style={[
|
|
81
|
+
styles.screenBanner,
|
|
82
|
+
{ maxHeight: ANIMATED_BANNER_HEIGHT + layoutOffset },
|
|
83
|
+
]}
|
|
84
|
+
>
|
|
79
85
|
{animatedHeader?.component({
|
|
80
86
|
animatedValue,
|
|
81
87
|
sharedValue,
|
package/Layout/screenHeader.tsx
CHANGED
|
@@ -13,9 +13,13 @@ import {
|
|
|
13
13
|
SearchHeader,
|
|
14
14
|
} from '../Application';
|
|
15
15
|
import { DuoGlassBackground } from '../Application/Components/DuoGlassBackground';
|
|
16
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
type HeaderContentLayout,
|
|
18
|
+
useHeaderFrameOptions,
|
|
19
|
+
useHeaderLayout,
|
|
20
|
+
} from '../Application/headerLayout';
|
|
17
21
|
import { getHeaderMargin } from './utils';
|
|
18
|
-
import {
|
|
22
|
+
import { ANIMATED_BANNER_HEIGHT } from './screenTypes';
|
|
19
23
|
import { HeaderType } from './types';
|
|
20
24
|
|
|
21
25
|
type ScreenHeaderParams = {
|
|
@@ -30,20 +34,18 @@ type ScreenHeaderParams = {
|
|
|
30
34
|
useShadowHeader: boolean;
|
|
31
35
|
gradientColor?: string;
|
|
32
36
|
headerBackground?: string;
|
|
33
|
-
|
|
37
|
+
layoutOffset: number;
|
|
34
38
|
contentLayout?: HeaderContentLayout;
|
|
35
39
|
};
|
|
36
40
|
|
|
37
41
|
/**
|
|
38
42
|
* Transparent header for an `inputSearchProps` Screen: its title fades out over the
|
|
39
|
-
* first 50pt of scroll while the search collapses into the bar
|
|
43
|
+
* first 50pt of scroll while the search collapses into the bar.
|
|
40
44
|
*/
|
|
41
45
|
const getSearchTitleOptions = (
|
|
42
46
|
sharedValue: SharedValue<number>,
|
|
43
|
-
searchTitleOptions: StackNavigationOptions,
|
|
44
47
|
): StackNavigationOptions => {
|
|
45
48
|
return {
|
|
46
|
-
...searchTitleOptions,
|
|
47
49
|
headerShown: true,
|
|
48
50
|
headerTransparent: true,
|
|
49
51
|
headerBackground: () => null,
|
|
@@ -77,14 +79,14 @@ export const useScreenHeader = ({
|
|
|
77
79
|
useShadowHeader,
|
|
78
80
|
gradientColor,
|
|
79
81
|
headerBackground,
|
|
80
|
-
|
|
82
|
+
layoutOffset,
|
|
81
83
|
contentLayout,
|
|
82
84
|
}: ScreenHeaderParams) => {
|
|
83
85
|
const currentTint = useRef<string | undefined>(undefined);
|
|
84
86
|
const appliedHeaderMode = useRef<string | undefined>(undefined);
|
|
85
87
|
const searchHeaderParams = useRef<SearchHeaderProps | undefined>(undefined);
|
|
86
|
-
const
|
|
87
|
-
const
|
|
88
|
+
const headerLayout = useHeaderLayout(contentLayout);
|
|
89
|
+
const frameOptions = useHeaderFrameOptions(contentLayout);
|
|
88
90
|
|
|
89
91
|
// keepTitle leaves a title the screen set itself when the same type is re-applied
|
|
90
92
|
const setHeaderType = useCallback(
|
|
@@ -113,7 +115,7 @@ export const useScreenHeader = ({
|
|
|
113
115
|
headerTitle: (props: any) => <HeaderTitle {...props} />,
|
|
114
116
|
};
|
|
115
117
|
if (inputSearchProps) {
|
|
116
|
-
options = getSearchTitleOptions(sharedValue
|
|
118
|
+
options = getSearchTitleOptions(sharedValue);
|
|
117
119
|
}
|
|
118
120
|
break;
|
|
119
121
|
|
|
@@ -147,7 +149,7 @@ export const useScreenHeader = ({
|
|
|
147
149
|
headerTitle: (props: any) => <HeaderTitle {...props} />,
|
|
148
150
|
};
|
|
149
151
|
if (inputSearchProps) {
|
|
150
|
-
options = getSearchTitleOptions(sharedValue
|
|
152
|
+
options = getSearchTitleOptions(sharedValue);
|
|
151
153
|
}
|
|
152
154
|
}
|
|
153
155
|
|
|
@@ -157,7 +159,7 @@ export const useScreenHeader = ({
|
|
|
157
159
|
|
|
158
160
|
navigation?.instance?.setOptions({
|
|
159
161
|
header: undefined,
|
|
160
|
-
...
|
|
162
|
+
...frameOptions,
|
|
161
163
|
...options,
|
|
162
164
|
});
|
|
163
165
|
},
|
|
@@ -170,8 +172,7 @@ export const useScreenHeader = ({
|
|
|
170
172
|
useShadowHeader,
|
|
171
173
|
hasSideBar,
|
|
172
174
|
quickReturnOptions,
|
|
173
|
-
|
|
174
|
-
searchTitleOptions,
|
|
175
|
+
frameOptions,
|
|
175
176
|
],
|
|
176
177
|
);
|
|
177
178
|
|
|
@@ -192,7 +193,7 @@ export const useScreenHeader = ({
|
|
|
192
193
|
return (
|
|
193
194
|
<DuoGlassBackground
|
|
194
195
|
animatedValue={sharedValue}
|
|
195
|
-
bannerBottom={
|
|
196
|
+
bannerBottom={ANIMATED_BANNER_HEIGHT + layoutOffset}
|
|
196
197
|
/>
|
|
197
198
|
);
|
|
198
199
|
}
|
|
@@ -219,7 +220,7 @@ export const useScreenHeader = ({
|
|
|
219
220
|
};
|
|
220
221
|
}
|
|
221
222
|
|
|
222
|
-
navigation?.instance?.setOptions({ ...
|
|
223
|
+
navigation?.instance?.setOptions({ ...frameOptions, ...options });
|
|
223
224
|
},
|
|
224
225
|
[
|
|
225
226
|
gradientColor,
|
|
@@ -228,20 +229,24 @@ export const useScreenHeader = ({
|
|
|
228
229
|
sharedValue,
|
|
229
230
|
useShadowHeader,
|
|
230
231
|
hasSideBar,
|
|
231
|
-
|
|
232
|
+
layoutOffset,
|
|
232
233
|
quickReturnOptions,
|
|
233
|
-
|
|
234
|
+
frameOptions,
|
|
234
235
|
],
|
|
235
236
|
);
|
|
236
237
|
|
|
237
238
|
const setAnimatedSearch = useCallback(() => {
|
|
238
|
-
const options = getSearchTitleOptions(sharedValue
|
|
239
|
-
navigation?.instance?.setOptions({
|
|
240
|
-
|
|
239
|
+
const options = getSearchTitleOptions(sharedValue);
|
|
240
|
+
navigation?.instance?.setOptions({
|
|
241
|
+
header: undefined,
|
|
242
|
+
...frameOptions,
|
|
243
|
+
...options,
|
|
244
|
+
});
|
|
245
|
+
}, [navigation?.instance, sharedValue, frameOptions]);
|
|
241
246
|
|
|
242
|
-
// the search field spans the content, clear of the side bar
|
|
243
|
-
// clusters; kept as numbers so the setter below stays stable
|
|
244
|
-
let searchWidth =
|
|
247
|
+
// the search field spans the content (or the stretch frame), clear of the side bar
|
|
248
|
+
// and status bar clusters; kept as numbers so the setter below stays stable
|
|
249
|
+
let searchWidth = headerLayout.frameWidth;
|
|
245
250
|
let searchLeft = Spacing.M;
|
|
246
251
|
if (layout.sideBar) {
|
|
247
252
|
searchWidth = layout.contentWidth - Spacing.M * 2;
|
|
@@ -260,7 +265,7 @@ export const useScreenHeader = ({
|
|
|
260
265
|
(params: SearchHeaderProps) => {
|
|
261
266
|
searchHeaderParams.current = params;
|
|
262
267
|
const options: StackNavigationOptions = {
|
|
263
|
-
...
|
|
268
|
+
...frameOptions,
|
|
264
269
|
headerRight: undefined,
|
|
265
270
|
headerTitleContainerStyle: {
|
|
266
271
|
width: searchWidth,
|
|
@@ -286,7 +291,7 @@ export const useScreenHeader = ({
|
|
|
286
291
|
|
|
287
292
|
navigation?.instance?.setOptions(options);
|
|
288
293
|
},
|
|
289
|
-
[navigation?.instance, sharedValue,
|
|
294
|
+
[navigation?.instance, sharedValue, frameOptions, searchWidth, searchLeft],
|
|
290
295
|
);
|
|
291
296
|
|
|
292
297
|
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 and the right cluster of the
|
|
87
|
-
* 600pt frame on wide windows (foldable inner display, tablet); the
|
|
88
|
-
*
|
|
86
|
+
* Optional. `stretch` centers back, title or search and the right cluster of the
|
|
87
|
+
* header in a 600pt frame on wide windows (foldable inner display, tablet); the
|
|
88
|
+
* background and status bar stay full width. Defaults to `grid`.
|
|
89
89
|
*/
|
|
90
90
|
contentLayout?: HeaderContentLayout;
|
|
91
91
|
|
package/package.json
CHANGED
|
@@ -1,113 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,54 +0,0 @@
|
|
|
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 };
|