@momo-kits/foundation 0.167.1-beta.5 → 0.167.1-duo-test.1

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.
Files changed (47) hide show
  1. package/Application/BottomSheet.tsx +115 -14
  2. package/Application/BottomTab/BottomTabBar.tsx +6 -3
  3. package/Application/BottomTab/DuoBarCompression.tsx +135 -0
  4. package/Application/BottomTab/DuoTabBar.tsx +462 -0
  5. package/Application/BottomTab/index.tsx +150 -134
  6. package/Application/Components/DuoGlassBackground.tsx +179 -0
  7. package/Application/Components/DuoQuickReturnHeader.tsx +42 -0
  8. package/Application/Components/HeaderExtendHeader.tsx +75 -28
  9. package/Application/Components/HeaderLeft.tsx +38 -0
  10. package/Application/Components/HeaderRight.tsx +142 -9
  11. package/Application/Components/HeaderTitle.tsx +67 -17
  12. package/Application/Components/OptionalGlassView.ts +11 -0
  13. package/Application/Components/OptionalScrollObserver.ts +12 -0
  14. package/Application/Components/SearchHeader.tsx +22 -15
  15. package/Application/Components/SideBarButton.tsx +139 -0
  16. package/Application/ModalScreen.tsx +16 -2
  17. package/Application/NavigationContainer.tsx +36 -45
  18. package/Application/Navigator.ts +1 -3
  19. package/Application/StackScreen.tsx +63 -9
  20. package/Application/WidgetContainer.tsx +9 -7
  21. package/Application/device.ts +29 -0
  22. package/Application/types.ts +27 -1
  23. package/Application/utils.tsx +255 -7
  24. package/Consts/index.ts +0 -1
  25. package/Consts/theme.ts +5 -6
  26. package/Input/Input.tsx +3 -4
  27. package/Input/InputMoney.tsx +31 -51
  28. package/Input/InputPhoneNumber.tsx +3 -4
  29. package/Input/InputSearch.tsx +3 -4
  30. package/Input/InputTextArea.tsx +3 -4
  31. package/Layout/Card.tsx +8 -26
  32. package/Layout/FloatingButton.tsx +3 -3
  33. package/Layout/Item.tsx +1 -10
  34. package/Layout/ReservedRegions.tsx +47 -0
  35. package/Layout/Screen.tsx +199 -52
  36. package/Layout/Section.tsx +5 -18
  37. package/Layout/index.ts +4 -4
  38. package/Layout/styles.ts +5 -0
  39. package/Layout/utils.ts +465 -5
  40. package/Popup/PopupNotify.tsx +33 -22
  41. package/Popup/PopupPromotion.tsx +20 -8
  42. package/Popup/utils.ts +32 -0
  43. package/Text/index.tsx +2 -11
  44. package/Text/utils.ts +1 -2
  45. package/package.json +3 -2
  46. package/Consts/designSystemFont.ts +0 -38
  47. package/Layout/GridSystem.tsx +0 -137
package/Layout/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import Card from './Card';
2
2
  import Section from './Section';
3
- import GridSystem from './GridSystem';
4
- import { validateChildren } from './utils';
3
+ import { useScreenLayout, validateChildren } from './utils';
4
+ import type { ScreenLayout, SideBarEdge, SideBarLayout } from './utils';
5
5
  import { createContext } from 'react';
6
6
  import { GridContextProps } from './types';
7
7
  import Item from './Item';
@@ -18,14 +18,14 @@ const GridContext = createContext<GridContextProps>({
18
18
  getSizeSpan: () => 0,
19
19
  });
20
20
 
21
- export type { ScreenProps };
21
+ export type { ScreenProps, ScreenLayout, SideBarEdge, SideBarLayout };
22
22
 
23
23
  export {
24
24
  GridContext,
25
25
  Card,
26
26
  Section,
27
- GridSystem,
28
27
  validateChildren,
28
+ useScreenLayout,
29
29
  Item,
30
30
  ItemList,
31
31
  ItemSectionList,
package/Layout/styles.ts CHANGED
@@ -91,5 +91,10 @@ export default StyleSheet.create({
91
91
  },
92
92
  }),
