@shoutem/ui 9.0.5 → 9.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,11 +4,22 @@ import { initialWindowMetrics } from 'react-native-safe-area-context';
4
4
 
5
5
  export const NAVIGATION_HEADER_HEIGHT = 64;
6
6
 
7
+ // Fallback inset values used when initialWindowMetrics is null (race condition
8
+ // in large apps where JS evaluates before the safe-area native module inits).
9
+ // Bottom: 34pt — consistent across all notched iPhones since iPhone X (2017).
10
+ // Top: 59pt — matches Dynamic Island devices (iPhone 14+).
11
+ // Slightly too large for older notched devices (44–48pt), but using the
12
+ // largest one prevents content from being hidden under the notch/Dynamic Island.
13
+ const DEFAULT_IOS_TOP_INSET = 59;
14
+ const DEFAULT_IOS_BOTTOM_INSET = 34;
15
+
7
16
  export const isNotchedAndroid =
8
17
  Platform.OS === 'android' && DeviceInfo.hasNotch();
9
18
 
10
19
  export const NAVIGATION_BAR_HEIGHT = Platform.select({
11
- ios: NAVIGATION_HEADER_HEIGHT + initialWindowMetrics?.insets?.top,
20
+ ios:
21
+ NAVIGATION_HEADER_HEIGHT +
22
+ (initialWindowMetrics?.insets?.top ?? DEFAULT_IOS_TOP_INSET),
12
23
  android: isNotchedAndroid
13
24
  ? NAVIGATION_HEADER_HEIGHT + StatusBar.currentHeight
14
25
  : NAVIGATION_HEADER_HEIGHT,
@@ -16,10 +27,12 @@ export const NAVIGATION_BAR_HEIGHT = Platform.select({
16
27
  });
17
28
 
18
29
  export const HOME_INDICATOR_PADDING =
19
- Platform.OS === 'ios' ? initialWindowMetrics?.insets?.bottom : 0;
30
+ Platform.OS === 'ios'
31
+ ? initialWindowMetrics?.insets?.bottom ?? DEFAULT_IOS_BOTTOM_INSET
32
+ : 0;
20
33
 
21
34
  export const NOTCH_AREA_HEIGHT = Platform.select({
22
- ios: initialWindowMetrics?.insets?.top,
35
+ ios: initialWindowMetrics?.insets?.top ?? DEFAULT_IOS_TOP_INSET,
23
36
  android: isNotchedAndroid ? StatusBar.currentHeight : 0,
24
37
  default: 0,
25
38
  });
@@ -30,3 +43,49 @@ export const Device = {
30
43
  NOTCH_AREA_HEIGHT,
31
44
  NAVIGATION_HEADER_HEIGHT,
32
45
  };
46
+
47
+ // Lazy getters — resolve initialWindowMetrics on first render,
48
+ // when the native module is guaranteed to be ready.
49
+ let _topInset;
50
+ let _bottomInset;
51
+
52
+ const getTopInset = () => {
53
+ if (_topInset === undefined) {
54
+ // eslint-disable-next-line global-require
55
+ const metrics = require('react-native-safe-area-context')
56
+ .initialWindowMetrics;
57
+ _topInset = metrics?.insets?.top ?? DEFAULT_IOS_TOP_INSET;
58
+ }
59
+
60
+ return _topInset;
61
+ };
62
+
63
+ const getBottomInset = () => {
64
+ if (_bottomInset === undefined) {
65
+ // eslint-disable-next-line global-require
66
+ const metrics = require('react-native-safe-area-context')
67
+ .initialWindowMetrics;
68
+ _bottomInset = metrics?.insets?.bottom ?? DEFAULT_IOS_BOTTOM_INSET;
69
+ }
70
+
71
+ return _bottomInset;
72
+ };
73
+
74
+ export const getNavigationBarHeight = () =>
75
+ Platform.select({
76
+ ios: NAVIGATION_HEADER_HEIGHT + getTopInset(),
77
+ android: isNotchedAndroid
78
+ ? NAVIGATION_HEADER_HEIGHT + StatusBar.currentHeight
79
+ : NAVIGATION_HEADER_HEIGHT,
80
+ default: NAVIGATION_HEADER_HEIGHT,
81
+ });
82
+
83
+ export const getHomeIndicatorPadding = () =>
84
+ Platform.OS === 'ios' ? getBottomInset() : 0;
85
+
86
+ export const getNotchAreaHeight = () =>
87
+ Platform.select({
88
+ ios: getTopInset(),
89
+ android: isNotchedAndroid ? StatusBar.currentHeight : 0,
90
+ default: 0,
91
+ });
package/helpers/index.js CHANGED
@@ -1,5 +1,8 @@
1
1
  export {
2
2
  Device,
3
+ getHomeIndicatorPadding,
4
+ getNavigationBarHeight,
5
+ getNotchAreaHeight,
3
6
  HOME_INDICATOR_PADDING,
4
7
  isNotchedAndroid,
5
8
  NAVIGATION_BAR_HEIGHT,
package/index.js CHANGED
@@ -78,7 +78,14 @@ export { YearRangePicker } from './components/YearRangePicker';
78
78
  export * from './hooks';
79
79
 
80
80
  // Helpers
81
- export { calculateKeyboardOffset, Device, Keyboard } from './helpers';
81
+ export {
82
+ calculateKeyboardOffset,
83
+ Device,
84
+ getHomeIndicatorPadding,
85
+ getNavigationBarHeight,
86
+ getNotchAreaHeight,
87
+ Keyboard,
88
+ } from './helpers';
82
89
 
83
90
  // HTML
84
91
  export { Html } from './html';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shoutem/ui",
3
- "version": "9.0.5",
3
+ "version": "9.0.6",
4
4
  "description": "Styleable set of components for React Native applications",
5
5
  "scripts": {
6
6
  "lint": "eslint .",
@@ -1,8 +0,0 @@
1
- {
2
- "permissions": {
3
- "allow": [
4
- "Bash(npm whoami:*)",
5
- "Bash(npm config:*)"
6
- ]
7
- }
8
- }