-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Safe inset stuff for Android (still WIP)
- Loading branch information
Showing
16 changed files
with
90 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import NativeBridge from "@/NativeBridge"; | ||
import { useFlagStore } from "./flags"; | ||
|
||
export function loadHybridSafeInsets() { | ||
const flags = useFlagStore.getState(); | ||
|
||
if (!flags.isHybrid) { | ||
return; | ||
} | ||
|
||
if (!flags.isAndroid) { | ||
return; | ||
} | ||
|
||
const insetJson = NativeBridge.getSafeInset(); | ||
if (!insetJson) { | ||
return; | ||
} | ||
|
||
const values = { | ||
top: 0, | ||
bottom: 0, | ||
left: 0, | ||
right: 0, | ||
}; | ||
|
||
try { | ||
const inset = JSON.parse(insetJson); | ||
Object.assign(values, inset); | ||
|
||
// Apply pixel ratio | ||
values.top /= window.devicePixelRatio; | ||
values.bottom /= window.devicePixelRatio; | ||
values.left /= window.devicePixelRatio; | ||
values.right /= window.devicePixelRatio; | ||
} catch { | ||
// noop | ||
} | ||
|
||
const root = document.documentElement; | ||
|
||
root.style.setProperty("--safe-area-inset-top", `${values.top}px`); | ||
root.style.setProperty("--safe-area-inset-right", `${values.right}px`); | ||
root.style.setProperty("--safe-area-inset-bottom", `${values.bottom}px`); | ||
root.style.setProperty("--safe-area-inset-left", `${values.left}px`); | ||
} |