@momo-kits/foundation 0.169.17-beta.5 → 0.169.17-beta.6

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.
@@ -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 keep
27
- * it at phone size, centered.
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
- {!!bannerBackgroundColor && (
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.phoneBanner}>{content}</View>
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
- phoneBanner: {
137
+ centeredBanner: {
114
138
  width: HeaderBarMetrics.bannerWidth,
115
139
  height: '100%',
116
140
  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 { HeaderMetrics } from '../../Layout/utils';
20
+ import { getHeaderMargin } from '../../Layout/utils';
21
21
  import {
22
22
  HeaderBarMetrics,
23
23
  type HeaderContentLayout,
@@ -28,10 +28,12 @@ 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;
31
33
 
32
34
  /**
33
35
  * Extended header background: a gradient that collapses on scroll and, with
34
- * `inputSearchProps`, a full-width search that slides into the bar beside back/toolkit.
36
+ * `inputSearchProps`, a window-wide search that slides into the bar beside back/toolkit.
35
37
  */
36
38
  const HeaderExtendHeader: React.FC<{
37
39
  headerType?: HeaderType;
@@ -44,6 +46,10 @@ const HeaderExtendHeader: React.FC<{
44
46
  useShadowHeader?: boolean;
45
47
  gradientColor?: string;
46
48
  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
+ */
47
53
  contentLayout?: HeaderContentLayout;
48
54
  }> = ({
49
55
  headerType = 'default',
@@ -64,8 +70,12 @@ const HeaderExtendHeader: React.FC<{
64
70
  const headerBackground = customBackground ?? theme.assets?.headerBackground;
65
71
  const layout = useScreenLayout();
66
72
  const headerLayout = useHeaderLayout(contentLayout);
67
- // the stretch frame pulls the search in from both bar edges
68
- const frameShift = headerLayout.frameInset - sidePadding;
73
+ // collapsed into the bar, the search follows back and the right cluster into the
74
+ // frame, or the side margin React Navigation adds on large iOS windows (the larger)
75
+ let frameShift = headerLayout.frameInset - sidePadding;
76
+ if (!layout.sideBar) {
77
+ frameShift = Math.max(frameShift, getHeaderMargin(layout.width));
78
+ }
69
79
 
70
80
  const backLeft = buttonSize + sidePadding + titleGap;
71
81
  const defaultLeft = layout.sideBar ? SCREEN_PADDING : backLeft;
@@ -73,22 +83,22 @@ const HeaderExtendHeader: React.FC<{
73
83
  const measuredRightWidth = useHeaderRightWidth() ?? TOOLKIT_WIDTH;
74
84
  const defaultRightWidth = layout.sideBar ? 0 : measuredRightWidth;
75
85
  const headerRightWidth = customHeaderRightWidth ?? defaultRightWidth;
76
- const contentLeft = layout.insetLeft + SCREEN_PADDING + frameShift;
77
- const contentRight = layout.insetLeft + layout.contentWidth - frameShift;
86
+ const contentLeft = layout.insetLeft + SCREEN_PADDING;
87
+ const contentRight = layout.insetLeft + layout.contentWidth;
78
88
  // collapsed on the status bar row, the search stays between its clusters
79
89
  const clearanceLeft = layout.statusBarClearance?.left ?? 0;
80
90
  const clearanceRight = layout.statusBarClearance?.right ?? 0;
81
- const searchLeft = leftPosition + clearanceLeft + frameShift;
82
- const collapsedLeft = layout.insetLeft + searchLeft;
83
- const collapsedRight = contentRight - clearanceRight - headerRightWidth;
91
+ const searchLeft = leftPosition + clearanceLeft;
92
+ const collapsedLeft = layout.insetLeft + searchLeft + frameShift;
93
+ const barRight = contentRight - clearanceRight - frameShift;
94
+ const collapsedRight = barRight - headerRightWidth;
84
95
  const searchWidth = contentRight - contentLeft - SCREEN_PADDING;
85
96
  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
- // the iPhone Duo side bar keeps the content search size
91
- const searchSize = layout.sideBar ? 'default' : 'header';
97
+ // expanded search row under the bar: the search plus its vertical margins
98
+ const searchRowHeight = HeaderBarMetrics.searchBarHeight;
99
+ // a row taller than the search row (iPhone Duo) centers the collapsed search on the title
100
+ const titleRowHeight = heightHeader - layout.headerStatusBarHeight;
101
+ const collapsedRaise = (titleRowHeight - searchRowHeight) / 2;
92
102
 
93
103
  let useShadowHeader = useShadowHeaderProp;
94
104
  if (inputSearchProps && Platform.OS === 'android') {
@@ -101,7 +111,7 @@ const HeaderExtendHeader: React.FC<{
101
111
  height: interpolate(
102
112
  sharedValue.value,
103
113
  [0, 100],
104
- [heightHeader + 52, heightHeader],
114
+ [heightHeader + searchRowHeight, heightHeader],
105
115
  Extrapolation.CLAMP,
106
116
  ),
107
117
  }));
@@ -154,7 +164,7 @@ const HeaderExtendHeader: React.FC<{
154
164
  height: interpolate(
155
165
  sharedValue.value,
156
166
  [0, 100],
157
- [heightHeader + 52, heightHeader],
167
+ [heightHeader + EXTENDED_HEIGHT_EXTRA, heightHeader],
158
168
  Extrapolation.CLAMP,
159
169
  ),
160
170
  }));
@@ -215,7 +225,7 @@ const HeaderExtendHeader: React.FC<{
215
225
  <InputSearch
216
226
  {...inputSearchProps}
217
227
  ref={inputSearchRef}
218
- size={searchSize}
228
+ size={'header'}
219
229
  backgroundColor={'transparent'}
220
230
  showButtonText={false}
221
231
  />
@@ -1,5 +1,5 @@
1
1
  import { Colors, Radius, Spacing, Styles } from '../../Consts';
2
- import { InputRef, InputSearch, type InputSearchProps } from '../../Input';
2
+ import { InputRef, InputSearch } 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,6 +8,7 @@ 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';
11
12
  import { HeaderBarMetrics } from '../headerLayout';
12
13
  import { useHeaderRightWidth } from './useHeaderRightWidth';
13
14
 
@@ -36,10 +37,8 @@ const SearchHeader = React.forwardRef<InputRef, SearchHeaderProps>(
36
37
  const context = useContext<any>(MiniAppContext);
37
38
  const layout = useScreenLayout();
38
39
  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';
43
42
  }
44
43
 
45
44
  const sharedValue = useNormalizedSharedValue(animatedValue);
@@ -48,7 +47,10 @@ const SearchHeader = React.forwardRef<InputRef, SearchHeaderProps>(
48
47
  const headerRightWidth = props?.headerRightWidth ?? defaultRightWidth;
49
48
 
50
49
  // iPhone Duo side bar holds back: the search shares the content width with the buttons only
51
- const rowWidth = layout.width - leftPosition - sidePadding;
50
+ // large iOS windows: React Navigation narrows the header row by a margin each side
51
+ const headerMargin = getHeaderMargin(layout.width);
52
+ const rowWidth =
53
+ layout.width - leftPosition - sidePadding - headerMargin * 2;
52
54
  let searchMaxWidth = rowWidth - headerRightWidth;
53
55
  if (layout.sideBar) {
54
56
  searchMaxWidth = layout.contentWidth - Spacing.M * 2 - headerRightWidth;
@@ -118,7 +120,7 @@ const SearchHeader = React.forwardRef<InputRef, SearchHeaderProps>(
118
120
  <InputSearch
119
121
  ref={ref}
120
122
  {...props}
121
- size={searchSize}
123
+ size={'header'}
122
124
  backgroundColor={'transparent'}
123
125
  showButtonText={false}
124
126
  />
@@ -41,47 +41,9 @@ const ModalScreen: React.FC<any> = props => {
41
41
  if (props.route?.params?.isBottomSheet) {
42
42
  return <BottomSheet {...props} />;
43
43
  }
44
- if (props.route?.params?.fullScreen) {
45
- return <FullScreenModal {...props} />;
46
- }
47
44
  return <Modal {...props} />;
48
45
  };
49
46
 
50
- /**
51
- * Edge to edge layer for overlays that draw their own scrim (e.g. Coachmark):
52
- * no scrim, no animation, Android back is swallowed; the screen closes itself.
53
- */
54
- const FullScreenModal: React.FC<ModalParams> = props => {
55
- const { screen, onDismiss } = props.route.params;
56
- const Component = useRef(screen).current;
57
- const params = { ...props.route.params };
58
- delete params.screen;
59
-
60
- useEffect(() => {
61
- return () => {
62
- onDismiss?.();
63
- };
64
- }, [onDismiss]);
65
-
66
- useEffect(() => {
67
- const backHandler = BackHandler.addEventListener(
68
- 'hardwareBackPress',
69
- () => true,
70
- );
71
- return () => backHandler.remove();
72
- }, []);
73
-
74
- const handleClose = useCallback(() => {
75
- props.navigation.goBack();
76
- }, [props.navigation]);
77
-
78
- return (
79
- <View style={StyleSheet.absoluteFillObject}>
80
- <Component {...params} onRequestClose={handleClose} />
81
- </View>
82
- );
83
- };
84
-
85
47
  /**
86
48
  * Centered popup that fades and scales in over a scrim. On foldables it is
87
49
  * centered in the modal placement area, at most a popup wide.
@@ -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 { getHeaderMargin } from '../Layout/utils';
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
- // stretch frame on hold until design confirms it: `stretch` lays out like `grid`
12
- const IS_STRETCH_FRAME_ENABLED = false;
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, kept at the phone width on wide windows
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: 32,
36
+ searchHeight: 40,
37
+ searchBarHeight: 56,
32
38
  titleGap: Spacing.S,
33
39
  sidePadding: Spacing.M,
34
40
  gradientHeight: 154,
35
- bannerWidth: 375,
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 (on hold: same as `grid` for now). Background and status
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
- const isStretch = IS_STRETCH_FRAME_ENABLED && contentLayout === 'stretch';
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
- * 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.
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 { width } = useWindowDimensions();
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
- 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]);
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 keeps its phone width, centered; this
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 = {
@@ -96,8 +96,6 @@ export type ModalParams = {
96
96
  barrierDismissible?: boolean;
97
97
  modalStyle?: ViewStyle;
98
98
  useNativeModal?: boolean;
99
- /** Edge to edge screen with no scrim or animation; it closes itself. */
100
- fullScreen?: boolean;
101
99
  };
102
100
 
103
101
  export type BottomSheetParams = {
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 { ScreenProps } from './screenTypes';
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
- layoutOffset,
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
- layoutOffset,
286
+ bannerBottom,
283
287
  animatedValue.current,
284
288
  sharedValue,
285
289
  )}
@@ -1,7 +1,7 @@
1
1
  /** Header geometry. */
2
2
  export const HeaderMetrics = {
3
- /** Navigation bar row below the status bar. */
4
- barHeight: 52,
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. */
@@ -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 to the banner height plus
69
- * `layoutOffset`. Nothing without a component.
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
- layoutOffset: number,
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,
@@ -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 { ANIMATED_BANNER_HEIGHT } from './screenTypes';
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
- layoutOffset: number;
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
- layoutOffset,
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 headerLayout = useHeaderLayout(contentLayout);
89
- const frameOptions = useHeaderFrameOptions(contentLayout);
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
- ...frameOptions,
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
- frameOptions,
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={ANIMATED_BANNER_HEIGHT + layoutOffset}
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({ ...frameOptions, ...options });
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
- layoutOffset,
231
+ bannerBottom,
233
232
  quickReturnOptions,
234
- frameOptions,
233
+ barOptions,
235
234
  ],
236
235
  );
237
236
 
238
237
  const setAnimatedSearch = useCallback(() => {
239
- const options = getSearchTitleOptions(sharedValue);
240
- navigation?.instance?.setOptions({
241
- header: undefined,
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 (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;
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
- ...frameOptions,
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, frameOptions, searchWidth, searchLeft],
289
+ [navigation?.instance, sharedValue, searchOptions, searchWidth, searchLeft],
295
290
  );
296
291
 
297
292
  useEffect(() => {
@@ -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 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`.
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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/foundation",
3
- "version": "0.169.17-beta.5",
3
+ "version": "0.169.17-beta.6",
4
4
  "description": "React Native Component Kits",
5
5
  "main": "index.ts",
6
6
  "scripts": {},