@react-navigation/elements 1.3.26 → 1.3.28
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.
- package/lib/commonjs/SafeAreaProviderCompat.js +78 -13
- package/lib/commonjs/SafeAreaProviderCompat.js.map +1 -1
- package/lib/module/SafeAreaProviderCompat.js +79 -14
- package/lib/module/SafeAreaProviderCompat.js.map +1 -1
- package/lib/typescript/src/SafeAreaProviderCompat.d.ts +2 -1
- package/lib/typescript/src/SafeAreaProviderCompat.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/SafeAreaProviderCompat.tsx +87 -16
|
@@ -36,21 +36,86 @@ function SafeAreaProviderCompat(_ref) {
|
|
|
36
36
|
children,
|
|
37
37
|
style
|
|
38
38
|
} = _ref;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
39
|
+
const insets = React.useContext(_reactNativeSafeAreaContext.SafeAreaInsetsContext);
|
|
40
|
+
if (insets) {
|
|
41
|
+
// If we already have insets, don't wrap the stack in another safe area provider
|
|
42
|
+
// This avoids an issue with updates at the cost of potentially incorrect values
|
|
43
|
+
// https://github.com/react-navigation/react-navigation/issues/174
|
|
44
|
+
return /*#__PURE__*/React.createElement(_reactNative.View, {
|
|
45
|
+
style: [styles.container, style]
|
|
46
|
+
}, children);
|
|
47
|
+
}
|
|
48
|
+
if (_reactNative.Platform.OS === 'web') {
|
|
49
|
+
children = /*#__PURE__*/React.createElement(SafeAreaFrameProvider, {
|
|
50
|
+
initialMetrics: initialMetrics
|
|
51
51
|
}, children);
|
|
52
|
-
}
|
|
52
|
+
}
|
|
53
|
+
return /*#__PURE__*/React.createElement(_reactNativeSafeAreaContext.SafeAreaProvider, {
|
|
54
|
+
initialMetrics: initialMetrics,
|
|
55
|
+
style: style
|
|
56
|
+
}, children);
|
|
53
57
|
}
|
|
58
|
+
|
|
59
|
+
// FIXME: On the Web, the safe area frame value doesn't update on resize
|
|
60
|
+
// So we workaround this by measuring the frame on resize
|
|
61
|
+
const SafeAreaFrameProvider = _ref2 => {
|
|
62
|
+
let {
|
|
63
|
+
initialMetrics,
|
|
64
|
+
children
|
|
65
|
+
} = _ref2;
|
|
66
|
+
const element = React.useRef(null);
|
|
67
|
+
const [frame, setFrame] = React.useState(initialMetrics.frame);
|
|
68
|
+
React.useEffect(() => {
|
|
69
|
+
if (element.current == null) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const rect = element.current.getBoundingClientRect();
|
|
73
|
+
setFrame({
|
|
74
|
+
x: rect.x,
|
|
75
|
+
y: rect.y,
|
|
76
|
+
width: rect.width,
|
|
77
|
+
height: rect.height
|
|
78
|
+
});
|
|
79
|
+
let timeout;
|
|
80
|
+
const observer = new ResizeObserver(entries => {
|
|
81
|
+
const entry = entries[0];
|
|
82
|
+
if (entry) {
|
|
83
|
+
const {
|
|
84
|
+
x,
|
|
85
|
+
y,
|
|
86
|
+
width,
|
|
87
|
+
height
|
|
88
|
+
} = entry.contentRect;
|
|
89
|
+
|
|
90
|
+
// Debounce the frame updates to avoid too many updates in a short time
|
|
91
|
+
clearTimeout(timeout);
|
|
92
|
+
timeout = setTimeout(() => {
|
|
93
|
+
setFrame({
|
|
94
|
+
x,
|
|
95
|
+
y,
|
|
96
|
+
width,
|
|
97
|
+
height
|
|
98
|
+
});
|
|
99
|
+
}, 100);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
observer.observe(element.current);
|
|
103
|
+
return () => {
|
|
104
|
+
observer.disconnect();
|
|
105
|
+
clearTimeout(timeout);
|
|
106
|
+
};
|
|
107
|
+
}, []);
|
|
108
|
+
return /*#__PURE__*/React.createElement(_reactNativeSafeAreaContext.SafeAreaFrameContext.Provider, {
|
|
109
|
+
value: frame
|
|
110
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
111
|
+
ref: element,
|
|
112
|
+
style: {
|
|
113
|
+
..._reactNative.StyleSheet.absoluteFillObject,
|
|
114
|
+
pointerEvents: 'none',
|
|
115
|
+
visibility: 'hidden'
|
|
116
|
+
}
|
|
117
|
+
}), children);
|
|
118
|
+
};
|
|
54
119
|
SafeAreaProviderCompat.initialMetrics = initialMetrics;
|
|
55
120
|
const styles = _reactNative.StyleSheet.create({
|
|
56
121
|
container: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["width","height","Dimensions","get","initialMetrics","Platform","OS","initialWindowMetrics","frame","x","y","insets","top","left","right","bottom","SafeAreaProviderCompat","children","style","styles","container","StyleSheet","create","flex"],"sourceRoot":"../../src","sources":["SafeAreaProviderCompat.tsx"],"mappings":";;;;;;AAAA;AACA;AAQA;
|
|
1
|
+
{"version":3,"names":["width","height","Dimensions","get","initialMetrics","Platform","OS","initialWindowMetrics","frame","x","y","insets","top","left","right","bottom","SafeAreaProviderCompat","children","style","React","useContext","SafeAreaInsetsContext","styles","container","SafeAreaFrameProvider","element","useRef","setFrame","useState","useEffect","current","rect","getBoundingClientRect","timeout","observer","ResizeObserver","entries","entry","contentRect","clearTimeout","setTimeout","observe","disconnect","StyleSheet","absoluteFillObject","pointerEvents","visibility","create","flex"],"sourceRoot":"../../src","sources":["SafeAreaProviderCompat.tsx"],"mappings":";;;;;;AAAA;AACA;AAQA;AAMwC;AAAA;AAOxC,MAAM;EAAEA,KAAK,GAAG,CAAC;EAAEC,MAAM,GAAG;AAAE,CAAC,GAAGC,uBAAU,CAACC,GAAG,CAAC,QAAQ,CAAC;;AAE1D;AACA;AACA;AACA,MAAMC,cAAc,GAClBC,qBAAQ,CAACC,EAAE,KAAK,KAAK,IAAIC,gDAAoB,IAAI,IAAI,GACjD;EACEC,KAAK,EAAE;IAAEC,CAAC,EAAE,CAAC;IAAEC,CAAC,EAAE,CAAC;IAAEV,KAAK;IAAEC;EAAO,CAAC;EACpCU,MAAM,EAAE;IAAEC,G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ACjBC,MAAM,EAAE8B,IAAI,CAAC9B;IACf,CAAC,CAAC;IAEF,IAAIgC,OAAuB;IAE3B,MAAMC,QAAQ,GAAG,IAAIC,cAAc,CAAEC,OAAO,IAAK;MAC/C,MAAMC,KAAK,GAAGD,OAAO,CAAC,CAAC,CAAC;MAExB,IAAIC,KAAK,EAAE;QACT,MAAM;UAAE5B,CAAC;UAAEC,CAAC;UAAEV,KAAK;UAAEC;QAAO,CAAC,GAAGoC,KAAK,CAACC,WAAW;;QAEjD;QACAC,YAAY,CAACN,OAAO,CAAC;QACrBA,OAAO,GAAGO,UAAU,CAAC,MAAM;UACzBb,QAAQ,CAAC;YAAElB,CAAC;YAAEC,CAAC;YAAEV,KAAK;YAAEC;UAAO,CAAC,CAAC;QACnC,CAAC,EAAE,GAAG,CAAC;MACT;IACF,CAAC,CAAC;IAEFiC,QAAQ,CAACO,OAAO,CAAChB,OAAO,CAACK,OAAO,CAAC;IAEjC,OAAO,MAAM;MACXI,QAAQ,CAACQ,UAAU,EAAE;MACrBH,YAAY,CAACN,OAAO,CAAC;IACvB,CAAC;EACH,CAAC,EAAE,EAAE,CAAC;EAEN,oBACE,oBAAC,gDAAoB,CAAC,QAAQ;IAAC,KAAK,EAAEzB;EAAM,gBAC1C;IACE,GAAG,EAAEiB,OAAQ;IACb,KAAK,EAAE;MACL,GAAGkB,uBAAU,CAACC,kBAAkB;MAChCC,aAAa,EAAE,MAAM;MACrBC,UAAU,EAAE;IACd;EAAE,EACF,EACD7B,QAAQ,CACqB;AAEpC,CAAC;AAEDD,sBAAsB,CAACZ,cAAc,GAAGA,cAAc;AAEtD,MAAMkB,MAAM,GAAGqB,uBAAU,CAACI,MAAM,CAAC;EAC/BxB,SAAS,EAAE;IACTyB,IAAI,EAAE;EACR;AACF,CAAC,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { Dimensions, Platform, StyleSheet, View } from 'react-native';
|
|
3
|
-
import { initialWindowMetrics, SafeAreaInsetsContext, SafeAreaProvider } from 'react-native-safe-area-context';
|
|
3
|
+
import { initialWindowMetrics, SafeAreaFrameContext, SafeAreaInsetsContext, SafeAreaProvider } from 'react-native-safe-area-context';
|
|
4
4
|
const {
|
|
5
5
|
width = 0,
|
|
6
6
|
height = 0
|
|
@@ -28,21 +28,86 @@ export default function SafeAreaProviderCompat(_ref) {
|
|
|
28
28
|
children,
|
|
29
29
|
style
|
|
30
30
|
} = _ref;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
31
|
+
const insets = React.useContext(SafeAreaInsetsContext);
|
|
32
|
+
if (insets) {
|
|
33
|
+
// If we already have insets, don't wrap the stack in another safe area provider
|
|
34
|
+
// This avoids an issue with updates at the cost of potentially incorrect values
|
|
35
|
+
// https://github.com/react-navigation/react-navigation/issues/174
|
|
36
|
+
return /*#__PURE__*/React.createElement(View, {
|
|
37
|
+
style: [styles.container, style]
|
|
38
|
+
}, children);
|
|
39
|
+
}
|
|
40
|
+
if (Platform.OS === 'web') {
|
|
41
|
+
children = /*#__PURE__*/React.createElement(SafeAreaFrameProvider, {
|
|
42
|
+
initialMetrics: initialMetrics
|
|
43
43
|
}, children);
|
|
44
|
-
}
|
|
44
|
+
}
|
|
45
|
+
return /*#__PURE__*/React.createElement(SafeAreaProvider, {
|
|
46
|
+
initialMetrics: initialMetrics,
|
|
47
|
+
style: style
|
|
48
|
+
}, children);
|
|
45
49
|
}
|
|
50
|
+
|
|
51
|
+
// FIXME: On the Web, the safe area frame value doesn't update on resize
|
|
52
|
+
// So we workaround this by measuring the frame on resize
|
|
53
|
+
const SafeAreaFrameProvider = _ref2 => {
|
|
54
|
+
let {
|
|
55
|
+
initialMetrics,
|
|
56
|
+
children
|
|
57
|
+
} = _ref2;
|
|
58
|
+
const element = React.useRef(null);
|
|
59
|
+
const [frame, setFrame] = React.useState(initialMetrics.frame);
|
|
60
|
+
React.useEffect(() => {
|
|
61
|
+
if (element.current == null) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const rect = element.current.getBoundingClientRect();
|
|
65
|
+
setFrame({
|
|
66
|
+
x: rect.x,
|
|
67
|
+
y: rect.y,
|
|
68
|
+
width: rect.width,
|
|
69
|
+
height: rect.height
|
|
70
|
+
});
|
|
71
|
+
let timeout;
|
|
72
|
+
const observer = new ResizeObserver(entries => {
|
|
73
|
+
const entry = entries[0];
|
|
74
|
+
if (entry) {
|
|
75
|
+
const {
|
|
76
|
+
x,
|
|
77
|
+
y,
|
|
78
|
+
width,
|
|
79
|
+
height
|
|
80
|
+
} = entry.contentRect;
|
|
81
|
+
|
|
82
|
+
// Debounce the frame updates to avoid too many updates in a short time
|
|
83
|
+
clearTimeout(timeout);
|
|
84
|
+
timeout = setTimeout(() => {
|
|
85
|
+
setFrame({
|
|
86
|
+
x,
|
|
87
|
+
y,
|
|
88
|
+
width,
|
|
89
|
+
height
|
|
90
|
+
});
|
|
91
|
+
}, 100);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
observer.observe(element.current);
|
|
95
|
+
return () => {
|
|
96
|
+
observer.disconnect();
|
|
97
|
+
clearTimeout(timeout);
|
|
98
|
+
};
|
|
99
|
+
}, []);
|
|
100
|
+
return /*#__PURE__*/React.createElement(SafeAreaFrameContext.Provider, {
|
|
101
|
+
value: frame
|
|
102
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
103
|
+
ref: element,
|
|
104
|
+
style: {
|
|
105
|
+
...StyleSheet.absoluteFillObject,
|
|
106
|
+
pointerEvents: 'none',
|
|
107
|
+
visibility: 'hidden'
|
|
108
|
+
}
|
|
109
|
+
}), children);
|
|
110
|
+
};
|
|
46
111
|
SafeAreaProviderCompat.initialMetrics = initialMetrics;
|
|
47
112
|
const styles = StyleSheet.create({
|
|
48
113
|
container: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","Dimensions","Platform","StyleSheet","View","initialWindowMetrics","SafeAreaInsetsContext","SafeAreaProvider","width","height","get","initialMetrics","OS","frame","x","y","insets","top","left","right","bottom","SafeAreaProviderCompat","children","style","styles","container","create","flex"],"sourceRoot":"../../src","sources":["SafeAreaProviderCompat.tsx"],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SACEC,UAAU,EACVC,QAAQ,EAERC,UAAU,EACVC,IAAI,QAEC,cAAc;AACrB,SACEC,oBAAoB,EACpBC,qBAAqB,EACrBC,gBAAgB,QACX,gCAAgC;AAOvC,MAAM;EAAEC,KAAK,GAAG,CAAC;EAAEC,MAAM,GAAG;AAAE,CAAC,
|
|
1
|
+
{"version":3,"names":["React","Dimensions","Platform","StyleSheet","View","initialWindowMetrics","SafeAreaFrameContext","SafeAreaInsetsContext","SafeAreaProvider","width","height","get","initialMetrics","OS","frame","x","y","insets","top","left","right","bottom","SafeAreaProviderCompat","children","style","useContext","styles","container","SafeAreaFrameProvider","element","useRef","setFrame","useState","useEffect","current","rect","getBoundingClientRect","timeout","observer","ResizeObserver","entries","entry","contentRect","clearTimeout","setTimeout","observe","disconnect","absoluteFillObject","pointerEvents","visibility","create","flex"],"sourceRoot":"../../src","sources":["SafeAreaProviderCompat.tsx"],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SACEC,UAAU,EACVC,QAAQ,EAERC,UAAU,EACVC,IAAI,QAEC,cAAc;AACrB,SACEC,oBAAoB,EAEpBC,oBAAoB,EACpBC,qBAAqB,EACrBC,gBAAgB,QACX,gCAAgC;AAOvC,MAAM;EAAEC,KAAK,GAAG,CAAC;EAAEC,MAAM,GAAG;AAAE,CAAC,GAAGT,UAAU,CAACU,GAAG,CAAC,QAAQ,CAAC;;AAE1D;AACA;AACA;AACA,MAAMC,cAAc,GAClBV,QAAQ,CAACW,EAAE,KAAK,KAAK,IAAIR,oBAA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EAAE;IACTwB,IAAI,EAAE;EACR;AACF,CAAC,CAAC"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { StyleProp, ViewStyle } from 'react-native';
|
|
3
|
+
import { type Metrics } from 'react-native-safe-area-context';
|
|
3
4
|
type Props = {
|
|
4
5
|
children: React.ReactNode;
|
|
5
6
|
style?: StyleProp<ViewStyle>;
|
|
6
7
|
};
|
|
7
8
|
declare function SafeAreaProviderCompat({ children, style }: Props): JSX.Element;
|
|
8
9
|
declare namespace SafeAreaProviderCompat {
|
|
9
|
-
var initialMetrics:
|
|
10
|
+
var initialMetrics: Metrics;
|
|
10
11
|
}
|
|
11
12
|
export default SafeAreaProviderCompat;
|
|
12
13
|
//# sourceMappingURL=SafeAreaProviderCompat.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SafeAreaProviderCompat.d.ts","sourceRoot":"","sources":["../../../src/SafeAreaProviderCompat.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAGL,SAAS,EAGT,SAAS,EACV,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"SafeAreaProviderCompat.d.ts","sourceRoot":"","sources":["../../../src/SafeAreaProviderCompat.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAGL,SAAS,EAGT,SAAS,EACV,MAAM,cAAc,CAAC;AACtB,OAAO,EAEL,KAAK,OAAO,EAIb,MAAM,gCAAgC,CAAC;AAExC,KAAK,KAAK,GAAG;IACX,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;CAC9B,CAAC;AAeF,iBAAwB,sBAAsB,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,KAAK,eAuBxE;kBAvBuB,sBAAsB;;;eAAtB,sBAAsB"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-navigation/elements",
|
|
3
3
|
"description": "UI Components for React Navigation",
|
|
4
|
-
"version": "1.3.
|
|
4
|
+
"version": "1.3.28",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react-native",
|
|
7
7
|
"react-navigation",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@react-native-masked-view/masked-view": "0.2.9",
|
|
41
|
-
"@react-navigation/native": "^6.1.
|
|
41
|
+
"@react-navigation/native": "^6.1.15",
|
|
42
42
|
"@testing-library/react-native": "^11.5.0",
|
|
43
43
|
"@types/react": "~18.0.27",
|
|
44
44
|
"@types/react-native": "~0.71.3",
|
|
@@ -68,5 +68,5 @@
|
|
|
68
68
|
]
|
|
69
69
|
]
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "55671f1be1c068e95925c33aa171be3ec63ff97b"
|
|
72
72
|
}
|
|
@@ -9,6 +9,8 @@ import {
|
|
|
9
9
|
} from 'react-native';
|
|
10
10
|
import {
|
|
11
11
|
initialWindowMetrics,
|
|
12
|
+
type Metrics,
|
|
13
|
+
SafeAreaFrameContext,
|
|
12
14
|
SafeAreaInsetsContext,
|
|
13
15
|
SafeAreaProvider,
|
|
14
16
|
} from 'react-native-safe-area-context';
|
|
@@ -32,26 +34,95 @@ const initialMetrics =
|
|
|
32
34
|
: initialWindowMetrics;
|
|
33
35
|
|
|
34
36
|
export default function SafeAreaProviderCompat({ children, style }: Props) {
|
|
37
|
+
const insets = React.useContext(SafeAreaInsetsContext);
|
|
38
|
+
|
|
39
|
+
if (insets) {
|
|
40
|
+
// If we already have insets, don't wrap the stack in another safe area provider
|
|
41
|
+
// This avoids an issue with updates at the cost of potentially incorrect values
|
|
42
|
+
// https://github.com/react-navigation/react-navigation/issues/174
|
|
43
|
+
return <View style={[styles.container, style]}>{children}</View>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (Platform.OS === 'web') {
|
|
47
|
+
children = (
|
|
48
|
+
<SafeAreaFrameProvider initialMetrics={initialMetrics}>
|
|
49
|
+
{children}
|
|
50
|
+
</SafeAreaFrameProvider>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
35
54
|
return (
|
|
36
|
-
<
|
|
37
|
-
{
|
|
38
|
-
|
|
39
|
-
// If we already have insets, don't wrap the stack in another safe area provider
|
|
40
|
-
// This avoids an issue with updates at the cost of potentially incorrect values
|
|
41
|
-
// https://github.com/react-navigation/react-navigation/issues/174
|
|
42
|
-
return <View style={[styles.container, style]}>{children}</View>;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return (
|
|
46
|
-
<SafeAreaProvider initialMetrics={initialMetrics} style={style}>
|
|
47
|
-
{children}
|
|
48
|
-
</SafeAreaProvider>
|
|
49
|
-
);
|
|
50
|
-
}}
|
|
51
|
-
</SafeAreaInsetsContext.Consumer>
|
|
55
|
+
<SafeAreaProvider initialMetrics={initialMetrics} style={style}>
|
|
56
|
+
{children}
|
|
57
|
+
</SafeAreaProvider>
|
|
52
58
|
);
|
|
53
59
|
}
|
|
54
60
|
|
|
61
|
+
// FIXME: On the Web, the safe area frame value doesn't update on resize
|
|
62
|
+
// So we workaround this by measuring the frame on resize
|
|
63
|
+
const SafeAreaFrameProvider = ({
|
|
64
|
+
initialMetrics,
|
|
65
|
+
children,
|
|
66
|
+
}: {
|
|
67
|
+
initialMetrics: Metrics;
|
|
68
|
+
children: React.ReactNode;
|
|
69
|
+
}) => {
|
|
70
|
+
const element = React.useRef<HTMLDivElement>(null);
|
|
71
|
+
const [frame, setFrame] = React.useState(initialMetrics.frame);
|
|
72
|
+
|
|
73
|
+
React.useEffect(() => {
|
|
74
|
+
if (element.current == null) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const rect = element.current.getBoundingClientRect();
|
|
79
|
+
|
|
80
|
+
setFrame({
|
|
81
|
+
x: rect.x,
|
|
82
|
+
y: rect.y,
|
|
83
|
+
width: rect.width,
|
|
84
|
+
height: rect.height,
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
let timeout: NodeJS.Timeout;
|
|
88
|
+
|
|
89
|
+
const observer = new ResizeObserver((entries) => {
|
|
90
|
+
const entry = entries[0];
|
|
91
|
+
|
|
92
|
+
if (entry) {
|
|
93
|
+
const { x, y, width, height } = entry.contentRect;
|
|
94
|
+
|
|
95
|
+
// Debounce the frame updates to avoid too many updates in a short time
|
|
96
|
+
clearTimeout(timeout);
|
|
97
|
+
timeout = setTimeout(() => {
|
|
98
|
+
setFrame({ x, y, width, height });
|
|
99
|
+
}, 100);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
observer.observe(element.current);
|
|
104
|
+
|
|
105
|
+
return () => {
|
|
106
|
+
observer.disconnect();
|
|
107
|
+
clearTimeout(timeout);
|
|
108
|
+
};
|
|
109
|
+
}, []);
|
|
110
|
+
|
|
111
|
+
return (
|
|
112
|
+
<SafeAreaFrameContext.Provider value={frame}>
|
|
113
|
+
<div
|
|
114
|
+
ref={element}
|
|
115
|
+
style={{
|
|
116
|
+
...StyleSheet.absoluteFillObject,
|
|
117
|
+
pointerEvents: 'none',
|
|
118
|
+
visibility: 'hidden',
|
|
119
|
+
}}
|
|
120
|
+
/>
|
|
121
|
+
{children}
|
|
122
|
+
</SafeAreaFrameContext.Provider>
|
|
123
|
+
);
|
|
124
|
+
};
|
|
125
|
+
|
|
55
126
|
SafeAreaProviderCompat.initialMetrics = initialMetrics;
|
|
56
127
|
|
|
57
128
|
const styles = StyleSheet.create({
|