feat(ui): paint VK status bar to the app theme (VKWebAppSetViewSettings)
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Has been skipped
CI / integration (pull_request) Has been skipped
CI / ui (pull_request) Successful in 58s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 2m13s

Parity with the Telegram chrome painting: on a VK Mini App launch and on
every theme change, set VK's status-bar appearance (and, on Android, the
action/navigation bar colours) from the app's live theme tokens, so the VK
chrome matches the UI instead of clashing.

syncVKChrome mirrors syncTelegramChrome; the status-bar appearance is
derived from the --bg token's luminance (appearanceForBg, unit-tested).
Wired into the VK onScheme handler (fires on launch + on theme change) and
setTheme. Docs: UI_DESIGN VK integration.
This commit is contained in:
Ilia Denisov
2026-07-01 13:54:14 +02:00
parent 4458f0e545
commit 5f9b4a7a38
4 changed files with 85 additions and 3 deletions
+18 -1
View File
@@ -31,7 +31,7 @@ import {
telegramCloudGet,
telegramCloudSet,
} from './telegram';
import { onVKPath, insideVK, vkInit, vkDisableSwipeBack, vkLaunchParams, vkUserName, vkStartParam, vkOnScheme, vkOnInsets } from './vk';
import { onVKPath, insideVK, vkInit, vkDisableSwipeBack, vkLaunchParams, vkUserName, vkStartParam, vkOnScheme, vkOnInsets, vkSetViewSettings, appearanceForBg } from './vk';
import { haptic } from './haptics';
import { CLOUD_PREFS_KEY, decodeClientPrefs, encodeClientPrefs } from './cloudprefs';
import { parseStartParam } from './deeplink';
@@ -552,6 +552,19 @@ function syncTelegramChrome(): void {
);
}
/**
* syncVKChrome paints VK's status bar (and, on Android, the action/navigation bars) from the app's
* live theme tokens, so the surrounding VK chrome matches the UI. A no-op outside VK. Parity with
* syncTelegramChrome.
*/
function syncVKChrome(): void {
if (!insideVK() || typeof document === 'undefined') return;
const cs = getComputedStyle(document.documentElement);
const bg = cs.getPropertyValue('--bg').trim();
const bgElev = cs.getPropertyValue('--bg-elev').trim();
void vkSetViewSettings(appearanceForBg(bg), bgElev, bg);
}
/**
* syncTelegramSafeArea mirrors Telegram's safe-area insets into CSS vars: the content-safe-area top
* (the height Telegram's native nav overlays the viewport in fullscreen) into --tg-content-top
@@ -694,6 +707,9 @@ export async function bootstrap(): Promise<void> {
// VK mobile webview's prefers-color-scheme does not track it).
void vkOnScheme((scheme) => {
if (app.theme === 'auto') applyTheme(scheme);
// Repaint VK's status/nav bars to the resolved theme; this handler also fires on launch, so it
// covers the initial paint (auto → the VK scheme just applied, explicit → the theme from boot).
syncVKChrome();
});
// Clear the device safe area from VK's insets — the VK mobile webview does not surface them via
// CSS env() (notably the Android home bar). max() keeps whichever of env() / the VK value is real.
@@ -995,6 +1011,7 @@ async function reconcileCloudPrefs(): Promise<void> {
export function setTheme(theme: ThemePref): void {
app.theme = theme;
applyTheme(theme);
syncVKChrome();
persistPrefs();
}