diff --git a/frameworks/src/core/components/component.h b/frameworks/src/core/components/component.h index a30fea8..56a0492 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 6c148f0..311e82a 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 fde1893..cd94474 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 41da0f4..98a2e57 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 daa866a..f4609a3 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 579dec4..505e7de 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