mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2024-11-26 16:52:10 +00:00
回退 'Pull Request !48371 : NavDestination支持跟手滑动隐藏标题栏&工具栏'
This commit is contained in:
parent
25f02007ce
commit
20ccc1d6e0
@ -1132,8 +1132,6 @@ frameworks/bridge/declarative_frontend/jsview/js_menu_item_group.h @arkuipopupwi
|
||||
frameworks/bridge/declarative_frontend/jsview/js_menu_item.h @arkuipopupwindow
|
||||
frameworks/bridge/declarative_frontend/jsview/js_navdestination_context.cpp @arkui_superman
|
||||
frameworks/bridge/declarative_frontend/jsview/js_navdestination_context.h @arkui_superman
|
||||
frameworks/bridge/declarative_frontend/jsview/js_navdestination_scrollable_processor.cpp @arkui_superman
|
||||
frameworks/bridge/declarative_frontend/jsview/js_navdestination_scrollable_processor.h @arkui_superman
|
||||
frameworks/bridge/declarative_frontend/jsview/js_navdestination.cpp @arkui_superman
|
||||
frameworks/bridge/declarative_frontend/jsview/js_navdestination.h @arkui_superman
|
||||
frameworks/bridge/declarative_frontend/jsview/js_navigation.cpp @arkui_superman
|
||||
|
@ -313,7 +313,6 @@ template("declarative_js_engine") {
|
||||
"jsview/js_nav_path_stack.cpp",
|
||||
"jsview/js_navdestination.cpp",
|
||||
"jsview/js_navdestination_context.cpp",
|
||||
"jsview/js_navdestination_scrollable_processor.cpp",
|
||||
"jsview/js_navigation.cpp",
|
||||
"jsview/js_navigation_stack.cpp",
|
||||
"jsview/js_navigation_utils.cpp",
|
||||
@ -857,7 +856,6 @@ template("declarative_js_engine_ng") {
|
||||
"jsview/js_nav_path_stack.cpp",
|
||||
"jsview/js_navdestination.cpp",
|
||||
"jsview/js_navdestination_context.cpp",
|
||||
"jsview/js_navdestination_scrollable_processor.cpp",
|
||||
"jsview/js_navigation.cpp",
|
||||
"jsview/js_navigation_stack.cpp",
|
||||
"jsview/js_navigation_utils.cpp",
|
||||
|
@ -27,7 +27,6 @@
|
||||
#include "bridge/declarative_frontend/jsview/js_navdestination_context.h"
|
||||
#include "bridge/declarative_frontend/jsview/js_navigation.h"
|
||||
#include "bridge/declarative_frontend/jsview/js_navigation_utils.h"
|
||||
#include "bridge/declarative_frontend/jsview/js_navdestination_scrollable_processor.h"
|
||||
#include "bridge/declarative_frontend/jsview/js_utils.h"
|
||||
#include "core/components_ng/base/view_stack_model.h"
|
||||
#include "core/components_ng/base/view_stack_processor.h"
|
||||
@ -93,21 +92,18 @@ bool ParseCommonTitle(const JSRef<JSObject>& jsObj)
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void JSNavDestination::Create()
|
||||
{
|
||||
NavDestinationModel::GetInstance()->Create();
|
||||
NavDestinationModel::GetInstance()->SetScrollableProcessor(
|
||||
[]() { return AceType::MakeRefPtr<JSNavDestinationScrollableProcessor>(); });
|
||||
}
|
||||
|
||||
void JSNavDestination::Create(const JSCallbackInfo& info)
|
||||
{
|
||||
if (info.Length() <= 0) {
|
||||
NavDestinationModel::GetInstance()->Create();
|
||||
NavDestinationModel::GetInstance()->SetScrollableProcessor(
|
||||
[]() { return AceType::MakeRefPtr<JSNavDestinationScrollableProcessor>(); });
|
||||
return;
|
||||
}
|
||||
|
||||
@ -126,8 +122,6 @@ void JSNavDestination::Create(const JSCallbackInfo& info)
|
||||
auto navPathInfo = AceType::MakeRefPtr<JSNavPathInfo>();
|
||||
ctx->SetNavPathInfo(navPathInfo);
|
||||
NavDestinationModel::GetInstance()->Create(std::move(builderFunc), std::move(ctx));
|
||||
NavDestinationModel::GetInstance()->SetScrollableProcessor(
|
||||
[]() { return AceType::MakeRefPtr<JSNavDestinationScrollableProcessor>(); });
|
||||
return;
|
||||
} else if (info[0]->IsObject()) {
|
||||
// first parameter = pathInfo{'moduleName': stringA, 'pagePath': stringB}
|
||||
@ -140,8 +134,6 @@ void JSNavDestination::Create(const JSCallbackInfo& info)
|
||||
moduleName = infoObj->GetProperty(NG::NAVIGATION_MODULE_NAME)->ToString();
|
||||
pagePath = infoObj->GetProperty(NG::NAVIGATION_PAGE_PATH)->ToString();
|
||||
NavDestinationModel::GetInstance()->Create();
|
||||
NavDestinationModel::GetInstance()->SetScrollableProcessor(
|
||||
[]() { return AceType::MakeRefPtr<JSNavDestinationScrollableProcessor>(); });
|
||||
NavDestinationModel::GetInstance()->SetNavDestinationPathInfo(moduleName, pagePath);
|
||||
return;
|
||||
}
|
||||
@ -172,8 +164,6 @@ void JSNavDestination::Create(const JSCallbackInfo& info)
|
||||
moduleName = infoObj->GetProperty(NG::NAVIGATION_MODULE_NAME)->ToString();
|
||||
pagePath = infoObj->GetProperty(NG::NAVIGATION_PAGE_PATH)->ToString();
|
||||
NavDestinationModel::GetInstance()->Create(std::move(builderFunc), std::move(ctx));
|
||||
NavDestinationModel::GetInstance()->SetScrollableProcessor(
|
||||
[]() { return AceType::MakeRefPtr<JSNavDestinationScrollableProcessor>(); });
|
||||
NavDestinationModel::GetInstance()->SetNavDestinationPathInfo(moduleName, pagePath);
|
||||
}
|
||||
}
|
||||
@ -558,26 +548,6 @@ void JSNavDestination::SetHideToolBar(const JSCallbackInfo& info)
|
||||
NavDestinationModel::GetInstance()->SetHideToolBar(isHide, isAnimated);
|
||||
}
|
||||
|
||||
void JSNavDestination::BindToScrollable(const JSCallbackInfo& info)
|
||||
{
|
||||
auto bindFunc = [&info](const RefPtr<NG::NavDestinationScrollableProcessor>& processor) {
|
||||
auto jsProcessor = AceType::DynamicCast<JSNavDestinationScrollableProcessor>(processor);
|
||||
CHECK_NULL_VOID(jsProcessor);
|
||||
jsProcessor->BindToScrollable(info);
|
||||
};
|
||||
NavDestinationModel::GetInstance()->UpdateBindingWithScrollable(std::move(bindFunc));
|
||||
}
|
||||
|
||||
void JSNavDestination::BindToNestedScrollable(const JSCallbackInfo& info)
|
||||
{
|
||||
auto bindFunc = [&info](const RefPtr<NG::NavDestinationScrollableProcessor>& processor) {
|
||||
auto jsProcessor = AceType::DynamicCast<JSNavDestinationScrollableProcessor>(processor);
|
||||
CHECK_NULL_VOID(jsProcessor);
|
||||
jsProcessor->BindToNestedScrollable(info);
|
||||
};
|
||||
NavDestinationModel::GetInstance()->UpdateBindingWithScrollable(std::move(bindFunc));
|
||||
}
|
||||
|
||||
void JSNavDestination::JSBind(BindingTarget globalObj)
|
||||
{
|
||||
JSNavDestinationContext::JSBind(globalObj);
|
||||
@ -609,8 +579,6 @@ void JSNavDestination::JSBind(BindingTarget globalObj)
|
||||
JSClass<JSNavDestination>::StaticMethod("toolbarConfiguration", &JSNavDestination::SetToolBarConfiguration);
|
||||
JSClass<JSNavDestination>::StaticMethod("hideToolBar", &JSNavDestination::SetHideToolBar);
|
||||
JSClass<JSNavDestination>::StaticMethod("systemTransition", &JSNavDestination::SetSystemTransition);
|
||||
JSClass<JSNavDestination>::StaticMethod("bindToScrollable", &JSNavDestination::BindToScrollable);
|
||||
JSClass<JSNavDestination>::StaticMethod("bindToNestedScrollable", &JSNavDestination::BindToNestedScrollable);
|
||||
JSClass<JSNavDestination>::InheritAndBind<JSContainerBase>(globalObj);
|
||||
}
|
||||
|
||||
|
@ -46,9 +46,7 @@ public:
|
||||
static void SetSystemBarStyle(const JSCallbackInfo& info);
|
||||
static void SetRecoverable(const JSCallbackInfo& info);
|
||||
static void SetSystemTransition(const JSCallbackInfo& info);
|
||||
static void BindToScrollable(const JSCallbackInfo& info);
|
||||
static void BindToNestedScrollable(const JSCallbackInfo& info);
|
||||
|
||||
|
||||
private:
|
||||
static void CreateForPartialUpdate(const JSCallbackInfo& info);
|
||||
};
|
||||
|
@ -1,367 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "frameworks/bridge/declarative_frontend/jsview/js_navdestination_scrollable_processor.h"
|
||||
|
||||
#include "base/log/ace_scoring_log.h"
|
||||
#include "bridge/declarative_frontend/engine/js_ref_ptr.h"
|
||||
#include "bridge/declarative_frontend/engine/js_types.h"
|
||||
|
||||
namespace OHOS::Ace::Framework {
|
||||
namespace {
|
||||
constexpr int32_t SHOW_TITLEBAR_AND_TOOLBAR_DELAY = 2000;
|
||||
constexpr float SCROLL_RATIO = 2.0f;
|
||||
|
||||
ScrollerObserver CreateObserver(
|
||||
WeakPtr<JSNavDestinationScrollableProcessor> weakProcessor, WeakPtr<JSScroller> weakScroller)
|
||||
{
|
||||
ScrollerObserver observer;
|
||||
auto touchEvent = [weakProcessor, weakScroller](const TouchEventInfo& info) {
|
||||
auto processor = weakProcessor.Upgrade();
|
||||
CHECK_NULL_VOID(processor);
|
||||
processor->HandleOnTouchEvent(weakScroller, info);
|
||||
};
|
||||
observer.onTouchEvent = AceType::MakeRefPtr<NG::TouchEventImpl>(std::move(touchEvent));
|
||||
|
||||
observer.onReachStartEvent = [weakProcessor, weakScroller]() {
|
||||
auto processor = weakProcessor.Upgrade();
|
||||
CHECK_NULL_VOID(processor);
|
||||
processor->HandleOnReachEvent(weakScroller, true);
|
||||
};
|
||||
|
||||
observer.onReachEndEvent = [weakProcessor, weakScroller]() {
|
||||
auto processor = weakProcessor.Upgrade();
|
||||
CHECK_NULL_VOID(processor);
|
||||
processor->HandleOnReachEvent(weakScroller, false);
|
||||
};
|
||||
|
||||
observer.onScrollStartEvent = [weakProcessor, weakScroller]() {
|
||||
auto processor = weakProcessor.Upgrade();
|
||||
CHECK_NULL_VOID(processor);
|
||||
processor->HandleOnScrollStartEvent(weakScroller);
|
||||
};
|
||||
|
||||
observer.onScrollStopEvent = [weakProcessor, weakScroller]() {
|
||||
auto processor = weakProcessor.Upgrade();
|
||||
CHECK_NULL_VOID(processor);
|
||||
processor->HandleOnScrollStopEvent(weakScroller);
|
||||
};
|
||||
|
||||
observer.onDidScrollEvent =
|
||||
[weakProcessor, weakScroller](Dimension dimension, ScrollSource source, bool isAtTop, bool isAtBottom) {
|
||||
auto processor = weakProcessor.Upgrade();
|
||||
CHECK_NULL_VOID(processor);
|
||||
processor->HandleOnDidScrollEvent(weakScroller, dimension, source, isAtTop, isAtBottom);
|
||||
};
|
||||
|
||||
return observer;
|
||||
}
|
||||
|
||||
std::vector<WeakPtr<JSScroller>> ParseScrollerArray(const JSCallbackInfo& info)
|
||||
{
|
||||
std::vector<WeakPtr<JSScroller>> scrollers;
|
||||
if (info.Length() < 1 || !info[0]->IsArray()) {
|
||||
return scrollers;
|
||||
}
|
||||
|
||||
auto scrollerArray = JSRef<JSArray>::Cast(info[0]);
|
||||
auto arraySize = scrollerArray->Length();
|
||||
for (size_t idx = 0; idx < arraySize; idx++) {
|
||||
auto item = scrollerArray->GetValueAt(idx);
|
||||
if (!item->IsObject()) {
|
||||
continue;
|
||||
}
|
||||
auto* scroller = JSRef<JSObject>::Cast(item)->Unwrap<JSScroller>();
|
||||
if (!scroller) {
|
||||
continue;
|
||||
}
|
||||
scrollers.emplace_back(AceType::WeakClaim(scroller));
|
||||
}
|
||||
return scrollers;
|
||||
}
|
||||
|
||||
std::vector<std::pair<WeakPtr<JSScroller>, WeakPtr<JSScroller>>> ParseNestedScrollerArray(const JSCallbackInfo& info)
|
||||
{
|
||||
std::vector<std::pair<WeakPtr<JSScroller>, WeakPtr<JSScroller>>> nestedScrollers;
|
||||
if (info.Length() < 1 || !info[0]->IsArray()) {
|
||||
return nestedScrollers;
|
||||
}
|
||||
|
||||
auto nestedScrollerArray = JSRef<JSArray>::Cast(info[0]);
|
||||
auto arraySize = nestedScrollerArray->Length();
|
||||
for (size_t idx = 0; idx < arraySize; idx++) {
|
||||
auto item = nestedScrollerArray->GetValueAt(idx);
|
||||
if (!item->IsObject()) {
|
||||
continue;
|
||||
}
|
||||
auto jsNestedScrollInfo = JSRef<JSObject>::Cast(item);
|
||||
auto jsChildScroller = jsNestedScrollInfo->GetProperty("child");
|
||||
auto jsParentScroller = jsNestedScrollInfo->GetProperty("parent");
|
||||
if (!jsChildScroller->IsObject() || !jsParentScroller->IsObject()) {
|
||||
continue;
|
||||
}
|
||||
auto* childScroller = JSRef<JSObject>::Cast(jsChildScroller)->Unwrap<JSScroller>();
|
||||
auto* parentScroller = JSRef<JSObject>::Cast(jsParentScroller)->Unwrap<JSScroller>();
|
||||
if (!childScroller || !parentScroller) {
|
||||
continue;
|
||||
}
|
||||
nestedScrollers.emplace_back(AceType::WeakClaim(childScroller), AceType::WeakClaim(parentScroller));
|
||||
}
|
||||
return nestedScrollers;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void JSNavDestinationScrollableProcessor::HandleOnTouchEvent(
|
||||
WeakPtr<JSScroller> weakScroller, const TouchEventInfo& info)
|
||||
{
|
||||
const auto& touches = info.GetTouches();
|
||||
if (touches.empty()) {
|
||||
return;
|
||||
}
|
||||
auto touchType = touches.front().GetTouchType();
|
||||
if (touchType != TouchType::DOWN && touchType != TouchType::UP && touchType != TouchType::CANCEL) {
|
||||
return;
|
||||
}
|
||||
auto navDestPattern = weakPattern_.Upgrade();
|
||||
CHECK_NULL_VOID(navDestPattern);
|
||||
auto it = scrollInfoMap_.find(weakScroller);
|
||||
if (it == scrollInfoMap_.end()) {
|
||||
return;
|
||||
}
|
||||
auto& scrollInfo = it->second;
|
||||
if (touchType == TouchType::DOWN) {
|
||||
scrollInfo.isTouching = true;
|
||||
if (!scrollInfo.isAtTop && !scrollInfo.isAtBottom) {
|
||||
// If we have started the task of showing titleBar/toolBar delayed task, we need to cancel it.
|
||||
navDestPattern->CancelShowTitleAndToolBarTask();
|
||||
}
|
||||
} else {
|
||||
scrollInfo.isTouching = false;
|
||||
if (!scrollInfo.isScrolling) {
|
||||
/**
|
||||
* When touching and scrolling stops, it is necessary to check
|
||||
* whether the titleBar&toolBar should be restored to its original position.
|
||||
*/
|
||||
navDestPattern->ResetTitleAndToolBarState();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void JSNavDestinationScrollableProcessor::HandleOnReachEvent(WeakPtr<JSScroller> weakScroller, bool isTopEvent)
|
||||
{
|
||||
auto it = scrollInfoMap_.find(weakScroller);
|
||||
if (it == scrollInfoMap_.end()) {
|
||||
return;
|
||||
}
|
||||
auto& scrollInfo = it->second;
|
||||
if (isTopEvent) {
|
||||
scrollInfo.isAtTop = true;
|
||||
} else {
|
||||
scrollInfo.isAtBottom = true;
|
||||
}
|
||||
}
|
||||
|
||||
void JSNavDestinationScrollableProcessor::HandleOnScrollStartEvent(WeakPtr<JSScroller> weakScroller)
|
||||
{
|
||||
auto it = scrollInfoMap_.find(weakScroller);
|
||||
if (it == scrollInfoMap_.end()) {
|
||||
return;
|
||||
}
|
||||
auto navDestPattern = weakPattern_.Upgrade();
|
||||
CHECK_NULL_VOID(navDestPattern);
|
||||
auto& scrollInfo = it->second;
|
||||
scrollInfo.isScrolling = true;
|
||||
if (!scrollInfo.isAtTop && !scrollInfo.isAtBottom && !scrollInfo.isTouching) {
|
||||
// If we have started the task of showing titleBar/toolBar delayed task, we need to cancel it.
|
||||
navDestPattern->CancelShowTitleAndToolBarTask();
|
||||
}
|
||||
}
|
||||
|
||||
void JSNavDestinationScrollableProcessor::HandleOnScrollStopEvent(WeakPtr<JSScroller> weakScroller)
|
||||
{
|
||||
auto it = scrollInfoMap_.find(weakScroller);
|
||||
if (it == scrollInfoMap_.end()) {
|
||||
return;
|
||||
}
|
||||
auto navDestPattern = weakPattern_.Upgrade();
|
||||
CHECK_NULL_VOID(navDestPattern);
|
||||
auto& scrollInfo = it->second;
|
||||
scrollInfo.isScrolling = false;
|
||||
if (!scrollInfo.parentScroller.has_value() && !scrollInfo.isTouching) {
|
||||
/**
|
||||
* When touching and scrolling stops, it is necessary to check
|
||||
* whether the titleBar&toolBar should be restored to its original position.
|
||||
*/
|
||||
navDestPattern->ResetTitleAndToolBarState();
|
||||
}
|
||||
}
|
||||
|
||||
void JSNavDestinationScrollableProcessor::HandleOnDidScrollEvent(
|
||||
WeakPtr<JSScroller> weakScroller, Dimension dimension, ScrollSource source, bool isAtTop, bool isAtBottom)
|
||||
{
|
||||
auto it = scrollInfoMap_.find(weakScroller);
|
||||
if (it == scrollInfoMap_.end()) {
|
||||
return;
|
||||
}
|
||||
auto navDestPattern = weakPattern_.Upgrade();
|
||||
CHECK_NULL_VOID(navDestPattern);
|
||||
auto& scrollInfo = it->second;
|
||||
if ((scrollInfo.isAtTop && isAtTop) || (scrollInfo.isAtBottom && isAtBottom)) {
|
||||
// If we have already scrolled to the top or bottom, just return.
|
||||
return;
|
||||
}
|
||||
|
||||
if (scrollInfo.isScrolling) {
|
||||
auto offset = dimension.ConvertToPx() / SCROLL_RATIO;
|
||||
if (NonPositive(offset) ||
|
||||
!(source == ScrollSource::SCROLLER || source == ScrollSource::SCROLLER_ANIMATION)) {
|
||||
/**
|
||||
* We will respond to user actions by scrolling up or down. But for the scrolling triggered by developers
|
||||
* through the frontend interface, we will only respond to scrolling down.
|
||||
*/
|
||||
navDestPattern->UpdateTitleAndToolBarHiddenOffset(offset);
|
||||
}
|
||||
}
|
||||
|
||||
auto isChildReachTop = !scrollInfo.isAtTop && isAtTop;
|
||||
auto isChildReachBottom = !scrollInfo.isAtBottom && isAtBottom;
|
||||
auto isParentAtTop = true;
|
||||
auto isParentAtBottom = true;
|
||||
if (scrollInfo.parentScroller.has_value()) {
|
||||
auto iter = scrollInfoMap_.find(scrollInfo.parentScroller.value());
|
||||
isParentAtTop = iter == scrollInfoMap_.end() || iter->second.isAtTop;
|
||||
isParentAtBottom = iter == scrollInfoMap_.end() || iter->second.isAtBottom;
|
||||
}
|
||||
/**
|
||||
* For non-nested scrolling component, we need show titleBar&toolBar immediately when scrolled
|
||||
* to the top or bottom. But for the nested scrolling components, the titleBar&toolBar can only be show
|
||||
* immediately when the parent component also reaches the top or bottom.
|
||||
*/
|
||||
if ((isChildReachTop && isParentAtTop) || (isChildReachBottom && isParentAtBottom)) {
|
||||
navDestPattern->ShowTitleAndToolBar();
|
||||
}
|
||||
|
||||
scrollInfo.isAtTop = isAtTop;
|
||||
scrollInfo.isAtBottom = isAtBottom;
|
||||
}
|
||||
|
||||
void JSNavDestinationScrollableProcessor::BindToScrollable(const JSCallbackInfo& info)
|
||||
{
|
||||
needUpdateBindingRelation_ = true;
|
||||
incommingScrollers_.clear();
|
||||
std::vector<WeakPtr<JSScroller>> scrollers = ParseScrollerArray(info);
|
||||
for (const auto& scroller : scrollers) {
|
||||
incommingScrollers_.emplace(scroller);
|
||||
}
|
||||
}
|
||||
|
||||
void JSNavDestinationScrollableProcessor::BindToNestedScrollable(const JSCallbackInfo& info)
|
||||
{
|
||||
needUpdateBindingRelation_ = true;
|
||||
incommingNestedScrollers_.clear();
|
||||
auto nestedScrollers = ParseNestedScrollerArray(info);
|
||||
for (const auto& scrollerPair : nestedScrollers) {
|
||||
incommingNestedScrollers_.emplace(scrollerPair.second, std::nullopt);
|
||||
incommingNestedScrollers_.emplace(scrollerPair.first, scrollerPair.second);
|
||||
}
|
||||
}
|
||||
|
||||
void JSNavDestinationScrollableProcessor::UpdateBindingRelation()
|
||||
{
|
||||
if (!needUpdateBindingRelation_) {
|
||||
return;
|
||||
}
|
||||
needUpdateBindingRelation_ = false;
|
||||
|
||||
// mark all scroller need unbind.
|
||||
for (auto& pair : scrollInfoMap_) {
|
||||
pair.second.needUnbind = true;
|
||||
}
|
||||
|
||||
CombineIncomingScrollers();
|
||||
BuildNewBindingRelation();
|
||||
RemoveUnneededBindingRelation();
|
||||
|
||||
if (!scrollInfoMap_.empty()) {
|
||||
return;
|
||||
}
|
||||
auto pattern = weakPattern_.Upgrade();
|
||||
CHECK_NULL_VOID(pattern);
|
||||
// we need show titlBar/toolBar when there is no binding relation.
|
||||
pattern->ShowTitleAndToolBar();
|
||||
}
|
||||
|
||||
void JSNavDestinationScrollableProcessor::CombineIncomingScrollers()
|
||||
{
|
||||
for (auto& scroller : incommingScrollers_) {
|
||||
NestedScrollers nestedScroller(scroller, std::nullopt);
|
||||
auto it = incommingNestedScrollers_.find(nestedScroller);
|
||||
if (it != incommingNestedScrollers_.end()) {
|
||||
continue;
|
||||
}
|
||||
incommingNestedScrollers_.emplace(nestedScroller);
|
||||
}
|
||||
incommingScrollers_.clear();
|
||||
}
|
||||
|
||||
void JSNavDestinationScrollableProcessor::BuildNewBindingRelation()
|
||||
{
|
||||
for (auto& scrollers : incommingNestedScrollers_) {
|
||||
auto it = scrollInfoMap_.find(scrollers.child);
|
||||
if (it != scrollInfoMap_.end()) {
|
||||
it->second.needUnbind = false;
|
||||
it->second.parentScroller = scrollers.parent;
|
||||
continue;
|
||||
}
|
||||
|
||||
auto jsScroller = scrollers.child.Upgrade();
|
||||
if (!jsScroller) {
|
||||
continue;
|
||||
}
|
||||
auto observer = CreateObserver(WeakClaim(this), scrollers.child);
|
||||
jsScroller->AddObserver(observer, nodeId_);
|
||||
ScrollInfo info;
|
||||
info.parentScroller = scrollers.parent;
|
||||
info.needUnbind = false;
|
||||
scrollInfoMap_.emplace(scrollers.child, info);
|
||||
}
|
||||
incommingNestedScrollers_.clear();
|
||||
}
|
||||
|
||||
void JSNavDestinationScrollableProcessor::RemoveUnneededBindingRelation()
|
||||
{
|
||||
auto infoIter = scrollInfoMap_.begin();
|
||||
for (; infoIter != scrollInfoMap_.end();) {
|
||||
if (!infoIter->second.needUnbind) {
|
||||
++infoIter;
|
||||
continue;
|
||||
}
|
||||
|
||||
auto jsScroller = infoIter->first.Upgrade();
|
||||
if (jsScroller) {
|
||||
jsScroller->RemoveObserver(nodeId_);
|
||||
}
|
||||
infoIter = scrollInfoMap_.erase(infoIter);
|
||||
}
|
||||
}
|
||||
|
||||
void JSNavDestinationScrollableProcessor::UnbindAllScrollers()
|
||||
{
|
||||
needUpdateBindingRelation_ = true;
|
||||
incommingScrollers_.clear();
|
||||
incommingNestedScrollers_.clear();
|
||||
UpdateBindingRelation();
|
||||
}
|
||||
} // namespace OHOS::Ace::Framework
|
@ -1,91 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_NAVDESTINATION_SCROLLABLE_PROCESSOR_H
|
||||
#define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_NAVDESTINATION_SCROLLABLE_PROCESSOR_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
#include <map>
|
||||
|
||||
#include "bridge/declarative_frontend/jsview/js_scroller.h"
|
||||
#include "core/components_ng/pattern/navrouter/navdestination_pattern.h"
|
||||
#include "core/components_ng/pattern/navrouter/navdestination_scrollable_processor.h"
|
||||
|
||||
namespace OHOS::Ace::Framework {
|
||||
class JSNavDestinationScrollableProcessor : public NG::NavDestinationScrollableProcessor {
|
||||
DECLARE_ACE_TYPE(JSNavDestinationScrollableProcessor, NG::NavDestinationScrollableProcessor)
|
||||
public:
|
||||
JSNavDestinationScrollableProcessor() = default;
|
||||
~JSNavDestinationScrollableProcessor() = default;
|
||||
|
||||
void UpdateBindingRelation() override;
|
||||
void SetNodeId(int32_t id) override
|
||||
{
|
||||
nodeId_ = id;
|
||||
}
|
||||
void SetNavDestinationPattern(WeakPtr<NG::NavDestinationPattern> pattern) override
|
||||
{
|
||||
weakPattern_ = pattern;
|
||||
}
|
||||
void UnbindAllScrollers() override;
|
||||
|
||||
void BindToScrollable(const JSCallbackInfo& info);
|
||||
void BindToNestedScrollable(const JSCallbackInfo& info);
|
||||
|
||||
void HandleOnTouchEvent(WeakPtr<JSScroller> jsScrollerWeak, const TouchEventInfo& info);
|
||||
void HandleOnReachEvent(WeakPtr<JSScroller> jsScrollerWeak, bool isTopEvent);
|
||||
void HandleOnScrollStartEvent(WeakPtr<JSScroller> jsScrollerWeak);
|
||||
void HandleOnScrollStopEvent(WeakPtr<JSScroller> jsScrollerWeak);
|
||||
void HandleOnDidScrollEvent(
|
||||
WeakPtr<JSScroller> jsScrollerWeak, Dimension dimension, ScrollSource source, bool isAtTop, bool isAtBottom);
|
||||
|
||||
private:
|
||||
void CombineIncomingScrollers();
|
||||
void BuildNewBindingRelation();
|
||||
void RemoveUnneededBindingRelation();
|
||||
|
||||
struct NestedScrollers {
|
||||
NestedScrollers() = default;
|
||||
NestedScrollers(WeakPtr<JSScroller> childScroller, std::optional<WeakPtr<JSScroller>> parentScroller)
|
||||
: child(childScroller), parent(parentScroller) {}
|
||||
WeakPtr<JSScroller> child;
|
||||
std::optional<WeakPtr<JSScroller>> parent;
|
||||
|
||||
bool operator< (const NestedScrollers& other) const
|
||||
{
|
||||
return child < other.child;
|
||||
}
|
||||
};
|
||||
std::set<WeakPtr<JSScroller>> incommingScrollers_;
|
||||
std::set<NestedScrollers> incommingNestedScrollers_;
|
||||
bool needUpdateBindingRelation_ = false;
|
||||
|
||||
struct ScrollInfo {
|
||||
bool isTouching = false;
|
||||
bool isScrolling = false;
|
||||
bool isAtTop = false;
|
||||
bool isAtBottom = false;
|
||||
bool needUnbind = false;
|
||||
std::optional<WeakPtr<JSScroller>> parentScroller;
|
||||
};
|
||||
std::map<WeakPtr<JSScroller>, ScrollInfo> scrollInfoMap_;
|
||||
int32_t nodeId_ = 0;
|
||||
WeakPtr<NG::NavDestinationPattern> weakPattern_;
|
||||
};
|
||||
|
||||
} // namespace OHOS::Ace::Framework
|
||||
|
||||
#endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_NAVDESTINATION_SCROLLABLE_PROCESSOR_H
|
@ -20,7 +20,6 @@
|
||||
#include "bridge/declarative_frontend/engine/bindings.h"
|
||||
#include "core/components/scroll/scroll_controller_base.h"
|
||||
#include "core/components/scroll_bar/scroll_proxy.h"
|
||||
#include "core/components_ng/pattern/scrollable/scroller_observer_manager.h"
|
||||
|
||||
namespace OHOS::Ace::Framework {
|
||||
|
||||
@ -55,11 +54,9 @@ public:
|
||||
if (oldController) {
|
||||
ScrollerObserver observer;
|
||||
oldController->SetObserver(observer);
|
||||
oldController->SetObserverManager(nullptr);
|
||||
}
|
||||
if (controller) {
|
||||
controller->SetObserver(observer_);
|
||||
controller->SetObserverManager(observerMgr_);
|
||||
}
|
||||
controllerWeak_ = controller;
|
||||
}
|
||||
@ -95,16 +92,6 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void AddObserver(const ScrollerObserver& observer, int32_t id)
|
||||
{
|
||||
observerMgr_->AddObserver(observer, id);
|
||||
}
|
||||
|
||||
void RemoveObserver(int32_t id)
|
||||
{
|
||||
observerMgr_->RemoveObserver(id);
|
||||
}
|
||||
|
||||
private:
|
||||
bool ParseCurveParams(RefPtr<Curve>& curve, const JSRef<JSVal>& jsValue);
|
||||
|
||||
@ -116,7 +103,6 @@ private:
|
||||
int32_t instanceId_ = INSTANCE_ID_UNDEFINED;
|
||||
|
||||
ScrollerObserver observer_;
|
||||
RefPtr<ScrollerObserverManager> observerMgr_ = MakeRefPtr<ScrollerObserverManager>();
|
||||
};
|
||||
|
||||
} // namespace OHOS::Ace::Framework
|
||||
|
@ -24,7 +24,6 @@
|
||||
#include "core/animation/curve.h"
|
||||
#include "core/components/common/layout/constants.h"
|
||||
#include "core/components_ng/pattern/scrollable/scrollable_properties.h"
|
||||
#include "core/components_ng/pattern/scrollable/scroller_observer_manager.h"
|
||||
#include "core/event/ace_events.h"
|
||||
|
||||
namespace OHOS::Ace {
|
||||
@ -129,20 +128,7 @@ public:
|
||||
|
||||
virtual void SetObserver(const ScrollerObserver& observer) {}
|
||||
|
||||
virtual void SetObserverManager(const RefPtr<ScrollerObserverManager>& mgr)
|
||||
{
|
||||
observerMgr_ = mgr;
|
||||
}
|
||||
|
||||
virtual RefPtr<ScrollerObserverManager> GetObserverManager() const
|
||||
{
|
||||
return observerMgr_;
|
||||
}
|
||||
|
||||
virtual void StopAnimate() {}
|
||||
|
||||
protected:
|
||||
RefPtr<ScrollerObserverManager> observerMgr_ = nullptr;
|
||||
};
|
||||
} // namespace OHOS::Ace
|
||||
|
||||
|
@ -383,7 +383,6 @@ build_component_ng("pattern_ng") {
|
||||
"scrollable/scrollable_paint_property.cpp",
|
||||
"scrollable/scrollable_pattern.cpp",
|
||||
"scrollable/scrollable_utils.cpp",
|
||||
"scrollable/scroller_observer_manager.cpp",
|
||||
"search/search_event_hub.cpp",
|
||||
"search/search_gesture_event_hub.cpp",
|
||||
"search/search_layout_algorithm.cpp",
|
||||
|
@ -843,31 +843,4 @@ float NavigationTitleUtil::CalculateTitlebarOffset(const RefPtr<UINode>& titleBa
|
||||
// offsetY = The Y of the foldCrease + Adapt vertical displacement of hover state - the height of the status bar.
|
||||
return foldCrease.GetOffset().GetY() + TITLEBAR_VERTICAL_PADDING.ConvertToPx() - length;
|
||||
}
|
||||
|
||||
void NavigationTitleUtil::UpdateTitleOrToolBarTranslateYAndOpacity(const RefPtr<NavDestinationNodeBase>& nodeBase,
|
||||
const RefPtr<FrameNode>& barNode, float translate, bool isTitle)
|
||||
{
|
||||
CHECK_NULL_VOID(nodeBase);
|
||||
CHECK_NULL_VOID(barNode);
|
||||
auto renderContext = barNode->GetRenderContext();
|
||||
CHECK_NULL_VOID(renderContext);
|
||||
auto option = renderContext->GetTransformTranslateValue(TranslateOptions(0.0f, 0.0f, 0.0f));
|
||||
option.y = CalcDimension(translate, DimensionUnit::PX);
|
||||
renderContext->UpdateTransformTranslate(option);
|
||||
auto barHeight = renderContext->GetPaintRectWithoutTransform().Height();
|
||||
float opacity = 1.0f;
|
||||
if (!NearZero(barHeight)) {
|
||||
opacity = 1.0f - std::clamp(std::abs(translate) / barHeight, 0.0f, 1.0f);
|
||||
}
|
||||
renderContext->UpdateOpacity(opacity);
|
||||
if (isTitle) {
|
||||
return;
|
||||
}
|
||||
auto divider = AceType::DynamicCast<FrameNode>(nodeBase->GetToolBarDividerNode());
|
||||
CHECK_NULL_VOID(divider);
|
||||
auto dividerRenderContext = divider->GetRenderContext();
|
||||
CHECK_NULL_VOID(dividerRenderContext);
|
||||
dividerRenderContext->UpdateTransformTranslate(option);
|
||||
dividerRenderContext->UpdateOpacity(opacity);
|
||||
}
|
||||
} // namespace OHOS::Ace::NG
|
||||
|
@ -107,8 +107,6 @@ public:
|
||||
static RefPtr<FrameNode> CreatePopupDialogNode(
|
||||
const RefPtr<FrameNode> targetNode, const std::vector<NG::BarItem>& menuItems, int32_t index);
|
||||
static RefPtr<FrameNode> CreateSymbolDialog(const std::string& message, const RefPtr<FrameNode>& targetNode);
|
||||
static void UpdateTitleOrToolBarTranslateYAndOpacity(const RefPtr<NavDestinationNodeBase>& nodeBase,
|
||||
const RefPtr<FrameNode>& barNode, float translate, bool isTitle);
|
||||
};
|
||||
|
||||
} // namespace OHOS::Ace::NG
|
||||
|
@ -648,13 +648,6 @@ void NavigationToolbarUtil::MountToolBar(
|
||||
|
||||
bool hideToolBar = propertyBase->GetHideToolBarValue(false);
|
||||
auto currhideToolBar = navDestinationPatternBase->GetCurrHideToolBar();
|
||||
if (currhideToolBar.has_value() && currhideToolBar.value() != hideToolBar && hideToolBar) {
|
||||
/**
|
||||
* we need reset translate&opacity of toolBar when state change from show to hide.
|
||||
* @sa NavDestinationPattern::EnableTitleBarSwipe
|
||||
*/
|
||||
NavigationTitleUtil::UpdateTitleOrToolBarTranslateYAndOpacity(nodeBase, toolBarNode, 0.0f, false);
|
||||
}
|
||||
/**
|
||||
* 1. At the initial state, animation is not required;
|
||||
* 2. When toolbar is displayed at Title's menu position, no animation is needed for the toolbar.
|
||||
|
@ -22,7 +22,6 @@
|
||||
#include "core/components_ng/pattern/navigation/navigation_declaration.h"
|
||||
#include "core/components_ng/pattern/navigation/navigation_options.h"
|
||||
#include "core/components_ng/pattern/navrouter/navdestination_context.h"
|
||||
#include "core/components_ng/pattern/navrouter/navdestination_scrollable_processor.h"
|
||||
|
||||
namespace OHOS::Ace {
|
||||
class NavDestinationModel {
|
||||
@ -73,11 +72,7 @@ public:
|
||||
virtual void SetIgnoreLayoutSafeArea(const NG::SafeAreaExpandOpts& opts) {};
|
||||
virtual void SetSystemBarStyle(const RefPtr<SystemBarStyle>& style) {};
|
||||
virtual void SetSystemTransitionType(NG::NavigationSystemTransitionType type) {};
|
||||
virtual void SetScrollableProcessor(
|
||||
const std::function<RefPtr<NG::NavDestinationScrollableProcessor>()>& creator) {}
|
||||
virtual void UpdateBindingWithScrollable(
|
||||
std::function<void(const RefPtr<NG::NavDestinationScrollableProcessor>& processor)>&& callback) {}
|
||||
|
||||
|
||||
private:
|
||||
static std::unique_ptr<NavDestinationModel> instance_;
|
||||
static std::mutex mutex_;
|
||||
|
@ -897,38 +897,4 @@ void NavDestinationModelNG::SetSystemTransitionType(FrameNode* frameNode, NG::Na
|
||||
CHECK_NULL_VOID(navDestination);
|
||||
navDestination->SetSystemTransitionType(type);
|
||||
}
|
||||
|
||||
void NavDestinationModelNG::SetScrollableProcessor(
|
||||
const std::function<RefPtr<NG::NavDestinationScrollableProcessor>()>& creator)
|
||||
{
|
||||
CHECK_NULL_VOID(creator);
|
||||
auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
|
||||
CHECK_NULL_VOID(frameNode);
|
||||
auto node = AceType::DynamicCast<NavDestinationGroupNode>(Referenced::Claim<FrameNode>(frameNode));
|
||||
CHECK_NULL_VOID(node);
|
||||
auto pattern = node->GetPattern<NavDestinationPattern>();
|
||||
CHECK_NULL_VOID(pattern);
|
||||
if (!pattern->GetScrollableProcessor()) {
|
||||
auto processor = creator();
|
||||
if (processor) {
|
||||
processor->SetNodeId(node->GetId());
|
||||
processor->SetNavDestinationPattern(WeakPtr(pattern));
|
||||
}
|
||||
pattern->SetScrollableProcessor(processor);
|
||||
}
|
||||
}
|
||||
|
||||
void NavDestinationModelNG::UpdateBindingWithScrollable(
|
||||
std::function<void(const RefPtr<NG::NavDestinationScrollableProcessor>& processor)>&& callback)
|
||||
{
|
||||
CHECK_NULL_VOID(callback);
|
||||
auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
|
||||
CHECK_NULL_VOID(frameNode);
|
||||
auto node = AceType::DynamicCast<NavDestinationGroupNode>(Referenced::Claim<FrameNode>(frameNode));
|
||||
CHECK_NULL_VOID(node);
|
||||
auto pattern = node->GetPattern<NavDestinationPattern>();
|
||||
CHECK_NULL_VOID(pattern);
|
||||
auto processor = pattern->GetScrollableProcessor();
|
||||
callback(processor);
|
||||
}
|
||||
} // namespace OHOS::Ace::NG
|
||||
|
@ -72,11 +72,6 @@ public:
|
||||
std::function<void(WeakPtr<NG::FrameNode>)>&& symbol, uint32_t index);
|
||||
void SetSystemTransitionType(NG::NavigationSystemTransitionType type) override;
|
||||
static void SetSystemTransitionType(FrameNode* frameNode, NG::NavigationSystemTransitionType type);
|
||||
void SetScrollableProcessor(
|
||||
const std::function<RefPtr<NG::NavDestinationScrollableProcessor>()>& creator) override;
|
||||
void UpdateBindingWithScrollable(
|
||||
std::function<void(const RefPtr<NG::NavDestinationScrollableProcessor>& processor)>&& callback) override;
|
||||
|
||||
private:
|
||||
void CreateBackButton(const RefPtr<NavDestinationGroupNode>& navDestinationNode);
|
||||
void CreateImageButton(const RefPtr<NavDestinationGroupNode>& navDestinationNode);
|
||||
|
@ -29,9 +29,6 @@ namespace {
|
||||
std::atomic<uint64_t> g_navDestinationPatternNextAutoGenId = 0;
|
||||
// titlebar ZINDEX
|
||||
constexpr static int32_t DEFAULT_TITLEBAR_ZINDEX = 2;
|
||||
constexpr float TRANSLATE_THRESHOLD = 26.0f;
|
||||
const auto TRANSLATE_CURVE = AceType::MakeRefPtr<InterpolatingSpring>(0.0f, 1.0f, 228.0f, 30.0f);
|
||||
const auto TRANSLATE_DELAY = 2000;
|
||||
|
||||
void BuildMenu(const RefPtr<NavDestinationGroupNode>& navDestinationGroupNode, const RefPtr<TitleBarNode>& titleBarNode)
|
||||
{
|
||||
@ -75,17 +72,6 @@ void BuildMenu(const RefPtr<NavDestinationGroupNode>& navDestinationGroupNode, c
|
||||
navDestinationGroupNode->SetLandscapeMenu(landscapeMenuNode);
|
||||
}
|
||||
}
|
||||
|
||||
bool GetTitleOrToolBarTranslateAndHeight(const RefPtr<FrameNode>& barNode, float& translate, float& height)
|
||||
{
|
||||
CHECK_NULL_RETURN(barNode, false);
|
||||
auto renderContext = barNode->GetRenderContext();
|
||||
CHECK_NULL_RETURN(renderContext, false);
|
||||
auto options = renderContext->GetTransformTranslateValue(TranslateOptions(0.0f, 0.0f, 0.0f));
|
||||
translate = options.y.ConvertToPx();
|
||||
height = renderContext->GetPaintRectWithoutTransform().Height();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
NavDestinationPattern::NavDestinationPattern(const RefPtr<ShallowBuilder>& shallowBuilder)
|
||||
@ -102,9 +88,6 @@ NavDestinationPattern::NavDestinationPattern()
|
||||
NavDestinationPattern::~NavDestinationPattern()
|
||||
{
|
||||
customNode_ = nullptr;
|
||||
if (scrollableProcessor_) {
|
||||
scrollableProcessor_->UnbindAllScrollers();
|
||||
}
|
||||
}
|
||||
|
||||
void NavDestinationPattern::OnActive()
|
||||
@ -172,9 +155,6 @@ void NavDestinationPattern::OnModifyDone()
|
||||
CHECK_NULL_VOID(backButtonNode);
|
||||
titleBarPattern->InitBackButtonLongPressEvent(backButtonNode);
|
||||
}
|
||||
if (scrollableProcessor_) {
|
||||
scrollableProcessor_->UpdateBindingRelation();
|
||||
}
|
||||
}
|
||||
|
||||
void NavDestinationPattern::OnLanguageConfigurationUpdate()
|
||||
@ -270,12 +250,6 @@ void NavDestinationPattern::MountTitleBar(
|
||||
titleBarLayoutProperty->UpdatePropertyChangeFlag(PROPERTY_UPDATE_MEASURE);
|
||||
}
|
||||
|
||||
if (currHideTitleBar_.has_value() && currHideTitleBar_.value() != hideTitleBar && hideTitleBar) {
|
||||
/**
|
||||
* we need reset translate&opacity of titleBar when state change from show to hide. @sa EnableTitleBarSwipe
|
||||
*/
|
||||
NavigationTitleUtil::UpdateTitleOrToolBarTranslateYAndOpacity(hostNode, titleBarNode, 0.0f, true);
|
||||
}
|
||||
// At the initial state, animation is not required.
|
||||
if (!currHideTitleBar_.has_value() || !navDestinationLayoutProperty->GetIsAnimatedTitleBarValue(false)) {
|
||||
currHideTitleBar_ = hideTitleBar;
|
||||
@ -529,285 +503,4 @@ void NavDestinationPattern::CloseLongPressDialog()
|
||||
titleBarPattern->SetLargeFontPopUpDialogNode(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void NavDestinationPattern::UpdateTitleAndToolBarHiddenOffset(float offset)
|
||||
{
|
||||
CancelShowTitleAndToolBarTask();
|
||||
auto nodeBase = AceType::DynamicCast<NavDestinationNodeBase>(GetHost());
|
||||
CHECK_NULL_VOID(nodeBase);
|
||||
if (EnableTitleBarSwipe(nodeBase)) {
|
||||
auto titleBarNode = AceType::DynamicCast<TitleBarNode>(nodeBase->GetTitleBarNode());
|
||||
UpdateBarHiddenOffset(nodeBase, titleBarNode, offset, true);
|
||||
}
|
||||
if (EnableToolBarSwipe(nodeBase)) {
|
||||
auto toolBarNode = AceType::DynamicCast<NavToolbarNode>(nodeBase->GetToolBarNode());
|
||||
UpdateBarHiddenOffset(nodeBase, toolBarNode, offset, false);
|
||||
}
|
||||
}
|
||||
|
||||
void NavDestinationPattern::CancelShowTitleAndToolBarTask()
|
||||
{
|
||||
if (titleBarSwipeContext_.showBarTask) {
|
||||
titleBarSwipeContext_.showBarTask.Cancel();
|
||||
titleBarSwipeContext_.showBarTask.Reset(nullptr);
|
||||
}
|
||||
if (toolBarSwipeContext_.showBarTask) {
|
||||
toolBarSwipeContext_.showBarTask.Cancel();
|
||||
toolBarSwipeContext_.showBarTask.Reset(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void NavDestinationPattern::ResetTitleAndToolBarState()
|
||||
{
|
||||
auto nodeBase = AceType::DynamicCast<NavDestinationNodeBase>(GetHost());
|
||||
CHECK_NULL_VOID(nodeBase);
|
||||
if (EnableTitleBarSwipe(nodeBase)) {
|
||||
auto titleBarNode = AceType::DynamicCast<TitleBarNode>(nodeBase->GetTitleBarNode());
|
||||
ResetBarState(nodeBase, titleBarNode, true);
|
||||
}
|
||||
if (EnableToolBarSwipe(nodeBase)) {
|
||||
auto toolBarNode = AceType::DynamicCast<NavToolbarNode>(nodeBase->GetToolBarNode());
|
||||
ResetBarState(nodeBase, toolBarNode, false);
|
||||
}
|
||||
}
|
||||
|
||||
void NavDestinationPattern::ResetBarState(const RefPtr<NavDestinationNodeBase>& nodeBase,
|
||||
const RefPtr<FrameNode>& barNode, bool isTitle)
|
||||
{
|
||||
CHECK_NULL_VOID(nodeBase);
|
||||
CHECK_NULL_VOID(barNode);
|
||||
auto& ctx = GetSwipeContext(isTitle);
|
||||
if (ctx.isBarHiding || ctx.isBarShowing) {
|
||||
return;
|
||||
}
|
||||
|
||||
float translate = 0.0f;
|
||||
float barHeight = 0.0f;
|
||||
if (!GetTitleOrToolBarTranslateAndHeight(barNode, translate, barHeight) || NearZero(barHeight)) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto threshold = Dimension(TRANSLATE_THRESHOLD, DimensionUnit::VP).ConvertToPx();
|
||||
float halfBarHeight = barHeight / 2.0f;
|
||||
if (GreatOrEqual(threshold, halfBarHeight)) {
|
||||
threshold = halfBarHeight;
|
||||
}
|
||||
float showAreaHeight = barHeight - std::abs(translate);
|
||||
if (GreatNotEqual(showAreaHeight, 0.0f) && LessNotEqual(showAreaHeight, threshold)) {
|
||||
/**
|
||||
* Scroll to show a small portion of the titleBar&toolBar,
|
||||
* but the height of shownArea is less than the threshold,
|
||||
* it needs to be restored to the hidden state.
|
||||
*/
|
||||
StartHideOrShowBarInner(nodeBase, barHeight, translate, isTitle, true);
|
||||
} else if (GreatOrEqual(showAreaHeight, barHeight - threshold) && LessNotEqual(showAreaHeight, barHeight)) {
|
||||
/**
|
||||
* Scroll to hide a small portion of the titleBar&toolBar,
|
||||
* but the height of hiddenArea is less than the threshold,
|
||||
* it needs to be restored to the shown state.
|
||||
*/
|
||||
StartHideOrShowBarInner(nodeBase, barHeight, translate, isTitle, false);
|
||||
} else {
|
||||
// After a period of inactivity, the titleBar&toolBar needs to be shown again.
|
||||
PostShowBarDelayedTask(isTitle);
|
||||
}
|
||||
}
|
||||
|
||||
bool NavDestinationPattern::EnableTitleBarSwipe(const RefPtr<NavDestinationNodeBase>& nodeBase)
|
||||
{
|
||||
CHECK_NULL_RETURN(nodeBase, false);
|
||||
auto property = nodeBase->GetLayoutProperty<NavDestinationLayoutPropertyBase>();
|
||||
CHECK_NULL_RETURN(property, false);
|
||||
return !property->GetHideTitleBarValue(false);
|
||||
}
|
||||
|
||||
bool NavDestinationPattern::EnableToolBarSwipe(const RefPtr<NavDestinationNodeBase>& nodeBase)
|
||||
{
|
||||
CHECK_NULL_RETURN(nodeBase, false);
|
||||
auto property = nodeBase->GetLayoutProperty<NavDestinationLayoutPropertyBase>();
|
||||
CHECK_NULL_RETURN(property, false);
|
||||
return !property->GetHideToolBarValue(false);
|
||||
}
|
||||
|
||||
void NavDestinationPattern::UpdateBarHiddenOffset(
|
||||
const RefPtr<NavDestinationNodeBase>& nodeBase, const RefPtr<FrameNode>& barNode, float offset, bool isTitle)
|
||||
{
|
||||
CHECK_NULL_VOID(nodeBase);
|
||||
CHECK_NULL_VOID(barNode);
|
||||
auto& ctx = GetSwipeContext(isTitle);
|
||||
if (ctx.isBarShowing || ctx.isBarHiding) {
|
||||
return;
|
||||
}
|
||||
|
||||
float preTranslate = 0.0f;
|
||||
float barHeight = 0.0f;
|
||||
if (!GetTitleOrToolBarTranslateAndHeight(barNode, preTranslate, barHeight) || NearZero(barHeight)) {
|
||||
return;
|
||||
}
|
||||
|
||||
float newTranslate = 0.0f;
|
||||
if (isTitle) {
|
||||
newTranslate = std::clamp(preTranslate - offset, -barHeight, 0.0f);
|
||||
} else {
|
||||
newTranslate = std::clamp(preTranslate + offset, 0.0f, barHeight);
|
||||
}
|
||||
NavigationTitleUtil::UpdateTitleOrToolBarTranslateYAndOpacity(nodeBase, barNode, newTranslate, isTitle);
|
||||
|
||||
auto threshold = Dimension(TRANSLATE_THRESHOLD, DimensionUnit::VP).ConvertToPx();
|
||||
float halfBarHeight = barHeight / 2.0f;
|
||||
if (GreatOrEqual(threshold, halfBarHeight)) {
|
||||
threshold = halfBarHeight;
|
||||
}
|
||||
if (Positive(offset) && LessNotEqual(std::abs(preTranslate), threshold) &&
|
||||
GreatOrEqual(std::abs(newTranslate), threshold)) {
|
||||
// When the scrolling up distance exceeds the threshold, it is necessary to start the hide animation.
|
||||
StartHideOrShowBarInner(nodeBase, barHeight, newTranslate, isTitle, true);
|
||||
} else if (Negative(offset) && LessNotEqual(barHeight - std::abs(preTranslate), threshold) &&
|
||||
GreatOrEqual(barHeight - std::abs(newTranslate), threshold)) {
|
||||
// When the scrolling down distance exceeds the threshold, it is necessary to start the show animation.
|
||||
StartHideOrShowBarInner(nodeBase, barHeight, newTranslate, isTitle, false);
|
||||
}
|
||||
}
|
||||
|
||||
void NavDestinationPattern::ShowTitleAndToolBar()
|
||||
{
|
||||
auto nodeBase = AceType::DynamicCast<NavDestinationNodeBase>(GetHost());
|
||||
CHECK_NULL_VOID(nodeBase);
|
||||
if (EnableTitleBarSwipe(nodeBase)) {
|
||||
auto titleBarNode = AceType::DynamicCast<TitleBarNode>(nodeBase->GetTitleBarNode());
|
||||
float translate = 0.0f;
|
||||
float barHeight = 0.0f;
|
||||
if (GetTitleOrToolBarTranslateAndHeight(titleBarNode, translate, barHeight)) {
|
||||
if (titleBarSwipeContext_.showBarTask) {
|
||||
titleBarSwipeContext_.showBarTask.Cancel();
|
||||
titleBarSwipeContext_.showBarTask.Reset(nullptr);
|
||||
}
|
||||
StopHideBarIfNeeded(translate, true);
|
||||
StartHideOrShowBarInner(nodeBase, barHeight, translate, true, false);
|
||||
}
|
||||
}
|
||||
if (EnableToolBarSwipe(nodeBase)) {
|
||||
auto toolBarNode = AceType::DynamicCast<NavToolbarNode>(nodeBase->GetToolBarNode());
|
||||
float translate = 0.0f;
|
||||
float barHeight = 0.0f;
|
||||
if (GetTitleOrToolBarTranslateAndHeight(toolBarNode, translate, barHeight)) {
|
||||
if (toolBarSwipeContext_.showBarTask) {
|
||||
toolBarSwipeContext_.showBarTask.Cancel();
|
||||
toolBarSwipeContext_.showBarTask.Reset(nullptr);
|
||||
}
|
||||
StopHideBarIfNeeded(translate, false);
|
||||
StartHideOrShowBarInner(nodeBase, barHeight, translate, false, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NavDestinationPattern::StartHideOrShowBarInner(
|
||||
const RefPtr<NavDestinationNodeBase>& nodeBase, float barHeight, float curTranslate, bool isTitle, bool isHide)
|
||||
{
|
||||
CHECK_NULL_VOID(nodeBase);
|
||||
auto barNode = GetBarNode(nodeBase, isTitle);
|
||||
CHECK_NULL_VOID(barNode);
|
||||
|
||||
auto propertyCallback = [weak = WeakClaim(this), barHeight, isTitle, isHide]() {
|
||||
auto pattern = weak.Upgrade();
|
||||
CHECK_NULL_VOID(pattern);
|
||||
auto nodeBase = AceType::DynamicCast<NavDestinationNodeBase>(pattern->GetHost());
|
||||
CHECK_NULL_VOID(nodeBase);
|
||||
auto barNode = pattern->GetBarNode(nodeBase, isTitle);
|
||||
CHECK_NULL_VOID(barNode);
|
||||
float translate = isHide ? (isTitle ? -barHeight : barHeight) : 0.0f;
|
||||
NavigationTitleUtil::UpdateTitleOrToolBarTranslateYAndOpacity(nodeBase, barNode, translate, isTitle);
|
||||
};
|
||||
auto finishCallback = [weak = WeakClaim(this), isTitle, isHide]() {
|
||||
auto pattern = weak.Upgrade();
|
||||
CHECK_NULL_VOID(pattern);
|
||||
auto nodeBase = AceType::DynamicCast<NavDestinationNodeBase>(pattern->GetHost());
|
||||
CHECK_NULL_VOID(nodeBase);
|
||||
auto barNode = pattern->GetBarNode(nodeBase, isTitle);
|
||||
CHECK_NULL_VOID(barNode);
|
||||
auto& ctx = pattern->GetSwipeContext(isTitle);
|
||||
if (isHide) {
|
||||
ctx.isBarHiding = false;
|
||||
} else {
|
||||
ctx.isBarShowing = false;
|
||||
}
|
||||
if (isHide) {
|
||||
pattern->PostShowBarDelayedTask(isTitle);
|
||||
}
|
||||
};
|
||||
AnimationOption option;
|
||||
option.SetCurve(TRANSLATE_CURVE);
|
||||
auto& ctx = GetSwipeContext(isTitle);
|
||||
if (isHide) {
|
||||
ctx.isBarHiding = true;
|
||||
} else {
|
||||
ctx.isBarShowing = true;
|
||||
}
|
||||
NavigationTitleUtil::UpdateTitleOrToolBarTranslateYAndOpacity(nodeBase, barNode, curTranslate, isTitle);
|
||||
AnimationUtils::Animate(option, propertyCallback, finishCallback);
|
||||
}
|
||||
|
||||
void NavDestinationPattern::StopHideBarIfNeeded(float curTranslate, bool isTitle)
|
||||
{
|
||||
auto& ctx = GetSwipeContext(isTitle);
|
||||
if (!ctx.isBarHiding) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto propertyCallback = [weak = WeakClaim(this), isTitle, curTranslate]() {
|
||||
auto pattern = weak.Upgrade();
|
||||
CHECK_NULL_VOID(pattern);
|
||||
auto nodeBase = AceType::DynamicCast<NavDestinationNodeBase>(pattern->GetHost());
|
||||
CHECK_NULL_VOID(nodeBase);
|
||||
auto barNode = pattern->GetBarNode(nodeBase, isTitle);
|
||||
CHECK_NULL_VOID(barNode);
|
||||
NavigationTitleUtil::UpdateTitleOrToolBarTranslateYAndOpacity(nodeBase, barNode, curTranslate, isTitle);
|
||||
};
|
||||
AnimationOption option;
|
||||
option.SetDuration(0);
|
||||
option.SetCurve(Curves::LINEAR);
|
||||
AnimationUtils::Animate(option, propertyCallback);
|
||||
ctx.isBarHiding = false;
|
||||
}
|
||||
|
||||
void NavDestinationPattern::PostShowBarDelayedTask(bool isTitle)
|
||||
{
|
||||
auto pipeline = GetContext();
|
||||
CHECK_NULL_VOID(pipeline);
|
||||
auto taskExecutor = pipeline->GetTaskExecutor();
|
||||
CHECK_NULL_VOID(taskExecutor);
|
||||
auto& ctx = GetSwipeContext(isTitle);
|
||||
if (ctx.showBarTask) {
|
||||
ctx.showBarTask.Cancel();
|
||||
}
|
||||
|
||||
ctx.showBarTask.Reset([weak = WeakClaim(this), isTitle]() {
|
||||
auto pattern = weak.Upgrade();
|
||||
CHECK_NULL_VOID(pattern);
|
||||
auto nodeBase = AceType::DynamicCast<NavDestinationNodeBase>(pattern->GetHost());
|
||||
CHECK_NULL_VOID(nodeBase);
|
||||
auto pipeline = nodeBase->GetContext();
|
||||
CHECK_NULL_VOID(pipeline);
|
||||
auto barNode = pattern->GetBarNode(nodeBase, isTitle);
|
||||
CHECK_NULL_VOID(barNode);
|
||||
float translate = 0.0f;
|
||||
float barHeight = 0.0f;
|
||||
if (!GetTitleOrToolBarTranslateAndHeight(barNode, translate, barHeight)) {
|
||||
return;
|
||||
}
|
||||
|
||||
pattern->StartHideOrShowBarInner(nodeBase, barHeight, translate, isTitle, false);
|
||||
pipeline->RequestFrame();
|
||||
});
|
||||
|
||||
taskExecutor->PostDelayedTask(ctx.showBarTask, TaskExecutor::TaskType::UI, TRANSLATE_DELAY,
|
||||
isTitle ? "ArkUINavDestinationShowTitleBar" : "ArkUINavDestinationShowToolBar");
|
||||
}
|
||||
|
||||
RefPtr<FrameNode> NavDestinationPattern::GetBarNode(const RefPtr<NavDestinationNodeBase>& nodeBase, bool isTitle)
|
||||
{
|
||||
CHECK_NULL_RETURN(nodeBase, nullptr);
|
||||
return isTitle ? AceType::DynamicCast<FrameNode>(nodeBase->GetTitleBarNode())
|
||||
: AceType::DynamicCast<FrameNode>(nodeBase->GetToolBarNode());
|
||||
}
|
||||
} // namespace OHOS::Ace::NG
|
||||
|
@ -29,7 +29,6 @@
|
||||
#include "core/components_ng/pattern/navrouter/navdestination_group_node.h"
|
||||
#include "core/components_ng/pattern/navrouter/navdestination_layout_algorithm.h"
|
||||
#include "core/components_ng/pattern/navrouter/navdestination_layout_property.h"
|
||||
#include "core/components_ng/pattern/navrouter/navdestination_scrollable_processor.h"
|
||||
#include "core/components_ng/pattern/pattern.h"
|
||||
#include "core/components_ng/syntax/shallow_builder.h"
|
||||
#include "core/components_v2/inspector/inspector_constants.h"
|
||||
@ -244,49 +243,7 @@ public:
|
||||
return isHideTitlebar_ ? 0.0_vp : SINGLE_LINE_TITLEBAR_HEIGHT;
|
||||
}
|
||||
|
||||
const RefPtr<NavDestinationScrollableProcessor>& GetScrollableProcessor() const
|
||||
{
|
||||
return scrollableProcessor_;
|
||||
}
|
||||
void SetScrollableProcessor(const RefPtr<NavDestinationScrollableProcessor>& processor)
|
||||
{
|
||||
scrollableProcessor_ = processor;
|
||||
}
|
||||
/**
|
||||
* Respond to the scrolling events of the internal scrolling components of NavDestination,
|
||||
* and hide part of the titleBar&toolBar( translate up or down in Y axis ), while changing
|
||||
* the opacity of the titleBar&toolBar.
|
||||
*/
|
||||
void UpdateTitleAndToolBarHiddenOffset(float offset);
|
||||
// show titleBar&toolBar immediately.
|
||||
void ShowTitleAndToolBar();
|
||||
// cancel the delayed task if we have started, which will show titleBar&toolBar in the feature time.
|
||||
void CancelShowTitleAndToolBarTask();
|
||||
// Restore the titleBar&toolBar to its original position (hide or show state).
|
||||
void ResetTitleAndToolBarState();
|
||||
|
||||
private:
|
||||
struct HideBarOnSwipeContext {
|
||||
CancelableCallback<void()> showBarTask;
|
||||
bool isBarShowing = false;
|
||||
bool isBarHiding = false;
|
||||
};
|
||||
HideBarOnSwipeContext& GetSwipeContext(bool isTitle)
|
||||
{
|
||||
return isTitle ? titleBarSwipeContext_ : toolBarSwipeContext_;
|
||||
}
|
||||
RefPtr<FrameNode> GetBarNode(const RefPtr<NavDestinationNodeBase>& nodeBase, bool isTitle);
|
||||
bool EnableTitleBarSwipe(const RefPtr<NavDestinationNodeBase>& nodeBase);
|
||||
bool EnableToolBarSwipe(const RefPtr<NavDestinationNodeBase>& nodeBase);
|
||||
void UpdateBarHiddenOffset(const RefPtr<NavDestinationNodeBase>& nodeBase,
|
||||
const RefPtr<FrameNode>& barNode, float offset, bool isTitle);
|
||||
void StartHideOrShowBarInner(const RefPtr<NavDestinationNodeBase>& nodeBase,
|
||||
float barHeight, float curTranslate, bool isTitle, bool isHide);
|
||||
void StopHideBarIfNeeded(float curTranslate, bool isTitle);
|
||||
void PostShowBarDelayedTask(bool isTitle);
|
||||
void ResetBarState(const RefPtr<NavDestinationNodeBase>& nodeBase,
|
||||
const RefPtr<FrameNode>& barNode, bool isTitle);
|
||||
|
||||
void UpdateNameIfNeeded(RefPtr<NavDestinationGroupNode>& hostNode);
|
||||
void UpdateBackgroundColorIfNeeded(RefPtr<NavDestinationGroupNode>& hostNode);
|
||||
void MountTitleBar(
|
||||
@ -311,10 +268,6 @@ private:
|
||||
|
||||
std::optional<RefPtr<SystemBarStyle>> backupStyle_;
|
||||
std::optional<RefPtr<SystemBarStyle>> currStyle_;
|
||||
|
||||
RefPtr<NavDestinationScrollableProcessor> scrollableProcessor_;
|
||||
HideBarOnSwipeContext titleBarSwipeContext_;
|
||||
HideBarOnSwipeContext toolBarSwipeContext_;
|
||||
};
|
||||
} // namespace OHOS::Ace::NG
|
||||
|
||||
|
@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_NAVROUTER_NAVDESTINATION_SCROLLABLE_PROCESSOR_H
|
||||
#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_NAVROUTER_NAVDESTINATION_SCROLLABLE_PROCESSOR_H
|
||||
|
||||
#include "frameworks/base/memory/ace_type.h"
|
||||
|
||||
namespace OHOS::Ace::NG {
|
||||
class NavDestinationPattern;
|
||||
|
||||
class NavDestinationScrollableProcessor : public AceType {
|
||||
DECLARE_ACE_TYPE(NavDestinationScrollableProcessor, AceType);
|
||||
|
||||
public:
|
||||
NavDestinationScrollableProcessor() = default;
|
||||
~NavDestinationScrollableProcessor() override = default;
|
||||
|
||||
virtual void UpdateBindingRelation() = 0;
|
||||
virtual void SetNodeId(int32_t id) = 0;
|
||||
virtual void SetNavDestinationPattern(WeakPtr<NavDestinationPattern> pattern) = 0;
|
||||
virtual void UnbindAllScrollers() = 0;
|
||||
};
|
||||
} // namespace OHOS::Ace::NG
|
||||
|
||||
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_NAVROUTER_NAVDESTINATION_SCROLLABLE_PROCESSOR_H
|
@ -2582,15 +2582,11 @@ void ScrollablePattern::FireOnScroll(float finalOffset, OnScrollEvent& onScroll)
|
||||
void ScrollablePattern::FireObserverOnTouch(const TouchEventInfo& info)
|
||||
{
|
||||
CHECK_NULL_VOID(positionController_);
|
||||
auto touchInfo = info;
|
||||
auto observer = positionController_->GetObserver();
|
||||
if (observer.onTouchEvent) {
|
||||
auto touchInfo = info;
|
||||
(*observer.onTouchEvent)(touchInfo);
|
||||
}
|
||||
auto obsMgr = positionController_->GetObserverManager();
|
||||
if (obsMgr) {
|
||||
obsMgr->HandleOnTouchEvent(touchInfo);
|
||||
}
|
||||
}
|
||||
|
||||
void ScrollablePattern::FireObserverOnReachStart()
|
||||
@ -2600,10 +2596,6 @@ void ScrollablePattern::FireObserverOnReachStart()
|
||||
if (observer.onReachStartEvent) {
|
||||
observer.onReachStartEvent();
|
||||
}
|
||||
auto obsMgr = positionController_->GetObserverManager();
|
||||
if (obsMgr) {
|
||||
obsMgr->HandleOnReachEvent(false);
|
||||
}
|
||||
}
|
||||
|
||||
void ScrollablePattern::FireObserverOnReachEnd()
|
||||
@ -2613,10 +2605,6 @@ void ScrollablePattern::FireObserverOnReachEnd()
|
||||
if (observer.onReachEndEvent) {
|
||||
observer.onReachEndEvent();
|
||||
}
|
||||
auto obsMgr = positionController_->GetObserverManager();
|
||||
if (obsMgr) {
|
||||
obsMgr->HandleOnReachEvent(true);
|
||||
}
|
||||
}
|
||||
|
||||
void ScrollablePattern::FireObserverOnScrollStart()
|
||||
@ -2626,10 +2614,6 @@ void ScrollablePattern::FireObserverOnScrollStart()
|
||||
if (observer.onScrollStartEvent) {
|
||||
observer.onScrollStartEvent();
|
||||
}
|
||||
auto obsMgr = positionController_->GetObserverManager();
|
||||
if (obsMgr) {
|
||||
obsMgr->HandleOnScrollStartEvent();
|
||||
}
|
||||
}
|
||||
|
||||
void ScrollablePattern::FireObserverOnScrollStop()
|
||||
@ -2639,10 +2623,6 @@ void ScrollablePattern::FireObserverOnScrollStop()
|
||||
if (observer.onScrollStopEvent) {
|
||||
observer.onScrollStopEvent();
|
||||
}
|
||||
auto obsMgr = positionController_->GetObserverManager();
|
||||
if (obsMgr) {
|
||||
obsMgr->HandleOnScrollStopEvent();
|
||||
}
|
||||
}
|
||||
|
||||
void ScrollablePattern::FireObserverOnDidScroll(float finalOffset)
|
||||
@ -2650,16 +2630,10 @@ void ScrollablePattern::FireObserverOnDidScroll(float finalOffset)
|
||||
OnScrollEvent onScroll = [weak = WeakClaim(this)](Dimension dimension, ScrollState state) {
|
||||
auto pattern = weak.Upgrade();
|
||||
CHECK_NULL_VOID(pattern && pattern->positionController_);
|
||||
auto source = pattern->ConvertScrollSource(pattern->scrollSource_);
|
||||
bool isAtTop = pattern->IsAtTop();
|
||||
bool isAtBottom = pattern->IsAtBottom();
|
||||
auto observer = pattern->positionController_->GetObserver();
|
||||
if (observer.onDidScrollEvent) {
|
||||
observer.onDidScrollEvent(dimension, source, isAtTop, isAtBottom);
|
||||
}
|
||||
auto obsMgr = pattern->positionController_->GetObserverManager();
|
||||
if (obsMgr) {
|
||||
obsMgr->HandleOnDidScrollEvent(dimension, source, isAtTop, isAtBottom);
|
||||
observer.onDidScrollEvent(dimension, pattern->ConvertScrollSource(pattern->scrollSource_),
|
||||
pattern->IsAtTop(), pattern->IsAtBottom());
|
||||
}
|
||||
};
|
||||
FireOnScroll(finalOffset, onScroll);
|
||||
|
@ -1,83 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "core/components_ng/pattern/scrollable/scroller_observer_manager.h"
|
||||
|
||||
namespace OHOS::Ace {
|
||||
void ScrollerObserverManager::AddObserver(const ScrollerObserver& obs, int32_t id)
|
||||
{
|
||||
observers_.emplace(id, obs);
|
||||
}
|
||||
|
||||
void ScrollerObserverManager::RemoveObserver(int32_t id)
|
||||
{
|
||||
auto it = observers_.find(id);
|
||||
if (it != observers_.end()) {
|
||||
observers_.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
void ScrollerObserverManager::HandleOnTouchEvent(TouchEventInfo& info)
|
||||
{
|
||||
for (const auto& pair : observers_) {
|
||||
if (pair.second.onTouchEvent) {
|
||||
(*pair.second.onTouchEvent)(info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ScrollerObserverManager::HandleOnReachEvent(bool end)
|
||||
{
|
||||
for (const auto& pair : observers_) {
|
||||
if (end) {
|
||||
if (pair.second.onReachEndEvent) {
|
||||
pair.second.onReachEndEvent();
|
||||
}
|
||||
} else {
|
||||
if (pair.second.onReachStartEvent) {
|
||||
pair.second.onReachStartEvent();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ScrollerObserverManager::HandleOnScrollStartEvent()
|
||||
{
|
||||
for (const auto& pair : observers_) {
|
||||
if (pair.second.onScrollStartEvent) {
|
||||
pair.second.onScrollStartEvent();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ScrollerObserverManager::HandleOnScrollStopEvent()
|
||||
{
|
||||
for (const auto& pair : observers_) {
|
||||
if (pair.second.onScrollStopEvent) {
|
||||
pair.second.onScrollStopEvent();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ScrollerObserverManager::HandleOnDidScrollEvent(
|
||||
Dimension dimension, ScrollSource source, bool isAtTop, bool isAtBottom)
|
||||
{
|
||||
for (const auto& pair : observers_) {
|
||||
if (pair.second.onDidScrollEvent) {
|
||||
pair.second.onDidScrollEvent(dimension, source, isAtTop, isAtBottom);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace OHOS::Ace::NG
|
@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SCROLLABLE_SCROLLER_OBSERVER_MANAGER_H
|
||||
#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SCROLLABLE_SCROLLER_OBSERVER_MANAGER_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "base/memory/referenced.h"
|
||||
#include "core/components_ng/pattern/scrollable/scrollable_properties.h"
|
||||
|
||||
namespace OHOS::Ace {
|
||||
class ScrollerObserverManager : public Referenced {
|
||||
public:
|
||||
ScrollerObserverManager() = default;
|
||||
~ScrollerObserverManager() = default;
|
||||
|
||||
void AddObserver(const ScrollerObserver& obs, int32_t id);
|
||||
void RemoveObserver(int32_t id);
|
||||
|
||||
void HandleOnTouchEvent(TouchEventInfo& info);
|
||||
void HandleOnReachEvent(bool end);
|
||||
void HandleOnScrollStartEvent();
|
||||
void HandleOnScrollStopEvent();
|
||||
void HandleOnDidScrollEvent(Dimension dimension, ScrollSource source, bool isAtTop, bool isAtBottom);
|
||||
|
||||
private:
|
||||
std::unordered_map<int32_t, ScrollerObserver> observers_;
|
||||
};
|
||||
} // namespace OHOS::Ace
|
||||
|
||||
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SCROLLABLE_SCROLLER_OBSERVER_MANAGER_H
|
@ -958,7 +958,6 @@ ohos_source_set("ace_components_pattern") {
|
||||
"$ace_root/frameworks/core/components_ng/pattern/scrollable/scrollable_paint_property.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/pattern/scrollable/scrollable_pattern.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/pattern/scrollable/scrollable_utils.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/pattern/scrollable/scroller_observer_manager.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/pattern/search/search_event_hub.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/pattern/search/search_gesture_event_hub.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/pattern/search/search_layout_algorithm.cpp",
|
||||
|
@ -407,7 +407,6 @@ ohos_unittest("web_pattern_unit_test_ohos") {
|
||||
"$ace_root/frameworks/core/components_ng/pattern/scrollable/scrollable_paint_property.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/pattern/scrollable/scrollable_pattern.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/pattern/scrollable/scrollable_utils.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/pattern/scrollable/scroller_observer_manager.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/pattern/search/search_event_hub.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/pattern/search/search_gesture_event_hub.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/pattern/search/search_layout_algorithm.cpp",
|
||||
|
Loading…
Reference in New Issue
Block a user