@momo-kits/foundation 0.169.16-beta.13 → 0.169.16-beta.15

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