提交 1e8e7096 编写于 作者: S shiqichang

Description:Slide right to return, and the list interface will move

issuesno:https://gitee.com/openharmony/graphic_ui/issues/I5SG6N
Feature or Bugfix: Feature
Binary Source:No
Signed-off-by: Nshiqichang <shiqichang@huawei.com>
Change-Id: I7b773b3db8361818019ec6639a96880b896e1dc3

Change-Id: I286e59b7c6b29e570273810b8318c7532ccd2ff3
上级 d982a7ca
......@@ -150,6 +150,7 @@ lite_library("ui") {
"frameworks/components/ui_texture_mapper.cpp",
"frameworks/components/ui_time_picker.cpp",
"frameworks/components/ui_toggle_button.cpp",
"frameworks/components/ui_tree_manager.cpp",
"frameworks/components/ui_view.cpp",
"frameworks/components/ui_view_group.cpp",
"frameworks/core/input_method_manager.cpp",
......
......@@ -15,6 +15,7 @@
#include "common/input_device_manager.h"
#include "common/task_manager.h"
#include "components/ui_tree_manager.h"
#include "gfx_utils/graphic_log.h"
namespace OHOS {
......@@ -26,6 +27,7 @@ InputDeviceManager* InputDeviceManager::GetInstance()
void InputDeviceManager::Init()
{
UITreeManager::GetInstance().RegistViewLifeEvent(OnViewLifeEvent);
if (INDEV_READ_PERIOD > 0) {
SetPeriod(INDEV_READ_PERIOD);
TaskManager::GetInstance()->Add(this);
......@@ -69,4 +71,15 @@ void InputDeviceManager::Clear()
{
deviceList_.Clear();
}
void InputDeviceManager::OnViewLifeEvent()
{
auto& devices = GetInstance()->deviceList_;
auto node = devices.Begin();
while (node != devices.End()) {
node->data_->OnViewLifeEvent();
node = node->next_;
}
}
} // namespace OHOS
/*
* Copyright (c) 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
*
* 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 "components/ui_tree_manager.h"
namespace OHOS {
UITreeManager& UITreeManager::GetInstance()
{
static UITreeManager manager;
return manager;
}
void UITreeManager::RegistViewLifeEvent(ViewFunc* func)
{
auto p = lifeEvents_.Begin();
if (func == nullptr) {
return;
}
while (p != lifeEvents_.End()) {
if (p->data_ == func) {
return;
}
p = p->next_;
}
lifeEvents_.PushBack(func);
}
void UITreeManager::UnregistViewLifeEvent(ViewFunc* func)
{
auto p = lifeEvents_.Begin();
while (p != lifeEvents_.End()) {
if (p->data_ == func) {
lifeEvents_.Remove(p);
return;
}
p = p->next_;
}
}
void UITreeManager::GetLastEvent(UIView*& view, ViewLifeEvent& event)
{
view = lastEventView_;
event = lastEvent_;
}
void UITreeManager::OnLifeEvent(UIView* view, ViewLifeEvent event)
{
lastEventView_ = view;
lastEvent_ = event;
auto p = lifeEvents_.Begin();
while (p != lifeEvents_.End()) {
p->data_();
p = p->next_;
}
}
} // namespace OHOS
/*
* Copyright (c) 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
*
* 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 GRAPHIC_LITE_UI_TREE_MANAGER_H
#define GRAPHIC_LITE_UI_TREE_MANAGER_H
#include "components/ui_view.h"
#include "gfx_utils/list.h"
namespace OHOS {
class UITreeManager final : public HeapBase {
public:
static UITreeManager &GetInstance();
enum ViewLifeEvent {
ADD,
REMOVE
};
using ViewFunc = void();
void RegistViewLifeEvent(ViewFunc* func);
void UnregistViewLifeEvent(ViewFunc* func);
void GetLastEvent(UIView*& view, ViewLifeEvent& event);
void OnLifeEvent(UIView*, ViewLifeEvent);
private:
List<ViewFunc*> lifeEvents_;
UIView* lastEventView_;
ViewLifeEvent lastEvent_;
};
} // namespace OHOS
#endif
......@@ -18,6 +18,7 @@
#include <cstring>
#include "components/root_view.h"
#include "components/ui_tree_manager.h"
#include "gfx_utils/graphic_log.h"
namespace OHOS {
......@@ -112,6 +113,7 @@ void UIViewGroup::Remove(UIView* view)
if ((childrenHead_ == nullptr) || (view == nullptr)) {
return;
}
UITreeManager::GetInstance().OnLifeEvent(view, UITreeManager::REMOVE);
#if LOCAL_RENDER
RootView::GetInstance()->RemoveViewFromInvalidMap(view);
......@@ -157,6 +159,7 @@ void UIViewGroup::RemoveAll()
UIView* tmp = nullptr;
while (node != nullptr) {
tmp = node;
UITreeManager::GetInstance().OnLifeEvent(node, UITreeManager::REMOVE);
node = node->GetNextSibling();
tmp->SetParent(nullptr);
tmp->SetNextSibling(nullptr);
......
......@@ -45,6 +45,8 @@ public:
constexpr static uint8_t STATE_RELEASE = 0;
constexpr static uint8_t STATE_PRESS = 1;
virtual void OnViewLifeEvent() {}
protected:
uint16_t rawDataState_;
......
......@@ -16,6 +16,7 @@
#include "dock/pointer_input_device.h"
#include "components/root_view.h"
#include "components/ui_tree_manager.h"
#include "core/render_manager.h"
#if ENABLE_AOD
#include "events/aod_callback.h"
......@@ -45,19 +46,6 @@ void PointerInputDevice::DispatchEvent(const DeviceData& data)
GRAPHIC_LOGE("No valid rootview to dispatch input event!\n");
return;
}
// invalid touchable and draggable view will be reset to nullptr
if ((touchableView_ != nullptr) && !RootView::FindSubView(*rootView, touchableView_)) {
touchableView_ = nullptr;
lastPos_ = curPos_;
}
if ((draggableView_ != nullptr) && !RootView::FindSubView(*rootView, draggableView_)) {
draggableView_ = nullptr;
lastPos_ = curPos_;
dragLastPos_ = curPos_;
dragLen_ = { 0, 0 };
dragStep_ = { 0, 0 };
isDragging_ = false;
}
if (data.state == STATE_PRESS) {
DispatchPressEvent(rootView);
......@@ -267,8 +255,8 @@ void PointerInputDevice::DispatchDragEndEvent()
OnDragEndEventHappen(*draggableView_);
#endif
}
dragLen_ = { 0, 0 };
dragStep_ = { 0, 0 };
dragLen_ = {0, 0};
dragStep_ = {0, 0};
draggableView_ = nullptr;
}
......@@ -319,4 +307,36 @@ void PointerInputDevice::DispatchCancelEvent()
}
cancelSent_ = true;
}
void PointerInputDevice::UpdateEventViews(UIView* view)
{
// view should not be nullptr
// invalid touchable and draggable view will be reset to nullptr
if ((touchableView_ != nullptr) && RootView::FindSubView(*view, touchableView_)) {
touchableView_ = nullptr;
lastPos_ = curPos_;
}
if ((draggableView_ != nullptr) && RootView::FindSubView(*view, draggableView_)) {
draggableView_ = nullptr;
lastPos_ = curPos_;
dragLastPos_ = curPos_;
dragLen_ = {0, 0};
dragStep_ = {0, 0};
isDragging_ = false;
}
}
void PointerInputDevice::OnViewLifeEvent()
{
UIView* view;
UITreeManager::ViewLifeEvent event;
UITreeManager::GetInstance().GetLastEvent(view, event);
if ((event != UITreeManager::REMOVE) || (view == nullptr)) {
return;
}
UpdateEventViews(view);
}
} // namespace OHOS
......@@ -34,6 +34,7 @@ public:
protected:
void DispatchEvent(const DeviceData& data) override;
void OnViewLifeEvent() override;
private:
UIView* touchableView_;
......@@ -60,6 +61,7 @@ private:
void DispatchLongPressEvent(uint32_t elapse);
void DispatchCancelEvent();
bool ProcessReleaseEvent();
void UpdateEventViews(UIView* view);
UIView* GetDraggableView(UIView* targetView) const
{
UIView* tempView = targetView;
......
......@@ -16,9 +16,9 @@
#ifndef GRAPHIC_LITE_INPUT_DEVICE_MANAGER_H
#define GRAPHIC_LITE_INPUT_DEVICE_MANAGER_H
#include "common/task.h"
#include "dock/input_device.h"
#include "gfx_utils/list.h"
#include "common/task.h"
namespace OHOS {
/**
......@@ -64,6 +64,8 @@ private:
InputDeviceManager(InputDeviceManager&&) = delete;
InputDeviceManager& operator=(InputDeviceManager&&) = delete;
static void OnViewLifeEvent();
List<InputDevice*> deviceList_;
};
} // namespace OHOS
......
......@@ -78,6 +78,7 @@ SOURCES += \
../../../../frameworks/components/ui_arc_scroll_bar.cpp \
../../../../frameworks/components/ui_axis.cpp \
../../../../frameworks/components/ui_box_progress.cpp \
../../../../frameworks/components/ui_tree_manager.cpp \
../../../../frameworks/components/ui_box_scroll_bar.cpp \
../../../../frameworks/components/ui_button.cpp \
../../../../frameworks/components/ui_canvas.cpp \
......@@ -217,6 +218,7 @@ HEADERS += \
../../../../frameworks/default_resource/check_box_res.h \
../../../../frameworks/dfx/key_event_injector.h \
../../../../frameworks/dfx/point_event_injector.h \
../../../../frameworks/components/ui_tree_manager.h \
../../../../frameworks/dfx/ui_view_bounds.h \
../../../../frameworks/dock/input_device.h \
../../../../frameworks/dock/pointer_input_device.h \
......
......@@ -66,6 +66,7 @@ graphic_ui_sources = [
"$GRAPHIC_UI_PATH/frameworks/components/ui_texture_mapper.cpp",
"$GRAPHIC_UI_PATH/frameworks/components/ui_time_picker.cpp",
"$GRAPHIC_UI_PATH/frameworks/components/ui_toggle_button.cpp",
"$GRAPHIC_UI_PATH/frameworks/components/ui_tree_manager.cpp",
"$GRAPHIC_UI_PATH/frameworks/components/ui_view.cpp",
"$GRAPHIC_UI_PATH/frameworks/components/ui_view_group.cpp",
"$GRAPHIC_UI_PATH/frameworks/core/input_method_manager.cpp",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册