Description: add component visible status change notify logic

IssueNo: I4M2B3
Feature or Bugfix: Feature
Binary Source:No

Signed-off-by: jiadexiang <jiadexiang@huawei.com>
This commit is contained in:
jiadexiang
2021-12-11 12:17:25 +08:00
parent 61776496a8
commit 3a62be23f3
6 changed files with 35 additions and 0 deletions
@@ -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
*/
@@ -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)
@@ -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 {
@@ -362,5 +362,16 @@ uint16_t FatalHandler::GetComponentCount() const
{
return componentNodes_.Size();
}
void FatalHandler::NotifyVisibleStatusChange(bool isVisible) const
{
ListNode<Component *> *node = componentNodes_.Begin();
while (node != componentNodes_.End()) {
if (node->data_ != nullptr) {
node->data_->OnVisibilityChanged(isVisible);
}
node = node->next_;
}
}
} // namespace ACELite
} // namespace OHOS
@@ -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;
@@ -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