• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16/// <reference path='./import.ts' />
17
18class MeidaCachedImageImageSrcModifier extends ModifierWithKey<PixelMap | ResourceStr | DrawableDescriptor | ASTCResource> {
19  constructor(value: PixelMap | ResourceStr | DrawableDescriptor | ASTCResource) {
20    super(value);
21  }
22  static identity: Symbol = Symbol('mediaCachedImageShowSrc');
23
24  applyPeer(node: KNode, reset: boolean): void {
25    if (reset) {
26      getUINativeModule().mediaCachedImage.setMediaCachedImageSrc(node, '');
27    } else {
28      if (isResource(this.value) || isString(this.value)) {
29        getUINativeModule().mediaCachedImage.setMediaCachedImageSrc(node, 0, this.value);
30      } else if (Array.isArray(this.value.sources)) {
31        getUINativeModule().mediaCachedImage.setMediaCachedImageSrc(
32          node, 1, this.value.sources, this.value.sources.length, this.value.column);
33      } else {
34        getUINativeModule().mediaCachedImage.setMediaCachedImageSrc(node, 0, this.value);
35      }
36    }
37  }
38}
39
40class MediaCachedImageAltModifier extends ModifierWithKey<ResourceStr | PixelMap> {
41  static identity: Symbol = Symbol('mediaCachedImageAlt');
42  applyPeer(node: KNode, reset: boolean): void {
43    if (reset) {
44      getUINativeModule().mediaCachedImage.resetAlt(node);
45    } else {
46      getUINativeModule().mediaCachedImage.setAlt(node, this.value!);
47    }
48  }
49  checkObjectDiff(): boolean {
50    return true;
51  }
52}
53
54class ArkMeidaCachedImageComponent extends ArkImageComponent implements ImageAttribute
55{
56  constructor(nativePtr: KNode, classType?: ModifierType) {
57    super(nativePtr, classType);
58  }
59  initialize(value: PixelMap | ResourceStr | DrawableDescriptor | ASTCResource): this {
60    modifierWithKey(this._modifiersWithKeys, MeidaCachedImageImageSrcModifier.identity, MeidaCachedImageImageSrcModifier, value);
61    return this;
62  }
63  alt(value: ResourceStr | PixelMap): this {
64    modifierWithKey(this._modifiersWithKeys, MediaCachedImageAltModifier.identity, MediaCachedImageAltModifier, value);
65    return this;
66  }
67}
68
69// @ts-ignore
70globalThis.MediaCachedImage.attributeModifier = function (modifier: ArkComponent): void {
71  attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => {
72    return new ArkMeidaCachedImageComponent(nativePtr);
73  }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJs) => {
74    return new modifierJS.MediaCachedImageModifier(nativePtr, classType);
75  });
76};