93
93
  },
94
+ footerClip: {
95
+ marginTop: -Spacing.XL,
96
+ paddingTop: Spacing.XL,
97
+ overflow: 'hidden',
98
+ },
94
99
  debugBaseLine: { borderWidth: 1, borderColor: Colors.green_06 },
95
100
  });
package/Layout/utils.ts CHANGED
@@ -1,5 +1,11 @@
1
- import React, { Fragment, ReactElement } from 'react';
2
- import { useWindowDimensions } from 'react-native';
1
+ import React, { Fragment, ReactElement, useContext } from 'react';
2
+ import { Platform, useWindowDimensions, ViewStyle } from 'react-native';
3
+ import {
4
+ EdgeInsets,
5
+ SafeAreaInsetsContext,
6
+ } from 'react-native-safe-area-context';
7
+ import { Spacing } from '../Consts';
8
+ import { ReservedRegion, ReservedRegionsContext } from './ReservedRegions';
3
9
 
4
10
  /**
5
11
  * validate children type
@@ -38,10 +44,464 @@ const validateChildren = (
38
44
  }
39
45
  };
40
46
 
47
+ /**
48
+ * Header geometry
49
+ * - barHeight: navigation bar row below the status bar
50
+ * - iPhoneMinHeight: header never shorter than this on iPhone (landscape, iPhone Duo)
51
+ * - statusBarMinInset: a smaller top inset means the status bar is not on the top edge
52
+ * - largeWidth / largeMargin: @react-navigation/elements Header gives its content row
53
+ * 5pt side margins on iOS from 414pt wide
54
+ */
55
+ const HeaderMetrics = {
56
+ barHeight: 52,
57
+ iPhoneMinHeight: 72,
58
+ statusBarMinInset: 20,
59
+ largeWidth: 414,
60
+ largeMargin: 5,
61
+ };
62
+
63
+ /**
64
+ * iPhone Duo geometry, iOS 27.1 (Xcode 27.1 simulator)
65
+ * - maxAspectRatio: both displays are near 1.42 (inner) and 1.45 (outer), every slab
66
+ * iPhone is 1.77 or taller
67
+ * - innerMinHeight: window height from which the inner display is in use (outer display
68
+ * is 466pt tall in landscape, inner display 669pt)
69
+ * - controlSize / itemPitch: vertical bar of 48pt circular controls, item groups as 48pt
70
+ * wide capsules at a 50pt pitch, 12pt from the strip's inner edge and 12pt apart
71
+ * - firstItemTop: with the status bar in the strip, the first control sits under the
72
+ * camera, clock and connectivity cluster (cluster ends near y 151 on the outer display,
73
+ * y 98 on the inner display in landscape)
74
+ * - outerHeaderHeight / outerCameraCenterY: on the outer display in portrait the header
75
+ * is 4pt taller than iPhoneMinHeight and its title lines up with the camera punchout
76
+ * (y 24–66 at the top of the strip)
77
+ * - edgeInset: on the outer display in landscape the strip holds no status bar, so its
78
+ * controls start this far from the top and stay this far above the bottom, unless a
79
+ * reserved region (the camera at either end) asks for more
80
+ * - innerStatusBarCenterY / innerStatusBarWidth: on the inner display in portrait the
81
+ * clock and connectivity cluster sits at the top right corner (x 550–643 of 669, clock
82
+ * digits centered on y 47); its reserved region, when reported, is taller than the glyphs
83
+ */
84
+ const DuoMetrics = {
85
+ maxAspectRatio: 1.6,
86
+ innerMinHeight: 600,
87
+ controlSize: 48,
88
+ itemPitch: 50,
89
+ firstItemTop: 170,
90
+ firstItemTopLandscape: 120,
91
+ outerHeaderHeight: 76,
92
+ outerCameraCenterY: 45,
93
+ edgeInset: 24,
94
+ innerStatusBarCenterY: 47,
95
+ innerStatusBarWidth: 120,
96
+ };
97
+
98
+ const NO_INSETS: EdgeInsets = { top: 0, right: 0, bottom: 0, left: 0 };
99
+
100
+ /**
101
+ * how far system regions reach into a side strip from its top and from its bottom end
102
+ * (e.g. the camera, which sits at either end depending on the rotation), and the center
103
+ * y of the region reaching furthest from the top
104
+ */
105
+ const getStripOcclusion = (
106
+ regions: ReservedRegion[],
107
+ stripLeft: number,
108
+ stripRight: number,
109
+ windowHeight: number,
110
+ ) =>
111
+ regions.reduce(
112
+ (occlusion, region) => {
113
+ const overlapsStrip =
114
+ region.x < stripRight && region.x + region.width > stripLeft;
115
+ if (!overlapsStrip) {
116
+ return occlusion;
117
+ }
118
+ const centerY = region.y + region.height / 2;
119
+ if (centerY < windowHeight / 2) {
120
+ if (region.y + region.height > occlusion.top) {
121
+ occlusion.top = region.y + region.height;
122
+ occlusion.topCenter = centerY;
123
+ }
124
+ } else {
125
+ occlusion.bottom = Math.max(occlusion.bottom, windowHeight - region.y);
126
+ }
127
+ return occlusion;
128
+ },
129
+ { top: 0, topCenter: 0, bottom: 0 },
130
+ );
131
+
132
+ /**
133
+ * how far the clock and battery clusters of a status bar on the top edge reach in from
134
+ * each side. `undefined` without reserved regions there
135
+ */
136
+ const getStatusBarClusters = (
137
+ regions: ReservedRegion[],
138
+ windowWidth: number,
139
+ topInset: number,
140
+ ) => {
141
+ const midX = windowWidth / 2;
142
+ const clusters = regions.filter(
143
+ region =>
144
+ region.y < topInset &&
145
+ region.y + region.height <= topInset &&
146
+ (region.x + region.width <= midX || region.x >= midX),
147
+ );
148
+ if (!clusters.length) {
149
+ return undefined;
150
+ }
151
+
152
+ return clusters.reduce(
153
+ (result, region) => {
154
+ if (region.x < midX) {
155
+ result.left = Math.max(result.left, region.x + region.width);
156
+ } else {
157
+ result.right = Math.max(result.right, windowWidth - region.x);
158
+ }
159
+ return result;
160
+ },
161
+ { left: 0, right: 0 },
162
+ );
163
+ };
164
+
165
+ const isIPhone = () =>
166
+ Platform.OS === 'ios' && Platform.constants.interfaceIdiom === 'phone';
167
+
168
+ /**
169
+ * Header height and the room it keeps above the bar row for the status bar. On iPhone the
170
+ * header is at least iPhoneMinHeight, and with the status bar off the top edge the row
171
+ * spans the whole header, so the title stays vertically centered.
172
+ */
173
+ const getHeaderLayout = (topInset: number) => {
174
+ const height = HeaderMetrics.barHeight + topInset;
175
+ if (!isIPhone()) {
176
+ return { headerHeight: height, headerStatusBarHeight: topInset };
177
+ }
178
+
179
+ return {
180
+ headerHeight: Math.max(height, HeaderMetrics.iPhoneMinHeight),
181
+ headerStatusBarHeight:
182
+ topInset < HeaderMetrics.statusBarMinInset ? 0 : topInset,
183
+ };
184
+ };
185
+
186
+ /**
187
+ * Header whose bar row is centered on a window y, at least iPhoneMinHeight tall and
188
+ * reaching 8pt below a side bar control centered there
189
+ */
190
+ const getCenteredHeaderLayout = (centerY: number) => {
191
+ const headerHeight = Math.max(
192
+ HeaderMetrics.iPhoneMinHeight,
193
+ centerY + DuoMetrics.controlSize / 2 + Spacing.S,
194
+ );
195
+ return {
196
+ headerHeight,
197
+ headerStatusBarHeight: Math.max(0, centerY * 2 - headerHeight),
198
+ };
199
+ };
200
+
201
+ export type SideBarEdge = 'left' | 'right';
202
+
203
+ export type SideBarLayout = {
204
+ /**
205
+ * Edge holding the side bar, the one with the larger safe-area inset.
206
+ */
207
+ edge: SideBarEdge;
208
+
209
+ /**
210
+ * Width of the side bar column, the safe-area inset on that edge.
211
+ */
212
+ width: number;
213
+
214
+ /**
215
+ * Window y of the first side bar item, below the navigation bar and the side status bar.
216
+ */
217
+ top: number;
218
+
219
+ /**
220
+ * Room to keep free above the window bottom, clear of a camera at the bottom end.
221
+ */
222
+ bottom: number;
223
+ };
224
+
225
+ export type ScreenLayout = {
226
+ /**
227
+ * Window width, from useWindowDimensions.
228
+ */
229
+ width: number;
230
+
231
+ /**
232
+ * Window height, from useWindowDimensions.
233
+ */
234
+ height: number;
235
+
236
+ /**
237
+ * `true` when running on iPhone Duo, outer or inner display.
238
+ */
239
+ isIPhoneDuo: boolean;
240
+
241
+ /**
242
+ * Raw safe-area insets.
243
+ */
244
+ insets: EdgeInsets;
245
+
246
+ /**
247
+ * Horizontal insets the screen content keeps clear of. 0 outside iPhone Duo.
248
+ */
249
+ insetLeft: number;
250
+ insetRight: number;
251
+
252
+ /**
253
+ * Width available to the screen content: window width minus the horizontal insets.
254
+ */
255
+ contentWidth: number;
256
+
257
+ /**
258
+ * Header height: the top safe-area inset plus the navigation bar row, at least 72pt on iPhone.
259
+ */
260
+ headerHeight: number;
261
+
262
+ /**
263
+ * Room above the navigation bar row for the status bar, the rest of headerHeight is
264
+ * the row, which centers the title vertically. 0 when the status bar is not on top.
265
+ */
266
+ headerStatusBarHeight: number;
267
+
268
+ /**
269
+ * Side column holding the back button and the toolkit, when iPhone Duo moves the
270
+ * bars to the side. `undefined` while the bars stay horizontal.
271
+ */
272
+ sideBar?: SideBarLayout;
273
+
274
+ /**
275
+ * Room the header row keeps from each side for the clock and battery clusters, when
276
+ * iPhone Duo puts the row on the status bar (inner display in portrait).
277
+ */
278
+ statusBarClearance?: StatusBarClearance;
279
+ };
280
+
281
+ export type StatusBarClearance = {
282
+ left: number;
283
+ right: number;
284
+ };
285
+
286
+ /**
287
+ * Detect iPhone Duo from the window shape and the safe area: a phone idiom window
288
+ * near square, or a phone with asymmetric side insets (slab iPhones report equal
289
+ * left / right insets in landscape, iPhone Duo moves the status bar to one side).
290
+ */
291
+ const isIPhoneDuoLayout = (
292
+ width: number,
293
+ height: number,
294
+ insets: EdgeInsets,
295
+ ) => {
296
+ if (!isIPhone()) {
297
+ return false;
298
+ }
299
+
300
+ const shortSide = Math.min(width, height);
301
+ const aspectRatio = shortSide > 0 ? Math.max(width, height) / shortSide : 0;
302
+ const isSquare = aspectRatio > 0 && aspectRatio < DuoMetrics.maxAspectRatio;
303
+
304
+ return isSquare || insets.left !== insets.right;
305
+ };
306
+
307
+ /**
308
+ * Screen layout for the current window: iPhone Duo detection, horizontal content insets,
309
+ * content width and the side bar. Follows the window through fold, unfold, rotation and
310
+ * Split View since it reads useWindowDimensions and the safe-area context.
311
+ */
312
+ const useScreenLayout = (): ScreenLayout => {
313
+ const { width, height } = useWindowDimensions();
314
+ const insets = useContext(SafeAreaInsetsContext) ?? NO_INSETS;
315
+ const reservedRegions = useContext(ReservedRegionsContext);
316
+
317
+ let headerLayout = getHeaderLayout(insets.top);
318
+ const isIPhoneDuo = isIPhoneDuoLayout(width, height, insets);
319
+ if (!isIPhoneDuo) {
320
+ return {
321
+ width,
322
+ height,
323
+ isIPhoneDuo,
324
+ insets,
325
+ insetLeft: 0,
326
+ insetRight: 0,
327
+ contentWidth: width,
328
+ ...headerLayout,
329
+ };
330
+ }
331
+
332
+ let statusBarClearance: StatusBarClearance | undefined;
333
+ const isInnerPortrait = height > width && width >= DuoMetrics.innerMinHeight;
334
+ if (isInnerPortrait && insets.top >= HeaderMetrics.statusBarMinInset) {
335
+ // the row shares the status bar band, between its clusters
336
+ const clusters = getStatusBarClusters(
337
+ reservedRegions,
338
+ width,
339
+ insets.top,
340
+ ) ?? { left: 0, right: DuoMetrics.innerStatusBarWidth + Spacing.S };
341
+ // center on the clock digits, the region center sits above them
342
+ headerLayout = {
343
+ headerHeight: DuoMetrics.innerStatusBarCenterY * 2,
344
+ headerStatusBarHeight: 0,
345
+ };
346
+ statusBarClearance = clusters;
347
+ }
348
+
349
+ const sideInset = Math.max(insets.left, insets.right);
350
+ let sideBar: SideBarLayout | undefined;
351
+ // narrower strips cannot host a control 12pt from the inner edge
352
+ if (sideInset >= DuoMetrics.controlSize + Spacing.M) {
353
+ const edge = insets.right >= insets.left ? 'right' : 'left';
354
+ const stripLeft = edge === 'right' ? width - sideInset : 0;
355
+ // keep controls clear of the camera and of the status bar cluster, which grows for
356
+ // calls and Live Activities. Region frames already include the system's margin
357
+ const occlusion = getStripOcclusion(
358
+ reservedRegions,
359
+ stripLeft,
360
+ stripLeft + sideInset,
361
+ height,
362
+ );
363
+
364
+ let top = statusBarClearance
365
+ ? headerLayout.headerHeight + Spacing.M
366
+ : insets.top + HeaderMetrics.barHeight + Spacing.M;
367
+ if (insets.top < HeaderMetrics.statusBarMinInset) {
368
+ // status bar lives in the strip: start under its cluster, as the native bar does
369
+ const isLandscape = width > height;
370
+ if (!isLandscape) {
371
+ top = DuoMetrics.firstItemTop;
372
+ } else if (height >= DuoMetrics.innerMinHeight) {
373
+ top = DuoMetrics.firstItemTopLandscape;
374
+ } else {
375
+ // outer display in landscape: no status bar in the strip, the title row centers
376
+ // on the camera when it sits at the top end, otherwise on the back button
377
+ top = DuoMetrics.edgeInset;
378
+ const titleCenterY =
379
+ occlusion.top > top
380
+ ? occlusion.topCenter
381
+ : top + DuoMetrics.controlSize / 2;
382
+ headerLayout = getCenteredHeaderLayout(titleCenterY);
383
+ }
384
+
385
+ if (height > width && width < DuoMetrics.innerMinHeight) {
386
+ // outer display: the row starts below the top so the title centers on the camera
387
+ headerLayout = {
388
+ headerHeight: DuoMetrics.outerHeaderHeight,
389
+ headerStatusBarHeight:
390
+ DuoMetrics.outerCameraCenterY * 2 - DuoMetrics.outerHeaderHeight,
391
+ };
392
+ }
393
+ }
394
+
395
+ sideBar = {
396
+ edge,
397
+ width: sideInset,
398
+ top: Math.max(top, occlusion.top),
399
+ bottom: Math.max(DuoMetrics.edgeInset, occlusion.bottom),
400
+ };
401
+ }
402
+
403
+ return {
404
+ width,
405
+ height,
406
+ isIPhoneDuo,
407
+ insets,
408
+ insetLeft: insets.left,
409
+ insetRight: insets.right,
410
+ contentWidth: width - insets.left - insets.right,
411
+ ...headerLayout,
412
+ sideBar,
413
+ statusBarClearance,
414
+ };
415
+ };
416
+
417
+ /**
418
+ * Header row options for react-navigation: its height, the room for the status bar, and
419
+ * on iPhone Duo inner portrait the buttons kept clear of the clock and battery clusters
420
+ */
421
+ const getHeaderRowOptions = ({
422
+ headerHeight,
423
+ headerStatusBarHeight,
424
+ statusBarClearance,
425
+ sideBar,
426
+ }: ScreenLayout) => ({
427
+ headerStyle: { height: headerHeight },
428
+ headerStatusBarHeight,
429
+ // side bar controls are absolute within the containers, padding would not move them
430
+ ...(statusBarClearance &&
431
+ !sideBar && {
432
+ headerLeftContainerStyle: { paddingLeft: statusBarClearance.left },
433
+ headerRightContainerStyle: { paddingRight: statusBarClearance.right },
434
+ }),
435
+ });
436
+
437
+ /**
438
+ * Side margin @react-navigation/elements Header adds to its content row
439
+ */
440
+ const getHeaderMargin = (width: number) =>
441
+ Platform.OS === 'ios' && width >= HeaderMetrics.largeWidth
442
+ ? HeaderMetrics.largeMargin
443
+ : 0;
444
+
445
+ /**
446
+ * Absolute style that floats a header item into the side bar, relative to the header
447
+ * container (left or right) rendering it, 12pt from the strip's inner edge.
448
+ * `undefined` while there is no side bar.
449
+ * @param container header container rendering the item
450
+ * @param slot position in the side bar, 0 for back, 1 for the toolkit below it
451
+ */
452
+ const useSideBarItemStyle = (
453
+ container: 'left' | 'right',
454
+ slot: number,
455
+ ): ViewStyle | undefined => {
456
+ const { width, insets, headerStatusBarHeight, sideBar } = useScreenLayout();
457
+ if (!sideBar) {
458
+ return undefined;
459
+ }
460
+
461
+ const margin = getHeaderMargin(width);
462
+ const columnLeft = sideBar.edge === 'left' ? 0 : width - sideBar.width;
463
+ const top =
464
+ sideBar.top -
465
+ headerStatusBarHeight +
466
+ slot * (DuoMetrics.controlSize + Spacing.M);
467
+ const innerEdgeStyle: ViewStyle =
468
+ sideBar.edge === 'right'
469
+ ? { alignItems: 'flex-start', paddingLeft: Spacing.M }
470
+ : { alignItems: 'flex-end', paddingRight: Spacing.M };
471
+
472
+ if (container === 'left') {
473
+ return {
474
+ position: 'absolute',
475
+ top,
476
+ left: columnLeft - margin - insets.left,
477
+ width: sideBar.width,
478
+ ...innerEdgeStyle,
479
+ };
480
+ }
481
+
482
+ const containerRight = width - margin - insets.right;
483
+ return {
484
+ position: 'absolute',
485
+ top,
486
+ right: containerRight - (columnLeft + sideBar.width),
487
+ width: sideBar.width,
488
+ ...innerEdgeStyle,
489
+ };
490
+ };
491
+
41
492
  const useGridSystem = () => {
42
- const windowSize = useWindowDimensions();
43
- const numberOfColumns = windowSize.width > 600 ? 24 : 12;
493
+ const { contentWidth } = useScreenLayout();
494
+ const numberOfColumns = contentWidth > 600 ? 24 : 12;
44
495
  return { numberOfColumns };
45
496
  };
