From 450352c54c36876e86b8f3c2f16995251e81c7f7 Mon Sep 17 00:00:00 2001 From: YueBiang Date: Thu, 15 Jul 2021 15:41:15 +0800 Subject: [PATCH] IssueNo:#I40TE4 Description:fix animation bugs Sig:graphic Feature or Bugfix:Bugfix Binary Source:No Signed-off-by: YueBiang --- frameworks/components/root_view.cpp | 7 +-- frameworks/components/ui_abstract_scroll.cpp | 2 +- frameworks/components/ui_button.cpp | 17 +++++-- interfaces/kits/components/ui_button.h | 7 +++ test/uitest/test_button/ui_test_button.cpp | 49 ++++++++++++++++++++ test/uitest/test_button/ui_test_button.h | 2 + 6 files changed, 75 insertions(+), 9 deletions(-) diff --git a/frameworks/components/root_view.cpp b/frameworks/components/root_view.cpp index 4a75da5..319f971 100755 --- a/frameworks/components/root_view.cpp +++ b/frameworks/components/root_view.cpp @@ -704,9 +704,6 @@ bool RootView::FindSubView(const UIView& parentView, const UIView* subView) void RootView::InitMapBufferInfo(BufferInfo* bufferInfo) { - uint32_t bufferSize = bufferInfo->width * bufferInfo->height * - (DrawUtils::GetPxSizeByColorMode(bufferInfo->mode) >> 3); // 3: Shift right 3 bits - dc_.mapBufferInfo = new BufferInfo(); if (dc_.mapBufferInfo == nullptr) { return; @@ -717,6 +714,10 @@ void RootView::InitMapBufferInfo(BufferInfo* bufferInfo) dc_.mapBufferInfo = nullptr; return; } + dc_.mapBufferInfo->mode = ARGB8888; + dc_.mapBufferInfo->stride = dc_.mapBufferInfo->width * + (DrawUtils::GetPxSizeByColorMode(dc_.mapBufferInfo->mode) >> 3); // 3: Shift right 3 bits + uint32_t bufferSize = dc_.mapBufferInfo->stride * dc_.mapBufferInfo->height; dc_.mapBufferInfo->virAddr = dc_.mapBufferInfo->phyAddr = BaseGfxEngine::GetInstance()->AllocBuffer(bufferSize, BUFFER_MAP_SURFACE); } diff --git a/frameworks/components/ui_abstract_scroll.cpp b/frameworks/components/ui_abstract_scroll.cpp index 830d5d6..e538d95 100755 --- a/frameworks/components/ui_abstract_scroll.cpp +++ b/frameworks/components/ui_abstract_scroll.cpp @@ -32,7 +32,7 @@ constexpr uint8_t DEFAULT_ROTATE_THRESHOLD = 4; namespace OHOS { #if DEFAULT_ANIMATION -class BarEaseInOutAnimator final : private AnimatorCallback { +class BarEaseInOutAnimator final : public AnimatorCallback { public: BarEaseInOutAnimator() = delete; BarEaseInOutAnimator(const BarEaseInOutAnimator&) = delete; diff --git a/frameworks/components/ui_button.cpp b/frameworks/components/ui_button.cpp index cd7fcf5..47ac4aa 100755 --- a/frameworks/components/ui_button.cpp +++ b/frameworks/components/ui_button.cpp @@ -35,6 +35,7 @@ UIButton::UIButton() state_(RELEASED), styleState_(RELEASED), #if DEFAULT_ANIMATION + enableAnimation_(true), animator_(*this), #endif buttonStyleAllocFlag_(false) @@ -175,7 +176,9 @@ bool UIButton::OnPressEvent(const PressEvent& event) Resize(contentWidth_, contentHeight_); Invalidate(); #if DEFAULT_ANIMATION - animator_.Start(); + if (enableAnimation_) { + animator_.Start(); + } #endif return UIView::OnPressEvent(event); } @@ -187,7 +190,9 @@ bool UIButton::OnReleaseEvent(const ReleaseEvent& event) Resize(contentWidth_, contentHeight_); Invalidate(); #if DEFAULT_ANIMATION - animator_.Start(); + if (enableAnimation_) { + animator_.Start(); + } #endif return UIView::OnReleaseEvent(event); } @@ -199,7 +204,9 @@ bool UIButton::OnCancelEvent(const CancelEvent& event) Resize(contentWidth_, contentHeight_); Invalidate(); #if DEFAULT_ANIMATION - animator_.Start(); + if (enableAnimation_) { + animator_.Start(); + } #endif return UIView::OnCancelEvent(event); } @@ -296,7 +303,7 @@ bool UIButton::OnPreDraw(Rect& invalidatedArea) const #if DEFAULT_ANIMATION void UIButton::OnPostDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea) { - if (state_ == ButtonState::PRESSED) { + if (state_ == ButtonState::PRESSED && enableAnimation_) { animator_.DrawMask(gfxDstBuffer, invalidatedArea); } UIView::OnPostDraw(gfxDstBuffer, invalidatedArea); @@ -371,4 +378,4 @@ void UIButton::ButtonAnimator::OnStop(UIView& view) } } #endif -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/interfaces/kits/components/ui_button.h b/interfaces/kits/components/ui_button.h index 9710823..d4b020d 100755 --- a/interfaces/kits/components/ui_button.h +++ b/interfaces/kits/components/ui_button.h @@ -395,6 +395,12 @@ public: styleState_ = state; } +#if DEFAULT_ANIMATION + void EnableButtonAnimation(bool enable) + { + enableAnimation_ = enable; + } +#endif protected: Image* defaultImgSrc_; Image* triggeredImgSrc_; @@ -410,6 +416,7 @@ protected: ButtonState styleState_; Style* buttonStyles_[BTN_STATE_NUM]; #if DEFAULT_ANIMATION + bool enableAnimation_; friend class ButtonAnimator; class ButtonAnimator final : public AnimatorCallback { public: diff --git a/test/uitest/test_button/ui_test_button.cpp b/test/uitest/test_button/ui_test_button.cpp index 3e66dd0..0b50bda 100755 --- a/test/uitest/test_button/ui_test_button.cpp +++ b/test/uitest/test_button/ui_test_button.cpp @@ -101,6 +101,14 @@ void UITestBUTTON::TearDown() delete toggleChangeListener1_; toggleChangeListener1_ = nullptr; } + if (enableAnimationListener_ != nullptr) { + delete enableAnimationListener_; + enableAnimationListener_ = nullptr; + } + if (disableAnimationListener_ != nullptr) { + delete disableAnimationListener_; + disableAnimationListener_ = nullptr; + } DeleteChildren(container_); container_ = nullptr; } @@ -608,6 +616,27 @@ private: bool touchable_; }; +#if DEFAULT_ANIMATION +class TestBtnAnimationListener : public UIView::OnClickListener { +public: + TestBtnAnimationListener(UIView* uiView, bool enableAnimation) + : uiView_(uiView), + enableAnimation_(enableAnimation) {} + + ~TestBtnAnimationListener() {} + + bool OnClick(UIView& view, const ClickEvent& event) override + { + static_cast(uiView_)->EnableButtonAnimation(enableAnimation_); + return true; + } + +private: + UIView* uiView_; + bool enableAnimation_; +}; +#endif + UILabel* GetTestUILabel(const char* titlename) { if (titlename == nullptr) { @@ -711,6 +740,26 @@ void UITestBUTTON::UIKit_Button_Test_002(UIScrollView* container, UIButton* butt container->Add(button13); container->Add(button14); container->Add(button15); + +#if DEFAULT_ANIMATION + UILabelButton* button16 = GetTestUIButton("开启动效", 340, 1040, button); // 340: x-coordinate, 1040: y-coordinate + if (enableAnimationListener_ == nullptr) { + enableAnimationListener_ = + static_cast(new TestBtnAnimationListener((UIView*)button, true)); + } + button16->SetOnClickListener(enableAnimationListener_); + + UILabelButton* button17 = GetTestUIButton("关闭动效", 340, 1090, button); // 340: x-coordinate, 1090: y-coordinate + if (disableAnimationListener_ == nullptr) { + disableAnimationListener_ = + static_cast(new TestBtnAnimationListener((UIView*)button, false)); + } + button17->EnableButtonAnimation(false); + button17->SetOnClickListener(disableAnimationListener_); + + container->Add(button16); + container->Add(button17); +#endif } void UITestBUTTON::UIKit_Button_Test_001() diff --git a/test/uitest/test_button/ui_test_button.h b/test/uitest/test_button/ui_test_button.h index 6da0ec8..0f9821f 100755 --- a/test/uitest/test_button/ui_test_button.h +++ b/test/uitest/test_button/ui_test_button.h @@ -87,6 +87,8 @@ private: UIView::OnClickListener* clickUpListener_ = nullptr; UIView::OnClickListener* clickDownListener_ = nullptr; UIView::OnClickListener* clickSmallListener_ = nullptr; + UIView::OnClickListener* enableAnimationListener_ = nullptr; + UIView::OnClickListener* disableAnimationListener_ = nullptr; }; } // namespace OHOS #endif // UI_TEST_BUTTON_H -- GitLab