mirror of
https://github.com/openharmony/ace_ace_engine.git
synced 2026-07-25 22:05:46 -04:00
fix the problem of grids and scroller
Signed-off-by: yan-shuifeng <yanshuifeng@huawei.com> Change-Id: I3a84caede0bf41aa85efc97e5cd3f9c0c6920ab6
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2022 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
|
||||
@@ -15,11 +15,10 @@
|
||||
|
||||
#include "bridge/declarative_frontend/jsview/js_scroller.h"
|
||||
|
||||
#include "bridge/declarative_frontend/jsview/js_view_common_def.h"
|
||||
|
||||
#include "base/geometry/axis.h"
|
||||
#include "base/utils/linear_map.h"
|
||||
#include "base/utils/utils.h"
|
||||
#include "bridge/declarative_frontend/jsview/js_view_common_def.h"
|
||||
#include "core/animation/curves.h"
|
||||
#include "core/components/common/layout/align_declaration.h"
|
||||
|
||||
@@ -39,15 +38,9 @@ constexpr AlignDeclaration::Edge EDGE_TABLE[] = {
|
||||
};
|
||||
|
||||
// corresponding to EDGE_TABLE[]
|
||||
constexpr ScrollEdgeType EDGE_TYPE_TABLE[] = {
|
||||
ScrollEdgeType::SCROLL_TOP,
|
||||
ScrollEdgeType::SCROLL_NONE,
|
||||
ScrollEdgeType::SCROLL_BOTTOM,
|
||||
ScrollEdgeType::SCROLL_NONE,
|
||||
ScrollEdgeType::SCROLL_TOP,
|
||||
ScrollEdgeType::SCROLL_NONE,
|
||||
ScrollEdgeType::SCROLL_BOTTOM
|
||||
};
|
||||
constexpr ScrollEdgeType EDGE_TYPE_TABLE[] = { ScrollEdgeType::SCROLL_TOP, ScrollEdgeType::SCROLL_NONE,
|
||||
ScrollEdgeType::SCROLL_BOTTOM, ScrollEdgeType::SCROLL_NONE, ScrollEdgeType::SCROLL_TOP, ScrollEdgeType::SCROLL_NONE,
|
||||
ScrollEdgeType::SCROLL_BOTTOM };
|
||||
|
||||
const LinearMapNode<RefPtr<Curve>> CURVE_MAP[] = {
|
||||
{ "ease", Curves::EASE },
|
||||
@@ -122,6 +115,10 @@ void JSScroller::ScrollTo(const JSCallbackInfo& args)
|
||||
} else {
|
||||
LOGD("ScrollTo(%lf, %lf)", xOffset.Value(), yOffset.Value());
|
||||
}
|
||||
if (!controller_) {
|
||||
LOGE("controller_ is nullptr");
|
||||
return;
|
||||
}
|
||||
auto direction = controller_->GetScrollDirection();
|
||||
auto position = direction == Axis::VERTICAL ? yOffset : xOffset;
|
||||
controller_->AnimateTo(position, duration, curve);
|
||||
@@ -134,8 +131,11 @@ void JSScroller::ScrollEdge(const JSCallbackInfo& args)
|
||||
LOGW("Invalid params");
|
||||
return;
|
||||
}
|
||||
|
||||
LOGD("ScrollEdge(%d)", static_cast<int32_t>(edge));
|
||||
if (!controller_) {
|
||||
LOGE("controller_ is nullptr");
|
||||
return;
|
||||
}
|
||||
LOGD("ScrollEdge(%{public}d)", static_cast<int32_t>(edge));
|
||||
ScrollEdgeType edgeType = EDGE_TYPE_TABLE[static_cast<int32_t>(edge)];
|
||||
controller_->ScrollToEdge(edgeType, true);
|
||||
}
|
||||
@@ -147,6 +147,10 @@ void JSScroller::ScrollToIndex(const JSCallbackInfo& args)
|
||||
LOGW("Invalid params");
|
||||
return;
|
||||
}
|
||||
if (!controller_) {
|
||||
LOGE("controller_ is nullptr");
|
||||
return;
|
||||
}
|
||||
controller_->JumpTo(index, SCROLL_FROM_JUMP);
|
||||
}
|
||||
|
||||
@@ -166,15 +170,21 @@ void JSScroller::ScrollPage(const JSCallbackInfo& args)
|
||||
|
||||
Axis direction = Axis::NONE;
|
||||
ConvertFromJSValue(obj->GetProperty("direction"), DIRECTION_TABLE, direction);
|
||||
|
||||
LOGD("ScrollPage(%s, %d)", next ? "true" : "false", static_cast<int32_t>(direction));
|
||||
if (!controller_) {
|
||||
LOGE("controller_ is nullptr");
|
||||
return;
|
||||
}
|
||||
LOGD("ScrollPage(%{public}s, %{public}d)", next ? "true" : "false", static_cast<int32_t>(direction));
|
||||
controller_->ScrollPage(!next, true);
|
||||
}
|
||||
|
||||
void JSScroller::CurrentOffset(const JSCallbackInfo& args)
|
||||
{
|
||||
LOGD("CurrentOffset()");
|
||||
|
||||
if (!controller_) {
|
||||
LOGE("controller_ is nullptr");
|
||||
return;
|
||||
}
|
||||
auto retObj = JSRef<JSObject>::New();
|
||||
auto offset = controller_->GetCurrentOffset();
|
||||
retObj->SetProperty("xOffset", offset.GetX());
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef FOUNDATION_ACE_FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_COMPONENTS_FOR_EACH_COMPONENT_H
|
||||
#define FOUNDATION_ACE_FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_COMPONENTS_FOR_EACH_COMPONENT_H
|
||||
|
||||
|
||||
@@ -24,11 +24,6 @@
|
||||
|
||||
namespace OHOS::Ace {
|
||||
|
||||
RefPtr<RenderNode> GridLayoutElement::CreateRenderNode()
|
||||
{
|
||||
return ComponentGroupElement::CreateRenderNode();
|
||||
}
|
||||
|
||||
void GridLayoutElement::Update()
|
||||
{
|
||||
ComponentGroupElement::Update();
|
||||
@@ -45,7 +40,7 @@ bool GridLayoutElement::RequestNextFocus(bool vertical, bool reverse, const Rect
|
||||
bool ret = false;
|
||||
while (!ret) {
|
||||
int32_t focusIndex = grid->RequestNextFocus(vertical, reverse);
|
||||
int32_t size = GetChildrenList().size();
|
||||
auto size = static_cast<int32_t>(GetChildrenList().size());
|
||||
if (focusIndex < 0 || focusIndex >= size) {
|
||||
return false;
|
||||
}
|
||||
@@ -74,7 +69,17 @@ void GridLayoutElement::ApplyRenderChild(const RefPtr<RenderElement>& renderChil
|
||||
return;
|
||||
}
|
||||
|
||||
auto context = context_.Upgrade();
|
||||
if (context && context->GetIsDeclarative()) {
|
||||
ComponentGroupElement::ApplyRenderChild(renderChild);
|
||||
return;
|
||||
}
|
||||
|
||||
auto proxy = RenderItemProxy::Create();
|
||||
if (!proxy) {
|
||||
LOGE("fail to create proxy node");
|
||||
return;
|
||||
}
|
||||
proxy->AddChild(renderChild->GetRenderNode());
|
||||
proxy->Attach(context_);
|
||||
renderNode_->AddChild(proxy);
|
||||
@@ -82,8 +87,6 @@ void GridLayoutElement::ApplyRenderChild(const RefPtr<RenderElement>& renderChil
|
||||
|
||||
void GridLayoutElement::PerformBuild()
|
||||
{
|
||||
children_.clear();
|
||||
renderNode_->ClearChildren();
|
||||
ComponentGroupElement::PerformBuild();
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,6 @@ public:
|
||||
void PerformBuild() override;
|
||||
|
||||
private:
|
||||
RefPtr<RenderNode> CreateRenderNode() override;
|
||||
void ApplyRenderChild(const RefPtr<RenderElement>& renderChild) override;
|
||||
};
|
||||
|
||||
|
||||
@@ -73,11 +73,6 @@ const std::map<bool, std::map<bool, std::map<bool, KeyDirection>>> DIRECTION_MAP
|
||||
|
||||
} // namespace
|
||||
|
||||
void RenderGridLayout::OnChildAdded(const RefPtr<RenderNode>& renderNode)
|
||||
{
|
||||
RenderNode::OnChildAdded(renderNode);
|
||||
}
|
||||
|
||||
void RenderGridLayout::Update(const RefPtr<Component>& component)
|
||||
{
|
||||
const RefPtr<GridLayoutComponent> grid = AceType::DynamicCast<GridLayoutComponent>(component);
|
||||
@@ -837,6 +832,7 @@ void RenderGridLayout::PerformLayout()
|
||||
needRestoreScene_ = false;
|
||||
isDragChangeLayout_ = false;
|
||||
gridMatrix_.clear();
|
||||
itemsInGrid_.clear();
|
||||
if (GetChildren().empty()) {
|
||||
return;
|
||||
}
|
||||
@@ -909,10 +905,10 @@ void RenderGridLayout::BackGridMatrix()
|
||||
gridItemPosition_.clear();
|
||||
std::map<int32_t, GridItemIndexPosition> backData;
|
||||
ParseRestoreScenePosition(gridMatrixBack_, backData);
|
||||
for (auto iter = backData.begin(); iter != backData.end(); iter++) {
|
||||
if (iter->first >= 0 && iter->first < (int32_t)itemsInGrid_.size()) {
|
||||
auto item = itemsInGrid_[iter->first];
|
||||
gridItemPosition_[iter->first] = Point(item->GetPosition().GetX(), item->GetPosition().GetY());
|
||||
for (auto& iter : backData) {
|
||||
if (iter.first >= 0 && iter.first < (int32_t)itemsInGrid_.size()) {
|
||||
auto item = itemsInGrid_[iter.first];
|
||||
gridItemPosition_[iter.first] = Point(item->GetPosition().GetX(), item->GetPosition().GetY());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1693,6 +1689,11 @@ void RenderGridLayout::PerformLayoutForEditGrid()
|
||||
LOGD("%{public}d %{public}d %{public}d %{public}d", rowIndex, colIndex, itemRowSpan, itemColSpan);
|
||||
}
|
||||
}
|
||||
auto hiddenItem = dragingItemRenderNode_.Upgrade();
|
||||
if (hiddenItem) {
|
||||
hiddenItem->SetVisible(false);
|
||||
DisableChild(hiddenItem, dragingItemIndex_);
|
||||
}
|
||||
}
|
||||
|
||||
void RenderGridLayout::PerformLayoutForStaticGrid()
|
||||
|
||||
@@ -126,8 +126,6 @@ class RenderGridLayout : public RenderNode {
|
||||
public:
|
||||
static RefPtr<RenderNode> Create();
|
||||
|
||||
void OnChildAdded(const RefPtr<RenderNode>& renderNode) override;
|
||||
|
||||
void Update(const RefPtr<Component>& component) override;
|
||||
|
||||
void PerformLayout() override;
|
||||
@@ -248,7 +246,7 @@ protected:
|
||||
|
||||
const RefPtr<RenderGridLayout> GetPreTargetRenderGrid() const
|
||||
{
|
||||
return preTargetRenderGrid_;
|
||||
return preTargetRenderGrid_.Upgrade();
|
||||
}
|
||||
|
||||
void SetMainTargetRenderGrid(const RefPtr<RenderGridLayout>& mainTargetRenderGrid)
|
||||
@@ -258,7 +256,7 @@ protected:
|
||||
|
||||
const RefPtr<RenderGridLayout> GetMainTargetRenderGrid() const
|
||||
{
|
||||
return mainTargetRenderGrid_;
|
||||
return mainTargetRenderGrid_.Upgrade();
|
||||
}
|
||||
|
||||
void SetLongPressPoint(const Point& lastLongPressPoint)
|
||||
@@ -437,8 +435,8 @@ protected:
|
||||
std::map<int32_t, std::map<int32_t, Size>> gridCells_;
|
||||
|
||||
RefPtr<GestureRecognizer> dragDropGesture_;
|
||||
RefPtr<RenderGridLayout> preTargetRenderGrid_ = nullptr;
|
||||
RefPtr<RenderGridLayout> mainTargetRenderGrid_ = nullptr;
|
||||
WeakPtr<RenderGridLayout> preTargetRenderGrid_ = nullptr;
|
||||
WeakPtr<RenderGridLayout> mainTargetRenderGrid_ = nullptr;
|
||||
|
||||
// The list of renderNodes of items in the grid
|
||||
std::vector<RefPtr<RenderNode>> itemsInGrid_;
|
||||
|
||||
@@ -92,6 +92,7 @@ void TabController::SetPendingIndex(int32_t index)
|
||||
return;
|
||||
}
|
||||
pendingIndex_ = index;
|
||||
indexDefined_ = false;
|
||||
}
|
||||
|
||||
void TabController::SetIndexByController(int32_t index, bool blockEvent)
|
||||
@@ -103,7 +104,6 @@ void TabController::SetIndexByController(int32_t index, bool blockEvent)
|
||||
if (index >= totalCount_) {
|
||||
LOGI("index is large than total, %{public}d, %{public}d", index, totalCount_);
|
||||
SetPendingIndex(index);
|
||||
indexDefined_ = false;
|
||||
return;
|
||||
}
|
||||
indexDefined_ = true;
|
||||
|
||||
@@ -161,6 +161,7 @@ void RenderNode::RemoveChild(const RefPtr<RenderNode>& child)
|
||||
children_.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
OnChildRemoved(child);
|
||||
disappearingNodes_.remove(child);
|
||||
// check whether child has config transition or will cause child memory leak.
|
||||
|
||||
Reference in New Issue
Block a user