46
497
 
47
- export { useGridSystem, validateChildren };
498
+ export {
499
+ DuoMetrics,
500
+ HeaderMetrics,
501
+ getHeaderMargin,
502
+ getHeaderRowOptions,
503
+ useGridSystem,
504
+ useScreenLayout,
505
+ useSideBarItemStyle,
506
+ validateChildren,
507
+ };
@@ -1,11 +1,5 @@
1
1
  import React, { useContext, useRef, useState } from 'react';
2
- import {
3
- Dimensions,
4
- ScrollView,
5
- StyleSheet,
6
- TouchableOpacity,
7
- View,
8
- } from 'react-native';
2
+ import { ScrollView, StyleSheet, TouchableOpacity, View } from 'react-native';
9
3
  import { ApplicationContext, MiniAppContext } from '../Context';
10
4
  import { Button } from '../Button';
11
5
  import { Colors, Radius, Spacing, Styles } from '../Consts';
@@ -13,7 +7,8 @@ import { Icon } from '../Icon';
13
7
  import { Image } from '../Image';
14
8
  import { Text, useScaleSize } from '../Text';
15
9
  import { PopupNotifyProps } from './types';
16
- import { runOnJS } from 'react-native-reanimated';
10
+ import { scheduleOnRN } from 'react-native-worklets';
11
+ import { usePopupMaxHeight, usePopupWidth } from './utils';
17
12
 
