@momo-kits/foundation 0.169.17-beta.1 → 0.169.17-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.
@@ -78,7 +78,7 @@ export const TabLabel: React.FC<{
78
78
  <MiniAppContext.Provider
79
79
  value={{
80
80
  ...context,
81
- fontScale: { useOSScaleRate: false, appScaleRate: 1 },
81
+ fontScale: { useOSScaleRate: false, userScaleRate: 1 },
82
82
  }}
83
83
  >
84
84
  <Text numberOfLines={1} typography={typography} color={color}>
@@ -78,6 +78,14 @@ const clamp = (value: number, min: number, max: number) => {
78
78
  return Math.min(Math.max(value, min), max);
79
79
  };
80
80
 
81
+ /**
82
+ * True when the window's short side reaches a foldable inner display (Galaxy Z Fold,
83
+ * Pixel Fold, iPhone Duo inner); short side, so a phone in landscape stays a phone.
84
+ */
85
+ const isFoldableWindow = (width: number, height: number) => {
86
+ return Math.min(width, height) >= FOLDABLE_MIN_WIDTH;
87
+ };
88
+
81
89
  /**
82
90
  * Modal geometry for a window, pure so it can be tested without a device.
83
91
  */
@@ -88,10 +96,9 @@ const getModalLayout = ({
88
96
  isDuo,
89
97
  hinge,
90
98
  }: ModalLayoutInput): ModalLayout => {
91
- const shortSide = Math.min(width, height);
92
- // short side, so a phone in landscape stays a phone
93
- const isFoldable = isDuo || shortSide >= FOLDABLE_MIN_WIDTH;
94
- const isDuoOuter = isDuo && shortSide < FOLDABLE_MIN_WIDTH;
99
+ const isWideWindow = isFoldableWindow(width, height);
100
+ const isFoldable = isDuo || isWideWindow;
101
+ const isDuoOuter = isDuo && !isWideWindow;
95
102
  const hingeRight = hinge ? hinge.x + hinge.width : 0;
96
103
  const hasHinge = !!hinge && hinge.x > 0;
97
104
  const isHingeInWindow = hingeRight < width - insets.right;
@@ -166,6 +173,7 @@ const useModalLayout = (): ModalLayout => {
166
173
 
167
174
  export {
168
175
  getModalLayout,
176
+ isFoldableWindow,
169
177
  useModalLayout,
170
178
  POPUP_MAX_WIDTH,
171
179
  POPUP_MIN_WIDTH,
@@ -0,0 +1,93 @@
1
+ import React from 'react';
2
+ import { StyleSheet, TouchableOpacity, View } from 'react-native';
3
+ import { Colors, Spacing, Styles } from '../Consts';
4
+ import { Image } from '../Image';
5
+ import { Text } from '../Text';
6
+ import { Typography } from '../Text/types';
7
+ import styles from './styles';
8
+
9
+ const FLAG_SIZE = 24;
10
+
11
+ type CountryCodeViewProps = {
12
+ countryCode: string;
13
+ countryFlag: string;
14
+ typography: Typography;
15
+ textColor: string;
16
+ dividerHeight: number;
17
+ componentId: string;
18
+ isDisabled: boolean;
19
+ onPress?: () => void;
20
+ };
21
+
22
+ /**
23
+ * Flag, dial code and divider ahead of a phone number. Only becomes a button
24
+ * when `onPress` is given, so the default render stays a plain view.
25
+ */
26
+ const CountryCodeView: React.FC<CountryCodeViewProps> = ({
27
+ countryCode,
28
+ countryFlag,
29
+ typography,
30
+ textColor,
31
+ dividerHeight,
32
+ componentId,
33
+ isDisabled,
34
+ onPress,
35
+ }) => {
36
+ const content = (
37
+ <>
38
+ <Image
39
+ source={{ uri: countryFlag }}
40
+ style={innerStyle.iconFlag}
41
+ resizeMode="contain"
42
+ accessibilityLabel={`${componentId}|leading-icon`}
43
+ />
44
+ <View style={{ width: Spacing.XS }} />
45
+ <Text typography={typography} color={textColor}>
46
+ {countryCode}
47
+ </Text>
48
+ </>
49
+ );
50
+
51
+ const renderContent = () => {
52
+ if (!onPress) {
53
+ return content;
54
+ }
55
+ return (
56
+ <TouchableOpacity
57
+ style={Styles.row}
58
+ onPress={onPress}
59
+ disabled={isDisabled}
60
+ accessibilityRole="button"
61
+ accessibilityLabel={`${componentId}|leading-icon-touch|${countryCode}`}
62
+ accessibilityState={{ disabled: isDisabled }}
63
+ >
64
+ {content}
65
+ </TouchableOpacity>
66
+ );
67
+ };
68
+
69
+ return (
70
+ <View style={[styles.leadingIconContainer, Styles.row]}>
71
+ {renderContent()}
72
+ <View
73
+ style={[
74
+ styles.phoneNumberDivider,
75
+ {
76
+ height: dividerHeight,
77
+ backgroundColor: Colors.black_04,
78
+ },
79
+ ]}
80
+ />
81
+ </View>
82
+ );
83
+ };
84
+
85
+ const innerStyle = StyleSheet.create({
86
+ iconFlag: {
87
+ width: FLAG_SIZE,
88
+ height: FLAG_SIZE,
89
+ marginHorizontal: Spacing.XXS,
90
+ },
91
+ });
92
+
93
+ export { CountryCodeView };
@@ -6,7 +6,6 @@ import React, {
6
6
  useState,
7
7
  } from 'react';
8
8
  import {
9
- StyleSheet,
10
9
  TextInput,
11
10
  TextInputFocusEvent,
12
11
  TouchableOpacity,
@@ -18,12 +17,11 @@ import {
18
17
  ComponentContext,
19
18
  MiniAppContext,
20
19
  } from '../Context';
21
- import { Colors, Spacing, Styles } from '../Consts';
22
20
  import { Icon } from '../Icon';
23
- import { Image } from '../Image';
24
- import { useScaleSize, Text, exportFontFamily } from '../Text';
21
+ import { useScaleSize, exportFontFamily } from '../Text';
25
22
  import { Typography } from '../Text/types';
26
23
  import { CLEAR_ICON_SIZE } from './constants';
24
+ import { CountryCodeView } from './CountryCodeView';
27
25
  import { ErrorView } from './ErrorView';
28
26
  import { InputPhoneNumberProps } from './index';
29
27
  import { RenderTrailing } from './RenderTrailing';
@@ -36,11 +34,13 @@ const LARGE_FONT_SIZE = 18;
36
34
  const SMALL_DIVIDER_HEIGHT = 24;
37
35
  const LARGE_DIVIDER_HEIGHT = 32;
38
36
  const FOCUSED_BORDER_WIDTH = 1.5;
39
- const FLAG_SIZE = 24;
37
+ const DEFAULT_COUNTRY_CODE = '+84';
38
+ const DEFAULT_COUNTRY_FLAG =
39
+ 'https://static.momocdn.net/app/img/icon/ic-qrcode-package/ic_vn_flag.png';
40
40
 
41
41
  /**
42
- * Vietnamese phone number input with a fixed flag and `+84` prefix, number pad
43
- * by default, plus clear and trailing icons.
42
+ * Phone number input behind a country flag and dial code (Vietnam `+84` by
43
+ * default), number pad by default, plus clear and trailing icons.
44
44
  */
45
45
  const InputPhoneNumber = forwardRef(
46
46
  (
@@ -66,6 +66,9 @@ const InputPhoneNumber = forwardRef(
66
66
  editable = true,
67
67
  showClearIcon = true,
68
68
  defaultValue,
69
+ countryCode = DEFAULT_COUNTRY_CODE,
70
+ countryFlag = DEFAULT_COUNTRY_FLAG,
71
+ onPressLeadingIcon,
69
72
  ...props
70
73
  }: InputPhoneNumberProps,
71
74
  ref,
@@ -182,29 +185,16 @@ const InputPhoneNumber = forwardRef(
182
185
  ]}
183
186
  >
184
187
  <View style={styles.inputView}>
185
- <View style={[styles.leadingIconContainer, Styles.row]}>
186
- <Image
187
- source={{
188
- uri: 'https://static.momocdn.net/app/img/icon/ic-qrcode-package/ic_vn_flag.png',
189
- }}
190
- style={innerStyle.iconFlag}
191
- resizeMode="contain"
192
- accessibilityLabel={`${componentId}|leading-icon`}
193
- />
194
- <View style={{ width: Spacing.XS }} />
195
- <Text typography={typography} color={textColor}>
196
- {'+84'}
197
- </Text>
198
- <View
199
- style={[
200
- styles.phoneNumberDivider,
201
- {
202
- height: dividerHeight,
203
- backgroundColor: Colors.black_04,
204
- },
205
- ]}
206
- />
207
- </View>
188
+ <CountryCodeView
189
+ countryCode={countryCode}
190
+ countryFlag={countryFlag}
191
+ typography={typography}
192
+ textColor={textColor}
193
+ dividerHeight={dividerHeight}
194
+ componentId={componentId}
195
+ isDisabled={disabled || !editable}
196
+ onPress={onPressLeadingIcon}
197
+ />
208
198
  <SystemTextInput
209
199
  {...props}
210
200
  accessibilityLabel={`${componentId}`}
@@ -302,12 +292,4 @@ const InputPhoneNumber = forwardRef(
302
292
  },
303
293
  );
304
294
 
305
- const innerStyle = StyleSheet.create({
306
- iconFlag: {
307
- width: FLAG_SIZE,
308
- height: FLAG_SIZE,
309
- marginHorizontal: Spacing.XXS,
310
- },
311
- });
312
-
313
295
  export default InputPhoneNumber;
package/Input/index.tsx CHANGED
@@ -351,9 +351,22 @@ export interface InputDropDownProps extends TouchableOpacityProps {
351
351
 
352
352
  export interface InputPhoneNumberProps extends InputProps {
353
353
  /**
354
- * Optional. Currently unused: the displayed prefix is always `+84`.
354
+ * Optional. Dial code shown verbatim before the number.
355
+ * Defaults to `+84` if not provided.
355
356
  */
356
357
  countryCode?: string;
358
+
359
+ /**
360
+ * Optional. URL of the flag image shown before the dial code.
361
+ * Defaults to the Vietnam flag if not provided.
362
+ */
363
+ countryFlag?: string;
364
+
365
+ /**
366
+ * Optional. Called when the flag or dial code is pressed (e.g. to pick a country),
367
+ * which then reads as a button. Ignored while `disabled` or `editable={false}`.
368
+ */
369
+ onPressLeadingIcon?: () => void;
357
370
  }
358
371
 
359
372
  export type InputRef = {
package/Layout/Screen.tsx CHANGED
@@ -31,7 +31,11 @@ import { BottomTabInsetContext } from '../Application/BottomTab/BottomTabInset';
31
31
  import { ScreenProps } from './screenTypes';
32
32
  import { renderAnimatedHeader, renderContent } from './screenContent';
33
33
  import { createScrollHandlers } from './screenScroll';
34
- import { ScreenFooter } from './screenFooter';
34
+ import {
35
+ renderFooterSpacer,
36
+ ScreenFooter,
37
+ useFooterLayout,
38
+ } from './screenFooter';
35
39
  import { useScreenHeader } from './screenHeader';
36
40
  import { useScreenQuickReturn } from './screenQuickReturn';
37
41
 
@@ -53,6 +57,8 @@ const Screen = forwardRef(
53
57
  headerComponent: Header,
54
58
  footerComponent: Footer,
55
59
  marginFooter = true,
60
+ footerStyle,
61
+ footerHasImageBackground: hasImageFooter,
56
62
  layoutOffset = -56,
57
63
  headerRightWidth,
58
64
  backgroundColor,
@@ -78,6 +84,7 @@ const Screen = forwardRef(
78
84
  const insets = useSafeAreaInsets();
79
85
  const frame = useSafeAreaFrame();
80
86
  const heightHeader = useHeaderHeight();
87
+ const footerLayout = useFooterLayout(layout, footerStyle, hasImageFooter);
81
88
 
82
89
  const animatedValue = useRef<Animated.Value>(
83
90
  customAnimatedValue ?? new Animated.Value(0),
@@ -195,7 +202,7 @@ const Screen = forwardRef(
195
202
 
196
203
  let floatingButtonBottom = bottomInset + Spacing.S;
197
204
  if (Footer) {
198
- floatingButtonBottom = 12;
205
+ floatingButtonBottom = 12 + footerLayout.overlap;
199
206
  } else if (isTab) {
200
207
  floatingButtonBottom = 12 + duoTabInset;
201
208
  }
@@ -285,6 +292,7 @@ const Screen = forwardRef(
285
292
  )}
286
293
 
287
294
  {useGridLayout ? renderContent(children, layout) : children}
295
+ {renderFooterSpacer(footerLayout.overlap)}
288
296
  </Component>
289
297
 
290
298
  {floatingButtonProps && (
@@ -306,9 +314,7 @@ const Screen = forwardRef(
306
314
  <ScreenFooter
307
315
  footer={Footer}
308
316
  marginFooter={marginFooter}
309
- insetLeft={layout.insetLeft}
310
- insetRight={layout.insetRight}
311
- hasContentInset={hasContentInset}
317
+ layout={footerLayout}
312
318
  isTab={isTab}
313
319
  duoTabInset={duoTabInset}
314
320
  bottomInset={bottomInset}
@@ -24,16 +24,22 @@ export interface SectionProps extends ViewProps {
24
24
  * Optional. Background image for the Section component.
25
25
  */
26
26
  backgroundImage?: string;
27
+
28
+ /**
29
+ * Optional. Caps the row width, side margins excluded; a capped row is centered.
30
+ */
31
+ maxWidth?: number;
27
32
  }
28
33
 
29
34
  /**
30
- * Content-wide grid row (12 or 24 columns) with optional side margins; child Items size
31
- * themselves from its GridContext.
35
+ * Content-wide grid row (12 or 24 columns) with optional side margins, capped by
36
+ * `maxWidth`; child Items size themselves from its GridContext.
32
37
  */
33
38
  const Section: React.FC<SectionProps> = ({
34
39
  children,
35
40
  useMargin = true,
36
41
  backgroundImage,
42
+ maxWidth,
37
43
  style,
38
44
  ...props
39
45
  }) => {
@@ -45,7 +51,11 @@ const Section: React.FC<SectionProps> = ({
45
51
  if (useMargin) {
46
52
  margin = 12;
47
53
  }
48
- const widthSection = contentWidth - margin * 2;
54
+ const isCapped = maxWidth !== undefined;
55
+ let widthSection = contentWidth - margin * 2;
56
+ if (isCapped) {
57
+ widthSection = Math.min(widthSection, maxWidth);
58
+ }
49
59
 
50
60
  const columnsWidth = widthSection - gutterSize * (numberOfColumns - 1);
51
61
  const sizePerSpan = columnsWidth / numberOfColumns - 1 / numberOfColumns;
@@ -68,6 +78,7 @@ const Section: React.FC<SectionProps> = ({
68
78
  style,
69
79
  styles.protectedStyle,
70
80
  styles.rowWrap,
81
+ isCapped && styles.centered,
71
82
  {
72
83
  width: widthSection,
73
84
  marginHorizontal: margin,
@@ -0,0 +1,56 @@
1
+ import { getFooterGeometry, getFooterStyle } from '../screenFooter';
2
+
3
+ // the grid row pulls in every foundation component; geometry does not render
4
+ jest.mock('../Section', () => ({ __esModule: true, default: () => null }));
5
+
6
+ const PHONE = { width: 390, height: 844, contentWidth: 390 };
7
+ const FOLD_PORTRAIT = { width: 760, height: 900, contentWidth: 760 };
8
+ const FOLD_LANDSCAPE = { width: 860, height: 700, contentWidth: 860 };
9
+ const TABLET = { width: 1194, height: 834, contentWidth: 1194 };
10
+ const ANCHORED = {
11
+ footerStyle: 'anchored' as const,
12
+ hasImageBackground: false,
13
+ };
14
+ const SHEET = { footerStyle: 'sheet' as const, hasImageBackground: false };
15
+
16
+ describe('getFooterGeometry', () => {
17
+ it('keeps the phone footer below 600pt, landscape included', () => {
18
+ expect(getFooterGeometry({ ...PHONE, ...SHEET }).kind).toBe('phone');
19
+ const landscape = { width: 844, height: 390, contentWidth: 844 };
20
+ expect(getFooterGeometry({ ...landscape, ...SHEET }).kind).toBe('phone');
21
+ });
22
+
23
+ it('caps the width at 600pt below an 800pt window, 800pt from it', () => {
24
+ expect(getFooterGeometry({ ...FOLD_PORTRAIT, ...ANCHORED })).toEqual({
25
+ kind: 'anchored',
26
+ width: 600,
27
+ });
28
+ expect(getFooterGeometry({ ...FOLD_LANDSCAPE, ...SHEET })).toEqual({
29
+ kind: 'sheet',
30
+ width: 800,
31
+ });
32
+ expect(getFooterGeometry({ ...TABLET, ...SHEET }).width).toBe(800);
33
+ });
34
+
35
+ it('keeps the width inside the content area minus its margins', () => {
36
+ const duoInner = { width: 669, height: 900, contentWidth: 585 };
37
+ expect(getFooterGeometry({ ...duoInner, ...ANCHORED }).width).toBe(561);
38
+ });
39
+
40
+ it('drops the sheet for an image background', () => {
41
+ const input = { ...FOLD_LANDSCAPE, ...SHEET, hasImageBackground: true };
42
+ expect(getFooterGeometry(input).kind).toBe('anchored');
43
+ });
44
+ });
45
+
46
+ describe('getFooterStyle', () => {
47
+ it('lets the screen prop win over the host config', () => {
48
+ expect(getFooterStyle('anchored', 'sheet')).toBe('anchored');
49
+ expect(getFooterStyle(undefined, 'sheet')).toBe('sheet');
50
+ });
51
+
52
+ it('falls back to anchored for a missing or unknown value', () => {
53
+ expect(getFooterStyle()).toBe('anchored');
54
+ expect(getFooterStyle(undefined, 'floating')).toBe('anchored');
55
+ });
56
+ });
@@ -1,15 +1,54 @@
1
- import React, { ReactNode } from 'react';
2
- import { View } from 'react-native';
1
+ import React, { ReactNode, useCallback, useContext, useState } from 'react';
2
+ import { LayoutChangeEvent, StyleProp, View, ViewStyle } from 'react-native';
3
+ import { isFoldableWindow } from '../Application/modalLayout';
4
+ import { ApplicationContext, MiniAppContext } from '../Context';
3
5
  import { Spacing } from '../Consts';
6
+ import { ScreenLayout } from './layoutTypes';
7
+ import { ScreenFooterStyle } from './types';
4
8
  import Section from './Section';
5
9
  import styles from './styles';
6
10
 
11
+ // Foldable footer spec, shared with the Compose / SwiftUI kits
12
+ const FOOTER_MAX_WIDTH = 600;
13
+ const FOOTER_WIDE_MAX_WIDTH = 800;
14
+ const FOOTER_WIDE_WINDOW_MIN_WIDTH = 800;
15
+ const FOOTER_BORDER_WIDTH = 1;
16
+
17
+ type FooterKind = 'phone' | 'anchored' | 'sheet';
18
+
19
+ type FooterGeometry = { kind: FooterKind; width: number };
20
+
21
+ type DesignSystemContext = {
22
+ designSystemConfig?: { config?: { footerStyle?: unknown } };
23
+ };
24
+
25
+ type FooterGeometryInput = {
26
+ width: number;
27
+ height: number;
28
+ contentWidth: number;
29
+ footerStyle: ScreenFooterStyle;
30
+ hasImageBackground: boolean;
31
+ };
32
+
33
+ type FooterLayout = FooterGeometry & {
34
+ hasBorder: boolean;
35
+ /**
36
+ * `false` on a foldable with an image background, so the screen's image shows through.
37
+ */
38
+ hasSurface: boolean;
39
+ insetLeft: number;
40
+ insetRight: number;
41
+ /**
42
+ * Height the sheet overlaps the body by; 0 while the footer sits below the body.
43
+ */
44
+ overlap: number;
45
+ handleLayout: (event: LayoutChangeEvent) => void;
46
+ };
47
+
7
48
  type ScreenFooterProps = {
8
49
  footer: ReactNode;
9
50
  marginFooter: boolean;
10
- insetLeft: number;
11
- insetRight: number;
12
- hasContentInset: boolean;
51
+ layout: FooterLayout;
13
52
  isTab: boolean;
14
53
  duoTabInset: number;
15
54
  bottomInset: number;
@@ -17,47 +56,168 @@ type ScreenFooterProps = {
17
56
  };
18
57
 
19
58
  /**
20
- * Screen footer on the surface color with a top shadow, padded above the home indicator,
21
- * or above the floating tab bar on a tab screen.
59
+ * The screen prop wins over the host's design system config; anything else is `anchored`.
60
+ */
61
+ const getFooterStyle = (
62
+ footerStyle?: ScreenFooterStyle,
63
+ configured?: unknown,
64
+ ): ScreenFooterStyle => {
65
+ if ((footerStyle ?? configured) === 'sheet') {
66
+ return 'sheet';
67
+ }
68
+ return 'anchored';
69
+ };
70
+
71
+ /**
72
+ * Footer kind and width (anchored content or sheet) for a window, pure so it can be
73
+ * tested without a device. Phones, iPhone Duo outer included, keep the shadowed bar.
74
+ */
75
+ const getFooterGeometry = ({
76
+ width,
77
+ height,
78
+ contentWidth,
79
+ footerStyle,
80
+ hasImageBackground,
81
+ }: FooterGeometryInput): FooterGeometry => {
82
+ if (!isFoldableWindow(width, height)) {
83
+ return { kind: 'phone', width: contentWidth };
84
+ }
85
+
86
+ let maxWidth = FOOTER_MAX_WIDTH;
87
+ if (width >= FOOTER_WIDE_WINDOW_MIN_WIDTH) {
88
+ maxWidth = FOOTER_WIDE_MAX_WIDTH;
89
+ }
90
+ const footerWidth = Math.min(contentWidth - Spacing.M * 2, maxWidth);
91
+ // an image background spans the window, so it never sits in a sheet
92
+ const isSheet = footerStyle === 'sheet' && !hasImageBackground;
93
+ return { kind: isSheet ? 'sheet' : 'anchored', width: footerWidth };
94
+ };
95
+
96
+ /**
97
+ * Footer layout for the screen layout. A sheet overlaps the body, so its measured
98
+ * height comes back as `overlap` for the body to pad its end by.
99
+ */
100
+ const useFooterLayout = (
101
+ layout: ScreenLayout,
102
+ footerStyle?: ScreenFooterStyle,
103
+ hasImageBackground = false,
104
+ ): FooterLayout => {
105
+ const context: DesignSystemContext | undefined = useContext(MiniAppContext);
106
+ const [height, setHeight] = useState(0);
107
+ const handleLayout = useCallback((event: LayoutChangeEvent) => {
108
+ setHeight(event.nativeEvent.layout.height);
109
+ }, []);
110
+
111
+ const configured = context?.designSystemConfig?.config?.footerStyle;
112
+ const geometry = getFooterGeometry({
113
+ width: layout.width,
114
+ height: layout.height,
115
+ contentWidth: layout.contentWidth,
116
+ footerStyle: getFooterStyle(footerStyle, configured),
117
+ hasImageBackground,
118
+ });
119
+
120
+ let overlap = 0;
121
+ if (geometry.kind === 'sheet') {
122
+ overlap = height;
123
+ }
124
+ return {
125
+ ...geometry,
126
+ hasBorder: geometry.kind === 'anchored' && !hasImageBackground,
127
+ hasSurface: geometry.kind === 'phone' || !hasImageBackground,
128
+ insetLeft: layout.insetLeft,
129
+ insetRight: layout.insetRight,
130
+ overlap,
131
+ handleLayout,
132
+ };
133
+ };
134
+
135
+ /**
136
+ * Spacer at the end of the body so a sheet footer does not cover its last element.
137
+ */
138
+ const renderFooterSpacer = (overlap: number) => {
139
+ if (!overlap) {
140
+ return null;
141
+ }
142
+ return <View style={{ height: overlap }} />;
143
+ };
144
+
145
+ /**
146
+ * Screen footer on the surface color above the home indicator or the floating tab bar.
147
+ * Phones keep the top shadow; foldables cap the content under a full-width bar with a
148
+ * top border (`anchored`) or in a centered sheet over the body (`sheet`).
22
149
  */
23
- export const ScreenFooter = ({
150
+ const ScreenFooter = ({
24
151
  footer,
25
152
  marginFooter,
26
- insetLeft,
27
- insetRight,
28
- hasContentInset,
153
+ layout,
29
154
  isTab,
30
155
  duoTabInset,
31
156
  bottomInset,
32
157
  surfaceColor,
33
158
  }: ScreenFooterProps) => {
159
+ const { theme } = useContext(ApplicationContext);
34
160
  let bottomSpace = bottomInset;
35
161
  if (isTab && duoTabInset) {
36
162
  bottomSpace = duoTabInset;
37
163
  }
38
164
 
165
+ const { kind, insetLeft, insetRight } = layout;
166
+ const hasContentInset = insetLeft > 0 || insetRight > 0;
167
+ const margin = marginFooter ? Spacing.M : 0;
168
+
169
+ // one view tree for every kind, so folding keeps the footer content's state
170
+ let containerStyle: StyleProp<ViewStyle> = [
171
+ kind === 'phone' && hasContentInset && styles.footerClip,
172
+ { marginLeft: insetLeft, marginRight: insetRight },
173
+ ];
174
+ let surfaceStyle: StyleProp<ViewStyle> = styles.shadow;
175
+ let sectionMaxWidth: number | undefined;
176
+ if (kind === 'anchored') {
177
+ surfaceStyle = [
178
+ styles.footerBar,
179
+ layout.hasBorder && {
180
+ borderTopWidth: FOOTER_BORDER_WIDTH,
181
+ borderTopColor: theme.colors.border.default,
182
+ },
183
+ ];
184
+ sectionMaxWidth = layout.width;
185
+ }
186
+ if (kind === 'sheet') {
187
+ containerStyle = [containerStyle, { marginTop: -layout.overlap }];
188
+ surfaceStyle = [styles.footerSheet, { width: layout.width }];
189
+ sectionMaxWidth = layout.width - margin * 2;
190
+ }
191
+
39
192
  return (
40
193
  <View
41
194
  pointerEvents={'box-none'}
42
- style={[
43
- hasContentInset && styles.footerClip,
44
- {
45
- marginLeft: insetLeft,
46
- marginRight: insetRight,
47
- },
48
- ]}
195
+ onLayout={layout.handleLayout}
196
+ style={containerStyle}
49
197
  >
50
198
  <View
51
199
  style={[
52
- styles.shadow,
200
+ surfaceStyle,
53
201
  {
54
202
  paddingBottom: bottomSpace + Spacing.S,
55
- backgroundColor: surfaceColor,
203
+ backgroundColor: layout.hasSurface ? surfaceColor : undefined,
56
204
  },
57
205
  ]}
58
206
  >
59
- <Section useMargin={marginFooter}>{footer}</Section>
207
+ <Section useMargin={marginFooter} maxWidth={sectionMaxWidth}>
208
+ {footer}
209
+ </Section>
60
210
  </View>
61
211
  </View>
62
212
  );
63
213
  };
214
+
215
+ export type { FooterLayout };
216
+
217
+ export {
218
+ ScreenFooter,
219
+ getFooterGeometry,
220
+ getFooterStyle,
221
+ renderFooterSpacer,
222
+ useFooterLayout,
223
+ };
@@ -7,7 +7,7 @@ import {
7
7
  SearchHeaderProps,
8
8
  } from '../Application/types';
9
9
  import { FloatingButtonProps } from './FloatingButton';
10
- import { HeaderType } from './types';
10
+ import { HeaderType, ScreenFooterStyle } from './types';
11
11
  import { InputRef } from '../Input';
12
12
  import type { HeaderContentLayout } from '../Application/headerLayout';
13
13
 
@@ -65,6 +65,21 @@ export interface ScreenProps extends ViewProps {
65
65
  */
66
66
  marginFooter?: boolean;
67
67
 
68
+ /**
69
+ * Optional. Footer look on foldable inner displays and wide windows: `anchored`, a
70
+ * full-width bar with a top border, or `sheet`, a centered sheet over the body. Content
71
+ * is capped at 600pt (800pt on windows from 800pt). Defaults to the host's design
72
+ * system config (`footerStyle`), else `anchored`. Phones keep the current footer.
73
+ */
74
+ footerStyle?: ScreenFooterStyle;
75
+
76
+ /**
77
+ * Optional. If `true`, the screen draws an image behind the footer: on foldables the
78
+ * footer drops its surface fill, sheet and top border so the image shows through.
79
+ * Defaults to `false`.
80
+ */
81
+ footerHasImageBackground?: boolean;
82
+
68
83
  /**
69
84
  * Optional. Background color of the screen.
70
85
  */
package/Layout/styles.ts CHANGED
@@ -91,6 +91,15 @@ export default StyleSheet.create({
91
91
  },
92
92
  }),
93
93
  },
94
+ footerBar: {
95
+ paddingTop: Spacing.S,
96
+ },
97
+ footerSheet: {
98
+ paddingTop: Spacing.S,
99
+ alignSelf: 'center',
100
+ borderTopLeftRadius: Radius.XL,
101
+ borderTopRightRadius: Radius.XL,
102
+ },
94
103
  footerClip: {
95
104
  marginTop: -Spacing.XL,
96
105
  paddingTop: Spacing.XL,
@@ -98,5 +107,6 @@ export default StyleSheet.create({
98
107
  },
99
108
  debugBaseLine: { borderWidth: 1, borderColor: Colors.green_06 },
100
109
  expanded: { flex: 1 },
110
+ centered: { alignSelf: 'center' },
101
111
  rowWrap: { flexDirection: 'row', flexWrap: 'wrap' },
102
112
  });
package/Layout/types.ts CHANGED
@@ -2,6 +2,12 @@ import { NavigationOptions, SearchHeaderProps } from '../Application/types';
2
2
 
3
3
  export type HeaderType = 'default' | 'extended' | 'none';
4
4
 
5
+ /**
6
+ * Screen footer look on foldable inner displays and wide windows: `anchored` is a
7
+ * full-width bar with a top border, `sheet` a centered sheet over the body.
8
+ */
9
+ export type ScreenFooterStyle = 'anchored' | 'sheet';
10
+
5
11
  export type ScreenRef = {
6
12
  /**
7
13
  * Applies navigation options to the screen's header.
package/Text/utils.ts CHANGED
@@ -5,50 +5,24 @@ import { MiniAppContext } from '../Context';
5
5
  const DEFAULT_SCREEN_SIZE = 375;
6
6
  const MAX_FONT_SCALE = 1.5;
7
7
  const MAX_DEVICE_SCALE = 5;
8
- const APP_SCALE_LEVELS = [1, 1.2, 1.3, 1.4];
9
8
 
10
9
  type MiniAppScale = {
11
10
  scaleSizeMaxRate?: number;
12
- fontScale?: {
13
- useOSScaleRate?: boolean;
14
- appScaleRate?: number;
15
- /** @deprecated Use `appScaleRate`. Still sent by the host. */
16
- userScaleRate?: number;
17
- };
18
- };
19
-
20
- /**
21
- * Snaps a host scale rate to the nearest app scale level (1, 1.2, 1.3, 1.4),
22
- * ties going lower, so legacy rates (1.1, 1.6) resolve like the host does.
23
- */
24
- const toAppScaleRate = (rate?: number) => {
25
- if (!rate) {
26
- return APP_SCALE_LEVELS[0];
27
- }
28
- const percent = Math.round(rate * 100);
29
- const distance = (level: number) =>
30
- Math.abs(Math.round(level * 100) - percent);
31
- return APP_SCALE_LEVELS.reduce((best, level) =>
32
- distance(level) < distance(best) ? level : best,
33
- );
11
+ fontScale?: { useOSScaleRate?: boolean; userScaleRate?: number };
34
12
  };
35
13
 
36
14
  /**
37
15
  * Scales `size` by screen width (+5 max) and OS font scale (max `scaleRate`,
38
16
  * else the ScaleSizeProvider rate, else 1.5), taking the larger, or by the mini
39
- * app `fontScale.appScaleRate`; a provider rate caps both at `size × rate`.
17
+ * app `fontScale.userScaleRate`; a provider rate caps both at `size × rate`.
40
18
  */
41
19
  const useScaleSize = (size: number, scaleRate?: number) => {
42
20
  const { width } = useWindowDimensions();
43
21
  const context = useContext<MiniAppScale | undefined>(MiniAppContext);
44
22
  const scaleSizeMaxRate = context?.scaleSizeMaxRate;
45
23
  const maxSize = scaleSizeMaxRate ? size * scaleSizeMaxRate : Infinity;
46
- const appScale = context?.fontScale;
47
- if (appScale?.useOSScaleRate === false) {
48
- const rate = toAppScaleRate(
49
- appScale.appScaleRate ?? appScale.userScaleRate,
50
- );
51
- return Math.min(size * rate, maxSize);
24
+ if (context?.fontScale?.useOSScaleRate === false) {
25
+ return Math.min(size * (context.fontScale.userScaleRate ?? 1), maxSize);
52
26
  }
53
27
  const fontScale = PixelRatio.getFontScale();
54
28
  const deviceScale = width / DEFAULT_SCREEN_SIZE;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/foundation",
3
- "version": "0.169.17-beta.1",
3
+ "version": "0.169.17-beta.10",
4
4
  "description": "React Native Component Kits",
5
5
  "main": "index.ts",
6
6
  "scripts": {},