mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-20 11:06:06 +00:00
fix(mobile): put the top bar beside a Duo's status capsule and the page below it, full width
Keeping the whole right inset clear gave up a strip of the full height for a capsule that only sits in the corner. The iOS app now measures an element in a top corner (iOS 26 safe area with corner adaptation, vertical against horizontal) and hands its reach and width to the page: the floating bars stand beside it, the page keeps the full width and starts below it. Without such an element, on every other device and before iOS 26, nothing changes.
This commit is contained in:
@@ -120,18 +120,47 @@ class TrekBridgeViewController: CAPBridgeViewController {
|
|||||||
bottom: max(0, safe.bottom - (window.bounds.maxY - frame.maxY)),
|
bottom: max(0, safe.bottom - (window.bounds.maxY - frame.maxY)),
|
||||||
right: max(0, safe.right - (window.bounds.maxX - frame.maxX))
|
right: max(0, safe.right - (window.bounds.maxX - frame.maxX))
|
||||||
)
|
)
|
||||||
if !force, insets == publishedSafeArea { return }
|
let corner = cornerElement(in: frame, window: window)
|
||||||
|
if !force, insets == publishedSafeArea, corner == publishedCorner { return }
|
||||||
publishedSafeArea = insets
|
publishedSafeArea = insets
|
||||||
|
publishedCorner = corner
|
||||||
let px = { (v: CGFloat) in "'\(Int(v.rounded(.up)))px'" }
|
let px = { (v: CGFloat) in "'\(Int(v.rounded(.up)))px'" }
|
||||||
let js = "(function(s){"
|
let js = "(function(s){"
|
||||||
+ "s.setProperty('--trek-native-safe-top',\(px(insets.top)));"
|
+ "s.setProperty('--trek-native-safe-top',\(px(insets.top)));"
|
||||||
+ "s.setProperty('--trek-native-safe-left',\(px(insets.left)));"
|
+ "s.setProperty('--trek-native-safe-left',\(px(insets.left)));"
|
||||||
+ "s.setProperty('--trek-native-safe-right',\(px(insets.right)));"
|
+ "s.setProperty('--trek-native-safe-right',\(px(insets.right)));"
|
||||||
+ "s.setProperty('--trek-native-safe-bottom',\(px(insets.bottom)));"
|
+ "s.setProperty('--trek-native-safe-bottom',\(px(insets.bottom)));"
|
||||||
|
+ "s.setProperty('--trek-native-corner-bottom',\(px(corner.top)));"
|
||||||
|
+ "s.setProperty('--trek-native-corner-left',\(px(corner.left)));"
|
||||||
|
+ "s.setProperty('--trek-native-corner-right',\(px(corner.right)));"
|
||||||
+ "})(document.documentElement.style)"
|
+ "})(document.documentElement.style)"
|
||||||
webView.evaluateJavaScript(js, completionHandler: nil)
|
webView.evaluateJavaScript(js, completionHandler: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var publishedCorner: UIEdgeInsets?
|
||||||
|
|
||||||
|
/// An element in a top corner of the screen, such as the status capsule of
|
||||||
|
/// an iPhone Duo: how far down it reaches (top) and how wide it is on its
|
||||||
|
/// side (left/right), in the web view's coordinates; zero where there is
|
||||||
|
/// none. iOS 26 tells a corner apart from a whole edge: the safe area with
|
||||||
|
/// the corner avoided vertically reaches lower than the one avoiding it
|
||||||
|
/// horizontally, which in turn is wider on the corner's side. The page puts
|
||||||
|
/// its top bar beside the element and starts its content below it, using
|
||||||
|
/// the full width (mobile.css), instead of giving up a strip of the whole
|
||||||
|
/// height.
|
||||||
|
private func cornerElement(in frame: CGRect, window: UIWindow) -> UIEdgeInsets {
|
||||||
|
guard #available(iOS 26.0, *) else { return .zero }
|
||||||
|
let vertical = view.edgeInsets(for: .safeArea(cornerAdaptation: .vertical))
|
||||||
|
let horizontal = view.edgeInsets(for: .safeArea(cornerAdaptation: .horizontal))
|
||||||
|
guard vertical.top > horizontal.top + 1 else { return .zero }
|
||||||
|
return UIEdgeInsets(
|
||||||
|
top: max(0, vertical.top - frame.minY),
|
||||||
|
left: max(0, horizontal.left - vertical.left - frame.minX),
|
||||||
|
bottom: 0,
|
||||||
|
right: max(0, horizontal.right - vertical.right - (window.bounds.maxX - frame.maxX))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - A proxy's sign-in page
|
// MARK: - A proxy's sign-in page
|
||||||
|
|
||||||
/// Over a proxy's sign-in page (Pangolin, authentik, ...) the server's UI is
|
/// Over a proxy's sign-in page (Pangolin, authentik, ...) the server's UI is
|
||||||
|
|||||||
@@ -70,11 +70,22 @@
|
|||||||
--m-safe-l: max(env(safe-area-inset-left, 0px), var(--trek-native-safe-left, 0px));
|
--m-safe-l: max(env(safe-area-inset-left, 0px), var(--trek-native-safe-left, 0px));
|
||||||
--m-safe-r: max(env(safe-area-inset-right, 0px), var(--trek-native-safe-right, 0px));
|
--m-safe-r: max(env(safe-area-inset-right, 0px), var(--trek-native-safe-right, 0px));
|
||||||
--m-safe-top: calc(var(--m-safe-t) + 12px);
|
--m-safe-top: calc(var(--m-safe-t) + 12px);
|
||||||
/* A side inset plus a little air, for the floating bars: next to a Duo's
|
/* An element in a top corner of the screen, such as an iPhone Duo's status
|
||||||
* status capsule a bar that ends exactly at the inset reads as touching it.
|
* capsule, as the iOS app measures it (TrekBridgeViewController
|
||||||
* Without an inset the air is 0 too (min() of 0 and 8px). */
|
* cornerElement): how far down it reaches and how wide it is on its side.
|
||||||
--m-safe-l-gap: calc(var(--m-safe-l) + min(var(--m-safe-l), 8px));
|
* The floating bars stand beside it; the page keeps the side's full width
|
||||||
--m-safe-r-gap: calc(var(--m-safe-r) + min(var(--m-safe-r), 8px));
|
* and starts below it, instead of giving up a strip of the whole height to
|
||||||
|
* an inset that only exists in the corner. 0 everywhere else. */
|
||||||
|
--m-corner-b: var(--trek-native-corner-bottom, 0px);
|
||||||
|
--m-bar-l: max(var(--m-safe-l), var(--trek-native-corner-left, 0px));
|
||||||
|
--m-bar-r: max(var(--m-safe-r), var(--trek-native-corner-right, 0px));
|
||||||
|
--m-page-l: max(0px, var(--m-safe-l) - var(--trek-native-corner-left, 0px));
|
||||||
|
--m-page-r: max(0px, var(--m-safe-r) - var(--trek-native-corner-right, 0px));
|
||||||
|
/* A bar's side inset plus a little air: next to a Duo's status capsule a
|
||||||
|
* bar that ends exactly at the inset reads as touching it. Without an inset
|
||||||
|
* the air is 0 too (min() of 0 and 8px). */
|
||||||
|
--m-safe-l-gap: calc(var(--m-bar-l) + min(var(--m-bar-l), 8px));
|
||||||
|
--m-safe-r-gap: calc(var(--m-bar-r) + min(var(--m-bar-r), 8px));
|
||||||
/* The navigation rail's share of the leading edge (wide windows only), what
|
/* The navigation rail's share of the leading edge (wide windows only), what
|
||||||
* every full-width fixed bar and the page column start after. */
|
* every full-width fixed bar and the page column start after. */
|
||||||
--m-rail-w: 0px;
|
--m-rail-w: 0px;
|
||||||
@@ -611,15 +622,19 @@ html[dir='rtl']:has(.m-shell[data-size='wide'], .m-shell[data-size='split']) .m-
|
|||||||
inset-inline-end: var(--m-safe-l-gap, 0px);
|
inset-inline-end: var(--m-safe-l-gap, 0px);
|
||||||
}
|
}
|
||||||
/* The page itself keeps clear of the sides' safe area, as iOS asks of every
|
/* The page itself keeps clear of the sides' safe area, as iOS asks of every
|
||||||
app: on a Duo the status capsule stands in the right inset, and cards under
|
app, and starts below an element in a top corner: on a Duo the status
|
||||||
the top bar ran beneath it (TestFlight feedback). Margins, so the rail's
|
capsule ran over the cards under the top bar (TestFlight feedback). The
|
||||||
wide:ps on the same element stays; fixed layers are the window's and keep
|
padding lifts the content only by what the capsule reaches below the top
|
||||||
their own rules. The rail already takes the leading inset on a wide window. */
|
bar's row (about 70px under the top clearance), so with no corner element
|
||||||
|
it is 0. Margins, so the rail's wide:ps on the same element stays; fixed
|
||||||
|
layers are the window's and keep their own rules. The rail already takes
|
||||||
|
the leading inset on a wide window. */
|
||||||
.m-page {
|
.m-page {
|
||||||
margin-inline: var(--m-safe-l, 0px) var(--m-safe-r, 0px);
|
margin-inline: var(--m-page-l, 0px) var(--m-page-r, 0px);
|
||||||
|
padding-top: max(0px, calc(var(--m-corner-b, 0px) + 12px - var(--m-safe-top, 12px) - 70px));
|
||||||
}
|
}
|
||||||
html[dir='rtl'] .m-page {
|
html[dir='rtl'] .m-page {
|
||||||
margin-inline: var(--m-safe-r, 0px) var(--m-safe-l, 0px);
|
margin-inline: var(--m-page-r, 0px) var(--m-page-l, 0px);
|
||||||
}
|
}
|
||||||
html:has(.m-shell[data-size='wide'], .m-shell[data-size='split']) .m-page {
|
html:has(.m-shell[data-size='wide'], .m-shell[data-size='split']) .m-page {
|
||||||
margin-inline-start: 0;
|
margin-inline-start: 0;
|
||||||
|
|||||||
@@ -74,8 +74,8 @@ describe('safe area in the touch shell', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('FE-MOB-CHROME-006: a side inset gets a little air, and none where there is no inset', () => {
|
it('FE-MOB-CHROME-006: a side inset gets a little air, and none where there is no inset', () => {
|
||||||
expect(css).toContain('--m-safe-r-gap: calc(var(--m-safe-r) + min(var(--m-safe-r), 8px));');
|
expect(css).toContain('--m-safe-r-gap: calc(var(--m-bar-r) + min(var(--m-bar-r), 8px));');
|
||||||
expect(css).toContain('--m-safe-l-gap: calc(var(--m-safe-l) + min(var(--m-safe-l), 8px));');
|
expect(css).toContain('--m-safe-l-gap: calc(var(--m-bar-l) + min(var(--m-bar-l), 8px));');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('FE-MOB-CHROME-007: on a wide window the bars end before the trailing inset, by their box, not a margin', () => {
|
it('FE-MOB-CHROME-007: on a wide window the bars end before the trailing inset, by their box, not a margin', () => {
|
||||||
@@ -91,12 +91,26 @@ describe('safe area in the touch shell', () => {
|
|||||||
|
|
||||||
it('FE-MOB-CHROME-008: the page keeps clear of the side insets, the leading one left to the rail on a wide window', () => {
|
it('FE-MOB-CHROME-008: the page keeps clear of the side insets, the leading one left to the rail on a wide window', () => {
|
||||||
expect(css.split('\n.m-page {')[1]?.split('}')[0] ?? '').toContain(
|
expect(css.split('\n.m-page {')[1]?.split('}')[0] ?? '').toContain(
|
||||||
'margin-inline: var(--m-safe-l, 0px) var(--m-safe-r, 0px);'
|
'margin-inline: var(--m-page-l, 0px) var(--m-page-r, 0px);'
|
||||||
);
|
);
|
||||||
expect(css.split("html[dir='rtl'] .m-page {")[1]?.split('}')[0] ?? '').toContain(
|
expect(css.split("html[dir='rtl'] .m-page {")[1]?.split('}')[0] ?? '').toContain(
|
||||||
'margin-inline: var(--m-safe-r, 0px) var(--m-safe-l, 0px);'
|
'margin-inline: var(--m-page-r, 0px) var(--m-page-l, 0px);'
|
||||||
);
|
);
|
||||||
const wide = "html:has(.m-shell[data-size='wide'], .m-shell[data-size='split']) .m-page {";
|
const wide = "html:has(.m-shell[data-size='wide'], .m-shell[data-size='split']) .m-page {";
|
||||||
expect(css.split(wide)[1]?.split('}')[0] ?? '').toContain('margin-inline-start: 0;');
|
expect(css.split(wide)[1]?.split('}')[0] ?? '').toContain('margin-inline-start: 0;');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('FE-MOB-CHROME-009: an element in a top corner moves the bars beside it and the page below it, not a whole strip aside', () => {
|
||||||
|
// The bars avoid the wider of the side inset and the corner element.
|
||||||
|
expect(css).toContain('--m-bar-r: max(var(--m-safe-r), var(--trek-native-corner-right, 0px));');
|
||||||
|
expect(css).toContain('--m-bar-l: max(var(--m-safe-l), var(--trek-native-corner-left, 0px));');
|
||||||
|
// The page gives the corner's width back and starts below the corner instead.
|
||||||
|
expect(css).toContain('--m-page-r: max(0px, var(--m-safe-r) - var(--trek-native-corner-right, 0px));');
|
||||||
|
expect(css).toContain('--m-page-l: max(0px, var(--m-safe-l) - var(--trek-native-corner-left, 0px));');
|
||||||
|
expect(css.split('\n.m-page {')[1]?.split('}')[0] ?? '').toContain(
|
||||||
|
'padding-top: max(0px, calc(var(--m-corner-b, 0px) + 12px - var(--m-safe-top, 12px) - 70px));'
|
||||||
|
);
|
||||||
|
// Without a corner element (every other device, iOS before 26) nothing moves.
|
||||||
|
expect(css).toContain('--m-corner-b: var(--trek-native-corner-bottom, 0px);');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user