Skip to content

Commit 1407351

Browse files
committed
fix: qr code dialog layout
1 parent 3cbef3e commit 1407351

File tree

4 files changed

+29
-15
lines changed

4 files changed

+29
-15
lines changed

entry/src/main/ets/dialogs/QRCodeDialog.ets

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,23 @@ import { BusinessError } from '@kit.BasicServicesKit';
33
import { image } from '@kit.ImageKit';
44
import { hilog } from '@kit.PerformanceAnalysisKit';
55
import { copyText } from '../utils/TokenUtils';
6+
import { window } from '@kit.ArkUI';
67

78
@Preview
89
@CustomDialog
910
export struct QRCodeDialog {
1011
controller?: CustomDialogController;
1112
@Prop content: string = '';
13+
@Prop winSize: window.Size;
1214
@State pixelMap: image.PixelMap | undefined = undefined
15+
@State qrSize: number = px2vp(Math.min(this.winSize.width, this.winSize.height)) * 0.8;
1316

1417
aboutToAppear(): void {
1518
this.pixelMap = undefined;
1619
let options: generateBarcode.CreateOptions = {
1720
scanType: scanCore.ScanType.QR_CODE,
18-
height: 400,
19-
width: 400
21+
height: this.qrSize,
22+
width: this.qrSize
2023
}
2124
try {
2225
// 码图生成接口,成功返回PixelMap格式图片
@@ -33,19 +36,24 @@ export struct QRCodeDialog {
3336
}
3437

3538
build() {
36-
Flex({ justifyContent: FlexAlign.Center }) {
37-
Column({ space: 10 }){
38-
if (this.pixelMap) {
39-
Image(this.pixelMap).width(300).height(300).objectFit(ImageFit.Contain)
40-
}
41-
Text(this.content)
42-
.fontSize(10)
43-
.fontColor($r('app.color.str_gray'))
44-
.onClick(() => {
45-
copyText(this.content, "uri copied");
46-
})
39+
Column({ space: 10 }) {
40+
if (this.pixelMap) {
41+
Image(this.pixelMap)
42+
.objectFit(ImageFit.Contain)
43+
.constraintSize({ maxHeight: this.qrSize })
44+
.layoutWeight(1)
4745
}
46+
Text() {
47+
Span(this.content)
48+
}
49+
.fontSize(10)
50+
.fontColor($r('app.color.str_gray'))
51+
.onClick(() => {
52+
copyText(this.content, "uri copied");
53+
})
54+
4855
}
4956
.padding(20)
57+
.width('100%')
5058
}
5159
}

entry/src/main/ets/entryability/EntryAbility.ets

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export class AppWindowInfo {
2020
@Trace AvoidBottomHeight: number = 0;
2121
@Trace WidthBreakpoint: WidthBreakpoint = 0;
2222
@Trace HeightBreakpoint: HeightBreakpoint = 0;
23+
@Trace Size: window.Size = { width: 0, height: 0};
2324
}
2425

2526
export default class EntryAbility extends UIAbility {
@@ -30,6 +31,7 @@ export default class EntryAbility extends UIAbility {
3031
let heightBp: HeightBreakpoint = this.uiContext!.getWindowHeightBreakpoint();
3132
win.WidthBreakpoint = widthBp;
3233
win.HeightBreakpoint = heightBp;
34+
win.Size = windowSize;
3335
};
3436

3537
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {

entry/src/main/ets/pages/Index.ets

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ struct Index {
408408
TabBarVisible: false,
409409
appBottomAvoidHeight: this.window.AvoidBottomHeight,
410410
appTopAvoidHeight: this.window.AvoidTopHeight,
411+
appWindowSize: this.window.Size,
411412
updateTokenConfig: this.updateTokenConfig,
412413
updateTokenConfigs: this.updateTokenConfigs,
413414
token_hide_enable: this.token_hide_enable,
@@ -427,6 +428,7 @@ struct Index {
427428
TabBarVisible: true,
428429
appBottomAvoidHeight: this.window.AvoidBottomHeight,
429430
appTopAvoidHeight: this.window.AvoidTopHeight,
431+
appWindowSize: this.window.Size,
430432
updateTokenConfig: this.updateTokenConfig,
431433
updateTokenConfigs: this.updateTokenConfigs,
432434
token_hide_enable: this.token_hide_enable,

entry/src/main/ets/pages/TokenListPage.ets

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { AppPreference, SettingValue } from "../utils/AppPreference";
77
import { otpType, TokenConfig } from "../utils/TokenConfig";
88
import { TokenStore } from "../utils/TokenStore";
99
import { convertToken2URI, ScanBarCode } from "../utils/TokenUtils";
10-
import { curves } from "@kit.ArkUI";
10+
import { curves, window } from "@kit.ArkUI";
1111
import { url } from "@kit.ArkTS";
1212
import { decodeProtobuf } from "../utils/GoogleAuthUtils";
1313
import { URIConfigDialog } from "../dialogs/URIConfigDialog";
@@ -20,6 +20,7 @@ export struct TokenListPage {
2020
@Require @Param Tokens: TokenConfig[] = [];
2121
@Require @Param appBottomAvoidHeight: number = 0;
2222
@Require @Param appTopAvoidHeight: number = 0;
23+
@Require @Param appWindowSize: window.Size = { width: 0, height: 0 };
2324
@Require @Param TabBarVisible: boolean = true;
2425
@Event updateTokenConfig: (conf: TokenConfig, toast: boolean) => void = () => {};
2526
@Event updateTokenConfigs: (tokens: Array<TokenConfig>) => void = () => {};
@@ -289,7 +290,8 @@ export struct TokenListPage {
289290
.onClick(() => {
290291
this.dialog_qrcode = new CustomDialogController({
291292
builder: QRCodeDialog({
292-
content: convertToken2URI(conf)
293+
content: convertToken2URI(conf),
294+
winSize: this.appWindowSize
293295
})
294296
});
295297
this.dialog_qrcode.open();

0 commit comments

Comments
 (0)