@momo-kits/foundation 0.169.16-beta.1 → 0.169.16-beta.10

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,6 @@ import BackgroundImageView from './BackgroundImageView';
17
17
  import { type AnimatedCompatValue } from '../utils';
18
18
  import { useNormalizedSharedValue } from '../hooks';
19
19
  import { useScreenLayout } from '../../Layout';
20
- import { HeaderMetrics } from '../../Layout/utils';
21
20
  import {
22
21
  HeaderBarMetrics,
23
22
  type HeaderContentLayout,
@@ -28,10 +27,14 @@ import { useHeaderRightWidth } from './useHeaderRightWidth';
28
27
  const { buttonSize, pillWidth, sidePadding, titleGap } = HeaderBarMetrics;
29
28
  const SCREEN_PADDING = sidePadding;
30
29
  const TOOLKIT_WIDTH = pillWidth + sidePadding;
30
+ // the iPhone Duo side bar keeps the content search size: 36pt plus its 8pt margins
31
+ const DUO_SEARCH_ROW_HEIGHT = 52;
32
+ // the extended header without search grows this much past the bar until scrolled
33
+ const EXTENDED_HEIGHT_EXTRA = 52;
31
34
 
32
35
  /**
33
36
  * Extended header background: a gradient that collapses on scroll and, with
34
- * `inputSearchProps`, a full-width search that slides into the bar beside back/toolkit.
37
+ * `inputSearchProps`, a window-wide search that slides into the bar beside back/toolkit.
35
38
  */
36
39
  const HeaderExtendHeader: React.FC<{
37
40
  headerType?: HeaderType;
@@ -44,6 +47,9 @@ const HeaderExtendHeader: React.FC<{
44
47
  useShadowHeader?: boolean;
45
48
  gradientColor?: string;
46
49
  headerBackground?: string;
50
+ /**
51
+ * @deprecated Ignored: the search spans the window with either content layout.
52
+ */
47
53
  contentLayout?: HeaderContentLayout;
48
54
  }> = ({
49
55
  headerType = 'default',
@@ -55,7 +61,6 @@ const HeaderExtendHeader: React.FC<{
55
61
  useShadowHeader: useShadowHeaderProp = true,
56
62
  gradientColor: customGradientColor,
57
63
  headerBackground: customBackground,
58
- contentLayout,
59
64
  }) => {
60
65
  const { theme } = useContext(ApplicationContext);
61
66
  const context = useContext<any>(MiniAppContext);
@@ -63,9 +68,7 @@ const HeaderExtendHeader: React.FC<{
63
68
  const gradientColor = customGradientColor ?? theme.colors.gradient;
64
69
  const headerBackground = customBackground ?? theme.assets?.headerBackground;
65
70
  const layout = useScreenLayout();
66
- const headerLayout = useHeaderLayout(contentLayout);
67
- // the stretch frame pulls the search in from both bar edges
68
- const frameShift = headerLayout.frameInset - sidePadding;
71
+ const headerLayout = useHeaderLayout();
69
72
 
70
73
  const backLeft = buttonSize + sidePadding + titleGap;
71
74
  const defaultLeft = layout.sideBar ? SCREEN_PADDING : backLeft;
@@ -73,22 +76,26 @@ const HeaderExtendHeader: React.FC<{
73
76
  const measuredRightWidth = useHeaderRightWidth() ?? TOOLKIT_WIDTH;
74
77
  const defaultRightWidth = layout.sideBar ? 0 : measuredRightWidth;
75
78
  const headerRightWidth = customHeaderRightWidth ?? defaultRightWidth;
76
- const contentLeft = layout.insetLeft + SCREEN_PADDING + frameShift;
77
- const contentRight = layout.insetLeft + layout.contentWidth - frameShift;
79
+ const contentLeft = layout.insetLeft + SCREEN_PADDING;
80
+ const contentRight = layout.insetLeft + layout.contentWidth;
78
81
  // collapsed on the status bar row, the search stays between its clusters
79
82
  const clearanceLeft = layout.statusBarClearance?.left ?? 0;
80
83
  const clearanceRight = layout.statusBarClearance?.right ?? 0;
81
- const searchLeft = leftPosition + clearanceLeft + frameShift;
84
+ const searchLeft = leftPosition + clearanceLeft;
82
85
  const collapsedLeft = layout.insetLeft + searchLeft;
83
86
  const collapsedRight = contentRight - clearanceRight - headerRightWidth;
84
87
  const searchWidth = contentRight - contentLeft - SCREEN_PADDING;
85
88
  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
89
  // the iPhone Duo side bar keeps the content search size
91
90
  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;
92
99
 
93
100
  let useShadowHeader = useShadowHeaderProp;
94
101
  if (inputSearchProps && Platform.OS === 'android') {
@@ -101,7 +108,7 @@ const HeaderExtendHeader: React.FC<{
101
108
  height: interpolate(
102
109
  sharedValue.value,
103
110
  [0, 100],
104
- [heightHeader + 52, heightHeader],
111
+ [heightHeader + searchRowHeight, heightHeader],
105
112
  Extrapolation.CLAMP,
106
113
  ),
107
114
  }));
@@ -154,7 +161,7 @@ const HeaderExtendHeader: React.FC<{
154
161
  height: interpolate(
155
162
  sharedValue.value,
156
163
  [0, 100],
157
- [heightHeader + 52, heightHeader],
164
+ [heightHeader + EXTENDED_HEIGHT_EXTRA, heightHeader],
158
165
  Extrapolation.CLAMP,
159
166
  ),
160
167
  }));
@@ -0,0 +1,60 @@
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
+ });
@@ -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
- // stretch frame on hold until design confirms it: `stretch` lays out like `grid`
12
- const IS_STRETCH_FRAME_ENABLED = false;
11
+ // banner image on wide windows and the iPhone Duo inner display: phone (375) × 1.2
12
+ const WIDE_BANNER_SCALE = 1.2;
13
13
 
14
14
  /**
15
15
  * Top navigation geometry on every device
@@ -17,10 +17,11 @@ const IS_STRETCH_FRAME_ENABLED = false;
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
20
21
  * - titleGap: space between back and the title, and the title and the right cluster
21
22
  * - sidePadding: bar edge to back and to the right cluster
22
23
  * - gradientHeight: header gradient, kept at the phone height on wide windows
23
- * - bannerWidth: animated banner image, kept at the phone width on wide windows
24
+ * - bannerWidth: animated banner image on wide windows, centered (phone × 1.2)
24
25
  */
25
26
  const HeaderBarMetrics = {
26
27
  buttonSize: 32,
@@ -28,17 +29,17 @@ const HeaderBarMetrics = {
28
29
  pillWidth: 72,
29
30
  pillHeight: 32,
30
31
  clusterWidth: 112,
31
- searchHeight: 32,
32
+ searchHeight: 40,
33
+ searchBarHeight: 56,
32
34
  titleGap: Spacing.S,
33
35
  sidePadding: Spacing.M,
34
36
  gradientHeight: 154,
35
- bannerWidth: 375,
37
+ bannerWidth: 450,
36
38
  };
37
39
 
38
40
  /**
39
41
  * `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.
42
+ * frame on wide windows. Background, status bar and the search always span the window.
42
43
  */
43
44
  type HeaderContentLayout = 'grid' | 'stretch';
44
45
 
@@ -53,6 +54,10 @@ type HeaderLayout = typeof HeaderBarMetrics & {
53
54
  * inner display, portrait and landscape.
54
55
  */
55
56
  isBannerCentered: boolean;
57
+ /**
58
+ * Banner size against the phone banner: `WIDE_BANNER_SCALE` when centered, else 1.
59
+ */
60
+ bannerScale: number;
56
61
  /**
57
62
  * Window edge to back and to the right cluster: `sidePadding`, or centering the
58
63
  * row in the 600pt frame with `stretch` on a wide window.
@@ -84,15 +89,19 @@ const getHeaderLayout = ({
84
89
  const isLargeWindow = Math.min(width, height) >= FOLDABLE_MIN_WIDTH;
85
90
  const isWide = !isDuo && isLargeWindow;
86
91
  let frameInset = sidePadding;
87
- const isStretch = IS_STRETCH_FRAME_ENABLED && contentLayout === 'stretch';
88
- if (isWide && isStretch) {
92
+ if (isWide && contentLayout === 'stretch') {
89
93
  const centered = (width - HEADER_FRAME_MAX_WIDTH) / 2;
90
94
  frameInset = Math.max(sidePadding, centered);
91
95
  }
96
+ let bannerScale = 1;
97
+ if (isLargeWindow) {
98
+ bannerScale = WIDE_BANNER_SCALE;
99
+ }
92
100
  return {
93
101
  ...HeaderBarMetrics,
94
102
  isWide,
95
103
  isBannerCentered: isLargeWindow,
104
+ bannerScale,
96
105
  frameInset,
97
106
  frameWidth: width - frameInset * 2,
98
107
  };
@@ -117,6 +126,25 @@ const useHeaderLayout = (contentLayout?: HeaderContentLayout): HeaderLayout => {
117
126
  }, [width, height, isDuo, contentLayout]);
118
127
  };
119
128
 
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
+
120
148
  const TITLE_CONTAINER_RESET: ViewStyle = {
121
149
  marginLeft: 0,
122
150
  marginEnd: 0,
@@ -138,7 +166,7 @@ const useHeaderFrameOptions = (
138
166
  const { width } = useWindowDimensions();
139
167
  const isDuo = isIPhoneDuo();
140
168
  return useMemo(() => {
141
- if (!IS_STRETCH_FRAME_ENABLED || contentLayout !== 'stretch' || isDuo) {
169
+ if (contentLayout !== 'stretch' || isDuo) {
142
170
  return undefined;
143
171
  }
144
172
  // the header content row already sits this far in on large iOS windows
@@ -161,8 +189,10 @@ export type { HeaderContentLayout, HeaderLayout };
161
189
  export {
162
190
  HeaderBarMetrics,
163
191
  HEADER_FRAME_MAX_WIDTH,
192
+ SEARCH_FRAME_RESET,
164
193
  TITLE_CONTAINER_RESET,
165
194
  getHeaderLayout,
195
+ getSearchHeaderHeight,
166
196
  getTitleBudget,
167
197
  useHeaderLayout,
168
198
  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 = {
package/Layout/Card.tsx CHANGED
@@ -1,13 +1,12 @@
1
1
  import React, { useContext } from 'react';
2
2
  import { View, ViewProps } from 'react-native';
3
- import { GRID_GUTTER, GRID_MARGIN } from './constants';
4
- import { useGridSystem } from './useGridSystem';
3
+ import { useGridSystem, useScreenLayout } from './utils';
5
4
  import { GridContextProps } from './types';
6
5
  import { GridContext } from './index';
7
6
  import { Image } from '../Image';
8
7
  import { ApplicationContext } from '../Context';
9
8
  import styles from './styles';
10
- import { Radius, Shadow } from '../Consts';
9
+ import { Radius, Shadow, Spacing } from '../Consts';
11
10
 
12
11
  export interface CardProps extends ViewProps {
13
12
  /**
@@ -22,7 +21,7 @@ export interface CardProps extends ViewProps {
22
21
  }
23
22
 
24
23
  /**
25
- * Surface card across the grid width minus 12pt margins, with its own grid for child
24
+ * Surface card across the content width minus 12pt margins, with its own grid for child
26
25
  * Items; optional background image and light shadow.
27
26
  */
28
27
  const Card: React.FC<CardProps> = ({
@@ -33,18 +32,19 @@ const Card: React.FC<CardProps> = ({
33
32
  ...props
34
33
  }) => {
35
34
  const { theme } = useContext(ApplicationContext);
36
- const { numberOfColumns, gridWidth, gridOffset } = useGridSystem();
35
+ const { numberOfColumns } = useGridSystem();
36
+ const { contentWidth } = useScreenLayout();
37
37
 
38
- const gutterSize = GRID_GUTTER;
39
- const margin = GRID_MARGIN;
40
- const widthSection = gridWidth - margin * 2;
38
+ const gutterSize = 8;
39
+ const margin = 12;
40
+ const widthSection = contentWidth - margin * 2;
41
41
  const innerWidth = widthSection - margin * 2;
42
42
  const columnsWidth = innerWidth - gutterSize * (numberOfColumns - 1);
43
43
  const sizePerSpan = columnsWidth / numberOfColumns - 1 / numberOfColumns;
44
44
 
45
45
  const gridContext: GridContextProps = {
46
46
  numberOfColumns,
47
- gutterSize: GRID_GUTTER,
47
+ gutterSize: Spacing.S,
48
48
  sizePerSpan,
49
49
  getSizeSpan: span => {
50
50
  return sizePerSpan * span + gutterSize * (span - 1);
@@ -63,7 +63,7 @@ const Card: React.FC<CardProps> = ({
63
63
  styles.card,
64
64
  {
65
65
  width: widthSection,
66
- marginHorizontal: gridOffset + margin,
66
+ marginHorizontal: margin,
67
67
  gap: gutterSize,
68
68
  },
69
69
  !!backgroundImage && { backgroundColor: undefined },
package/Layout/Item.tsx CHANGED
@@ -7,12 +7,12 @@ import { SpanNumber } from './types';
7
7
 
8
8
  export interface ItemProps extends ViewProps {
9
9
  /**
10
- * Width in grid columns (1-36, out of the grid's 12, 24 or 36). Defaults to the full row.
10
+ * Width in grid columns (1-12). Defaults to the full row.
11
11
  */
12
12
  widthSpan?: SpanNumber;
13
13
 
14
14
  /**
15
- * Optional. Height in grid spans (1-36, out of the grid's 12, 24 or 36). Unset keeps the content height.
15
+ * Optional. Height in grid spans (1-12). Unset keeps the content height.
16
16
  */
17
17
  heightSpan?: SpanNumber;
18
18
  }
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
 
@@ -225,7 +229,6 @@ const Screen = forwardRef(
225
229
  useShadowHeader={useShadowHeader}
226
230
  gradientColor={gradientColor}
227
231
  headerBackground={headerBackground}
228
- contentLayout={contentLayout}
229
232
  />
230
233
  );
231
234
  };
@@ -279,7 +282,7 @@ const Screen = forwardRef(
279
282
  >
280
283
  {renderAnimatedHeader(
281
284
  animatedHeader,
282
- layoutOffset,
285
+ bannerBottom,
283
286
  animatedValue.current,
284
287
  sharedValue,
285
288
  )}
@@ -1,11 +1,11 @@
1
1
  import React from 'react';
2
2
  import { View, ViewProps } from 'react-native';
3
- import { GRID_GUTTER, GRID_MARGIN } from './constants';
4
- import { useGridSystem } from './useGridSystem';
3
+ import { useGridSystem, useScreenLayout } from './utils';
5
4
  import { GridContextProps } from './types';
6
5
  import { GridContext } from './index';
7
6
  import styles from './styles';
8
7
  import { Image } from '../Image';
8
+ import { Spacing } from '../Consts';
9
9
 
10
10
  export interface SectionProps extends ViewProps {
11
11
  /**
@@ -37,21 +37,22 @@ const Section: React.FC<SectionProps> = ({
37
37
  style,
38
38
  ...props
39
39
  }) => {
40
- const { numberOfColumns, gridWidth, gridOffset } = useGridSystem();
40
+ const { numberOfColumns } = useGridSystem();
41
+ const { contentWidth } = useScreenLayout();
41
42
 
42
- const gutterSize = GRID_GUTTER;
43
+ const gutterSize = 12;
43
44
  let margin = 0;
44
45
  if (useMargin) {
45
- margin = GRID_MARGIN;
46
+ margin = 12;
46
47
  }
47
- const widthSection = gridWidth - margin * 2;
48
+ const widthSection = contentWidth - margin * 2;
48
49
 
49
50
  const columnsWidth = widthSection - gutterSize * (numberOfColumns - 1);
50
51
  const sizePerSpan = columnsWidth / numberOfColumns - 1 / numberOfColumns;
51
52
 
52
53
  const gridContext: GridContextProps = {
53
54
  numberOfColumns,
54
- gutterSize: GRID_GUTTER,
55
+ gutterSize: Spacing.M,
55
56
  sizePerSpan,
56
57
  getSizeSpan: span => {
57
58
  return span * sizePerSpan + gutterSize * (span - 1);
@@ -69,7 +70,7 @@ const Section: React.FC<SectionProps> = ({
69
70
  styles.rowWrap,
70
71
  {
71
72
  width: widthSection,
72
- marginHorizontal: gridOffset + margin,
73
+ marginHorizontal: margin,
73
74
  gap: gutterSize,
74
75
  },
75
76
  ]}
@@ -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 (`searchOptions`).
44
40
  */
45
41
  const getSearchTitleOptions = (
46
42
  sharedValue: SharedValue<number>,
43
+ searchOptions: StackNavigationOptions,
47
44
  ): StackNavigationOptions => {
48
45
  return {
46
+ ...searchOptions,
49
47
  headerShown: true,
50
48
  headerTransparent: true,
51
49
  headerBackground: () => null,
@@ -79,14 +77,16 @@ 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 { barOptions, searchOptions } = useHeaderBarOptions(
87
+ layout,
88
+ contentLayout,
89
+ );
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, searchOptions);
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, searchOptions);
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
- ...frameOptions,
162
+ ...barOptions,
163
163
  ...options,
164
164
  });
165
165
  },
@@ -172,7 +172,8 @@ export const useScreenHeader = ({
172
172
  useShadowHeader,
173
173
  hasSideBar,
174
174
  quickReturnOptions,
175
- frameOptions,
175
+ barOptions,
176
+ searchOptions,
176
177
  ],
177
178
  );
178
179
 
@@ -193,7 +194,7 @@ export const useScreenHeader = ({
193
194
  return (
194
195
  <DuoGlassBackground
195
196
  animatedValue={sharedValue}
196
- bannerBottom={ANIMATED_BANNER_HEIGHT + layoutOffset}
197
+ bannerBottom={bannerBottom}
197
198
  />
198
199
  );
199
200
  }
@@ -220,7 +221,7 @@ export const useScreenHeader = ({
220
221
  };
221
222
  }
222
223
 
223
- navigation?.instance?.setOptions({ ...frameOptions, ...options });
224
+ navigation?.instance?.setOptions({ ...barOptions, ...options });
224
225
  },
225
226
  [
226
227
  gradientColor,
@@ -229,24 +230,20 @@ export const useScreenHeader = ({
229
230
  sharedValue,
230
231
  useShadowHeader,
231
232
  hasSideBar,
232
- layoutOffset,
233
+ bannerBottom,
233
234
  quickReturnOptions,
234
- frameOptions,
235
+ barOptions,
235
236
  ],
236
237
  );
237
238
 
238
239
  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]);
240
+ const options = getSearchTitleOptions(sharedValue, searchOptions);
241
+ navigation?.instance?.setOptions({ header: undefined, ...options });
242
+ }, [navigation?.instance, sharedValue, searchOptions]);
246
243
 
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;
244
+ // the search field spans the content, clear of the side bar and status bar
245
+ // clusters; kept as numbers so the setter below stays stable
246
+ let searchWidth = layout.width - Spacing.M * 2;
250
247
  let searchLeft = Spacing.M;
251
248
  if (layout.sideBar) {
252
249
  searchWidth = layout.contentWidth - Spacing.M * 2;
@@ -265,7 +262,7 @@ export const useScreenHeader = ({
265
262
  (params: SearchHeaderProps) => {
266
263
  searchHeaderParams.current = params;
267
264
  const options: StackNavigationOptions = {
268
- ...frameOptions,
265
+ ...searchOptions,
269
266
  headerRight: undefined,
270
267
  headerTitleContainerStyle: {
271
268
  width: searchWidth,
@@ -291,7 +288,7 @@ export const useScreenHeader = ({
291
288
 
292
289
  navigation?.instance?.setOptions(options);
293
290
  },
294
- [navigation?.instance, sharedValue, frameOptions, searchWidth, searchLeft],
291
+ [navigation?.instance, sharedValue, searchOptions, searchWidth, searchLeft],
295
292
  );
296
293
 
297
294
  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
 
package/Layout/types.ts CHANGED
@@ -13,43 +13,7 @@ export type ScreenRef = {
13
13
  */
14
14
  setSearchHeader: (params: SearchHeaderProps) => void;
15
15
  };
16
- export type SpanNumber =
17
- | 1
18
- | 2
19
- | 3
20
- | 4
21
- | 5
22
- | 6
23
- | 7
24
- | 8
25
- | 9
26
- | 10
27
- | 11
28
- | 12
29
- | 13
30
- | 14
31
- | 15
32
- | 16
33
- | 17
34
- | 18
35
- | 19
36
- | 20
37
- | 21
38
- | 22
39
- | 23
40
- | 24
41
- | 25
42
- | 26
43
- | 27
44
- | 28
45
- | 29
46
- | 30
47
- | 31
48
- | 32
49
- | 33
50
- | 34
51
- | 35
52
- | 36;
16
+ export type SpanNumber = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
53
17
 
54
18
  export type GridContextProps = {
55
19
  /**
@@ -0,0 +1,47 @@
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 };
package/Layout/utils.ts CHANGED
@@ -357,6 +357,13 @@ const useSideBarItemStyle = (
357
357
  };
358
358
  };
359
359
 
360
+ /** Column count of the content grid: 24 on content wider than 600pt, otherwise 12. */
361
+ const useGridSystem = () => {
362
+ const { contentWidth } = useScreenLayout();
363
+ const numberOfColumns = contentWidth > 600 ? 24 : 12;
364
+ return { numberOfColumns };
365
+ };
366
+
360
367
  export type { ScreenLayout, SideBarEdge, SideBarLayout, StatusBarClearance };
361
368
 
362
369
  export {
@@ -365,6 +372,7 @@ export {
365
372
  InnerEdgeStyles,
366
373
  getHeaderMargin,
367
374
  getHeaderRowOptions,
375
+ useGridSystem,
368
376
  useScreenLayout,
369
377
  useSideBarItemStyle,
370
378
  validateChildren,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/foundation",
3
- "version": "0.169.16-beta.1",
3
+ "version": "0.169.16-beta.10",
4
4
  "description": "React Native Component Kits",
5
5
  "main": "index.ts",
6
6
  "scripts": {},
@@ -1,19 +0,0 @@
1
- const GRID_MARGIN = 12;
2
- const GRID_GUTTER = 12;
3
- const GRID_PHONE_MAX_WIDTH = 600;
4
- const GRID_TABLET_MIN_WIDTH = 800;
5
- const GRID_DESKTOP_MIN_WIDTH = 1100;
6
- const GRID_PHONE_COLUMNS = 12;
7
- const GRID_TABLET_COLUMNS = 24;
8
- const GRID_DESKTOP_COLUMNS = 36;
9
-
10
- export {
11
- GRID_DESKTOP_COLUMNS,
12
- GRID_DESKTOP_MIN_WIDTH,
13
- GRID_GUTTER,
14
- GRID_MARGIN,
15
- GRID_PHONE_COLUMNS,
16
- GRID_PHONE_MAX_WIDTH,
17
- GRID_TABLET_COLUMNS,
18
- GRID_TABLET_MIN_WIDTH,
19
- };
@@ -1,49 +0,0 @@
1
- import {
2
- GRID_DESKTOP_COLUMNS,
3
- GRID_DESKTOP_MIN_WIDTH,
4
- GRID_PHONE_COLUMNS,
5
- GRID_PHONE_MAX_WIDTH,
6
- GRID_TABLET_COLUMNS,
7
- GRID_TABLET_MIN_WIDTH,
8
- } from './constants';
9
- import { useScreenLayout } from './utils';
10
-
11
- /**
12
- * Column count for a content width: 12 below 800pt, 24 below 1100pt, 36 from there
13
- */
14
- const getGridColumns = (width: number) => {
15
- if (width >= GRID_DESKTOP_MIN_WIDTH) {
16
- return GRID_DESKTOP_COLUMNS;
17
- }
18
- if (width >= GRID_TABLET_MIN_WIDTH) {
19
- return GRID_TABLET_COLUMNS;
20
- }
21
- return GRID_PHONE_COLUMNS;
22
- };
23
-
24
- /**
25
- * Grid width for a content width: the 12-column grid stops at 600pt and is centered,
26
- * the wider grids fill the content
27
- */
28
- const getGridWidth = (width: number) => {
29
- if (width < GRID_TABLET_MIN_WIDTH) {
30
- return Math.min(width, GRID_PHONE_MAX_WIDTH);
31
- }
32
- return width;
33
- };
34
-
35
- /**
36
- * Grid for the current content width: column count, grid width and the horizontal
37
- * offset that centers a grid narrower than the content
38
- */
39
- const useGridSystem = () => {
40
- const { contentWidth } = useScreenLayout();
41
- const gridWidth = getGridWidth(contentWidth);
42
- return {
43
- numberOfColumns: getGridColumns(contentWidth),
44
- gridWidth,
45
- gridOffset: (contentWidth - gridWidth) / 2,
46
- };
47
- };
48
-
49
- export { useGridSystem };