diff --git a/frameworks/src/core/components/component.h b/frameworks/src/core/components/component.h index a30fea845f90c419271eb161abc3592294559f89..56a0492655eb39e3a0755199662d168158cb70a5 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 6c148f057b84c546e30821d67df99ee2e160a0de..311e82a8f7dda75fc72c5e035aae4352082e4d3b 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 fde1893e6eecb6e034b2192c7272d5d9e5d1bab7..cd94474b4251f0ba0d62a695e2acfdfaf63b4882 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 41da0f4e4924935c8c74aad9d26f269803aec398..98a2e579ee33186a099dc3dff242a9f32e058d46 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 daa866abae294f09df05d81d40c39f34a9875274..f4609a3828b1026b5f6036b6317f9648923bd8f6 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 579dec49d34fa9eafd5a794a02ad959c54085873..505e7de4379fd00015a5fbd78f88dccfbc45c8bf 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