18
13
  const PopupNotify: React.FC<PopupNotifyProps> = ({
19
14
  image,
@@ -29,7 +24,8 @@ const PopupNotify: React.FC<PopupNotifyProps> = ({
29
24
  const context = useContext<any>(MiniAppContext);
30
25
  const { theme, navigator, translate } = useContext(ApplicationContext);
31
26
  const [scrollContent, setScrollContent] = useState(false);
32
- const { width: widthDevice } = Dimensions.get('window');
27
+ const popupWidth = usePopupWidth();
28
+ const maxHeight = usePopupMaxHeight();
33
29
  const scaledMaxHeight = useScaleSize(172);
34
30
 
35
31
  const showBaseLineDebug = context?.features?.showBaseLineDebug ?? false;
@@ -50,7 +46,7 @@ const PopupNotify: React.FC<PopupNotifyProps> = ({
50
46
  onRequestClose?.(callback);
51
47
  } else {
52
48
  navigator?.pop();
53
- runOnJS(() => callback?.())();
49
+ scheduleOnRN(() => callback?.());
54
50
  }
55
51
  };
56
52
 
@@ -172,18 +168,8 @@ const PopupNotify: React.FC<PopupNotifyProps> = ({
172
168
  }
173
169
  };
174
170
 
175
- return (
176
- <View
177
- accessibilityLabel={'popup_notify'}
178
- style={[
179
- styles.container,
180
- {
181
- backgroundColor: theme.colors.background.surface,
182
- width: widthDevice - Spacing.XL * 2,
183
- },
184
- showBaseLineDebug && styles.debugBaseLine,
185
- ]}
186
- >
171
+ const body = (
172
+ <>
187
173
  {!!image && <Image source={{ uri: image }} style={styles.image} />}
188
174
  <View style={styles.content}>
189
175
  <Text
@@ -225,6 +211,30 @@ const PopupNotify: React.FC<PopupNotifyProps> = ({
225
211
  </View>
226
212
  )}
227
213
  </View>
214
+ </>
215
+ );
216
+
217
+ return (
218
+ <View
219
+ accessibilityLabel={'popup_notify'}
220
+ style={[
221
+ styles.container,
222
+ {
223
+ backgroundColor: theme.colors.background.surface,
224
+ width: popupWidth,
225
+ maxHeight,
226
+ },
227
+ showBaseLineDebug && styles.debugBaseLine,
228
+ ]}
229
+ >
230
+ {maxHeight === undefined ? (
231
+ body
232
+ ) : (
233
+ // scrolls when iPhone Duo landscape is too short; actions stay visible
234
+ <ScrollView style={styles.body} bounces={false}>
235
+ {body}
236
+ </ScrollView>
237
+ )}
228
238
  <View style={styles.contentAction}>{buildAction()}</View>
229
239
  {buildCloseIcon()}
230
240
  </View>
@@ -242,6 +252,7 @@ const styles = StyleSheet.create({
242
252
  aspectRatio: 1.7777,
243
253
  overflow: 'hidden',
244
254
  },
255
+ body: { flexShrink: 1 },
245
256
  content: { padding: Spacing.XL },
246
257
  description: {
247
258
  marginTop: Spacing.S,
@@ -1,10 +1,16 @@
1
1
  import React, { useContext, useRef } from 'react';
2
- import { Dimensions, StyleSheet, TouchableOpacity, View } from 'react-native';
2
+ import { StyleSheet, TouchableOpacity, View } from 'react-native';
3
3
  import { PopupPromotionProps } from './types';
4
4
  import { ApplicationContext, MiniAppContext } from '../Context';
5
5
  import { Image } from '../Image';
6
6
  import { Colors, Radius, Spacing } from '../Consts';
7
7
  import { Icon } from '../Icon';
8
+ import { usePopupMaxHeight, usePopupWidth } from './utils';
9
+
10
+ const ASPECT_RATIO = 0.72;
11
+ const ICON_CLOSE_SIZE = 20;
12
+ // close button row under the image: marginTop + vertical padding + icon
13
+ const CLOSE_ROW_HEIGHT = Spacing.S * 3 + ICON_CLOSE_SIZE;
8
14
 
9
15
  const PopupPromotion: React.FC<PopupPromotionProps> = ({
10
16
  image,
@@ -14,7 +20,13 @@ const PopupPromotion: React.FC<PopupPromotionProps> = ({
14
20
  }) => {
15
21
  const context = useContext<any>(MiniAppContext);
16
22
  const { theme, navigator } = useContext(ApplicationContext);
17
- const { width: widthDevice } = Dimensions.get('window');
23
+ const popupWidth = usePopupWidth();
24
+ const maxHeight = usePopupMaxHeight();
25
+ // fit the portrait image by height when iPhone Duo leaves too little room
26
+ const imageWidth =
27
+ maxHeight === undefined
28
+ ? popupWidth
29
+ : Math.min(popupWidth, (maxHeight - CLOSE_ROW_HEIGHT) * ASPECT_RATIO);
18
30
  const closeAction = useRef('touch_outside');
19
31
 
20
32
  const showBaseLineDebug = context?.features?.showBaseLineDebug ?? false;
@@ -69,7 +81,7 @@ const PopupPromotion: React.FC<PopupPromotionProps> = ({
69
81
  return (
70
82
  <View
71
83
  accessibilityLabel={'popup_promotion'}
72
- style={showBaseLineDebug && styles.debugBaseLine}
84
+ style={[{ width: imageWidth }, showBaseLineDebug && styles.debugBaseLine]}
73
85
  >
74
86
  <TouchableOpacity onPress={() => onAction(onActionClick)}>
75
87
  <Image
@@ -80,7 +92,7 @@ const PopupPromotion: React.FC<PopupPromotionProps> = ({
80
92
  style={[
81
93
  styles.container,
82
94
  {
83
- width: widthDevice - Spacing.XL * 2,
95
+ width: imageWidth,
84
96
  },
85
97
  ]}
86
98
  />
@@ -92,7 +104,7 @@ const PopupPromotion: React.FC<PopupPromotionProps> = ({
92
104
 
93
105
  const styles = StyleSheet.create({
94
106
  container: {
95
- aspectRatio: 0.72,
107
+ aspectRatio: ASPECT_RATIO,
96
108
  width: '100%',
97
109
  },
98
110
  debugBaseLine: { borderWidth: 1, borderColor: Colors.green_06 },
@@ -103,11 +115,11 @@ const styles = StyleSheet.create({
103
115
  marginTop: Spacing.S,
104
116
  },
105
117
  iconButton: {
106
- padding: 8,
118
+ padding: Spacing.S,
107
119
  },
108
120
  iconClose: {
109
- width: 20,
110
- height: 20,
121
+ width: ICON_CLOSE_SIZE,
122
+ height: ICON_CLOSE_SIZE,
111
123
  alignItems: 'center',
112
124
  justifyContent: 'center',
113
125
  borderRadius: Radius.M,