From 3a62be23f3202a3c0c354e039f37f685f6ac44d3 Mon Sep 17 00:00:00 2001 From: jiadexiang Date: Sat, 11 Dec 2021 12:17:25 +0800 Subject: [PATCH] Description: add component visible status change notify logic IssueNo: I4M2B3 Feature or Bugfix: Feature Binary Source:No Signed-off-by: jiadexiang --- frameworks/src/core/components/component.h | 4 ++++ .../src/core/components/swiper_component.cpp | 16 ++++++++++++++++ .../src/core/components/swiper_component.h | 1 + frameworks/src/core/context/fatal_handler.cpp | 11 +++++++++++ frameworks/src/core/context/fatal_handler.h | 1 + frameworks/src/core/context/js_ability_impl.cpp | 2 ++ 6 files changed, 35 insertions(+) diff --git a/frameworks/src/core/components/component.h b/frameworks/src/core/components/component.h index a30fea84..56a04926 100755 --- a/frameworks/src/core/components/component.h +++ b/frameworks/src/core/components/component.h @@ -173,6 +173,10 @@ public: { UNUSED(child); } + /** + * @brief OnVisibleChanged the component can be notified if the visibility status is changed + */ + virtual void OnVisibilityChanged(bool isVisible) {} /** * @brief OnViewAttached called when the native view is attached to the tree */ diff --git a/frameworks/src/core/components/swiper_component.cpp b/frameworks/src/core/components/swiper_component.cpp index 6c148f05..311e82a8 100755 --- a/frameworks/src/core/components/swiper_component.cpp +++ b/frameworks/src/core/components/swiper_component.cpp @@ -105,6 +105,22 @@ void SwiperComponent::AttachView(const Component *child) SetPageIndex(); } +void SwiperComponent::OnVisibilityChanged(bool isVisible) +{ + if (changeListener_ == nullptr) { + return; + } + if (!isVisible) { + swiperView_.SetOnSwipeListener(nullptr); + return; + } + // component will be visible + if (swiperView_.GetOnSwipeListener() != nullptr) { + return; + } + swiperView_.SetOnSwipeListener(changeListener_); +} + bool SwiperComponent::RegisterPrivateEventListener(uint16_t eventTypeId, jerry_value_t funcValue, bool isStopPropagation) diff --git a/frameworks/src/core/components/swiper_component.h b/frameworks/src/core/components/swiper_component.h index fde1893e..cd94474b 100644 --- a/frameworks/src/core/components/swiper_component.h +++ b/frameworks/src/core/components/swiper_component.h @@ -38,6 +38,7 @@ protected: bool ProcessChildren() override; bool RegisterPrivateEventListener(uint16_t eventTypeId, jerry_value_t funcValue, bool isStopPropagation) override; void AttachView(const Component *child) override; + void OnVisibilityChanged(bool isVisible) override; private: class ChangeListener : public UISwipeView::OnSwipeListener { diff --git a/frameworks/src/core/context/fatal_handler.cpp b/frameworks/src/core/context/fatal_handler.cpp index 41da0f4e..98a2e579 100644 --- a/frameworks/src/core/context/fatal_handler.cpp +++ b/frameworks/src/core/context/fatal_handler.cpp @@ -362,5 +362,16 @@ uint16_t FatalHandler::GetComponentCount() const { return componentNodes_.Size(); } + +void FatalHandler::NotifyVisibleStatusChange(bool isVisible) const +{ + ListNode *node = componentNodes_.Begin(); + while (node != componentNodes_.End()) { + if (node->data_ != nullptr) { + node->data_->OnVisibilityChanged(isVisible); + } + node = node->next_; + } +} } // namespace ACELite } // namespace OHOS diff --git a/frameworks/src/core/context/fatal_handler.h b/frameworks/src/core/context/fatal_handler.h index daa866ab..f4609a38 100644 --- a/frameworks/src/core/context/fatal_handler.h +++ b/frameworks/src/core/context/fatal_handler.h @@ -52,6 +52,7 @@ public: void SetCurrentPageRootView(UIView *pageRoot); void DumpFatalTrace(int errorCode) const; uint16_t GetComponentCount() const; + void NotifyVisibleStatusChange(bool isVisible) const; // define all fatal error below, please note the jerry fatal defines, avoid conflicts static const int ERR_INVALID = 0; static const int ERR_NATIVE_OUT_OF_MEMORY = 200; diff --git a/frameworks/src/core/context/js_ability_impl.cpp b/frameworks/src/core/context/js_ability_impl.cpp index 579dec49..505e7de4 100644 --- a/frameworks/src/core/context/js_ability_impl.cpp +++ b/frameworks/src/core/context/js_ability_impl.cpp @@ -137,6 +137,7 @@ void JSAbilityImpl::Show() const return; } router_->Show(); + FatalHandler::GetInstance().NotifyVisibleStatusChange(true); } void JSAbilityImpl::Hide() const @@ -146,6 +147,7 @@ void JSAbilityImpl::Hide() const return; } router_->Hide(); + FatalHandler::GetInstance().NotifyVisibleStatusChange(false); } void JSAbilityImpl::NotifyBackPressed() const -- Gitee