@pmate/bridge 0.1.1 → 0.1.2
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/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PropsWithChildren, useEffect, useMemo, useState } from "react"
|
|
1
|
+
import { PropsWithChildren, ReactNode, useEffect, useMemo, useState } from "react"
|
|
2
2
|
import { PmateBridgeContext } from "./context"
|
|
3
3
|
import {
|
|
4
4
|
getFallbackSafeInsets,
|
|
@@ -13,11 +13,13 @@ import type { DeviceInfoState, SafeInsetsState } from "./types"
|
|
|
13
13
|
|
|
14
14
|
export type PmateBridgeProviderProps = PropsWithChildren<{
|
|
15
15
|
disableSafeAreaVars?: boolean
|
|
16
|
+
loadingFallback?: ReactNode
|
|
16
17
|
}>
|
|
17
18
|
|
|
18
19
|
export function PmateBridgeProvider({
|
|
19
20
|
children,
|
|
20
21
|
disableSafeAreaVars = false,
|
|
22
|
+
loadingFallback = null,
|
|
21
23
|
}: PmateBridgeProviderProps) {
|
|
22
24
|
const [safeInsetsState, setSafeInsetsState] = useState<SafeInsetsState>({
|
|
23
25
|
insets: getFallbackSafeInsets(),
|
|
@@ -87,7 +89,12 @@ export function PmateBridgeProvider({
|
|
|
87
89
|
[deviceInfoState, isPmate, safeInsetsState]
|
|
88
90
|
)
|
|
89
91
|
|
|
92
|
+
const runtimeReady = !isPmate || safeInsetsState.ready
|
|
90
93
|
const content = disableSafeAreaVars ? children : <SafeAreaVarsProvider>{children}</SafeAreaVarsProvider>
|
|
91
94
|
|
|
92
|
-
return
|
|
95
|
+
return (
|
|
96
|
+
<PmateBridgeContext.Provider value={contextValue}>
|
|
97
|
+
{runtimeReady ? content : loadingFallback}
|
|
98
|
+
</PmateBridgeContext.Provider>
|
|
99
|
+
)
|
|
93
100
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { PropsWithChildren,
|
|
1
|
+
import { PropsWithChildren, useLayoutEffect } from "react"
|
|
2
2
|
import { useSafeInsets } from "./hooks"
|
|
3
3
|
|
|
4
4
|
export function SafeAreaVarsProvider({ children }: PropsWithChildren) {
|
|
5
5
|
const { insets } = useSafeInsets()
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
useLayoutEffect(() => {
|
|
8
8
|
if (typeof document === "undefined") {
|
|
9
9
|
return
|
|
10
10
|
}
|