From fd0654c87acf56dcc434f83dd6e66fb14d7b92f2 Mon Sep 17 00:00:00 2001 From: youbing54 Date: Fri, 27 Sep 2024 10:25:46 +0800 Subject: [PATCH] =?UTF-8?q?IssueNo:=20https://gitee.com/openharmony/arkui?= =?UTF-8?q?=5Face=5Fengine=5Flite/issues/IAU1NA=20describe:=20Component::S?= =?UTF-8?q?etAnimationStyle=E8=B6=85=E5=A4=A7=E5=87=BD=E6=95=B0=E6=95=B4?= =?UTF-8?q?=E6=94=B9=20Feature=20or=20Bugfix:=20Bugfix=20Binary=20Source:Y?= =?UTF-8?q?es=20Signed-off-by:=20youbing54?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frameworks/src/core/components/component.cpp | 131 +++++++++++++------ frameworks/src/core/components/component.h | 10 ++ 2 files changed, 102 insertions(+), 39 deletions(-) diff --git a/frameworks/src/core/components/component.cpp b/frameworks/src/core/components/component.cpp index bf7b67ba..507b5004 100644 --- a/frameworks/src/core/components/component.cpp +++ b/frameworks/src/core/components/component.cpp @@ -862,6 +862,93 @@ void Component::SetAnimationKeyFrames(int16_t keyId, int32_t valueFrom, int32_t } } +void Component::SetAnimationDuration(const AppStyleItem *styleItem, const char *strValue) +{ + if ((styleItem == nullptr) || (!const_cast(styleItem)->UpdateNumValToStr()) + || strValue == nullptr) { + HILOG_ERROR(HILOG_MODULE_ACE, "SetAnimationDuration fail"); + return; + } + + if (!IsStyleValueTypeString(styleItem)) { + HILOG_ERROR(HILOG_MODULE_ACE, "style animation during value is invalid!"); + return; + } + trans_->during = ParseToMilliseconds(strValue); +} + +void Component::SetAnimationTimingFunction(const char *strValue, size_t strLen) +{ + if (strValue == nullptr) { + HILOG_ERROR(HILOG_MODULE_ACE, "SetAnimationTimingFunction fail"); + return; + } + + uint16_t animationTimingKeyId = KeyParser::ParseKeyId(strValue, strLen); + switch (animationTimingKeyId) { + case K_EASE_IN: + trans_->easing = EasingType::EASE_IN; + break; + case K_EASE_OUT: + trans_->easing = EasingType::EASE_OUT; + break; + case K_EASE_IN_OUT: + trans_->easing = EasingType::EASE_IN_OUT; + break; + default: + trans_->easing = EasingType::LINEAR; + break; + } +} + +void Component::SetAnimationFillMode(const char *strValue, size_t strLen) +{ + if (strValue == nullptr) { + HILOG_ERROR(HILOG_MODULE_ACE, "SetAnimationFillMode fail"); + return; + } + + uint16_t animationFillKeyId = KeyParser::ParseKeyId(strValue, strLen); + switch (animationFillKeyId) { + case K_FORWARDS: + trans_->fill = OptionsFill::FORWARDS; + break; + default: + trans_->fill = OptionsFill::FNONE; + break; + } +} + +void Component::SetAnimationDelay(const AppStyleItem *styleItem, const char *strValue) +{ + if ((styleItem == nullptr) || (!const_cast(styleItem)->UpdateNumValToStr()) + || strValue == nullptr) { + HILOG_ERROR(HILOG_MODULE_ACE, "SetAnimationDelay fail"); + return; + } + + if (!IsStyleValueTypeString(styleItem)) { + HILOG_ERROR(HILOG_MODULE_ACE, "style animation delay value is invalid!"); + return; + } + trans_->delay = ParseToMilliseconds(strValue); +} + +void Component::SetAnimationIterationCount(const AppStyleItem *styleItem, const char *strValue) +{ + if ((styleItem == nullptr) || (!const_cast(styleItem)->UpdateNumValToStr()) + || strValue == nullptr) { + HILOG_ERROR(HILOG_MODULE_ACE, "SetAnimationIterationCount fail"); + return; + } + + if (!IsStyleValueTypeString(styleItem)) { + HILOG_ERROR(HILOG_MODULE_ACE, "style iteration count value is invalid!"); + return; + } + trans_->iterations = TransitionImpl::GetNumIterations(strValue); +} + void Component::SetAnimationStyle(const UIView &view, const AppStyleItem *styleItem, const int16_t keyId) { // special for "animation-iteration-count" which value could be a number or string "infinite" @@ -885,57 +972,23 @@ void Component::SetAnimationStyle(const UIView &view, const AppStyleItem *styleI } switch (keyId) { case K_ANIMATION_DURATION: { - if (!IsStyleValueTypeString(styleItem)) { - HILOG_ERROR(HILOG_MODULE_ACE, "style animation during value is invalid!"); - return; - } - trans_->during = ParseToMilliseconds(strValue); + SetAnimationDuration(styleItem, strValue); break; } case K_ANIMATION_TIMING_FUNCTION: { - uint16_t animationTimingKeyId = KeyParser::ParseKeyId(strValue, strLen); - switch (animationTimingKeyId) { - case K_EASE_IN: - trans_->easing = EasingType::EASE_IN; - break; - case K_EASE_OUT: - trans_->easing = EasingType::EASE_OUT; - break; - case K_EASE_IN_OUT: - trans_->easing = EasingType::EASE_IN_OUT; - break; - default: - trans_->easing = EasingType::LINEAR; - break; - } + SetAnimationTimingFunction(strValue, strLen); break; } case K_ANIMATION_FILL_MODE: { - uint16_t animationFillKeyId = KeyParser::ParseKeyId(strValue, strLen); - switch (animationFillKeyId) { - case K_FORWARDS: - trans_->fill = OptionsFill::FORWARDS; - break; - default: - trans_->fill = OptionsFill::FNONE; - break; - } + SetAnimationFillMode(strValue, strLen); break; } case K_ANIMATION_DELAY: { - if (!IsStyleValueTypeString(styleItem)) { - HILOG_ERROR(HILOG_MODULE_ACE, "style animation delay value is invalid!"); - return; - } - trans_->delay = ParseToMilliseconds(strValue); + SetAnimationDelay(styleItem, strValue); break; } case K_ANIMATION_ITERATION_COUNT: { - if (!IsStyleValueTypeString(styleItem)) { - HILOG_ERROR(HILOG_MODULE_ACE, "style iteration count value is invalid!"); - return; - } - trans_->iterations = TransitionImpl::GetNumIterations(strValue); + SetAnimationIterationCount(styleItem, strValue); break; } default: diff --git a/frameworks/src/core/components/component.h b/frameworks/src/core/components/component.h index 727bb354..7194fd7a 100644 --- a/frameworks/src/core/components/component.h +++ b/frameworks/src/core/components/component.h @@ -593,6 +593,16 @@ private: */ void RemoveAllChildren(); + void SetAnimationDuration(const AppStyleItem *styleItem, const char *strValue); + + void SetAnimationTimingFunction(const char *strValue, size_t strLen); + + void SetAnimationFillMode(const char *strValue, size_t strLen); + + void SetAnimationDelay(const AppStyleItem *styleItem, const char *strValue); + + void SetAnimationIterationCount(const AppStyleItem *styleItem, const char *strValue); + /** * @brief childHead_ the child list */ -- Gitee