fix(UI): not full screen on apk
This commit is contained in:
@@ -1,15 +1,27 @@
|
||||
package com.imyeyu.gao.customer;
|
||||
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.webkit.WebSettings;
|
||||
import androidx.activity.OnBackPressedCallback;
|
||||
import androidx.core.graphics.Insets;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.core.view.WindowCompat;
|
||||
import androidx.core.view.WindowInsetsCompat;
|
||||
import com.getcapacitor.BridgeActivity;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class MainActivity extends BridgeActivity {
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
applyEdgeToEdge();
|
||||
getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
|
||||
@Override
|
||||
public void handleOnBackPressed() {
|
||||
@@ -26,4 +38,67 @@ public class MainActivity extends BridgeActivity {
|
||||
getBridge().getWebView().getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 让窗口真正 edge-to-edge,安全区由 Web 侧按 --tui-safe-* 补齐。
|
||||
*
|
||||
* 这里必须自己接管 insets:Capacitor 8 的 SystemBars 只认 WebView 内核版本
|
||||
* (getWebViewMajorVersion() >= 140 才认为内核能自己处理安全区,见 SystemBars.java),
|
||||
* 低内核机型上它会一边给 DecorView 加状态栏高度的 padding 把 WebView 缩回去,
|
||||
* 一边又把真实的安全区注入成 CSS 变量,结果顶部被让了两次。
|
||||
* 这个监听器在 Bridge 初始化之后注册,直接覆盖掉它:padding 归零、变量照旧注入。
|
||||
*/
|
||||
private void applyEdgeToEdge() {
|
||||
Window window = getWindow();
|
||||
WindowCompat.setDecorFitsSystemWindows(window, false);
|
||||
window.setStatusBarColor(Color.TRANSPARENT);
|
||||
window.setNavigationBarColor(Color.TRANSPARENT);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
WindowManager.LayoutParams attributes = window.getAttributes();
|
||||
attributes.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
|
||||
window.setAttributes(attributes);
|
||||
}
|
||||
|
||||
View decorView = window.getDecorView();
|
||||
ViewCompat.setOnApplyWindowInsetsListener(decorView, (view, windowInsets) -> {
|
||||
view.setPadding(0, 0, 0, 0);
|
||||
Insets systemBars = windowInsets.getInsets(
|
||||
WindowInsetsCompat.Type.systemBars() | WindowInsetsCompat.Type.displayCutout()
|
||||
);
|
||||
boolean keyboardVisible = windowInsets.isVisible(WindowInsetsCompat.Type.ime());
|
||||
injectSafeArea(systemBars, keyboardVisible);
|
||||
return windowInsets;
|
||||
});
|
||||
ViewCompat.requestApplyInsets(decorView);
|
||||
}
|
||||
|
||||
/**
|
||||
* 把系统栏尺寸折算成 CSS 像素后写进 html 的 CSS 变量。
|
||||
*
|
||||
* 键盘弹出时底部归零,否则 Web 侧的安全区会和键盘顶起来的区域叠加。
|
||||
*/
|
||||
private void injectSafeArea(Insets systemBars, boolean keyboardVisible) {
|
||||
if (getBridge() == null || getBridge().getWebView() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
float density = getResources().getDisplayMetrics().density;
|
||||
int top = Math.round(systemBars.top / density);
|
||||
int right = Math.round(systemBars.right / density);
|
||||
int bottom = Math.round((keyboardVisible ? 0 : systemBars.bottom) / density);
|
||||
int left = Math.round(systemBars.left / density);
|
||||
|
||||
String script = String.format(
|
||||
Locale.US,
|
||||
"document.documentElement.style.setProperty('--safe-area-inset-top','%dpx');" +
|
||||
"document.documentElement.style.setProperty('--safe-area-inset-right','%dpx');" +
|
||||
"document.documentElement.style.setProperty('--safe-area-inset-bottom','%dpx');" +
|
||||
"document.documentElement.style.setProperty('--safe-area-inset-left','%dpx');",
|
||||
top,
|
||||
right,
|
||||
bottom,
|
||||
left
|
||||
);
|
||||
getBridge().getWebView().evaluateJavascript(script, null);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@
|
||||
"less": "^4.3.0",
|
||||
"pinia": "^3.0.2",
|
||||
"tdesign-mobile-vue": "^1.17.1",
|
||||
"timi-tdesign-mobile": "^1.3.0",
|
||||
"timi-tdesign-mobile": "^1.3.1",
|
||||
"timi-ts": "^1.0.0",
|
||||
"timi-web": "^1.0.2",
|
||||
"timi-web-api": "^1.0.2",
|
||||
|
||||
Generated
+5
-5
@@ -47,8 +47,8 @@ importers:
|
||||
specifier: ^1.17.1
|
||||
version: 1.17.1(patch_hash=c98db305008fbfd00046666ca890e1c6cb88257c0619418694689cddf8cd78c3)(vue@3.5.40(typescript@5.8.3))
|
||||
timi-tdesign-mobile:
|
||||
specifier: ^1.3.0
|
||||
version: 1.3.0(@floating-ui/dom@1.8.0)(@tiptap/core@3.33.0(@tiptap/pm@3.33.0))(@tiptap/extensions@3.33.0(@tiptap/core@3.33.0(@tiptap/pm@3.33.0))(@tiptap/pm@3.33.0))(typescript@5.8.3)(vue-router@4.5.1(vue@3.5.40(typescript@5.8.3)))(vue@3.5.40(typescript@5.8.3))
|
||||
specifier: ^1.3.1
|
||||
version: 1.3.1(@floating-ui/dom@1.8.0)(@tiptap/core@3.33.0(@tiptap/pm@3.33.0))(@tiptap/extensions@3.33.0(@tiptap/core@3.33.0(@tiptap/pm@3.33.0))(@tiptap/pm@3.33.0))(typescript@5.8.3)(vue-router@4.5.1(vue@3.5.40(typescript@5.8.3)))(vue@3.5.40(typescript@5.8.3))
|
||||
timi-ts:
|
||||
specifier: ^1.0.0
|
||||
version: 1.0.0
|
||||
@@ -2748,8 +2748,8 @@ packages:
|
||||
through2@4.0.2:
|
||||
resolution: {integrity: sha512-iOqSav00cVxEEICeD7TjLB1sueEL+81Wpzp2bY17uZjZN0pWZPuo4suZ/61VujxmqSGFfgOcNuTZ85QJwNZQpw==}
|
||||
|
||||
timi-tdesign-mobile@1.3.0:
|
||||
resolution: {integrity: sha512-VnLiER0nOgneS2VuPs6bSl33OnxZId8CYp8E6s+3ZbylNlaA5k7P85wTQPwGYbP0/NSl2HtGi9j2Xtp9gi0VOA==}
|
||||
timi-tdesign-mobile@1.3.1:
|
||||
resolution: {integrity: sha512-6hz7MSqseCUyyJzRiyQjymMDfSZ3kJrFP6J5DxHpE1pJ8xeByCzKgELS4CnO4187mqPEx46TtF03qB9XS4Mpuw==}
|
||||
engines: {node: '>=20.0.0'}
|
||||
peerDependencies:
|
||||
vue: ^3.5.0
|
||||
@@ -5849,7 +5849,7 @@ snapshots:
|
||||
dependencies:
|
||||
readable-stream: 3.6.2
|
||||
|
||||
timi-tdesign-mobile@1.3.0(@floating-ui/dom@1.8.0)(@tiptap/core@3.33.0(@tiptap/pm@3.33.0))(@tiptap/extensions@3.33.0(@tiptap/core@3.33.0(@tiptap/pm@3.33.0))(@tiptap/pm@3.33.0))(typescript@5.8.3)(vue-router@4.5.1(vue@3.5.40(typescript@5.8.3)))(vue@3.5.40(typescript@5.8.3)):
|
||||
timi-tdesign-mobile@1.3.1(@floating-ui/dom@1.8.0)(@tiptap/core@3.33.0(@tiptap/pm@3.33.0))(@tiptap/extensions@3.33.0(@tiptap/core@3.33.0(@tiptap/pm@3.33.0))(@tiptap/pm@3.33.0))(typescript@5.8.3)(vue-router@4.5.1(vue@3.5.40(typescript@5.8.3)))(vue@3.5.40(typescript@5.8.3)):
|
||||
dependencies:
|
||||
tdesign-mobile-vue: 1.17.1(patch_hash=c98db305008fbfd00046666ca890e1c6cb88257c0619418694689cddf8cd78c3)(vue@3.5.40(typescript@5.8.3))
|
||||
timi-web: 1.0.2(@floating-ui/dom@1.8.0)(@tiptap/core@3.33.0(@tiptap/pm@3.33.0))(@tiptap/extensions@3.33.0(@tiptap/core@3.33.0(@tiptap/pm@3.33.0))(@tiptap/pm@3.33.0))(typescript@5.8.3)(vue@3.5.40(typescript@5.8.3))
|
||||
|
||||
+23
-3
@@ -3,21 +3,38 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { Capacitor, SystemBars, SystemBarsStyle } from "@capacitor/core";
|
||||
import { useGlobalUIStore } from "@/store/globalUI";
|
||||
import { useSettingStore } from "@/store/settingStore";
|
||||
|
||||
const globalUIStore = useGlobalUIStore();
|
||||
const settingStore = useSettingStore();
|
||||
const darkMediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
|
||||
const prefersDark = ref(darkMediaQuery.matches);
|
||||
|
||||
const resolvedThemeMode = computed(() => {
|
||||
const resolvedThemeMode = computed<"light" | "dark">(() => {
|
||||
if (globalUIStore.themeMode === "system") {
|
||||
const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
|
||||
return mediaQuery.matches ? "dark" : "light";
|
||||
return prefersDark.value ? "dark" : "light";
|
||||
}
|
||||
|
||||
return globalUIStore.themeMode;
|
||||
});
|
||||
|
||||
async function syncSystemBars(themeMode: "light" | "dark"): Promise<void> {
|
||||
if (!Capacitor.isNativePlatform()) {
|
||||
return;
|
||||
}
|
||||
|
||||
await SystemBars.setStyle({
|
||||
// DARK 表示深色系统栏配浅色图标,所以深色主题要用它
|
||||
style: themeMode === "dark" ? SystemBarsStyle.Dark : SystemBarsStyle.Light
|
||||
});
|
||||
}
|
||||
|
||||
function handleSystemThemeChange(event: MediaQueryListEvent): void {
|
||||
prefersDark.value = event.matches;
|
||||
}
|
||||
|
||||
async function unlockSoundOnUserGesture(): Promise<void> {
|
||||
await settingStore.unlockSoundPlayers();
|
||||
}
|
||||
@@ -28,6 +45,7 @@ watch(
|
||||
const rootElement = document.documentElement;
|
||||
rootElement.classList.toggle("theme-dark", themeMode === "dark");
|
||||
rootElement.dataset.theme = themeMode;
|
||||
void syncSystemBars(themeMode).catch(() => undefined);
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
@@ -54,10 +72,12 @@ watch(
|
||||
|
||||
onMounted(() => {
|
||||
settingStore.loadSoundPlayers();
|
||||
darkMediaQuery.addEventListener("change", handleSystemThemeChange);
|
||||
window.addEventListener("pointerdown", unlockSoundOnUserGesture, { once: true });
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
darkMediaQuery.removeEventListener("change", handleSystemThemeChange);
|
||||
window.removeEventListener("pointerdown", unlockSoundOnUserGesture);
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -119,7 +119,7 @@ html.theme-dark body {
|
||||
min-height: 0;
|
||||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 1rem);
|
||||
padding-bottom: calc(var(--tui-safe-bottom, 0px) + 1rem);
|
||||
-webkit-overflow-scrolling: touch;
|
||||
|
||||
.t-pull-down-refresh__track {
|
||||
|
||||
@@ -361,7 +361,7 @@ onUnmounted(() => {
|
||||
flex: 1;
|
||||
overflow: auto;
|
||||
min-height: 0;
|
||||
padding-bottom: env(safe-area-inset-bottom, 0);
|
||||
padding-bottom: var(--tui-safe-bottom, 0px);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -313,7 +313,7 @@ function toDateValue(date: Date): number {
|
||||
.day-record-panel,
|
||||
.filter-popup {
|
||||
gap: .875rem;
|
||||
padding: 1rem 0 calc(1rem + env(safe-area-inset-bottom, 0)) 0;
|
||||
padding: 1rem 0 calc(1rem + var(--tui-safe-bottom, 0px)) 0;
|
||||
display: flex;
|
||||
background: #f5f5f8;
|
||||
border-radius: 1rem 1rem 0 0;
|
||||
@@ -344,7 +344,7 @@ function toDateValue(date: Date): number {
|
||||
}
|
||||
|
||||
.filter-popup {
|
||||
padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom, 0)) 1rem;
|
||||
padding: 1rem 1rem calc(1rem + var(--tui-safe-bottom, 0px)) 1rem;
|
||||
|
||||
.popup-head,
|
||||
.popup-body {
|
||||
|
||||
@@ -311,7 +311,7 @@ function updateSelectedSkuIdList(value: string[]): void {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
padding-bottom: env(safe-area-inset-bottom, 0);
|
||||
padding-bottom: var(--tui-safe-bottom, 0px);
|
||||
|
||||
.selector {
|
||||
border-radius: 0;
|
||||
|
||||
@@ -275,7 +275,7 @@ watch(() => props.sessionKey, async () => {
|
||||
.ai-conversation-list {
|
||||
width: min(70vw, 24rem);
|
||||
height: 100vh;
|
||||
padding: calc(var(--tui-nav-height) + .5rem) 0 calc(1rem + env(safe-area-inset-bottom, 0px));
|
||||
padding: calc(var(--tui-nav-height) + .5rem) 0 calc(1rem + var(--tui-safe-bottom, 0px));
|
||||
display: flex;
|
||||
overflow: auto;
|
||||
position: relative;
|
||||
|
||||
@@ -528,7 +528,7 @@ onMounted(async () => {
|
||||
.package-config-edit {
|
||||
gap: 1rem;
|
||||
display: flex;
|
||||
padding: 0 0 calc(1rem + env(safe-area-inset-bottom, 0));
|
||||
padding: 0 0 calc(1rem + var(--tui-safe-bottom, 0px));
|
||||
flex-direction: column;
|
||||
|
||||
.form {
|
||||
|
||||
@@ -280,7 +280,7 @@ onMounted(async () => {
|
||||
.bottom-actions {
|
||||
left: 1rem;
|
||||
right: 1rem;
|
||||
bottom: calc(.75rem + env(safe-area-inset-bottom, 0));
|
||||
bottom: calc(.75rem + var(--tui-safe-bottom, 0px));
|
||||
position: fixed;
|
||||
|
||||
.t-button {
|
||||
|
||||
@@ -554,7 +554,7 @@ onUnmounted(() => {
|
||||
right: 1rem;
|
||||
gap: .75rem;
|
||||
z-index: 20;
|
||||
bottom: calc(.75rem + env(safe-area-inset-bottom, 0));
|
||||
bottom: calc(.75rem + var(--tui-safe-bottom, 0px));
|
||||
display: flex;
|
||||
position: fixed;
|
||||
|
||||
|
||||
@@ -616,7 +616,7 @@ onMounted(async () => {
|
||||
|
||||
<style scoped lang="less">
|
||||
.point-rule-edit {
|
||||
padding: 0 0 calc(1rem + env(safe-area-inset-bottom, 0));
|
||||
padding: 0 0 calc(1rem + var(--tui-safe-bottom, 0px));
|
||||
|
||||
.form {
|
||||
gap: 1rem;
|
||||
|
||||
@@ -468,7 +468,7 @@ watch(resolveId, async (id, previousId) => {
|
||||
}
|
||||
|
||||
.revoke-popup {
|
||||
padding: .5rem 1rem calc(1rem + env(safe-area-inset-bottom, 0));
|
||||
padding: .5rem 1rem calc(1rem + var(--tui-safe-bottom, 0px));
|
||||
|
||||
.tip {
|
||||
margin: 0 0 .75rem;
|
||||
|
||||
@@ -179,7 +179,7 @@ function setSkuStatus(value: boolean | string | number): void {
|
||||
}
|
||||
|
||||
.sku-popup {
|
||||
padding: 1rem 0 calc(1rem + env(safe-area-inset-bottom, 0px));
|
||||
padding: 1rem 0 calc(1rem + var(--tui-safe-bottom, 0px));
|
||||
max-height: 100%;
|
||||
overflow-y: auto;
|
||||
|
||||
|
||||
@@ -141,7 +141,7 @@ function setBaseUnit(index: number): void {
|
||||
.batch-editor {
|
||||
max-height: 100%;
|
||||
overflow-y: auto;
|
||||
padding: 1rem 0 calc(1rem + env(safe-area-inset-bottom, 0px));
|
||||
padding: 1rem 0 calc(1rem + var(--tui-safe-bottom, 0px));
|
||||
|
||||
.editor-context {
|
||||
gap: .25rem;
|
||||
|
||||
@@ -174,7 +174,7 @@ function setBaseUnit(index: number): void {
|
||||
.product-sku-unit-editor {
|
||||
gap: .75rem;
|
||||
display: flex;
|
||||
padding: .5rem 1rem calc(1rem + env(safe-area-inset-bottom, 0px));
|
||||
padding: .5rem 1rem calc(1rem + var(--tui-safe-bottom, 0px));
|
||||
max-height: 100%;
|
||||
overflow-y: auto;
|
||||
flex-direction: column;
|
||||
|
||||
@@ -232,7 +232,7 @@ watch(() => [visible.value, props.operation] as const, ([isVisible]) => {
|
||||
|
||||
<style scoped lang="less">
|
||||
.operation-popup {
|
||||
padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0));
|
||||
padding-bottom: calc(1rem + var(--tui-safe-bottom, 0px));
|
||||
|
||||
.form {
|
||||
margin: 0;
|
||||
|
||||
@@ -603,7 +603,7 @@ onMounted(() => {
|
||||
.sales-order-create {
|
||||
gap: 1rem;
|
||||
display: flex;
|
||||
padding: calc(var(--tui-nav-height) + 1rem) 0 calc(6.5rem + env(safe-area-inset-bottom, 0));
|
||||
padding: calc(var(--tui-nav-height) + 1rem) 0 calc(6.5rem + var(--tui-safe-bottom, 0px));
|
||||
flex-direction: column;
|
||||
|
||||
.form {
|
||||
@@ -753,10 +753,10 @@ onMounted(() => {
|
||||
left: 1.5rem;
|
||||
right: 1.5rem;
|
||||
border: 1px solid rgba(0, 0, 0, .05);
|
||||
bottom: calc(env(safe-area-inset-bottom, 0) + 1rem);
|
||||
bottom: calc(var(--tui-safe-bottom, 0px) + 1rem);
|
||||
z-index: 12;
|
||||
display: flex;
|
||||
padding: .5rem 1rem calc(.5rem + env(safe-area-inset-bottom, 0)) 1rem;
|
||||
padding: .5rem 1rem calc(.5rem + var(--tui-safe-bottom, 0px)) 1rem;
|
||||
position: fixed;
|
||||
align-items: center;
|
||||
border-radius: 1.75rem;
|
||||
|
||||
@@ -195,7 +195,7 @@ onMounted(async () => {
|
||||
}
|
||||
|
||||
.footer {
|
||||
padding: 1.25rem 1rem calc(1rem + env(safe-area-inset-bottom, 0));
|
||||
padding: 1.25rem 1rem calc(1rem + var(--tui-safe-bottom, 0px));
|
||||
text-align: center;
|
||||
|
||||
p {
|
||||
|
||||
@@ -265,7 +265,7 @@ watch(() => [props.diaryId, route.params.id], () => {
|
||||
|
||||
<style scoped lang="less">
|
||||
.store-diary-detail {
|
||||
padding: 0 0 calc(1rem + env(safe-area-inset-bottom, 0));
|
||||
padding: 0 0 calc(1rem + var(--tui-safe-bottom, 0px));
|
||||
|
||||
.header {
|
||||
margin: 0 1rem;
|
||||
|
||||
@@ -262,7 +262,7 @@ async function removeStore(id: string): Promise<void> {
|
||||
<style scoped lang="less">
|
||||
.store-edit {
|
||||
gap: 1rem;
|
||||
padding: 0 0 calc(1rem + env(safe-area-inset-bottom, 0)) 0;
|
||||
padding: 0 0 calc(1rem + var(--tui-safe-bottom, 0px)) 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
|
||||
@@ -391,7 +391,7 @@ onBeforeRouteLeave(() => {
|
||||
}
|
||||
|
||||
.footer {
|
||||
padding: 1.25rem 1rem calc(1rem + env(safe-area-inset-bottom, 0));
|
||||
padding: 1.25rem 1rem calc(1rem + var(--tui-safe-bottom, 0px));
|
||||
text-align: center;
|
||||
|
||||
p {
|
||||
|
||||
@@ -244,7 +244,7 @@ onMounted(() => {
|
||||
<style scoped lang="less">
|
||||
.profile-page {
|
||||
gap: 1rem;
|
||||
padding: 0 0 calc(1rem + env(safe-area-inset-bottom, 0)) 0;
|
||||
padding: 0 0 calc(1rem + var(--tui-safe-bottom, 0px)) 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user