diff --git a/frameworks/components/root_view.cpp b/frameworks/components/root_view.cpp index 4a75da531012baa00080072447747be0d498fab2..319f971e14696dbff6a5b2c900bf684816a47eb8 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 830d5d680409b28c634f8ed3a5935d5c7a6c35b7..e538d95de1f60f865fd8baf1e7a9f1fbc6de5c7b 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 cd7fcf5c393fb041623ee98c77ef5c8dd418055d..47ac4aa7387bcb60a8208325cc03335e0aab90a6 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 97108230b9e1b1a36d8fa037063186258f4273fb..d4b020d2edc2b4a5fde1bb40d33c3dd666dfff9b 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 3e66dd06dd7bf356eda3f82155f60b1e8cf4c193..0b50bdad6b35ba35d1d20beeacca46806a463ecc 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 6da0ec878e3ed93e584bfaf13fd31fa223947aec..0f9821f33612542fb72052a260790973471e034a 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