@momo-kits/foundation 0.169.16-beta.10 → 0.169.16-beta.11
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/BottomTab/index.tsx +7 -5
- package/Application/Components/HeaderAnimated.tsx +9 -33
- package/Application/Components/HeaderExtendHeader.tsx +15 -22
- package/Application/headerLayout.ts +10 -40
- package/Application/types.header.ts +1 -7
- package/Application/types.tabs.ts +2 -1
- package/Application/utils.ts +17 -0
- package/Layout/Screen.tsx +4 -7
- package/Layout/layoutMetrics.ts +2 -2
- package/Layout/screenContent.tsx +10 -4
- package/Layout/screenHeader.tsx +31 -28
- package/Layout/screenTypes.ts +3 -3
- package/package.json +1 -1
- package/Application/__tests__/headerLayout.test.ts +0 -60
- package/Layout/useHeaderBarOptions.ts +0 -47
|
@@ -23,8 +23,9 @@ import { BottomTabInsetContext } from './BottomTabInset';
|
|
|
23
23
|
import { DuoBarCompressionProvider } from './DuoBarCompression';
|
|
24
24
|
import LegacyBottomTab from './Legacy';
|
|
25
25
|
import TabScreen from './TabScreen';
|
|
26
|
-
import { ApplicationContext } from '../../Context';
|
|
26
|
+
import { ApplicationContext, MiniAppContext } from '../../Context';
|
|
27
27
|
import { useScreenLayout } from '../../Layout';
|
|
28
|
+
import { isLegacyBottomTabDesignSystem } from '../utils';
|
|
28
29
|
|
|
29
30
|
type SceneInterpolator = BottomTabNavigationOptions['sceneStyleInterpolator'];
|
|
30
31
|
|
|
@@ -192,13 +193,14 @@ const FloatingBottomTab: React.FC<BottomTabProps> = ({
|
|
|
192
193
|
};
|
|
193
194
|
|
|
194
195
|
/**
|
|
195
|
-
* App tab navigator. `useLegacy
|
|
196
|
-
* iPhone Duo always uses the
|
|
196
|
+
* App tab navigator. `useLegacy`, else the host's `designSystemConfig`, picks the
|
|
197
|
+
* pre-redesign docked bar on phones; iPhone Duo always uses the rail or floating bar.
|
|
197
198
|
*/
|
|
198
199
|
const BottomTab: React.FC<BottomTabProps> = props => {
|
|
199
200
|
const { isIPhoneDuo } = useScreenLayout();
|
|
200
|
-
|
|
201
|
-
|
|
201
|
+
const context = useContext<object | undefined>(MiniAppContext);
|
|
202
|
+
const isLegacy = props.useLegacy ?? isLegacyBottomTabDesignSystem(context);
|
|
203
|
+
if (isLegacy && !isIPhoneDuo) {
|
|
202
204
|
return <LegacyBottomTab {...props} />;
|
|
203
205
|
}
|
|
204
206
|
return <FloatingBottomTab {...props} />;
|
|
@@ -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,6 +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 { HeaderMetrics } from '../../Layout/utils';
|
|
20
21
|
import {
|
|
21
22
|
HeaderBarMetrics,
|
|
22
23
|
type HeaderContentLayout,
|
|
@@ -27,14 +28,10 @@ import { useHeaderRightWidth } from './useHeaderRightWidth';
|
|
|
27
28
|
const { buttonSize, pillWidth, sidePadding, titleGap } = HeaderBarMetrics;
|
|
28
29
|
const SCREEN_PADDING = sidePadding;
|
|
29
30
|
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;
|
|
34
31
|
|
|
35
32
|
/**
|
|
36
33
|
* Extended header background: a gradient that collapses on scroll and, with
|
|
37
|
-
* `inputSearchProps`, a
|
|
34
|
+
* `inputSearchProps`, a full-width search that slides into the bar beside back/toolkit.
|
|
38
35
|
*/
|
|
39
36
|
const HeaderExtendHeader: React.FC<{
|
|
40
37
|
headerType?: HeaderType;
|
|
@@ -47,9 +44,6 @@ const HeaderExtendHeader: React.FC<{
|
|
|
47
44
|
useShadowHeader?: boolean;
|
|
48
45
|
gradientColor?: string;
|
|
49
46
|
headerBackground?: string;
|
|
50
|
-
/**
|
|
51
|
-
* @deprecated Ignored: the search spans the window with either content layout.
|
|
52
|
-
*/
|
|
53
47
|
contentLayout?: HeaderContentLayout;
|
|
54
48
|
}> = ({
|
|
55
49
|
headerType = 'default',
|
|
@@ -61,6 +55,7 @@ const HeaderExtendHeader: React.FC<{
|
|
|
61
55
|
useShadowHeader: useShadowHeaderProp = true,
|
|
62
56
|
gradientColor: customGradientColor,
|
|
63
57
|
headerBackground: customBackground,
|
|
58
|
+
contentLayout,
|
|
64
59
|
}) => {
|
|
65
60
|
const { theme } = useContext(ApplicationContext);
|
|
66
61
|
const context = useContext<any>(MiniAppContext);
|
|
@@ -68,7 +63,9 @@ const HeaderExtendHeader: React.FC<{
|
|
|
68
63
|
const gradientColor = customGradientColor ?? theme.colors.gradient;
|
|
69
64
|
const headerBackground = customBackground ?? theme.assets?.headerBackground;
|
|
70
65
|
const layout = useScreenLayout();
|
|
71
|
-
const headerLayout = useHeaderLayout();
|
|
66
|
+
const headerLayout = useHeaderLayout(contentLayout);
|
|
67
|
+
// the stretch frame pulls the search in from both bar edges
|
|
68
|
+
const frameShift = headerLayout.frameInset - sidePadding;
|
|
72
69
|
|
|
73
70
|
const backLeft = buttonSize + sidePadding + titleGap;
|
|
74
71
|
const defaultLeft = layout.sideBar ? SCREEN_PADDING : backLeft;
|
|
@@ -76,26 +73,22 @@ const HeaderExtendHeader: React.FC<{
|
|
|
76
73
|
const measuredRightWidth = useHeaderRightWidth() ?? TOOLKIT_WIDTH;
|
|
77
74
|
const defaultRightWidth = layout.sideBar ? 0 : measuredRightWidth;
|
|
78
75
|
const headerRightWidth = customHeaderRightWidth ?? defaultRightWidth;
|
|
79
|
-
const contentLeft = layout.insetLeft + SCREEN_PADDING;
|
|
80
|
-
const contentRight = layout.insetLeft + layout.contentWidth;
|
|
76
|
+
const contentLeft = layout.insetLeft + SCREEN_PADDING + frameShift;
|
|
77
|
+
const contentRight = layout.insetLeft + layout.contentWidth - frameShift;
|
|
81
78
|
// collapsed on the status bar row, the search stays between its clusters
|
|
82
79
|
const clearanceLeft = layout.statusBarClearance?.left ?? 0;
|
|
83
80
|
const clearanceRight = layout.statusBarClearance?.right ?? 0;
|
|
84
|
-
const searchLeft = leftPosition + clearanceLeft;
|
|
81
|
+
const searchLeft = leftPosition + clearanceLeft + frameShift;
|
|
85
82
|
const collapsedLeft = layout.insetLeft + searchLeft;
|
|
86
83
|
const collapsedRight = contentRight - clearanceRight - headerRightWidth;
|
|
87
84
|
const searchWidth = contentRight - contentLeft - SCREEN_PADDING;
|
|
88
85
|
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
|
+
|
|
89
90
|
// the iPhone Duo side bar keeps the content search size
|
|
90
91
|
const searchSize = layout.sideBar ? 'default' : 'header';
|
|
91
|
-
// expanded search row under the bar: the search plus its vertical margins
|
|
92
|
-
let searchRowHeight = HeaderBarMetrics.searchBarHeight;
|
|
93
|
-
if (layout.sideBar) {
|
|
94
|
-
searchRowHeight = DUO_SEARCH_ROW_HEIGHT;
|
|
95
|
-
}
|
|
96
|
-
// a row taller than the search row (iPhone Duo) centers the collapsed search on the title
|
|
97
|
-
const titleRowHeight = heightHeader - layout.headerStatusBarHeight;
|
|
98
|
-
const collapsedRaise = (titleRowHeight - searchRowHeight) / 2;
|
|
99
92
|
|
|
100
93
|
let useShadowHeader = useShadowHeaderProp;
|
|
101
94
|
if (inputSearchProps && Platform.OS === 'android') {
|
|
@@ -108,7 +101,7 @@ const HeaderExtendHeader: React.FC<{
|
|
|
108
101
|
height: interpolate(
|
|
109
102
|
sharedValue.value,
|
|
110
103
|
[0, 100],
|
|
111
|
-
[heightHeader +
|
|
104
|
+
[heightHeader + 52, heightHeader],
|
|
112
105
|
Extrapolation.CLAMP,
|
|
113
106
|
),
|
|
114
107
|
}));
|
|
@@ -161,7 +154,7 @@ const HeaderExtendHeader: React.FC<{
|
|
|
161
154
|
height: interpolate(
|
|
162
155
|
sharedValue.value,
|
|
163
156
|
[0, 100],
|
|
164
|
-
[heightHeader +
|
|
157
|
+
[heightHeader + 52, heightHeader],
|
|
165
158
|
Extrapolation.CLAMP,
|
|
166
159
|
),
|
|
167
160
|
}));
|
|
@@ -8,8 +8,8 @@ import { isIPhoneDuo } from './utils';
|
|
|
8
8
|
|
|
9
9
|
// Top navigation spec, shared with the Compose / SwiftUI kits
|
|
10
10
|
const HEADER_FRAME_MAX_WIDTH = 600;
|
|
11
|
-
//
|
|
12
|
-
const
|
|
11
|
+
// stretch frame on hold until design confirms it: `stretch` lays out like `grid`
|
|
12
|
+
const IS_STRETCH_FRAME_ENABLED = false;
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Top navigation geometry on every device
|
|
@@ -17,11 +17,10 @@ const WIDE_BANNER_SCALE = 1.2;
|
|
|
17
17
|
* - pillWidth / pillHeight: help center | home capsule
|
|
18
18
|
* - clusterWidth: shortcut, gap and pill on the right of the bar
|
|
19
19
|
* - searchHeight: search field inside the header
|
|
20
|
-
* - searchBarHeight: header row holding the search, taller than the plain bar
|
|
21
20
|
* - titleGap: space between back and the title, and the title and the right cluster
|
|
22
21
|
* - sidePadding: bar edge to back and to the right cluster
|
|
23
22
|
* - gradientHeight: header gradient, kept at the phone height on wide windows
|
|
24
|
-
* - bannerWidth: animated banner image
|
|
23
|
+
* - bannerWidth: animated banner image, kept at the phone width on wide windows
|
|
25
24
|
*/
|
|
26
25
|
const HeaderBarMetrics = {
|
|
27
26
|
buttonSize: 32,
|
|
@@ -29,17 +28,17 @@ const HeaderBarMetrics = {
|
|
|
29
28
|
pillWidth: 72,
|
|
30
29
|
pillHeight: 32,
|
|
31
30
|
clusterWidth: 112,
|
|
32
|
-
searchHeight:
|
|
33
|
-
searchBarHeight: 56,
|
|
31
|
+
searchHeight: 32,
|
|
34
32
|
titleGap: Spacing.S,
|
|
35
33
|
sidePadding: Spacing.M,
|
|
36
34
|
gradientHeight: 154,
|
|
37
|
-
bannerWidth:
|
|
35
|
+
bannerWidth: 375,
|
|
38
36
|
};
|
|
39
37
|
|
|
40
38
|
/**
|
|
41
39
|
* `grid` keeps the header row at the bar edges, `stretch` centers it in a 600pt
|
|
42
|
-
* 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.
|
|
43
42
|
*/
|
|
44
43
|
type HeaderContentLayout = 'grid' | 'stretch';
|
|
45
44
|
|
|
@@ -54,10 +53,6 @@ type HeaderLayout = typeof HeaderBarMetrics & {
|
|
|
54
53
|
* inner display, portrait and landscape.
|
|
55
54
|
*/
|
|
56
55
|
isBannerCentered: boolean;
|
|
57
|
-
/**
|
|
58
|
-
* Banner size against the phone banner: `WIDE_BANNER_SCALE` when centered, else 1.
|
|
59
|
-
*/
|
|
60
|
-
bannerScale: number;
|
|
61
56
|
/**
|
|
62
57
|
* Window edge to back and to the right cluster: `sidePadding`, or centering the
|
|
63
58
|
* row in the 600pt frame with `stretch` on a wide window.
|
|
@@ -89,19 +84,15 @@ const getHeaderLayout = ({
|
|
|
89
84
|
const isLargeWindow = Math.min(width, height) >= FOLDABLE_MIN_WIDTH;
|
|
90
85
|
const isWide = !isDuo && isLargeWindow;
|
|
91
86
|
let frameInset = sidePadding;
|
|
92
|
-
|
|
87
|
+
const isStretch = IS_STRETCH_FRAME_ENABLED && contentLayout === 'stretch';
|
|
88
|
+
if (isWide && isStretch) {
|
|
93
89
|
const centered = (width - HEADER_FRAME_MAX_WIDTH) / 2;
|
|
94
90
|
frameInset = Math.max(sidePadding, centered);
|
|
95
91
|
}
|
|
96
|
-
let bannerScale = 1;
|
|
97
|
-
if (isLargeWindow) {
|
|
98
|
-
bannerScale = WIDE_BANNER_SCALE;
|
|
99
|
-
}
|
|
100
92
|
return {
|
|
101
93
|
...HeaderBarMetrics,
|
|
102
94
|
isWide,
|
|
103
95
|
isBannerCentered: isLargeWindow,
|
|
104
|
-
bannerScale,
|
|
105
96
|
frameInset,
|
|
106
97
|
frameWidth: width - frameInset * 2,
|
|
107
98
|
};
|
|
@@ -126,25 +117,6 @@ const useHeaderLayout = (contentLayout?: HeaderContentLayout): HeaderLayout => {
|
|
|
126
117
|
}, [width, height, isDuo, contentLayout]);
|
|
127
118
|
};
|
|
128
119
|
|
|
129
|
-
/**
|
|
130
|
-
* Header height once the search sits in its row: the row grows to `searchBarHeight`,
|
|
131
|
-
* a taller row (iPhone landscape, iPhone Duo) keeps its height.
|
|
132
|
-
*/
|
|
133
|
-
const getSearchHeaderHeight = (
|
|
134
|
-
headerHeight: number,
|
|
135
|
-
statusBarHeight: number,
|
|
136
|
-
) => {
|
|
137
|
-
const rowHeight = headerHeight - statusBarHeight;
|
|
138
|
-
const { searchBarHeight } = HeaderBarMetrics;
|
|
139
|
-
return statusBarHeight + Math.max(rowHeight, searchBarHeight);
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
// a search spans the window, so back and the right cluster leave the stretch frame
|
|
143
|
-
const SEARCH_FRAME_RESET: StackNavigationOptions = {
|
|
144
|
-
headerLeftContainerStyle: { paddingLeft: 0 },
|
|
145
|
-
headerRightContainerStyle: { paddingRight: 0 },
|
|
146
|
-
};
|
|
147
|
-
|
|
148
120
|
const TITLE_CONTAINER_RESET: ViewStyle = {
|
|
149
121
|
marginLeft: 0,
|
|
150
122
|
marginEnd: 0,
|
|
@@ -166,7 +138,7 @@ const useHeaderFrameOptions = (
|
|
|
166
138
|
const { width } = useWindowDimensions();
|
|
167
139
|
const isDuo = isIPhoneDuo();
|
|
168
140
|
return useMemo(() => {
|
|
169
|
-
if (contentLayout !== 'stretch' || isDuo) {
|
|
141
|
+
if (!IS_STRETCH_FRAME_ENABLED || contentLayout !== 'stretch' || isDuo) {
|
|
170
142
|
return undefined;
|
|
171
143
|
}
|
|
172
144
|
// the header content row already sits this far in on large iOS windows
|
|
@@ -189,10 +161,8 @@ export type { HeaderContentLayout, HeaderLayout };
|
|
|
189
161
|
export {
|
|
190
162
|
HeaderBarMetrics,
|
|
191
163
|
HEADER_FRAME_MAX_WIDTH,
|
|
192
|
-
SEARCH_FRAME_RESET,
|
|
193
164
|
TITLE_CONTAINER_RESET,
|
|
194
165
|
getHeaderLayout,
|
|
195
|
-
getSearchHeaderHeight,
|
|
196
166
|
getTitleBudget,
|
|
197
167
|
useHeaderLayout,
|
|
198
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 = {
|
|
@@ -36,7 +36,8 @@ export type BottomTabProps = {
|
|
|
36
36
|
/**
|
|
37
37
|
* Renders the pre-redesign docked phone bar instead of the floating one. Ignores
|
|
38
38
|
* `showDot`, `floatingButton.labelContent` and `compressionBehavior`; not on iPhone Duo.
|
|
39
|
-
* Defaults to
|
|
39
|
+
* Defaults to the host's `designSystemConfig.useLegacyBottomTab`, else true; pass
|
|
40
|
+
* false for the floating bar.
|
|
40
41
|
*/
|
|
41
42
|
useLegacy?: boolean;
|
|
42
43
|
};
|
package/Application/utils.ts
CHANGED
|
@@ -12,6 +12,10 @@ type AnimatedCompatValue = Animated.Value | SharedValue<number>;
|
|
|
12
12
|
|
|
13
13
|
type NavigationTreeState = NavigationState | PartialState<NavigationState>;
|
|
14
14
|
|
|
15
|
+
type DesignSystemContext = {
|
|
16
|
+
designSystemConfig?: { useLegacyBottomTab?: unknown };
|
|
17
|
+
};
|
|
18
|
+
|
|
15
19
|
/**
|
|
16
20
|
* True when `value` has a callable property `name`. Safe on null and primitives.
|
|
17
21
|
*/
|
|
@@ -77,6 +81,18 @@ const isWhiteListDesignSystem = (context: any): boolean => {
|
|
|
77
81
|
return context?.designSystemConfig?.isWhiteListDesignSystem === true;
|
|
78
82
|
};
|
|
79
83
|
|
|
84
|
+
/**
|
|
85
|
+
* True when the host config asks for the legacy docked BottomTab. Legacy unless
|
|
86
|
+
* the host sends a boolean `designSystemConfig.useLegacyBottomTab`.
|
|
87
|
+
*/
|
|
88
|
+
const isLegacyBottomTabDesignSystem = (context?: DesignSystemContext) => {
|
|
89
|
+
const useLegacyBottomTab = context?.designSystemConfig?.useLegacyBottomTab;
|
|
90
|
+
if (typeof useLegacyBottomTab !== 'boolean') {
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
return useLegacyBottomTab;
|
|
94
|
+
};
|
|
95
|
+
|
|
80
96
|
/**
|
|
81
97
|
* Shorter edge of a screen or window size.
|
|
82
98
|
*/
|
|
@@ -103,5 +119,6 @@ export {
|
|
|
103
119
|
setAutomationID,
|
|
104
120
|
getStackDepth,
|
|
105
121
|
isWhiteListDesignSystem,
|
|
122
|
+
isLegacyBottomTabDesignSystem,
|
|
106
123
|
isIPhoneDuo,
|
|
107
124
|
};
|
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
|
|
|
@@ -229,6 +225,7 @@ const Screen = forwardRef(
|
|
|
229
225
|
useShadowHeader={useShadowHeader}
|
|
230
226
|
gradientColor={gradientColor}
|
|
231
227
|
headerBackground={headerBackground}
|
|
228
|
+
contentLayout={contentLayout}
|
|
232
229
|
/>
|
|
233
230
|
);
|
|
234
231
|
};
|
|
@@ -282,7 +279,7 @@ const Screen = forwardRef(
|
|
|
282
279
|
>
|
|
283
280
|
{renderAnimatedHeader(
|
|
284
281
|
animatedHeader,
|
|
285
|
-
|
|
282
|
+
layoutOffset,
|
|
286
283
|
animatedValue.current,
|
|
287
284
|
sharedValue,
|
|
288
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
|
-
searchOptions: StackNavigationOptions,
|
|
44
47
|
): StackNavigationOptions => {
|
|
45
48
|
return {
|
|
46
|
-
...searchOptions,
|
|
47
49
|
headerShown: true,
|
|
48
50
|
headerTransparent: true,
|
|
49
51
|
headerBackground: () => null,
|
|
@@ -77,16 +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
|
-
|
|
88
|
-
contentLayout,
|
|
89
|
-
);
|
|
88
|
+
const headerLayout = useHeaderLayout(contentLayout);
|
|
89
|
+
const frameOptions = useHeaderFrameOptions(contentLayout);
|
|
90
90
|
|
|
91
91
|
// keepTitle leaves a title the screen set itself when the same type is re-applied
|
|
92
92
|
const setHeaderType = useCallback(
|
|
@@ -115,7 +115,7 @@ export const useScreenHeader = ({
|
|
|
115
115
|
headerTitle: (props: any) => <HeaderTitle {...props} />,
|
|
116
116
|
};
|
|
117
117
|
if (inputSearchProps) {
|
|
118
|
-
options = getSearchTitleOptions(sharedValue
|
|
118
|
+
options = getSearchTitleOptions(sharedValue);
|
|
119
119
|
}
|
|
120
120
|
break;
|
|
121
121
|
|
|
@@ -149,7 +149,7 @@ export const useScreenHeader = ({
|
|
|
149
149
|
headerTitle: (props: any) => <HeaderTitle {...props} />,
|
|
150
150
|
};
|
|
151
151
|
if (inputSearchProps) {
|
|
152
|
-
options = getSearchTitleOptions(sharedValue
|
|
152
|
+
options = getSearchTitleOptions(sharedValue);
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
155
|
|
|
@@ -159,7 +159,7 @@ export const useScreenHeader = ({
|
|
|
159
159
|
|
|
160
160
|
navigation?.instance?.setOptions({
|
|
161
161
|
header: undefined,
|
|
162
|
-
...
|
|
162
|
+
...frameOptions,
|
|
163
163
|
...options,
|
|
164
164
|
});
|
|
165
165
|
},
|
|
@@ -172,8 +172,7 @@ export const useScreenHeader = ({
|
|
|
172
172
|
useShadowHeader,
|
|
173
173
|
hasSideBar,
|
|
174
174
|
quickReturnOptions,
|
|
175
|
-
|
|
176
|
-
searchOptions,
|
|
175
|
+
frameOptions,
|
|
177
176
|
],
|
|
178
177
|
);
|
|
179
178
|
|
|
@@ -194,7 +193,7 @@ export const useScreenHeader = ({
|
|
|
194
193
|
return (
|
|
195
194
|
<DuoGlassBackground
|
|
196
195
|
animatedValue={sharedValue}
|
|
197
|
-
bannerBottom={
|
|
196
|
+
bannerBottom={ANIMATED_BANNER_HEIGHT + layoutOffset}
|
|
198
197
|
/>
|
|
199
198
|
);
|
|
200
199
|
}
|
|
@@ -221,7 +220,7 @@ export const useScreenHeader = ({
|
|
|
221
220
|
};
|
|
222
221
|
}
|
|
223
222
|
|
|
224
|
-
navigation?.instance?.setOptions({ ...
|
|
223
|
+
navigation?.instance?.setOptions({ ...frameOptions, ...options });
|
|
225
224
|
},
|
|
226
225
|
[
|
|
227
226
|
gradientColor,
|
|
@@ -230,20 +229,24 @@ export const useScreenHeader = ({
|
|
|
230
229
|
sharedValue,
|
|
231
230
|
useShadowHeader,
|
|
232
231
|
hasSideBar,
|
|
233
|
-
|
|
232
|
+
layoutOffset,
|
|
234
233
|
quickReturnOptions,
|
|
235
|
-
|
|
234
|
+
frameOptions,
|
|
236
235
|
],
|
|
237
236
|
);
|
|
238
237
|
|
|
239
238
|
const setAnimatedSearch = useCallback(() => {
|
|
240
|
-
const options = getSearchTitleOptions(sharedValue
|
|
241
|
-
navigation?.instance?.setOptions({
|
|
242
|
-
|
|
239
|
+
const options = getSearchTitleOptions(sharedValue);
|
|
240
|
+
navigation?.instance?.setOptions({
|
|
241
|
+
header: undefined,
|
|
242
|
+
...frameOptions,
|
|
243
|
+
...options,
|
|
244
|
+
});
|
|
245
|
+
}, [navigation?.instance, sharedValue, frameOptions]);
|
|
243
246
|
|
|
244
|
-
// the search field spans the content, clear of the side bar
|
|
245
|
-
// clusters; kept as numbers so the setter below stays stable
|
|
246
|
-
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;
|
|
247
250
|
let searchLeft = Spacing.M;
|
|
248
251
|
if (layout.sideBar) {
|
|
249
252
|
searchWidth = layout.contentWidth - Spacing.M * 2;
|
|
@@ -262,7 +265,7 @@ export const useScreenHeader = ({
|
|
|
262
265
|
(params: SearchHeaderProps) => {
|
|
263
266
|
searchHeaderParams.current = params;
|
|
264
267
|
const options: StackNavigationOptions = {
|
|
265
|
-
...
|
|
268
|
+
...frameOptions,
|
|
266
269
|
headerRight: undefined,
|
|
267
270
|
headerTitleContainerStyle: {
|
|
268
271
|
width: searchWidth,
|
|
@@ -288,7 +291,7 @@ export const useScreenHeader = ({
|
|
|
288
291
|
|
|
289
292
|
navigation?.instance?.setOptions(options);
|
|
290
293
|
},
|
|
291
|
-
[navigation?.instance, sharedValue,
|
|
294
|
+
[navigation?.instance, sharedValue, frameOptions, searchWidth, searchLeft],
|
|
292
295
|
);
|
|
293
296
|
|
|
294
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,60 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getHeaderLayout,
|
|
3
|
-
getSearchHeaderHeight,
|
|
4
|
-
HeaderBarMetrics,
|
|
5
|
-
} from '../headerLayout';
|
|
6
|
-
|
|
7
|
-
const PHONE = { width: 375, height: 812 };
|
|
8
|
-
const FOLD_INNER = { width: 760, height: 840 };
|
|
9
|
-
const DUO_INNER = { width: 932, height: 678 };
|
|
10
|
-
|
|
11
|
-
describe('getHeaderLayout', () => {
|
|
12
|
-
it('keeps the phone row at the bar edges with a full-width banner', () => {
|
|
13
|
-
const layout = getHeaderLayout({ ...PHONE, isDuo: false });
|
|
14
|
-
expect(layout.isWide).toBe(false);
|
|
15
|
-
expect(layout.isBannerCentered).toBe(false);
|
|
16
|
-
expect(layout.bannerScale).toBe(1);
|
|
17
|
-
expect(layout.frameInset).toBe(HeaderBarMetrics.sidePadding);
|
|
18
|
-
expect(layout.frameWidth).toBe(351);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it('keeps the grid row at the bar edges on a 760 window', () => {
|
|
22
|
-
const layout = getHeaderLayout({ ...FOLD_INNER, isDuo: false });
|
|
23
|
-
expect(layout.isWide).toBe(true);
|
|
24
|
-
expect(layout.frameInset).toBe(HeaderBarMetrics.sidePadding);
|
|
25
|
-
expect(layout.frameWidth).toBe(736);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('centers the stretch row in the 600 frame on a 760 window', () => {
|
|
29
|
-
const input = { ...FOLD_INNER, isDuo: false };
|
|
30
|
-
const layout = getHeaderLayout({ ...input, contentLayout: 'stretch' });
|
|
31
|
-
expect(layout.frameInset).toBe(80);
|
|
32
|
-
expect(layout.frameWidth).toBe(600);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('scales the centered banner to 450 on a 760 window', () => {
|
|
36
|
-
const layout = getHeaderLayout({ ...FOLD_INNER, isDuo: false });
|
|
37
|
-
expect(layout.isBannerCentered).toBe(true);
|
|
38
|
-
expect(layout.bannerScale).toBe(1.2);
|
|
39
|
-
expect(layout.bannerWidth).toBe(450);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('centers the banner on the iPhone Duo inner display, without the frame', () => {
|
|
43
|
-
const input = { ...DUO_INNER, isDuo: true };
|
|
44
|
-
const layout = getHeaderLayout({ ...input, contentLayout: 'stretch' });
|
|
45
|
-
expect(layout.isWide).toBe(false);
|
|
46
|
-
expect(layout.isBannerCentered).toBe(true);
|
|
47
|
-
expect(layout.bannerScale).toBe(1.2);
|
|
48
|
-
expect(layout.frameInset).toBe(HeaderBarMetrics.sidePadding);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
describe('getSearchHeaderHeight', () => {
|
|
53
|
-
it('grows a 48 bar row to the 56 search row', () => {
|
|
54
|
-
expect(getSearchHeaderHeight(48 + 47, 47)).toBe(56 + 47);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('keeps a row taller than the search row', () => {
|
|
58
|
-
expect(getSearchHeaderHeight(72, 0)).toBe(72);
|
|
59
|
-
});
|
|
60
|
-
});
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { useMemo } from 'react';
|
|
2
|
-
import type { StackNavigationOptions } from '@react-navigation/stack';
|
|
3
|
-
import {
|
|
4
|
-
getSearchHeaderHeight,
|
|
5
|
-
type HeaderContentLayout,
|
|
6
|
-
SEARCH_FRAME_RESET,
|
|
7
|
-
useHeaderFrameOptions,
|
|
8
|
-
} from '../Application/headerLayout';
|
|
9
|
-
import type { ScreenLayout } from './layoutTypes';
|
|
10
|
-
|
|
11
|
-
type HeaderBarOptions = {
|
|
12
|
-
barOptions: StackNavigationOptions;
|
|
13
|
-
searchOptions: StackNavigationOptions;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Header row options for the Screen setters: the plain bar in the `contentLayout`
|
|
18
|
-
* frame, and the taller search row, which spans the window and leaves the frame.
|
|
19
|
-
*/
|
|
20
|
-
const useHeaderBarOptions = (
|
|
21
|
-
layout: ScreenLayout,
|
|
22
|
-
contentLayout?: HeaderContentLayout,
|
|
23
|
-
): HeaderBarOptions => {
|
|
24
|
-
const frameOptions = useHeaderFrameOptions(contentLayout);
|
|
25
|
-
const { headerHeight, headerStatusBarHeight } = layout;
|
|
26
|
-
const searchHeight = getSearchHeaderHeight(
|
|
27
|
-
headerHeight,
|
|
28
|
-
headerStatusBarHeight,
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
// the height is re-applied on every header type, so a former search row does not stay
|
|
32
|
-
const barOptions = useMemo((): StackNavigationOptions => {
|
|
33
|
-
return { ...frameOptions, headerStyle: { height: headerHeight } };
|
|
34
|
-
}, [frameOptions, headerHeight]);
|
|
35
|
-
|
|
36
|
-
const searchOptions = useMemo((): StackNavigationOptions => {
|
|
37
|
-
const headerStyle = { height: searchHeight };
|
|
38
|
-
if (!frameOptions) {
|
|
39
|
-
return { headerStyle };
|
|
40
|
-
}
|
|
41
|
-
return { ...SEARCH_FRAME_RESET, headerStyle };
|
|
42
|
-
}, [frameOptions, searchHeight]);
|
|
43
|
-
|
|
44
|
-
return { barOptions, searchOptions };
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export { useHeaderBarOptions };
|