Skip to content

Commit

Permalink
Fix top padding and safe areas for iOS PWA
Browse files Browse the repository at this point in the history
  • Loading branch information
Pasithea0 committed Aug 15, 2024
1 parent 2e08ed9 commit d6a2b91
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
<meta name="theme-color" content="#120f1d" />

<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">

<link rel="apple-touch-startup-image"
media="screen and (device-width: 430px) and (device-height: 932px) and (-webkit-device-pixel-ratio: 3) and (orientation: landscape)"
href="/splash_screens/iPhone_15_Pro_Max__iPhone_15_Plus__iPhone_14_Pro_Max_landscape.png">
Expand Down
4 changes: 4 additions & 0 deletions src/assets/css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ html[data-no-scroll], html[data-no-scroll] body {
overflow: hidden;
}

.top-content {
padding-top: calc(env(safe-area-inset-top) - 20px);
}

.roll {
animation: roll 1s;
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/layout/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ export function Navigation(props: NavigationProps) {

{/* backgrounds - these are seperate because of z-index issues */}
<div
className="fixed z-[20] pointer-events-none left-0 right-0 top-0 min-h-[150px]"
className="top-content fixed z-[20] pointer-events-none left-0 right-0 top-0 min-h-[150px]"
style={{
top: `${bannerHeight}px`,
}}
>
<div
className={classNames(
"fixed left-0 right-0 h-20 flex items-center",
"fixed left-0 right-0 top-0 flex items-center",
props.doBackground
? "bg-background-main border-b border-utils-divider border-opacity-50"
: null,
Expand All @@ -78,7 +78,7 @@ export function Navigation(props: NavigationProps) {

{/* content */}
<div
className="fixed pointer-events-none left-0 right-0 z-[60] top-0 min-h-[150px]"
className="top-content fixed pointer-events-none left-0 right-0 z-[60] top-0 min-h-[150px]"
style={{
top: `${bannerHeight}px`,
}}
Expand Down
2 changes: 1 addition & 1 deletion src/components/player/base/TopControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function TopControls(props: {
<Transition
animation="slide-down"
show={props.show}
className="text-white"
className="top-content text-white"
>
{props.children}
</Transition>
Expand Down
20 changes: 15 additions & 5 deletions src/pages/parts/home/HeroPart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,30 @@ export function HeroPart({ setIsSticky, searchParams }: HeroPartProps) {
},
[setShowBg, setIsSticky],
);
const { width: windowWidth, height: windowHeight } = useWindowSize();

const { width: windowWidth } = useWindowSize();
// Detect if running as a PWA on iOS
const isIOSPWA =
/iPad|iPhone|iPod/i.test(navigator.userAgent) &&
window.matchMedia("(display-mode: standalone)").matches;

const topSpacing = 16;
const topSpacing = isIOSPWA ? 60 : 16;
const [stickyOffset, setStickyOffset] = useState(topSpacing);

const isLandscape = windowHeight < windowWidth && isIOSPWA;
const adjustedOffset = isLandscape
? -40 // landscape
: 0; // portrait

useEffect(() => {
if (windowWidth > 1200) {
if (windowWidth > 1280) {
// On large screens the bar goes inline with the nav elements
setStickyOffset(topSpacing);
} else {
// On smaller screens the bar goes below the nav elements
setStickyOffset(topSpacing + 60);
setStickyOffset(topSpacing + 60 + adjustedOffset);
}
}, [windowWidth]);
}, [adjustedOffset, topSpacing, windowWidth]);

const time = getTimeOfDay(new Date());
const title = randomT(`home.titles.${time}`);
Expand Down

0 comments on commit d6a2b91

Please sign in to comment.