diff --git a/frameworks/core/drawable/animated_drawable_descriptor.cpp b/frameworks/core/drawable/animated_drawable_descriptor.cpp index 0cb7b99cce1b80cb124b1b92be2b86fa32283da5..e0daa94e57d4524b64fa4401809bd1d9b5f6d65c 100644 --- a/frameworks/core/drawable/animated_drawable_descriptor.cpp +++ b/frameworks/core/drawable/animated_drawable_descriptor.cpp @@ -32,7 +32,7 @@ int32_t AnimatedDrawableDescriptor::GetTotalDuration() { auto size = pixelMapList_.size(); if (totalDuration_ < 0) { - totalDuration_ = static_cast(size); + totalDuration_ = static_cast(size*DEFAULT_DURATION); } return totalDuration_; } diff --git a/frameworks/core/drawable/animated_drawable_descriptor.h b/frameworks/core/drawable/animated_drawable_descriptor.h index 3f6ef9bb13499db43f87527c0d4e6e894960b834..d6ddb466330477ad72d4cd58116154e004950e32 100644 --- a/frameworks/core/drawable/animated_drawable_descriptor.h +++ b/frameworks/core/drawable/animated_drawable_descriptor.h @@ -57,6 +57,16 @@ public: return iterations_; } + void SetTotalDuration(const int32_t totalDuration) + { + totalDuration_ = totalDuration; + } + + void SetIterations(const int32_t iterations) + { + iterations_ = iterations; + } + private: int32_t totalDuration_ = -1; int32_t iterations_ = 1; diff --git a/interfaces/ets/ani/drawableDescriptor/ets/@ohos.arkui.drawableDescriptor.ets b/interfaces/ets/ani/drawableDescriptor/ets/@ohos.arkui.drawableDescriptor.ets index 0a01b419ee901b4cad1f67ce4fc8a25245124f11..008359ff08cb67649055814e42dd4ff67599fd99 100644 --- a/interfaces/ets/ani/drawableDescriptor/ets/@ohos.arkui.drawableDescriptor.ets +++ b/interfaces/ets/ani/drawableDescriptor/ets/@ohos.arkui.drawableDescriptor.ets @@ -105,10 +105,14 @@ export interface AnimationOptions { iterations?: number; } -export class AnimatedDrawableDescriptor { +export class AnimatedDrawableDescriptor extends DrawableDescriptor { private pixelMaps: Array private options: AnimationOptions | undefined = undefined constructor(pixelMaps: Array, options?: AnimationOptions) { + super() + if (pixelMaps.length > 0) { + this.pixelMap = pixelMaps[0] + } this.pixelMaps = pixelMaps this.options = options DrawableDescriptorInner.createAnimatedDrawable(this, pixelMaps, options) @@ -126,8 +130,8 @@ export class DrawableDescriptorInner { background?: image.PixelMap, mask?: image.PixelMap): void; native static createAnimatedDrawable( - value: AnimatedDrawableDescriptor, - pixelMaps: Array, + value: AnimatedDrawableDescriptor, + pixelMaps: Array, options?: AnimationOptions): void; native static createPixelMap(value: PixelMapDrawableDescriptor): void native static composePixelMap(value: LayeredDrawableDescriptor): void; diff --git a/interfaces/ets/ani/drawableDescriptor/src/drawable_descriptor_inner.cpp b/interfaces/ets/ani/drawableDescriptor/src/drawable_descriptor_inner.cpp index fe7dfda109a2d9593337f9ff6cb5cb4ad1a8f9d6..8c5294e3d05983d256e0c744c8cc60c0a69d8bc2 100644 --- a/interfaces/ets/ani/drawableDescriptor/src/drawable_descriptor_inner.cpp +++ b/interfaces/ets/ani/drawableDescriptor/src/drawable_descriptor_inner.cpp @@ -31,8 +31,9 @@ namespace OHOS::Ace::Ani { namespace { -const char PIXEL_MAP_CONSTRUCTOR[] = "L@ohos/multimedia/image/image/PixelMap;:"; -const char PIXEL_MAP_DRAWABLE[] = "L@ohos/arkui/drawableDescriptor/PixelMapDrawableDescriptor;"; +constexpr char PIXEL_MAP_CONSTRUCTOR[] = "L@ohos/multimedia/image/image/PixelMap;:"; +constexpr char PIXEL_MAP_DRAWABLE[] = "L@ohos/arkui/drawableDescriptor/PixelMapDrawableDescriptor;"; +constexpr char ARRAY_GET[] = "i:C{std.core.Object}"; } // namespace void CreatePixelMapDrawable( @@ -90,7 +91,7 @@ void CreateAnimatedDrawable(ani_env* env, [[maybe_unused]] ani_class aniClass, a ani_class arrayClass; env->FindClass("C{escompat.Array}", &arrayClass); ani_method getDataMethod; - env->Class_FindMethod(arrayClass, "$_get", nullptr, &getDataMethod); + env->Class_FindMethod(arrayClass, "$_get", ARRAY_GET, &getDataMethod); for (size_t index = 0; index < size; index++) { ani_ref pixelmapAni; env->Object_CallMethod_Ref(pixelmapsAni, getDataMethod, &pixelmapAni, index); @@ -98,6 +99,29 @@ void CreateAnimatedDrawable(ani_env* env, [[maybe_unused]] ani_class aniClass, a results.push_back(PixelMap::Create(pixelmap)); } drawable->SetPixelMapList(results); + if (isOptionsUndefined) { + return; + } + ani_boolean isDurationUndefined; + ani_boolean isIterationsUndefined; + ani_ref durationRef; + ani_ref iterationsRef; + env->Object_GetPropertyByName_Ref(optionsAni, "duration", &durationRef); + env->Object_GetPropertyByName_Ref(optionsAni, "iterations", &iterationsRef); + ani_object durationAni = static_cast(durationRef); + ani_object iterationsAni = static_cast(iterationsRef); + env->Reference_IsUndefined(durationAni, &isDurationUndefined); + env->Reference_IsUndefined(iterationsAni, &isIterationsUndefined); + if (!isDurationUndefined) { + ani_double duration; + env->Object_CallMethodByName_Double(durationAni, "unboxed", ":d", &duration); + drawable->SetTotalDuration(static_cast(duration)); + } + if (!isIterationsUndefined) { + ani_double iterations; + env->Object_CallMethodByName_Double(iterationsAni, "unboxed", ":d", &iterations); + drawable->SetIterations(static_cast(iterations)); + } } void CreatePixelMap(ani_env* env, [[maybe_unused]] ani_class aniClass, ani_object drawableAni)