Skip to content

Commit 79de181

Browse files
committed
fix(harmonyos): adapt welcome sheet to system insets
1 parent 9ad49de commit 79de181

10 files changed

Lines changed: 103 additions & 15 deletions

File tree

‎src/apps/mobile/android/app/src/main/kotlin/com/openbitfun/mobile/app/ui/theme/generated/MobileDesignTokens.kt‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ internal object MobileDesignColors {
1212
val StartWindowBackground = Color(0xFFFFFFFF)
1313
val Transparent = Color(0x00000000)
1414
val PageBg = Color(0xFFFFFFFF)
15+
val WelcomePageBg = Color(0xFFFFFFFF)
1516
val PageBgFade = Color(0x00FFFFFF)
1617
val PageBgOverlay = Color(0xB8FFFFFF)
1718
val Ink = Color(0xFF171717)
@@ -75,6 +76,7 @@ internal object MobileDesignColors {
7576
val StartWindowBackground = Color(0xFF000000)
7677
val Transparent = Color(0x00000000)
7778
val PageBg = Color(0xFF151514)
79+
val WelcomePageBg = Color(0xFF252522)
7880
val PageBgFade = Color(0x00151514)
7981
val PageBgOverlay = Color(0xB8151514)
8082
val Ink = Color(0xFFF4F3EF)
@@ -127,7 +129,7 @@ internal object MobileDesignColors {
127129
val CodeProperty = Color(0xFF9CC8D0)
128130
val CodeTargetBg = Color(0xFF5A4E24)
129131
val BrandDot = Color(0xFF16B9CE)
130-
val WelcomeDock = Color(0xFF171917)
132+
val WelcomeDock = Color(0xFF000000)
131133
val WelcomeButton = Color(0xFFFFFFFF)
132134
val WelcomeButtonLabel = Color(0xFF171917)
133135
val WelcomeSecondary = Color(0xFFB9BCB9)

‎src/apps/mobile/design-system/preview/generated/mobile-design-data.js‎

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/apps/mobile/design-system/tokens/mobile-tokens.json‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
"light": "#FFFFFF",
1818
"dark": "#151514"
1919
},
20+
"welcome_page_bg": {
21+
"light": "#FFFFFF",
22+
"dark": "#252522"
23+
},
2024
"page_bg_fade": {
2125
"light": "#00FFFFFF",
2226
"dark": "#00151514"
@@ -227,7 +231,7 @@
227231
},
228232
"welcome_dock": {
229233
"light": "#171917",
230-
"dark": "#171917"
234+
"dark": "#000000"
231235
},
232236
"welcome_button": {
233237
"light": "#FFFFFF",

‎src/apps/mobile/harmonyos/entry/src/main/ets/generated/MobileDesignTokens.ets‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export class MobileDesignColors {
1414
static readonly startWindowBackground: MobileColorPair = new MobileColorPair("#FFFFFF", "#000000");
1515
static readonly transparent: MobileColorPair = new MobileColorPair("#00000000", "#00000000");
1616
static readonly pageBg: MobileColorPair = new MobileColorPair("#FFFFFF", "#151514");
17+
static readonly welcomePageBg: MobileColorPair = new MobileColorPair("#FFFFFF", "#252522");
1718
static readonly pageBgFade: MobileColorPair = new MobileColorPair("#00FFFFFF", "#00151514");
1819
static readonly pageBgOverlay: MobileColorPair = new MobileColorPair("#B8FFFFFF", "#B8151514");
1920
static readonly ink: MobileColorPair = new MobileColorPair("#171717", "#F4F3EF");
@@ -66,7 +67,7 @@ export class MobileDesignColors {
6667
static readonly codeProperty: MobileColorPair = new MobileColorPair("#466D78", "#9CC8D0");
6768
static readonly codeTargetBg: MobileColorPair = new MobileColorPair("#FFF1BE", "#5A4E24");
6869
static readonly brandDot: MobileColorPair = new MobileColorPair("#16B9CE", "#16B9CE");
69-
static readonly welcomeDock: MobileColorPair = new MobileColorPair("#171917", "#171917");
70+
static readonly welcomeDock: MobileColorPair = new MobileColorPair("#171917", "#000000");
7071
static readonly welcomeButton: MobileColorPair = new MobileColorPair("#FFFFFF", "#FFFFFF");
7172
static readonly welcomeButtonLabel: MobileColorPair = new MobileColorPair("#171917", "#171917");
7273
static readonly welcomeSecondary: MobileColorPair = new MobileColorPair("#B9BCB9", "#B9BCB9");

‎src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/Theme.ets‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export const PAGE_BG: ResourceColor = $r('app.color.page_bg');
2+
export const WELCOME_PAGE_BG: ResourceColor = $r('app.color.welcome_page_bg');
23
/** PAGE_BG at zero alpha, per theme — the transparent end of a fade-out. */
34
export const PAGE_BG_FADE: ResourceColor = $r('app.color.page_bg_fade');
45
/**

‎src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/WelcomeHome.ets‎

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { RemoteI18n } from '../../i18n/RemoteI18n';
22
import { MobileDesignTypography, MobileDesignGeometry as G } from '../../generated/MobileDesignTokens';
33
import { MotionPreference } from '../../services/MotionPreference';
4+
import { WindowSystemBarService } from '../../services/WindowSystemBarService';
45
import { WelcomeBrandFlow } from './WelcomeBrandFlow';
5-
import { INK, PAGE_BG, MUTED, TRANSPARENT } from './Theme';
6+
import { INK, PAGE_BG, WELCOME_PAGE_BG, MUTED, TRANSPARENT } from './Theme';
67

78
/** A welcome composition with the C staggered-slide phrase timeline. */
89
@ComponentV2
@@ -13,10 +14,22 @@ export struct WelcomeHome {
1314
@Local elapsed: number = 0;
1415
@Local pageHeight: number = 700;
1516
@Local pageWidth: number = 390;
17+
@Local topInset: number = 0;
1618
private timer: number = -1;
1719
private started: number = 0;
20+
private immersiveCompact: boolean = false;
1821

19-
aboutToDisappear(): void { this.stop(); }
22+
aboutToDisappear(): void {
23+
this.stop();
24+
if (this.immersiveCompact) {
25+
const context = this.getUIContext().getHostContext();
26+
if (context) {
27+
void WindowSystemBarService.setLayoutFullScreen(context, false);
28+
}
29+
this.immersiveCompact = false;
30+
this.topInset = 0;
31+
}
32+
}
2033
private stop(): void { if (this.timer >= 0) clearInterval(this.timer); this.timer = -1; }
2134
private play(): void {
2235
this.stop();
@@ -57,7 +70,6 @@ export struct WelcomeHome {
5770
private landscape(): boolean {
5871
return this.pageWidth >= 840 && this.pageWidth / Math.max(1, this.pageHeight) >= 1.2;
5972
}
60-
6173
build() {
6274
Scroll() {
6375
Column() {
@@ -80,21 +92,52 @@ export struct WelcomeHome {
8092
}.width('100%').constraintSize({ minHeight: Math.max(540, this.pageHeight - G.welcomeHeaderHeight) })
8193
.justifyContent(FlexAlign.Center).padding({ bottom: 64 })
8294
} else {
83-
Column() { this.Hero() }
84-
.justifyContent(FlexAlign.Center).width('100%')
85-
.height(Math.max(300, this.pageHeight - G.welcomeHeaderHeight - 228))
86-
.padding({ bottom: 24 })
87-
this.Actions()
95+
Column() {
96+
Column() { this.Hero() }
97+
.justifyContent(FlexAlign.Center).width('100%')
98+
.layoutWeight(1)
99+
.constraintSize({ minHeight: 300 })
100+
.padding({ bottom: 24 })
101+
this.Actions()
102+
}.width('100%').height(Math.max(0,
103+
this.pageHeight - this.topInset - G.welcomeHeaderHeight))
88104
}
89105
}.width('100%')
90-
}.width('100%').height('100%').scrollBar(BarState.Off).backgroundColor(PAGE_BG)
106+
}.width('100%').height('100%').scrollBar(BarState.Off).backgroundColor(WELCOME_PAGE_BG)
107+
.padding({ top: this.topInset })
91108
.onSizeChange((_old: SizeOptions, size: SizeOptions) => {
92109
this.pageHeight = Number(size.height);
93110
this.pageWidth = Number(size.width);
111+
this.updateWindowLayout();
94112
})
95113
.onVisibleAreaChange([0], (visible: boolean) => { if (visible) this.play(); else this.stop(); })
96114
}
97115

116+
private updateWindowLayout(): void {
117+
const compact = this.pageWidth < 600;
118+
if (compact === this.immersiveCompact) {
119+
return;
120+
}
121+
const context = this.getUIContext().getHostContext();
122+
if (!context) {
123+
return;
124+
}
125+
this.immersiveCompact = compact;
126+
if (!compact) {
127+
this.topInset = 0;
128+
void WindowSystemBarService.setLayoutFullScreen(context, false);
129+
return;
130+
}
131+
void WindowSystemBarService.setLayoutFullScreen(context, true).then(async (): Promise<void> => {
132+
if (this.immersiveCompact) {
133+
const topInsetPx: number = await WindowSystemBarService.topSystemInsetPx(context);
134+
if (this.immersiveCompact) {
135+
this.topInset = this.getUIContext().px2vp(topInsetPx);
136+
}
137+
}
138+
});
139+
}
140+
98141
@Builder
99142
private Hero() {
100143
Column({ space: this.wide() ? 16 : 20 }) {
@@ -126,6 +169,7 @@ export struct WelcomeHome {
126169
.padding({ left: G.welcomeGutter, right: G.welcomeGutter, top: this.wide() ? 0 : G.welcomeGutter,
127170
bottom: this.wide() ? 0 : G.welcomeDockBottom })
128171
.backgroundColor(this.wide() ? TRANSPARENT : $r('app.color.welcome_dock'))
172+
.expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.BOTTOM])
129173
.borderRadius({ topLeft: G.welcomeDockRadius, topRight: G.welcomeDockRadius })
130174
}
131175
@Builder
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { Context } from '@kit.AbilityKit';
2+
import { window } from '@kit.ArkUI';
3+
4+
/** Platform window adapter for surfaces that need to draw behind system bars. */
5+
export class WindowSystemBarService {
6+
static async setLayoutFullScreen(context: Context, enabled: boolean): Promise<void> {
7+
try {
8+
const appWindow = await window.getLastWindow(context);
9+
await appWindow.setWindowLayoutFullScreen(enabled);
10+
} catch (_err) {
11+
// Window layout is best effort and must not block page rendering.
12+
}
13+
}
14+
15+
static async topSystemInsetPx(context: Context): Promise<number> {
16+
try {
17+
const appWindow = await window.getLastWindow(context);
18+
return appWindow.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM).topRect.height;
19+
} catch (_err) {
20+
return 0;
21+
}
22+
}
23+
}

‎src/apps/mobile/harmonyos/entry/src/main/resources/base/element/color.json‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
"name": "page_bg",
1313
"value": "#FFFFFF"
1414
},
15+
{
16+
"name": "welcome_page_bg",
17+
"value": "#FFFFFF"
18+
},
1519
{
1620
"name": "page_bg_fade",
1721
"value": "#00FFFFFF"

‎src/apps/mobile/harmonyos/entry/src/main/resources/dark/element/color.json‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
"name": "page_bg",
1313
"value": "#151514"
1414
},
15+
{
16+
"name": "welcome_page_bg",
17+
"value": "#252522"
18+
},
1519
{
1620
"name": "page_bg_fade",
1721
"value": "#00151514"
@@ -222,7 +226,7 @@
222226
},
223227
{
224228
"name": "welcome_dock",
225-
"value": "#171917"
229+
"value": "#000000"
226230
},
227231
{
228232
"name": "welcome_button",

‎src/apps/mobile/ios/OpenBitFun/Features/DesignSystem/GeneratedMobileDesignTokens.swift‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ enum MobileDesignColors {
2525
static let startWindowBackground = dynamic(light: 0xFFFFFFFF, dark: 0xFF000000)
2626
static let transparent = dynamic(light: 0x00000000, dark: 0x00000000)
2727
static let pageBg = dynamic(light: 0xFFFFFFFF, dark: 0xFF151514)
28+
static let welcomePageBg = dynamic(light: 0xFFFFFFFF, dark: 0xFF252522)
2829
static let pageBgFade = dynamic(light: 0x00FFFFFF, dark: 0x00151514)
2930
static let pageBgOverlay = dynamic(light: 0xB8FFFFFF, dark: 0xB8151514)
3031
static let ink = dynamic(light: 0xFF171717, dark: 0xFFF4F3EF)
@@ -77,7 +78,7 @@ enum MobileDesignColors {
7778
static let codeProperty = dynamic(light: 0xFF466D78, dark: 0xFF9CC8D0)
7879
static let codeTargetBg = dynamic(light: 0xFFFFF1BE, dark: 0xFF5A4E24)
7980
static let brandDot = dynamic(light: 0xFF16B9CE, dark: 0xFF16B9CE)
80-
static let welcomeDock = dynamic(light: 0xFF171917, dark: 0xFF171917)
81+
static let welcomeDock = dynamic(light: 0xFF171917, dark: 0xFF000000)
8182
static let welcomeButton = dynamic(light: 0xFFFFFFFF, dark: 0xFFFFFFFF)
8283
static let welcomeButtonLabel = dynamic(light: 0xFF171917, dark: 0xFF171917)
8384
static let welcomeSecondary = dynamic(light: 0xFFB9BCB9, dark: 0xFFB9BCB9)

0 commit comments

Comments
 (0)