symbol资源替换

Signed-off-by: 李蜜 <limi24@huawei.com>
This commit is contained in:
李蜜 2024-09-20 16:06:16 +08:00
parent 74e50cce90
commit f6d693f138
2 changed files with 33 additions and 34 deletions

View File

@ -13,17 +13,19 @@
* limitations under the License.
*/
if (!('finalizeConstruction' in ViewPU.prototype)) {
Reflect.set(ViewPU.prototype, 'finalizeConstruction', () => { });
}
const hiLog = requireNapi('hilog');
const userAuth = requireNapi('userIAM.userAuth');
const DOMAIN = 0x0007;
const TAG = 'useriam_auth_icon';
const ICON_UNAVAILABLE = 0;
const ICON_AVAILABLE = 1;
const TIMEOUT_MILLISECONDS = 5000;
const INVALID_PARAMETERS = 401;
const FACE_ICON_RESOURCE = 'sys.media.ohos_user_auth_icon_face';
const FINGERPRINT_ICON_RESOURCE = 'sys.media.ohos_user_auth_icon_fingerprint';
const FACE_ICON_RESOURCE = 'sys.symbol.face';
const FINGERPRINT_ICON_RESOURCE = 'sys.symbol.touchid';
export class UserAuthIcon extends ViewPU {
constructor(b1, c1, d1, e1 = -1, f1 = undefined, g1) {
super(b1, d1, e1, g1);
@ -42,9 +44,12 @@ export class UserAuthIcon extends ViewPU {
this.iconColor = { 'id': -1, 'type': 10001, params: ['sys.color.ohos_id_color_activated'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' };
this.authFlag = ICON_UNAVAILABLE;
this.__imageSource = new ObservedPropertySimplePU('', this, 'imageSource');
this.onAuthResult = (j1) => { };
this.onIconClick = () => { };
this.onAuthResult = (j1) => {
};
this.onIconClick = () => {
};
this.setInitiallyProvidedValue(c1);
this.finalizeConstruction();
}
setInitiallyProvidedValue(a1) {
if (a1.authParam !== undefined) {
@ -177,11 +182,10 @@ export class UserAuthIcon extends ViewPU {
Column.create();
}, Column);
this.observeComponentCreation2((d, e) => {
Image.create({ 'id': this.imageSource, params: [], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' });
Image.width(this.iconHeight);
Image.height(this.iconHeight);
Image.fillColor(this.iconColor);
Image.onClick(() => {
SymbolGlyph.create({ 'id': -1, 'type': -1, params: [this.imageSource], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' });
SymbolGlyph.fontSize(this.iconHeight);
SymbolGlyph.fontColor([this.iconColor]);
SymbolGlyph.onClick(() => {
this.info('start handle click event.');
if (this.onIconClick !== undefined) {
this.info('click event has response.');
@ -220,7 +224,7 @@ export class UserAuthIcon extends ViewPU {
}
this.info('end handle click event.');
});
}, Image);
}, SymbolGlyph);
Column.pop();
Row.pop();
}

View File

@ -22,8 +22,8 @@ const ICON_UNAVAILABLE: number = 0;
const ICON_AVAILABLE: number = 1;
const TIMEOUT_MILLISECONDS: number = 5000;
const INVALID_PARAMETERS: number = 401;
const FACE_ICON_RESOURCE: string = 'sys.media.ohos_user_auth_icon_face';
const FINGERPRINT_ICON_RESOURCE: string = 'sys.media.ohos_user_auth_icon_fingerprint';
const FACE_ICON_RESOURCE: string = 'sys.symbol.face';
const FINGERPRINT_ICON_RESOURCE: string = 'sys.symbol.touchid';
/**
* Declare UserAuthIcon, use for user authentication.
@ -45,7 +45,6 @@ export struct UserAuthIcon {
authType: [],
authTrustLevel: userAuth.AuthTrustLevel.ATL1
};
/**
* Set auth widget parameter.
*
@ -56,7 +55,6 @@ export struct UserAuthIcon {
widgetParam: userAuth.WidgetParam = {
title: ''
};
/**
* Set the height of the icon, width and height ratio 1:1.
*
@ -66,7 +64,6 @@ export struct UserAuthIcon {
* @since 12
*/
iconHeight?: Dimension = 64;
/**
* Set the color of the icon.
*
@ -76,10 +73,8 @@ export struct UserAuthIcon {
* @since 12
*/
iconColor?: ResourceColor = $r('sys.color.ohos_id_color_activated');
authFlag: number = ICON_UNAVAILABLE;
@State imageSource: string = '';
/**
* The authentication result code is returned through the callback.
* If the authentication is passed, the authentication token and auth type will be returned.
@ -89,15 +84,16 @@ export struct UserAuthIcon {
* @syscap SystemCapability.UserIAM.UserAuth.Core
* @since 12
*/
onAuthResult: (result: userAuth.UserAuthResult) => void = (result: userAuth.UserAuthResult) => {};
onAuthResult: (result: userAuth.UserAuthResult) => void = (result: userAuth.UserAuthResult) => {
};
/**
* When user click the icon, it will be returned through this callback.
*
* @syscap SystemCapability.UserIAM.UserAuth.Core
* @since 12
*/
onIconClick:() => void = () => {};
onIconClick: () => void = () => {
};
private initImageSource(authTypes: userAuth.UserAuthType[], authTrustLevel: userAuth.AuthTrustLevel): void {
if (authTypes.includes(userAuth.UserAuthType.FACE) && (!authTypes.includes(userAuth.UserAuthType.FINGERPRINT))) {
@ -195,10 +191,9 @@ export struct UserAuthIcon {
build() {
Row() {
Column() {
Image($r(this.imageSource))
.width(this.iconHeight)
.height(this.iconHeight)
.fillColor(this.iconColor)
SymbolGlyph($r(this.imageSource))
.fontSize(this.iconHeight)
.fontColor([this.iconColor])
.onClick(() => {
this.info('start handle click event.');
if (this.onIconClick !== undefined) {