mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2024-11-23 07:01:24 +00:00
revert arcswiper
Signed-off-by: zhangwt3652 <zhangwenting15@huawei.com>
This commit is contained in:
parent
276f69430c
commit
7cf74f3fa4
@ -377,7 +377,6 @@
|
||||
vtable?for?OHOS::Ace::NG::MovingPhotoLayoutProperty;
|
||||
vtable?for?OHOS::Ace::NG::MovingPhotoNode;
|
||||
vtable?for?OHOS::Ace::NG::TouchEventActuator;
|
||||
vtable?for?OHOS::Ace::NG::SwiperModelNG;
|
||||
|
||||
VTT?for?OHOS::Ace::NG::AccessibilityProperty;
|
||||
VTT?for?OHOS::Ace::NG::BoxLayoutAlgorithm;
|
||||
@ -386,13 +385,6 @@
|
||||
VTT?for?OHOS::Ace::NG::LayoutProperty;
|
||||
VTT?for?OHOS::Ace::NG::LongPressRecognizer;
|
||||
VTT?for?OHOS::Ace::NG::TouchEventActuator;
|
||||
|
||||
OHOS::Ace::LinearColor::TRANSPARENT;
|
||||
|
||||
"OHOS::Ace::CardScope::CurrentId()";
|
||||
"OHOS::Ace::NG::Gradient::AddColor(OHOS::Ace::NG::GradientColor const&)";
|
||||
"OHOS::Ace::Framework::JsConverter::ConvertNapiValueToJsVal(napi_value__*)";
|
||||
"OHOS::Ace::Framework::JsiObject::JsiObject(panda::CopyableGlobal<panda::ObjectRef> const&)";
|
||||
};
|
||||
local:
|
||||
*;
|
||||
|
@ -12,8 +12,5 @@
|
||||
# limitations under the License.
|
||||
|
||||
group("component_ext") {
|
||||
deps = [
|
||||
"arc_swiper:arcswiper",
|
||||
"movingphoto:movingphotoview",
|
||||
]
|
||||
deps = [ "movingphoto:movingphotoview" ]
|
||||
}
|
||||
|
@ -1,92 +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.
|
||||
|
||||
import("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni")
|
||||
import("//build/ohos.gni")
|
||||
import("//foundation/arkui/ace_engine/ace_config.gni")
|
||||
import("//foundation/arkui/ace_engine/build/ace_gen_obj.gni")
|
||||
|
||||
component_ext_path = "${ace_root}/component_ext"
|
||||
|
||||
additional_include_dirs = [ "${ace_root}" ]
|
||||
|
||||
es2abc_gen_abc("gen_arkui_arcswiper_abc") {
|
||||
src_js = rebase_path("arkui_arcswiper.js")
|
||||
dst_file = rebase_path(target_out_dir + "/arkui_arcswiper.abc")
|
||||
in_puts = [ "arkui_arcswiper.js" ]
|
||||
out_puts = [ target_out_dir + "/arkui_arcswiper.abc" ]
|
||||
extra_args = [ "--module" ]
|
||||
}
|
||||
|
||||
gen_obj("arkui_arcswiper_js") {
|
||||
input = "arkui_arcswiper.js"
|
||||
output = target_out_dir + "/arkui_arcswiper.o"
|
||||
snapshot_dep = []
|
||||
}
|
||||
|
||||
gen_obj("arkui_arcswiper_abc") {
|
||||
input = get_label_info(":gen_arkui_arcswiper_abc", "target_out_dir") +
|
||||
"/arkui_arcswiper.abc"
|
||||
output = target_out_dir + "arkui_arcswiper_abc.o"
|
||||
snapshot_dep = [ ":gen_arkui_arcswiper_abc" ]
|
||||
}
|
||||
|
||||
ohos_shared_library("arcswiper") {
|
||||
defines = [ "USE_ARK_ENGINE" ]
|
||||
sources = [
|
||||
"${component_ext_path}/arc_swiper/arc_swiper_napi.cpp",
|
||||
"${component_ext_path}/ext_common/ext_napi_utils.cpp",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"${component_ext_path}/ext_common/",
|
||||
"${component_ext_path}/arc_swiper/",
|
||||
"${ace_root}/frameworks",
|
||||
"$root_out_dir/arkui/framework",
|
||||
]
|
||||
include_dirs += additional_include_dirs
|
||||
|
||||
deps = [
|
||||
":gen_obj_src_arkui_arcswiper_abc",
|
||||
":gen_obj_src_arkui_arcswiper_js",
|
||||
"$ace_root/build:libace_compatible",
|
||||
"$ace_root/frameworks/core:ace_container_scope",
|
||||
"$ace_root/interfaces/inner_api/ace:ace_uicontent",
|
||||
"$ace_root/interfaces/napi/kits/plugincomponent:plugincomponent",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"bounds_checking_function:libsec_static",
|
||||
"ets_runtime:libark_jsruntime",
|
||||
"hilog:libhilog",
|
||||
"napi:ace_napi",
|
||||
]
|
||||
|
||||
ldflags = [ "-Wl,--gc-sections" ]
|
||||
|
||||
cflags = [
|
||||
"-fvisibility=hidden",
|
||||
"-fdata-sections",
|
||||
"-ffunction-sections",
|
||||
"-Os",
|
||||
]
|
||||
|
||||
cflags_cc = [
|
||||
"-fvisibility-inlines-hidden",
|
||||
"-Os",
|
||||
]
|
||||
|
||||
relative_install_dir = "module/arkui"
|
||||
subsystem_name = ace_engine_subsystem
|
||||
part_name = ace_engine_part
|
||||
}
|
@ -1,71 +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 COMPONENT_EXT_ARC_SWIPER_ARC_SWIPER_CONTROLLER_H
|
||||
#define COMPONENT_EXT_ARC_SWIPER_ARC_SWIPER_CONTROLLER_H
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include "base/memory/ace_type.h"
|
||||
#include "core/components/swiper/swiper_controller.h"
|
||||
|
||||
namespace OHOS::Ace::NG {
|
||||
|
||||
class JsArcSwiperController : public virtual AceType {
|
||||
DECLARE_ACE_TYPE(JsArcSwiperController, AceType)
|
||||
|
||||
public:
|
||||
JsArcSwiperController() = default;
|
||||
~JsArcSwiperController() override = default;
|
||||
|
||||
void ShowNext()
|
||||
{
|
||||
if (controller_) {
|
||||
controller_->ShowNext();
|
||||
}
|
||||
}
|
||||
|
||||
void ShowPrevious()
|
||||
{
|
||||
if (controller_) {
|
||||
controller_->ShowPrevious();
|
||||
}
|
||||
}
|
||||
|
||||
void FinishAnimation(const CommonFunc& onFinish)
|
||||
{
|
||||
if (!controller_) {
|
||||
return;
|
||||
}
|
||||
if (onFinish) {
|
||||
controller_->SetFinishCallback(onFinish);
|
||||
}
|
||||
controller_->FinishAnimation();
|
||||
}
|
||||
|
||||
void SetController(const RefPtr<SwiperController>& controller)
|
||||
{
|
||||
controller_ = controller;
|
||||
}
|
||||
|
||||
private:
|
||||
RefPtr<SwiperController> controller_;
|
||||
|
||||
ACE_DISALLOW_COPY_AND_MOVE(JsArcSwiperController);
|
||||
};
|
||||
|
||||
} // namespace OHOS::Ace::NG
|
||||
|
||||
#endif // COMPONENT_EXT_ARC_SWIPER_ARC_SWIPER_CONTROLLER_H
|
@ -1,141 +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 COMPONENT_EXT_ARC_SWIPER_ARC_SWIPER_INDICATOR_H
|
||||
#define COMPONENT_EXT_ARC_SWIPER_ARC_SWIPER_INDICATOR_H
|
||||
|
||||
#include <optional>
|
||||
|
||||
#include "base/memory/ace_type.h"
|
||||
#include "core/components_ng/pattern/swiper/swiper_model.h"
|
||||
#include "core/components_ng/property/gradient_property.h"
|
||||
|
||||
namespace OHOS::Ace::NG {
|
||||
|
||||
class JsArcSwiperIndicator : public virtual AceType {
|
||||
DECLARE_ACE_TYPE(JsArcSwiperIndicator, AceType)
|
||||
|
||||
public:
|
||||
JsArcSwiperIndicator() = default;
|
||||
~JsArcSwiperIndicator() override = default;
|
||||
|
||||
void SetArcDirection(SwiperArcDirection direction)
|
||||
{
|
||||
arcDirection_ = direction;
|
||||
}
|
||||
|
||||
SwiperArcDirection GetArcDirection() const
|
||||
{
|
||||
return arcDirection_.value();
|
||||
}
|
||||
|
||||
bool HasArcDirection() const
|
||||
{
|
||||
return arcDirection_.has_value();
|
||||
}
|
||||
|
||||
void SetItemColor(const Color& color)
|
||||
{
|
||||
itemColor_ = color;
|
||||
}
|
||||
|
||||
void ResetItemColor()
|
||||
{
|
||||
itemColor_.reset();
|
||||
}
|
||||
|
||||
const Color& GetItemColor() const
|
||||
{
|
||||
return itemColor_.value();
|
||||
}
|
||||
|
||||
bool HasItemColor() const
|
||||
{
|
||||
return itemColor_.has_value();
|
||||
}
|
||||
|
||||
void SetSelectedItemColor(const Color& color)
|
||||
{
|
||||
selectedItemColor_ = color;
|
||||
}
|
||||
|
||||
void ResetSelectedItemColor()
|
||||
{
|
||||
selectedItemColor_.reset();
|
||||
}
|
||||
|
||||
const Color& GetSelectedItemColor() const
|
||||
{
|
||||
return selectedItemColor_.value();
|
||||
}
|
||||
|
||||
bool HasSelectedItemColor() const
|
||||
{
|
||||
return selectedItemColor_.has_value();
|
||||
}
|
||||
|
||||
void SetContainerColor(const Color& color)
|
||||
{
|
||||
containerColor_ = color;
|
||||
}
|
||||
|
||||
void ResetContainerColor()
|
||||
{
|
||||
containerColor_.reset();
|
||||
}
|
||||
|
||||
const Color& GetContainerColor() const
|
||||
{
|
||||
return containerColor_.value();
|
||||
}
|
||||
|
||||
bool HasContainerColor() const
|
||||
{
|
||||
return containerColor_.has_value();
|
||||
}
|
||||
|
||||
void SetMaskColor(const NG::Gradient& GradientColor)
|
||||
{
|
||||
maskLinearGradientColor_ = GradientColor;
|
||||
}
|
||||
|
||||
void ResetMaskColor()
|
||||
{
|
||||
maskLinearGradientColor_.reset();
|
||||
}
|
||||
|
||||
const NG::Gradient& GetMaskColor() const
|
||||
{
|
||||
return maskLinearGradientColor_.value();
|
||||
}
|
||||
|
||||
bool HasMaskColor() const
|
||||
{
|
||||
return maskLinearGradientColor_.has_value();
|
||||
}
|
||||
|
||||
private:
|
||||
std::optional<SwiperArcDirection> arcDirection_;
|
||||
std::optional<Color> itemColor_;
|
||||
std::optional<Color> selectedItemColor_;
|
||||
std::optional<Color> containerColor_;
|
||||
std::optional<NG::Gradient> maskLinearGradientColor_;
|
||||
|
||||
ACE_DISALLOW_COPY_AND_MOVE(JsArcSwiperIndicator);
|
||||
};
|
||||
|
||||
} // namespace OHOS::Ace::NG
|
||||
|
||||
#endif // COMPONENT_EXT_ARC_SWIPER_ARC_SWIPER_INDICATOR_H
|
@ -1,660 +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 "arc_swiper_napi.h"
|
||||
|
||||
#include "arc_swiper_controller.h"
|
||||
#include "arc_swiper_indicator.h"
|
||||
#include "ext_napi_utils.h"
|
||||
|
||||
#include "bridge/declarative_frontend/engine/js_converter.h"
|
||||
#include "bridge/declarative_frontend/jsview/js_linear_gradient.h"
|
||||
#include "core/components/swiper/swiper_component.h"
|
||||
#include "core/components/swiper/swiper_indicator_theme.h"
|
||||
#include "core/components_ng/pattern/swiper/swiper_model_ng.h"
|
||||
|
||||
extern const char _binary_arkui_arcswiper_js_start[];
|
||||
extern const char _binary_arkui_arcswiper_abc_start[];
|
||||
#if !defined(IOS_PLATFORM)
|
||||
extern const char _binary_arkui_arcswiper_js_end[];
|
||||
extern const char _binary_arkui_arcswiper_abc_end[];
|
||||
#else
|
||||
extern const char* _binary_arkui_arcswiper_js_end;
|
||||
extern const char* _binary_arkui_arcswiper_abc_end;
|
||||
#endif
|
||||
|
||||
namespace OHOS::Ace {
|
||||
namespace {
|
||||
static constexpr const size_t MAX_ARG_NUM = 10;
|
||||
static constexpr const int32_t DEFAULT_DURATION = 400;
|
||||
static constexpr const int32_t THREE_CLOCK_DIRECTION = 0;
|
||||
static constexpr const int32_t SIX_CLOCK_DIRECTION = 1;
|
||||
static constexpr const int32_t NINE_CLOCK_DIRECTION = 2;
|
||||
} // namespace
|
||||
|
||||
std::unique_ptr<SwiperModel> SwiperModel::instance_ = nullptr;
|
||||
std::mutex SwiperModel::mutex_;
|
||||
|
||||
SwiperModel* SwiperModel::GetInstance()
|
||||
{
|
||||
if (!instance_) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (!instance_) {
|
||||
instance_.reset(new NG::SwiperModelNG());
|
||||
}
|
||||
}
|
||||
return instance_.get();
|
||||
}
|
||||
|
||||
napi_value JsCreate(napi_env env, napi_callback_info info)
|
||||
{
|
||||
auto controller = SwiperModel::GetInstance()->Create(true);
|
||||
SwiperModel::GetInstance()->SetIndicatorType(SwiperIndicatorType::ARC_DOT);
|
||||
|
||||
size_t argc = MAX_ARG_NUM;
|
||||
napi_value argv[MAX_ARG_NUM] = { nullptr };
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr));
|
||||
if (argc > 0 && ExtNapiUtils::CheckTypeForNapiValue(env, argv[0], napi_object)) {
|
||||
NG::JsArcSwiperController* jsController = nullptr;
|
||||
napi_unwrap(env, argv[0], (void**)&jsController);
|
||||
if (jsController) {
|
||||
jsController->SetController(controller);
|
||||
}
|
||||
}
|
||||
|
||||
return ExtNapiUtils::CreateNull(env);
|
||||
}
|
||||
|
||||
napi_value JsIndex(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t argc = MAX_ARG_NUM;
|
||||
napi_value argv[MAX_ARG_NUM] = { nullptr };
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr));
|
||||
NAPI_ASSERT(env, argc >= 1, "Wrong number of arguments");
|
||||
|
||||
int32_t index = 0;
|
||||
if (ExtNapiUtils::CheckTypeForNapiValue(env, argv[0], napi_number)) {
|
||||
index = ExtNapiUtils::GetCInt32(env, argv[0]);
|
||||
}
|
||||
index = index < 0 ? 0 : index;
|
||||
SwiperModel::GetInstance()->SetIndex(index);
|
||||
|
||||
return ExtNapiUtils::CreateNull(env);
|
||||
}
|
||||
|
||||
SwiperArcDotParameters GetArcDotIndicatorInfo(napi_env env, napi_value value)
|
||||
{
|
||||
SwiperArcDotParameters swiperParameters;
|
||||
auto pipelineContext = PipelineBase::GetCurrentContext();
|
||||
CHECK_NULL_RETURN(pipelineContext, swiperParameters);
|
||||
auto swiperIndicatorTheme = pipelineContext->GetTheme<SwiperIndicatorTheme>();
|
||||
CHECK_NULL_RETURN(swiperIndicatorTheme, swiperParameters);
|
||||
NG::JsArcSwiperIndicator* indicator = nullptr;
|
||||
napi_unwrap(env, value, (void**)&indicator);
|
||||
|
||||
// parse arcDirection
|
||||
swiperParameters.arcDirection = SwiperArcDirection::SIX_CLOCK_DIRECTION;
|
||||
if (indicator && indicator->HasArcDirection()) {
|
||||
swiperParameters.arcDirection = indicator->GetArcDirection();
|
||||
}
|
||||
// parse itemColor
|
||||
swiperParameters.itemColor =
|
||||
(indicator && indicator->HasItemColor()) ? indicator->GetItemColor() : swiperIndicatorTheme->GetArcItemColor();
|
||||
// parse selectedItemColor
|
||||
swiperParameters.selectedItemColor = (indicator && indicator->HasSelectedItemColor())
|
||||
? indicator->GetSelectedItemColor()
|
||||
: swiperIndicatorTheme->GetArcSelectedItemColor();
|
||||
// parse containerColor
|
||||
swiperParameters.containerColor = (indicator && indicator->HasContainerColor())
|
||||
? indicator->GetContainerColor()
|
||||
: swiperIndicatorTheme->GetArcContainerColor();
|
||||
// parse maskColor
|
||||
swiperParameters.maskColor =
|
||||
(indicator && indicator->HasMaskColor()) ? indicator->GetMaskColor() : swiperIndicatorTheme->GetArcMaskColor();
|
||||
|
||||
return swiperParameters;
|
||||
}
|
||||
|
||||
napi_value JsIndicator(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t argc = MAX_ARG_NUM;
|
||||
napi_value argv[MAX_ARG_NUM] = { nullptr };
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr));
|
||||
NAPI_ASSERT(env, argc >= 1, "Wrong number of arguments");
|
||||
|
||||
bool showIndicator = true;
|
||||
if (ExtNapiUtils::CheckTypeForNapiValue(env, argv[0], napi_boolean)) {
|
||||
showIndicator = ExtNapiUtils::GetBool(env, argv[0]);
|
||||
} else {
|
||||
SwiperModel::GetInstance()->SetIndicatorIsBoolean(false);
|
||||
SwiperArcDotParameters swiperParameters = GetArcDotIndicatorInfo(env, argv[0]);
|
||||
SwiperModel::GetInstance()->SetArcDotIndicatorStyle(swiperParameters);
|
||||
}
|
||||
|
||||
SwiperModel::GetInstance()->SetShowIndicator(showIndicator);
|
||||
|
||||
return ExtNapiUtils::CreateNull(env);
|
||||
}
|
||||
|
||||
napi_value JsDuration(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t argc = MAX_ARG_NUM;
|
||||
napi_value argv[MAX_ARG_NUM] = { nullptr };
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr));
|
||||
NAPI_ASSERT(env, argc >= 1, "Wrong number of arguments");
|
||||
|
||||
int32_t duration = DEFAULT_DURATION;
|
||||
if (ExtNapiUtils::CheckTypeForNapiValue(env, argv[0], napi_number)) {
|
||||
duration = ExtNapiUtils::GetCInt32(env, argv[0]);
|
||||
}
|
||||
duration = duration < 0 ? DEFAULT_DURATION : duration;
|
||||
SwiperModel::GetInstance()->SetDuration(duration);
|
||||
|
||||
return ExtNapiUtils::CreateNull(env);
|
||||
}
|
||||
|
||||
napi_value JsVertical(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t argc = MAX_ARG_NUM;
|
||||
napi_value argv[MAX_ARG_NUM] = { nullptr };
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr));
|
||||
NAPI_ASSERT(env, argc >= 1, "Wrong number of arguments");
|
||||
|
||||
bool isVertical = false;
|
||||
if (ExtNapiUtils::CheckTypeForNapiValue(env, argv[0], napi_boolean)) {
|
||||
isVertical = ExtNapiUtils::GetBool(env, argv[0]);
|
||||
}
|
||||
SwiperModel::GetInstance()->SetDirection(isVertical ? Axis::VERTICAL : Axis::HORIZONTAL);
|
||||
|
||||
return ExtNapiUtils::CreateNull(env);
|
||||
}
|
||||
|
||||
napi_value JsDisableSwipe(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t argc = MAX_ARG_NUM;
|
||||
napi_value argv[MAX_ARG_NUM] = { nullptr };
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr));
|
||||
NAPI_ASSERT(env, argc >= 1, "Wrong number of arguments");
|
||||
|
||||
bool isDisable = false;
|
||||
if (ExtNapiUtils::CheckTypeForNapiValue(env, argv[0], napi_boolean)) {
|
||||
isDisable = ExtNapiUtils::GetBool(env, argv[0]);
|
||||
}
|
||||
SwiperModel::GetInstance()->SetDisableSwipe(isDisable);
|
||||
|
||||
return ExtNapiUtils::CreateNull(env);
|
||||
}
|
||||
|
||||
napi_value JsOnChange(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t argc = MAX_ARG_NUM;
|
||||
napi_value thisVal = nullptr;
|
||||
napi_value argv[MAX_ARG_NUM] = { nullptr };
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVal, nullptr));
|
||||
NAPI_ASSERT(env, argc >= 1, "Wrong number of arguments");
|
||||
if (!ExtNapiUtils::CheckTypeForNapiValue(env, argv[0], napi_function)) {
|
||||
return ExtNapiUtils::CreateNull(env);
|
||||
}
|
||||
auto asyncEvent = std::make_shared<NapiAsyncEvent>(env, argv[0]);
|
||||
auto onChange = [asyncEvent](const BaseEventInfo* info) {
|
||||
napi_handle_scope scope = nullptr;
|
||||
napi_open_handle_scope(asyncEvent->GetEnv(), &scope);
|
||||
CHECK_NULL_VOID(scope);
|
||||
|
||||
const auto* eventInfo = TypeInfoHelper::DynamicCast<SwiperChangeEvent>(info);
|
||||
if (!eventInfo) {
|
||||
napi_close_handle_scope(asyncEvent->GetEnv(), scope);
|
||||
return;
|
||||
}
|
||||
napi_value arrayValue = ExtNapiUtils::CreateInt32(asyncEvent->GetEnv(), eventInfo->GetIndex());
|
||||
napi_value argv[1] = { arrayValue };
|
||||
asyncEvent->Call(1, argv);
|
||||
|
||||
napi_close_handle_scope(asyncEvent->GetEnv(), scope);
|
||||
};
|
||||
SwiperModel::GetInstance()->SetOnChange(std::move(onChange));
|
||||
return ExtNapiUtils::CreateNull(env);
|
||||
}
|
||||
|
||||
napi_value GetAnimationInfoJsObject(napi_env env, const AnimationCallbackInfo& info)
|
||||
{
|
||||
napi_value jsObject = ExtNapiUtils::CreateObject(env);
|
||||
|
||||
napi_value currentOffsetValue = ExtNapiUtils::CreateDouble(env, info.currentOffset.value_or(0.0f));
|
||||
ExtNapiUtils::SetNamedProperty(env, jsObject, "currentOffset", currentOffsetValue);
|
||||
napi_value targetOffsetValue = ExtNapiUtils::CreateDouble(env, info.targetOffset.value_or(0.0f));
|
||||
ExtNapiUtils::SetNamedProperty(env, jsObject, "targetOffset", targetOffsetValue);
|
||||
napi_value velocityValue = ExtNapiUtils::CreateDouble(env, info.velocity.value_or(0.0f));
|
||||
ExtNapiUtils::SetNamedProperty(env, jsObject, "velocity", velocityValue);
|
||||
|
||||
return jsObject;
|
||||
}
|
||||
|
||||
napi_value JsOnAnimationStart(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t argc = MAX_ARG_NUM;
|
||||
napi_value thisVal = nullptr;
|
||||
napi_value argv[MAX_ARG_NUM] = { nullptr };
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVal, nullptr));
|
||||
NAPI_ASSERT(env, argc >= 1, "Wrong number of arguments");
|
||||
if (!ExtNapiUtils::CheckTypeForNapiValue(env, argv[0], napi_function)) {
|
||||
return ExtNapiUtils::CreateNull(env);
|
||||
}
|
||||
auto asyncEvent = std::make_shared<NapiAsyncEvent>(env, argv[0]);
|
||||
auto onAnimationStart = [asyncEvent](int32_t index, int32_t targetIndex, const AnimationCallbackInfo& info) {
|
||||
napi_env env = asyncEvent->GetEnv();
|
||||
napi_handle_scope scope = nullptr;
|
||||
napi_open_handle_scope(env, &scope);
|
||||
CHECK_NULL_VOID(scope);
|
||||
|
||||
napi_value arrayValueOne = ExtNapiUtils::CreateInt32(env, index);
|
||||
napi_value arrayValueTwo = ExtNapiUtils::CreateInt32(env, targetIndex);
|
||||
napi_value arrayValueThree = GetAnimationInfoJsObject(env, info);
|
||||
|
||||
napi_value argv[3] = { arrayValueOne, arrayValueTwo, arrayValueThree };
|
||||
asyncEvent->Call(3, argv);
|
||||
|
||||
napi_close_handle_scope(env, scope);
|
||||
};
|
||||
SwiperModel::GetInstance()->SetOnAnimationStart(std::move(onAnimationStart));
|
||||
return ExtNapiUtils::CreateNull(env);
|
||||
}
|
||||
|
||||
napi_value JsOnAnimationEnd(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t argc = MAX_ARG_NUM;
|
||||
napi_value thisVal = nullptr;
|
||||
napi_value argv[MAX_ARG_NUM] = { nullptr };
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVal, nullptr));
|
||||
NAPI_ASSERT(env, argc >= 1, "Wrong number of arguments");
|
||||
if (!ExtNapiUtils::CheckTypeForNapiValue(env, argv[0], napi_function)) {
|
||||
return ExtNapiUtils::CreateNull(env);
|
||||
}
|
||||
auto asyncEvent = std::make_shared<NapiAsyncEvent>(env, argv[0]);
|
||||
auto onAnimationEnd = [asyncEvent](int32_t index, const AnimationCallbackInfo& info) {
|
||||
napi_env env = asyncEvent->GetEnv();
|
||||
napi_handle_scope scope = nullptr;
|
||||
napi_open_handle_scope(env, &scope);
|
||||
CHECK_NULL_VOID(scope);
|
||||
|
||||
napi_value arrayValueOne = ExtNapiUtils::CreateInt32(env, index);
|
||||
napi_value arrayValueTwo = GetAnimationInfoJsObject(env, info);
|
||||
|
||||
napi_value argv[2] = { arrayValueOne, arrayValueTwo };
|
||||
asyncEvent->Call(2, argv);
|
||||
|
||||
napi_close_handle_scope(env, scope);
|
||||
};
|
||||
SwiperModel::GetInstance()->SetOnAnimationEnd(std::move(onAnimationEnd));
|
||||
return ExtNapiUtils::CreateNull(env);
|
||||
}
|
||||
|
||||
napi_value JsOnGestureSwipe(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t argc = MAX_ARG_NUM;
|
||||
napi_value thisVal = nullptr;
|
||||
napi_value argv[MAX_ARG_NUM] = { nullptr };
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVal, nullptr));
|
||||
NAPI_ASSERT(env, argc >= 1, "Wrong number of arguments");
|
||||
if (!ExtNapiUtils::CheckTypeForNapiValue(env, argv[0], napi_function)) {
|
||||
return ExtNapiUtils::CreateNull(env);
|
||||
}
|
||||
auto asyncEvent = std::make_shared<NapiAsyncEvent>(env, argv[0]);
|
||||
auto onGestureSwipe = [asyncEvent](int32_t index, const AnimationCallbackInfo& info) {
|
||||
napi_env env = asyncEvent->GetEnv();
|
||||
napi_handle_scope scope = nullptr;
|
||||
napi_open_handle_scope(env, &scope);
|
||||
CHECK_NULL_VOID(scope);
|
||||
|
||||
napi_value arrayValueOne = ExtNapiUtils::CreateInt32(env, index);
|
||||
napi_value arrayValueTwo = GetAnimationInfoJsObject(env, info);
|
||||
|
||||
napi_value argv[2] = { arrayValueOne, arrayValueTwo };
|
||||
asyncEvent->Call(2, argv);
|
||||
|
||||
napi_close_handle_scope(env, scope);
|
||||
};
|
||||
SwiperModel::GetInstance()->SetOnGestureSwipe(std::move(onGestureSwipe));
|
||||
return ExtNapiUtils::CreateNull(env);
|
||||
}
|
||||
|
||||
napi_value ShowNext(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thisVar = nullptr;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, NULL));
|
||||
NG::JsArcSwiperController* controller = nullptr;
|
||||
napi_unwrap(env, thisVar, (void**)&controller);
|
||||
napi_value objectValue = ExtNapiUtils::CreateNull(env);
|
||||
CHECK_NULL_RETURN(controller, objectValue);
|
||||
controller->ShowNext();
|
||||
return objectValue;
|
||||
}
|
||||
|
||||
napi_value ShowPrevious(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thisVar = nullptr;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, NULL));
|
||||
NG::JsArcSwiperController* controller = nullptr;
|
||||
napi_unwrap(env, thisVar, (void**)&controller);
|
||||
napi_value objectValue = ExtNapiUtils::CreateNull(env);
|
||||
CHECK_NULL_RETURN(controller, objectValue);
|
||||
controller->ShowPrevious();
|
||||
return objectValue;
|
||||
}
|
||||
|
||||
napi_value FinishAnimation(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t argc = MAX_ARG_NUM;
|
||||
napi_value thisVal = nullptr;
|
||||
napi_value argv[MAX_ARG_NUM] = { nullptr };
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVal, nullptr));
|
||||
NG::JsArcSwiperController* controller = nullptr;
|
||||
napi_unwrap(env, thisVal, (void**)&controller);
|
||||
napi_value objectValue = ExtNapiUtils::CreateNull(env);
|
||||
CHECK_NULL_RETURN(controller, objectValue);
|
||||
|
||||
CommonFunc onFinish = nullptr;
|
||||
if (argc > 0 && ExtNapiUtils::CheckTypeForNapiValue(env, argv[0], napi_function)) {
|
||||
auto asyncEvent = std::make_shared<NapiAsyncEvent>(env, argv[0]);
|
||||
onFinish = [asyncEvent]() {
|
||||
napi_handle_scope scope = nullptr;
|
||||
napi_open_handle_scope(asyncEvent->GetEnv(), &scope);
|
||||
CHECK_NULL_VOID(scope);
|
||||
asyncEvent->Call(0, nullptr);
|
||||
napi_close_handle_scope(asyncEvent->GetEnv(), scope);
|
||||
};
|
||||
}
|
||||
controller->FinishAnimation(onFinish);
|
||||
|
||||
return objectValue;
|
||||
}
|
||||
|
||||
napi_value ArcSwiperControllerConstructor(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thisVar = nullptr;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr));
|
||||
auto controller = AceType::MakeRefPtr<NG::JsArcSwiperController>();
|
||||
CHECK_NULL_RETURN(controller, ExtNapiUtils::CreateNull(env));
|
||||
controller->IncRefCount();
|
||||
napi_wrap(
|
||||
env, thisVar, AceType::RawPtr(controller),
|
||||
[](napi_env env, void* data, void* hint) {
|
||||
auto* controller = reinterpret_cast<NG::JsArcSwiperController*>(data);
|
||||
controller->DecRefCount();
|
||||
},
|
||||
nullptr, nullptr);
|
||||
return thisVar;
|
||||
}
|
||||
|
||||
napi_value ArcDotIndicatorConstructor(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thisVar = nullptr;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr));
|
||||
auto indicator = AceType::MakeRefPtr<NG::JsArcSwiperIndicator>();
|
||||
CHECK_NULL_RETURN(indicator, ExtNapiUtils::CreateNull(env));
|
||||
indicator->IncRefCount();
|
||||
napi_wrap(
|
||||
env, thisVar, AceType::RawPtr(indicator),
|
||||
[](napi_env env, void* data, void* hint) {
|
||||
auto* indicator = reinterpret_cast<NG::JsArcSwiperIndicator*>(data);
|
||||
indicator->DecRefCount();
|
||||
},
|
||||
nullptr, nullptr);
|
||||
return thisVar;
|
||||
}
|
||||
|
||||
napi_value SetArcDirection(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thisVar = nullptr;
|
||||
size_t argc = MAX_ARG_NUM;
|
||||
napi_value argv[MAX_ARG_NUM] = { nullptr };
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL));
|
||||
NAPI_ASSERT(env, argc >= 1, "Wrong number of arguments");
|
||||
NG::JsArcSwiperIndicator* indicator = nullptr;
|
||||
napi_unwrap(env, thisVar, (void**)&indicator);
|
||||
CHECK_NULL_RETURN(indicator, thisVar);
|
||||
SwiperArcDirection arcDirection = SwiperArcDirection::SIX_CLOCK_DIRECTION;
|
||||
if (ExtNapiUtils::CheckTypeForNapiValue(env, argv[0], napi_number)) {
|
||||
arcDirection = static_cast<SwiperArcDirection>(ExtNapiUtils::GetCInt32(env, argv[0]));
|
||||
}
|
||||
indicator->SetArcDirection(arcDirection);
|
||||
return thisVar;
|
||||
}
|
||||
|
||||
napi_value SetItemColor(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thisVar = nullptr;
|
||||
size_t argc = MAX_ARG_NUM;
|
||||
napi_value argv[MAX_ARG_NUM] = { nullptr };
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL));
|
||||
NAPI_ASSERT(env, argc >= 1, "Wrong number of arguments");
|
||||
NG::JsArcSwiperIndicator* indicator = nullptr;
|
||||
napi_unwrap(env, thisVar, (void**)&indicator);
|
||||
CHECK_NULL_RETURN(indicator, thisVar);
|
||||
|
||||
Color colorVal;
|
||||
if (ExtNapiUtils::ParseColor(env, argv[0], colorVal)) {
|
||||
indicator->SetItemColor(colorVal);
|
||||
} else {
|
||||
indicator->ResetItemColor();
|
||||
}
|
||||
return thisVar;
|
||||
}
|
||||
|
||||
napi_value SetSelectedItemColor(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thisVar = nullptr;
|
||||
size_t argc = MAX_ARG_NUM;
|
||||
napi_value argv[MAX_ARG_NUM] = { nullptr };
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL));
|
||||
NAPI_ASSERT(env, argc >= 1, "Wrong number of arguments");
|
||||
NG::JsArcSwiperIndicator* indicator = nullptr;
|
||||
napi_unwrap(env, thisVar, (void**)&indicator);
|
||||
CHECK_NULL_RETURN(indicator, thisVar);
|
||||
|
||||
Color colorVal;
|
||||
if (ExtNapiUtils::ParseColor(env, argv[0], colorVal)) {
|
||||
indicator->SetSelectedItemColor(colorVal);
|
||||
} else {
|
||||
indicator->ResetSelectedItemColor();
|
||||
}
|
||||
return thisVar;
|
||||
}
|
||||
|
||||
napi_value SetBackgroundColor(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thisVar = nullptr;
|
||||
size_t argc = MAX_ARG_NUM;
|
||||
napi_value argv[MAX_ARG_NUM] = { nullptr };
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL));
|
||||
NAPI_ASSERT(env, argc >= 1, "Wrong number of arguments");
|
||||
NG::JsArcSwiperIndicator* indicator = nullptr;
|
||||
napi_unwrap(env, thisVar, (void**)&indicator);
|
||||
CHECK_NULL_RETURN(indicator, thisVar);
|
||||
|
||||
Color colorVal;
|
||||
if (ExtNapiUtils::ParseColor(env, argv[0], colorVal)) {
|
||||
indicator->SetContainerColor(colorVal);
|
||||
} else {
|
||||
indicator->ResetContainerColor();
|
||||
}
|
||||
return thisVar;
|
||||
}
|
||||
|
||||
bool ConvertGradientColor(napi_env env, napi_value value, NG::Gradient& gradient)
|
||||
{
|
||||
auto jsValue = Framework::JsConverter::ConvertNapiValueToJsVal(value);
|
||||
Framework::JSLinearGradient* jsLinearGradient =
|
||||
Framework::JSRef<Framework::JSObject>::Cast(jsValue)->Unwrap<Framework::JSLinearGradient>();
|
||||
|
||||
if (!jsLinearGradient || jsLinearGradient->GetGradient().empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t size = jsLinearGradient->GetGradient().size();
|
||||
if (size == 1) {
|
||||
// If there is only one color, then this color is used for both the begin and end side.
|
||||
NG::GradientColor gradientColor;
|
||||
gradientColor.SetLinearColor(LinearColor(jsLinearGradient->GetGradient().front().first));
|
||||
gradientColor.SetDimension(jsLinearGradient->GetGradient().front().second);
|
||||
gradient.AddColor(gradientColor);
|
||||
gradient.AddColor(gradientColor);
|
||||
return true;
|
||||
}
|
||||
|
||||
for (size_t colorIndex = 0; colorIndex < size; colorIndex++) {
|
||||
NG::GradientColor gradientColor;
|
||||
gradientColor.SetLinearColor(LinearColor(jsLinearGradient->GetGradient().at(colorIndex).first));
|
||||
gradientColor.SetDimension(jsLinearGradient->GetGradient().at(colorIndex).second);
|
||||
gradient.AddColor(gradientColor);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
napi_value SetMaskColor(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thisVar = nullptr;
|
||||
size_t argc = MAX_ARG_NUM;
|
||||
napi_value argv[MAX_ARG_NUM] = { nullptr };
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL));
|
||||
NAPI_ASSERT(env, argc >= 1, "Wrong number of arguments");
|
||||
NG::JsArcSwiperIndicator* indicator = nullptr;
|
||||
napi_unwrap(env, thisVar, (void**)&indicator);
|
||||
CHECK_NULL_RETURN(indicator, thisVar);
|
||||
|
||||
NG::Gradient gradient;
|
||||
if (ExtNapiUtils::CheckTypeForNapiValue(env, argv[0], napi_object) &&
|
||||
ConvertGradientColor(env, argv[0], gradient)) {
|
||||
indicator->SetMaskColor(gradient);
|
||||
} else {
|
||||
indicator->ResetMaskColor();
|
||||
}
|
||||
|
||||
return thisVar;
|
||||
}
|
||||
|
||||
napi_value InitArcSwiper(napi_env env, napi_value exports)
|
||||
{
|
||||
napi_property_descriptor desc[] = {
|
||||
DECLARE_NAPI_FUNCTION("create", JsCreate),
|
||||
DECLARE_NAPI_FUNCTION("index", JsIndex),
|
||||
DECLARE_NAPI_FUNCTION("indicator", JsIndicator),
|
||||
DECLARE_NAPI_FUNCTION("duration", JsDuration),
|
||||
DECLARE_NAPI_FUNCTION("vertical", JsVertical),
|
||||
DECLARE_NAPI_FUNCTION("disableSwipe", JsDisableSwipe),
|
||||
DECLARE_NAPI_FUNCTION("onChange", JsOnChange),
|
||||
DECLARE_NAPI_FUNCTION("onAnimationStart", JsOnAnimationStart),
|
||||
DECLARE_NAPI_FUNCTION("onAnimationEnd", JsOnAnimationEnd),
|
||||
DECLARE_NAPI_FUNCTION("onGestureSwipe", JsOnGestureSwipe),
|
||||
};
|
||||
NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc));
|
||||
return exports;
|
||||
}
|
||||
|
||||
napi_value InitArcDotIndicator(napi_env env, napi_value exports)
|
||||
{
|
||||
napi_value arcDotIndicatorClass = nullptr;
|
||||
napi_property_descriptor desc[] = {
|
||||
DECLARE_NAPI_FUNCTION("arcDirection", SetArcDirection),
|
||||
DECLARE_NAPI_FUNCTION("itemColor", SetItemColor),
|
||||
DECLARE_NAPI_FUNCTION("selectedItemColor", SetSelectedItemColor),
|
||||
DECLARE_NAPI_FUNCTION("backgroundColor", SetBackgroundColor),
|
||||
DECLARE_NAPI_FUNCTION("maskColor", SetMaskColor),
|
||||
};
|
||||
|
||||
NAPI_CALL(env, napi_define_class(env, "ArcDotIndicator", NAPI_AUTO_LENGTH, ArcDotIndicatorConstructor, nullptr,
|
||||
sizeof(desc) / sizeof(desc[0]), desc, &arcDotIndicatorClass));
|
||||
NAPI_CALL(env, napi_set_named_property(env, exports, "ArcDotIndicator", arcDotIndicatorClass));
|
||||
return exports;
|
||||
}
|
||||
|
||||
napi_value InitArcDirection(napi_env env, napi_value exports)
|
||||
{
|
||||
napi_value arcDirection = nullptr;
|
||||
napi_create_object(env, &arcDirection);
|
||||
napi_value prop = ExtNapiUtils::CreateInt32(env, THREE_CLOCK_DIRECTION);
|
||||
napi_set_named_property(env, arcDirection, "THREE_CLOCK_DIRECTION", prop);
|
||||
prop = ExtNapiUtils::CreateInt32(env, SIX_CLOCK_DIRECTION);
|
||||
napi_set_named_property(env, arcDirection, "SIX_CLOCK_DIRECTION", prop);
|
||||
prop = ExtNapiUtils::CreateInt32(env, NINE_CLOCK_DIRECTION);
|
||||
napi_set_named_property(env, arcDirection, "NINE_CLOCK_DIRECTION", prop);
|
||||
|
||||
NAPI_CALL(env, napi_set_named_property(env, exports, "ArcDirection", arcDirection));
|
||||
return exports;
|
||||
}
|
||||
|
||||
napi_value InitController(napi_env env, napi_value exports)
|
||||
{
|
||||
napi_value arcSwiperControllerClass = nullptr;
|
||||
napi_property_descriptor desc[] = {
|
||||
DECLARE_NAPI_FUNCTION("showNext", ShowNext),
|
||||
DECLARE_NAPI_FUNCTION("showPrevious", ShowPrevious),
|
||||
DECLARE_NAPI_FUNCTION("finishAnimation", FinishAnimation),
|
||||
};
|
||||
|
||||
NAPI_CALL(env, napi_define_class(env, "ArcSwiperController", NAPI_AUTO_LENGTH, ArcSwiperControllerConstructor,
|
||||
nullptr, sizeof(desc) / sizeof(desc[0]), desc, &arcSwiperControllerClass));
|
||||
NAPI_CALL(env, napi_set_named_property(env, exports, "ArcSwiperController", arcSwiperControllerClass));
|
||||
return exports;
|
||||
}
|
||||
|
||||
napi_value ExportArcSwiper(napi_env env, napi_value exports)
|
||||
{
|
||||
InitArcSwiper(env, exports);
|
||||
InitController(env, exports);
|
||||
InitArcDotIndicator(env, exports);
|
||||
InitArcDirection(env, exports);
|
||||
|
||||
return exports;
|
||||
}
|
||||
|
||||
} // namespace OHOS::Ace
|
||||
|
||||
extern "C" __attribute__((visibility("default"))) void NAPI_arkui_arcswiper_GetJSCode(const char** buf, int* bufLen)
|
||||
{
|
||||
if (buf != nullptr) {
|
||||
*buf = _binary_arkui_arcswiper_js_start;
|
||||
}
|
||||
|
||||
if (bufLen != nullptr) {
|
||||
*bufLen = _binary_arkui_arcswiper_js_end - _binary_arkui_arcswiper_js_start;
|
||||
}
|
||||
}
|
||||
|
||||
// arkui_arcswiper JS register
|
||||
extern "C" __attribute__((visibility("default"))) void NAPI_arkui_arcswiper_GetABCCode(const char** buf, int* buflen)
|
||||
{
|
||||
if (buf != nullptr) {
|
||||
*buf = _binary_arkui_arcswiper_abc_start;
|
||||
}
|
||||
if (buflen != nullptr) {
|
||||
*buflen = _binary_arkui_arcswiper_abc_end - _binary_arkui_arcswiper_abc_start;
|
||||
}
|
||||
}
|
||||
|
||||
static napi_module arcSwiperModule = {
|
||||
.nm_version = 1,
|
||||
.nm_flags = 0,
|
||||
.nm_filename = nullptr,
|
||||
.nm_register_func = OHOS::Ace::ExportArcSwiper,
|
||||
.nm_modname = "arkui.arcswiper",
|
||||
.nm_priv = ((void*)0),
|
||||
.reserved = { 0 },
|
||||
};
|
||||
|
||||
extern "C" __attribute__((constructor)) void RegisterArcSwiperModule()
|
||||
{
|
||||
napi_module_register(&arcSwiperModule);
|
||||
}
|
@ -1,39 +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 COMPONENT_EXT_ARC_SWIPER_ARC_SWIPER_NAPI_H
|
||||
#define COMPONENT_EXT_ARC_SWIPER_ARC_SWIPER_NAPI_H
|
||||
|
||||
#include "napi/native_api.h"
|
||||
#include "napi/native_node_api.h"
|
||||
|
||||
#include "core/components_ng/pattern/swiper/swiper_model.h"
|
||||
|
||||
namespace OHOS::Ace {
|
||||
napi_value JsCreate(napi_env env, napi_callback_info info);
|
||||
napi_value JsIndex(napi_env env, napi_callback_info info);
|
||||
napi_value JsIndicator(napi_env env, napi_callback_info info);
|
||||
napi_value JsDuration(napi_env env, napi_callback_info info);
|
||||
napi_value JsVertical(napi_env env, napi_callback_info info);
|
||||
napi_value JsDisableSwipe(napi_env env, napi_callback_info info);
|
||||
napi_value JsOnChange(napi_env env, napi_callback_info info);
|
||||
napi_value JsOnAnimationStart(napi_env env, napi_callback_info info);
|
||||
napi_value JsOnAnimationEnd(napi_env env, napi_callback_info info);
|
||||
napi_value JsOnGestureSwipe(napi_env env, napi_callback_info info);
|
||||
napi_value ShowNext(napi_env env, napi_callback_info info);
|
||||
napi_value ShowPrevious(napi_env env, napi_callback_info info);
|
||||
napi_value FinishAnimation(napi_env env, napi_callback_info info);
|
||||
} // namespace OHOS::Ace
|
||||
#endif // COMPONENT_EXT_ARC_SWIPER_ARC_SWIPER_NAPI_H
|
@ -1,97 +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.
|
||||
*/
|
||||
|
||||
const __ArcSwiper__ = requireInternal("arkui.arcswiper");
|
||||
|
||||
class ArcSwiper extends JSViewAbstract {
|
||||
static create(value) {
|
||||
__ArcSwiper__.create(value);
|
||||
}
|
||||
|
||||
static index(value) {
|
||||
__ArcSwiper__.index(value);
|
||||
}
|
||||
|
||||
static indicator(value) {
|
||||
__ArcSwiper__.indicator(value);
|
||||
}
|
||||
|
||||
static duration(value) {
|
||||
__ArcSwiper__.duration(value);
|
||||
}
|
||||
|
||||
static vertical(value) {
|
||||
__ArcSwiper__.vertical(value);
|
||||
}
|
||||
|
||||
static disableSwipe(value) {
|
||||
__ArcSwiper__.disableSwipe(value);
|
||||
}
|
||||
|
||||
static onChange(value) {
|
||||
__ArcSwiper__.onChange(value);
|
||||
}
|
||||
|
||||
static onAnimationStart(value) {
|
||||
__ArcSwiper__.onAnimationStart(value);
|
||||
}
|
||||
|
||||
static onAnimationEnd(value) {
|
||||
__ArcSwiper__.onAnimationEnd(value);
|
||||
}
|
||||
|
||||
static onGestureSwipe(value) {
|
||||
__ArcSwiper__.onGestureSwipe(value);
|
||||
}
|
||||
|
||||
static onClick(value) {
|
||||
__Common__.onClick(value);
|
||||
}
|
||||
|
||||
static onAppear(value) {
|
||||
__Common__.onAppear(value);
|
||||
}
|
||||
|
||||
static onDisAppear(value) {
|
||||
__Common__.onDisAppear(value);
|
||||
}
|
||||
|
||||
static onTouch(value) {
|
||||
__Common__.onTouch(value);
|
||||
}
|
||||
|
||||
static onHover(value) {
|
||||
__Common__.onHover(value);
|
||||
}
|
||||
|
||||
static onKeyEvent(value) {
|
||||
__Common__.onKeyEvent(value);
|
||||
}
|
||||
|
||||
static onDeleteEvent(value) {
|
||||
__Common__.onDeleteEvent(value);
|
||||
}
|
||||
|
||||
static remoteMessage(value) {
|
||||
__Common__.remoteMessage(value);
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
ArcSwiper,
|
||||
ArcSwiperController: __ArcSwiper__.ArcSwiperController,
|
||||
ArcDotIndicator: __ArcSwiper__.ArcDotIndicator,
|
||||
ArcDirection: __ArcSwiper__.ArcDirection,
|
||||
};
|
@ -21,30 +21,7 @@
|
||||
#include "napi/native_node_api.h"
|
||||
#include "securec.h"
|
||||
|
||||
#include "frameworks/base/json/json_util.h"
|
||||
#include "frameworks/core/common/card_scope.h"
|
||||
#include "frameworks/core/common/container.h"
|
||||
|
||||
namespace OHOS::Ace {
|
||||
namespace {
|
||||
constexpr uint32_t COLOR_ALPHA_OFFSET = 24;
|
||||
constexpr uint32_t COLOR_ALPHA_VALUE = 0xFF000000;
|
||||
constexpr uint32_t ERROR_COLOR_ID = -1;
|
||||
|
||||
enum class ResourceType : uint32_t {
|
||||
COLOR = 10001,
|
||||
FLOAT,
|
||||
STRING,
|
||||
PLURAL,
|
||||
BOOLEAN,
|
||||
INTARRAY,
|
||||
INTEGER,
|
||||
PATTERN,
|
||||
STRARRAY,
|
||||
MEDIA = 20000,
|
||||
RAWFILE = 30000
|
||||
};
|
||||
} // namespace
|
||||
|
||||
NapiAsyncEvent::NapiAsyncEvent(napi_env env, napi_value callback)
|
||||
{
|
||||
@ -103,20 +80,6 @@ napi_value ExtNapiUtils::CreateNull(napi_env env)
|
||||
return jsNull;
|
||||
}
|
||||
|
||||
napi_value ExtNapiUtils::CreateObject(napi_env env)
|
||||
{
|
||||
napi_value object = nullptr;
|
||||
NAPI_CALL(env, napi_create_object(env, &object));
|
||||
return object;
|
||||
}
|
||||
|
||||
napi_value ExtNapiUtils::CreateDouble(napi_env env, double value)
|
||||
{
|
||||
napi_value jsValue = nullptr;
|
||||
NAPI_CALL(env, napi_create_double(env, value, &jsValue));
|
||||
return jsValue;
|
||||
}
|
||||
|
||||
bool ExtNapiUtils::GetBool(napi_env env, napi_value value)
|
||||
{
|
||||
bool boolValue = false;
|
||||
@ -179,164 +142,4 @@ bool ExtNapiUtils::CheckTypeForNapiValue(napi_env env, napi_value param, napi_va
|
||||
|
||||
return valueType == expectType;
|
||||
}
|
||||
|
||||
uint32_t ColorAlphaAdapt(uint32_t origin)
|
||||
{
|
||||
uint32_t result = origin;
|
||||
if ((origin >> COLOR_ALPHA_OFFSET) == 0) {
|
||||
result = origin | COLOR_ALPHA_VALUE;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
RefPtr<ThemeConstants> ExtNapiUtils::GetThemeConstants(napi_env env, napi_value value)
|
||||
{
|
||||
napi_value jsBundleName = ExtNapiUtils::GetNamedProperty(env, value, "bundleName");
|
||||
napi_value jsModuleName = ExtNapiUtils::GetNamedProperty(env, value, "moduleName");
|
||||
std::string bundleName = ExtNapiUtils::GetStringFromValueUtf8(env, jsBundleName);
|
||||
std::string moduleName = ExtNapiUtils::GetStringFromValueUtf8(env, jsModuleName);
|
||||
|
||||
auto cardId = CardScope::CurrentId();
|
||||
if (cardId != INVALID_CARD_ID) {
|
||||
auto container = Container::Current();
|
||||
auto weak = container->GetCardPipeline(cardId);
|
||||
auto cardPipelineContext = weak.Upgrade();
|
||||
CHECK_NULL_RETURN(cardPipelineContext, nullptr);
|
||||
auto cardThemeManager = cardPipelineContext->GetThemeManager();
|
||||
CHECK_NULL_RETURN(cardThemeManager, nullptr);
|
||||
return cardThemeManager->GetThemeConstants(bundleName, moduleName);
|
||||
}
|
||||
|
||||
auto container = Container::CurrentSafely();
|
||||
CHECK_NULL_RETURN(container, nullptr);
|
||||
auto pipelineContext = container->GetPipelineContext();
|
||||
CHECK_NULL_RETURN(pipelineContext, nullptr);
|
||||
auto themeManager = pipelineContext->GetThemeManager();
|
||||
CHECK_NULL_RETURN(themeManager, nullptr);
|
||||
return themeManager->GetThemeConstants(bundleName, moduleName);
|
||||
}
|
||||
|
||||
bool ExtNapiUtils::ParseColor(napi_env env, napi_value value, Color& result)
|
||||
{
|
||||
napi_valuetype valueType = ExtNapiUtils::GetValueType(env, value);
|
||||
if (valueType != napi_number && valueType != napi_string && valueType != napi_object) {
|
||||
return false;
|
||||
}
|
||||
if (valueType == napi_number) {
|
||||
int32_t colorId = ExtNapiUtils::GetCInt32(env, value);
|
||||
result = Color(ColorAlphaAdapt(static_cast<uint32_t>(colorId)));
|
||||
return true;
|
||||
}
|
||||
if (valueType == napi_string) {
|
||||
std::string colorString = ExtNapiUtils::GetStringFromValueUtf8(env, value);
|
||||
return Color::ParseColorString(colorString, result);
|
||||
}
|
||||
return ParseColorFromResource(env, value, result);
|
||||
}
|
||||
|
||||
bool ExtNapiUtils::ParseColorFromResource(napi_env env, napi_value value, Color& colorResult)
|
||||
{
|
||||
auto themeConstants = GetThemeConstants(env, value);
|
||||
CHECK_NULL_RETURN(themeConstants, false);
|
||||
|
||||
napi_value jsColorId = ExtNapiUtils::GetNamedProperty(env, value, "id");
|
||||
napi_value jsParams = ExtNapiUtils::GetNamedProperty(env, value, "params");
|
||||
uint32_t colorId = ExtNapiUtils::GetCInt32(env, jsColorId);
|
||||
if (!ExtNapiUtils::IsArray(env, jsParams)) {
|
||||
return false;
|
||||
}
|
||||
if (colorId == ERROR_COLOR_ID) {
|
||||
uint32_t length;
|
||||
napi_get_array_length(env, jsParams, &length);
|
||||
auto jsonArray = JsonUtil::CreateArray(true);
|
||||
for (uint32_t i = 0; i < length; i++) {
|
||||
napi_value elementValue;
|
||||
napi_get_element(env, jsParams, i, &elementValue);
|
||||
std::string key = std::to_string(i);
|
||||
jsonArray->Put(key.c_str(), PutJsonValue(env, elementValue, key));
|
||||
}
|
||||
const char* jsonKey = std::to_string(0).c_str();
|
||||
std::string colorName = jsonArray->GetValue(jsonKey)->GetValue(jsonKey)->ToString();
|
||||
colorResult = themeConstants->GetColorByName(colorName);
|
||||
return true;
|
||||
}
|
||||
napi_value jsType = GetNamedProperty(env, value, "type");
|
||||
napi_valuetype valueType = GetValueType(env, jsType);
|
||||
if (valueType != napi_null && valueType == napi_number &&
|
||||
static_cast<uint32_t>(valueType) == static_cast<uint32_t>(ResourceType::STRING)) {
|
||||
auto value = themeConstants->GetString(ExtNapiUtils::GetCInt32(env, jsType));
|
||||
return Color::ParseColorString(value, colorResult);
|
||||
}
|
||||
if (valueType != napi_null && valueType == napi_number &&
|
||||
static_cast<uint32_t>(valueType) == static_cast<uint32_t>(ResourceType::INTEGER)) {
|
||||
auto value = themeConstants->GetInt(ExtNapiUtils::GetCInt32(env, jsType));
|
||||
colorResult = Color(ColorAlphaAdapt(value));
|
||||
return true;
|
||||
}
|
||||
colorResult = themeConstants->GetColor(colorId);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ExtNapiUtils::IsArray(napi_env env, napi_value value)
|
||||
{
|
||||
bool isArray = false;
|
||||
napi_status ret = napi_is_array(env, value, &isArray);
|
||||
if (ret == napi_ok) {
|
||||
return isArray;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
napi_value ExtNapiUtils::CreateUndefined(napi_env env)
|
||||
{
|
||||
napi_value undefined = nullptr;
|
||||
NAPI_CALL(env, napi_get_undefined(env, &undefined));
|
||||
return undefined;
|
||||
}
|
||||
|
||||
void ExtNapiUtils::SetNamedProperty(napi_env env, napi_value object, const std::string& propertyName, napi_value value)
|
||||
{
|
||||
if (GetValueType(env, object) != napi_object) {
|
||||
return;
|
||||
}
|
||||
|
||||
napi_set_named_property(env, object, propertyName.c_str(), value);
|
||||
}
|
||||
|
||||
napi_value ExtNapiUtils::GetNamedProperty(napi_env env, napi_value object, const std::string& propertyName)
|
||||
{
|
||||
if (GetValueType(env, object) != napi_object) {
|
||||
return CreateUndefined(env);
|
||||
}
|
||||
|
||||
napi_value value = nullptr;
|
||||
NAPI_CALL(env, napi_get_named_property(env, object, propertyName.c_str(), &value));
|
||||
return value;
|
||||
}
|
||||
|
||||
std::unique_ptr<JsonValue> ExtNapiUtils::PutJsonValue(napi_env env, napi_value value, std::string& key)
|
||||
{
|
||||
auto result = JsonUtil::Create(true);
|
||||
napi_valuetype valueType = ExtNapiUtils::GetValueType(env, value);
|
||||
switch (valueType) {
|
||||
case napi_boolean: {
|
||||
bool boolValue = ExtNapiUtils::GetBool(env, value);
|
||||
result->Put(key.c_str(), boolValue);
|
||||
break;
|
||||
}
|
||||
case napi_number: {
|
||||
int32_t intValue = ExtNapiUtils::GetCInt32(env, value);
|
||||
result->Put(key.c_str(), intValue);
|
||||
break;
|
||||
}
|
||||
case napi_string: {
|
||||
std::string stringValue = ExtNapiUtils::GetStringFromValueUtf8(env, value);
|
||||
result->Put(key.c_str(), stringValue.c_str());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
} // namespace OHOS::Ace
|
@ -22,8 +22,6 @@
|
||||
#include "napi/native_node_api.h"
|
||||
|
||||
#include "base/utils/macros.h"
|
||||
#include "frameworks/core/components/common/properties/color.h"
|
||||
#include "frameworks/core/components/theme/theme_constants.h"
|
||||
|
||||
namespace OHOS::Ace {
|
||||
class ACE_FORCE_EXPORT NapiAsyncEvent {
|
||||
@ -41,22 +39,12 @@ private:
|
||||
class ACE_FORCE_EXPORT ExtNapiUtils {
|
||||
public:
|
||||
static napi_value CreateInt32(napi_env env, int32_t code);
|
||||
static napi_value CreateObject(napi_env env);
|
||||
static napi_value CreateDouble(napi_env env, double value);
|
||||
static int32_t GetCInt32(napi_env env, napi_value value);
|
||||
static napi_value CreateNull(napi_env env);
|
||||
static napi_value CreateUndefined(napi_env env);
|
||||
static bool GetBool(napi_env env, napi_value value);
|
||||
static napi_valuetype GetValueType(napi_env env, napi_value value);
|
||||
static std::string GetStringFromValueUtf8(napi_env env, napi_value value);
|
||||
static bool CheckTypeForNapiValue(napi_env env, napi_value param, napi_valuetype expectType);
|
||||
static bool IsArray(napi_env env, napi_value value);
|
||||
static void SetNamedProperty(napi_env env, napi_value object, const std::string& propertyName, napi_value value);
|
||||
static napi_value GetNamedProperty(napi_env env, napi_value object, const std::string& propertyName);
|
||||
static bool ParseColorFromResource(napi_env env, napi_value value, Color& result);
|
||||
static bool ParseColor(napi_env env, napi_value value, Color& result);
|
||||
static RefPtr<ThemeConstants> GetThemeConstants(napi_env env, napi_value value);
|
||||
static std::unique_ptr<JsonValue> PutJsonValue(napi_env env, napi_value value, std::string& key);
|
||||
};
|
||||
} // namespace OHOS::Ace
|
||||
}
|
||||
#endif // FOUNDATION_ACE_COMPONENTEXT_EXT_COMMON_EXT_NAPI_UTILS_H
|
@ -22,7 +22,7 @@ namespace OHOS::Ace::Framework {
|
||||
|
||||
class JsConverter {
|
||||
public:
|
||||
ACE_FORCE_EXPORT static JSRef<JSVal> ConvertNapiValueToJsVal(napi_value nativeValue);
|
||||
static JSRef<JSVal> ConvertNapiValueToJsVal(napi_value nativeValue);
|
||||
static napi_value ConvertJsValToNapiValue(JSRef<JSVal> jsVal);
|
||||
};
|
||||
|
||||
|
@ -187,7 +187,7 @@ public:
|
||||
JsiObject();
|
||||
explicit JsiObject(panda::Local<panda::ObjectRef> val);
|
||||
explicit JsiObject(const EcmaVM *vm, panda::Local<panda::ObjectRef> val);
|
||||
ACE_FORCE_EXPORT explicit JsiObject(const panda::CopyableGlobal<panda::ObjectRef>& val);
|
||||
explicit JsiObject(const panda::CopyableGlobal<panda::ObjectRef>& val);
|
||||
bool IsUndefined() const;
|
||||
~JsiObject() override = default;
|
||||
enum InternalFieldIndex { INSTANCE = 0 };
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
namespace OHOS::Ace::Framework {
|
||||
|
||||
RefPtr<SwiperController> SwiperModelImpl::Create(bool isCreateArc)
|
||||
RefPtr<SwiperController> SwiperModelImpl::Create()
|
||||
{
|
||||
std::list<RefPtr<OHOS::Ace::Component>> componentChildren;
|
||||
RefPtr<OHOS::Ace::SwiperComponent> component = AceType::MakeRefPtr<OHOS::Ace::SwiperComponent>(componentChildren);
|
||||
|
@ -22,7 +22,7 @@ namespace OHOS::Ace::Framework {
|
||||
|
||||
class ACE_EXPORT SwiperModelImpl : public OHOS::Ace::SwiperModel {
|
||||
public:
|
||||
RefPtr<SwiperController> Create(bool isCreateArc = false) override;
|
||||
RefPtr<SwiperController> Create() override;
|
||||
void SetDirection(Axis axis) override;
|
||||
void SetIndex(uint32_t index) override;
|
||||
void SetAutoPlay(bool autoPlay) override;
|
||||
|
@ -40,7 +40,7 @@ public:
|
||||
CardScope::UpdateCurrent(restoreId_);
|
||||
}
|
||||
|
||||
ACE_FORCE_EXPORT static uint64_t CurrentId();
|
||||
static uint64_t CurrentId();
|
||||
|
||||
static void UpdateCurrent(uint64_t id);
|
||||
|
||||
|
@ -211,7 +211,7 @@ public:
|
||||
{}
|
||||
~LinearColor() = default;
|
||||
|
||||
ACE_FORCE_EXPORT static const LinearColor TRANSPARENT;
|
||||
static const LinearColor TRANSPARENT;
|
||||
static const LinearColor WHITE;
|
||||
static const LinearColor BLACK;
|
||||
static const LinearColor RED;
|
||||
|
@ -37,13 +37,6 @@ enum class SwiperDisplayMode {
|
||||
enum class SwiperIndicatorType {
|
||||
DOT = 0,
|
||||
DIGIT,
|
||||
ARC_DOT,
|
||||
};
|
||||
|
||||
enum class SwiperArcDirection {
|
||||
THREE_CLOCK_DIRECTION = 0,
|
||||
SIX_CLOCK_DIRECTION,
|
||||
NINE_CLOCK_DIRECTION,
|
||||
};
|
||||
|
||||
struct SwiperAttribute : Attribute {
|
||||
|
@ -19,7 +19,6 @@
|
||||
#include "core/components/theme/theme.h"
|
||||
#include "core/components/theme/theme_constants.h"
|
||||
#include "core/components/theme/theme_constants_defines.h"
|
||||
#include "core/components_ng/property/gradient_property.h"
|
||||
|
||||
namespace OHOS::Ace {
|
||||
namespace {
|
||||
@ -168,11 +167,6 @@ public:
|
||||
theme->indicatorDotPadding_ = SWIPER_INDICATOR_DOT_PADDING_DEFAULT;
|
||||
theme->indicatorDigitHeight_ = SWIPER_INDICATOR_DIGIT_HEIGHT;
|
||||
theme->indicatorDotItemSpace_ = SWIPER_INDICATOR_DOT_ITEM_SPACE;
|
||||
theme->arcSelectedItemColor_ = swiperPattern->GetAttr<Color>("dot_active_color", Color::TRANSPARENT);
|
||||
theme->arcItemColor_ = swiperPattern->GetAttr<Color>("dot_color", Color::TRANSPARENT);
|
||||
theme->arcMaskStartColor_ = swiperPattern->GetAttr<Color>("mask_color_start", Color::TRANSPARENT);
|
||||
theme->arcMaskEndColor_ = swiperPattern->GetAttr<Color>("mask_color_end", Color::TRANSPARENT);
|
||||
theme->arcContainerColor_ = swiperPattern->GetAttr<Color>("container_color", Color::TRANSPARENT);
|
||||
}
|
||||
};
|
||||
|
||||
@ -425,36 +419,6 @@ public:
|
||||
return indicatorPaddingDot_;
|
||||
}
|
||||
|
||||
const Color& GetArcItemColor() const
|
||||
{
|
||||
return arcItemColor_;
|
||||
}
|
||||
|
||||
const Color& GetArcSelectedItemColor() const
|
||||
{
|
||||
return arcSelectedItemColor_;
|
||||
}
|
||||
|
||||
const Color& GetArcContainerColor() const
|
||||
{
|
||||
return arcContainerColor_;
|
||||
}
|
||||
|
||||
NG::Gradient GetArcMaskColor() const
|
||||
{
|
||||
NG::GradientColor beginGradientColor;
|
||||
NG::GradientColor endGradientColor;
|
||||
beginGradientColor.SetLinearColor(LinearColor(arcMaskStartColor_));
|
||||
beginGradientColor.SetDimension(Dimension(0.0f));
|
||||
endGradientColor.SetLinearColor(LinearColor(arcMaskEndColor_));
|
||||
endGradientColor.SetDimension(Dimension(1.0f));
|
||||
NG::Gradient gradient;
|
||||
gradient.AddColor(beginGradientColor);
|
||||
gradient.AddColor(endGradientColor);
|
||||
|
||||
return gradient;
|
||||
}
|
||||
|
||||
const Dimension& GetIndicatorBgHeight() const
|
||||
{
|
||||
return indicatorBgHeight_;
|
||||
@ -535,11 +499,6 @@ private:
|
||||
Dimension indicatorDigitHeight_;
|
||||
Dimension indicatorDotItemSpace_;
|
||||
Dimension indicatorPaddingDot_;
|
||||
Color arcItemColor_;
|
||||
Color arcSelectedItemColor_;
|
||||
Color arcContainerColor_;
|
||||
Color arcMaskStartColor_;
|
||||
Color arcMaskEndColor_;
|
||||
uint32_t leftSymbolId_ = 0;
|
||||
uint32_t rightSymbolId_ = 0;
|
||||
uint32_t upSymbolId_ = 0;
|
||||
|
@ -438,7 +438,6 @@ build_component_ng("pattern_ng") {
|
||||
"stepper/stepper_model_ng.cpp",
|
||||
"stepper/stepper_node.cpp",
|
||||
"stepper/stepper_pattern.cpp",
|
||||
"swiper/arc_swiper_pattern.cpp",
|
||||
"swiper/swiper_accessibility_property.cpp",
|
||||
"swiper/swiper_helper.cpp",
|
||||
"swiper/swiper_layout_algorithm.cpp",
|
||||
@ -446,9 +445,6 @@ build_component_ng("pattern_ng") {
|
||||
"swiper/swiper_paint_method.cpp",
|
||||
"swiper/swiper_paint_property.cpp",
|
||||
"swiper/swiper_pattern.cpp",
|
||||
"swiper_indicator/circle_dot_indicator/circle_dot_indicator_layout_algorithm.cpp",
|
||||
"swiper_indicator/circle_dot_indicator/circle_dot_indicator_modifier.cpp",
|
||||
"swiper_indicator/circle_dot_indicator/circle_dot_indicator_paint_method.cpp",
|
||||
"swiper_indicator/digit_indicator/digit_indicator_layout_algorithm.cpp",
|
||||
"swiper_indicator/dot_indicator/dot_indicator_layout_algorithm.cpp",
|
||||
"swiper_indicator/dot_indicator/dot_indicator_modifier.cpp",
|
||||
@ -459,7 +455,6 @@ build_component_ng("pattern_ng") {
|
||||
"swiper_indicator/indicator_common/swiper_arrow_pattern.cpp",
|
||||
"swiper_indicator/indicator_common/swiper_indicator_accessibility_property.cpp",
|
||||
"swiper_indicator/indicator_common/swiper_indicator_pattern.cpp",
|
||||
"swiper_indicator/indicator_common/swiper_indicator_utils.cpp",
|
||||
"symbol/symbol_effect_options.cpp",
|
||||
"symbol/symbol_model_ng.cpp",
|
||||
"symbol/symbol_source_info.cpp",
|
||||
|
@ -1,112 +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/swiper/arc_swiper_pattern.h"
|
||||
|
||||
#include "core/components_ng/pattern/swiper_indicator/indicator_common/swiper_indicator_pattern.h"
|
||||
|
||||
namespace OHOS::Ace::NG {
|
||||
void ArcSwiperPattern::SaveCircleDotIndicatorProperty(const RefPtr<FrameNode>& indicatorNode)
|
||||
{
|
||||
CHECK_NULL_VOID(indicatorNode);
|
||||
auto indicatorPattern = indicatorNode->GetPattern<SwiperIndicatorPattern>();
|
||||
CHECK_NULL_VOID(indicatorPattern);
|
||||
auto layoutProperty = indicatorNode->GetLayoutProperty<SwiperIndicatorLayoutProperty>();
|
||||
CHECK_NULL_VOID(layoutProperty);
|
||||
auto paintProperty = indicatorNode->GetPaintProperty<CircleDotIndicatorPaintProperty>();
|
||||
CHECK_NULL_VOID(paintProperty);
|
||||
auto pipelineContext = GetHost()->GetContext();
|
||||
CHECK_NULL_VOID(pipelineContext);
|
||||
auto swiperIndicatorTheme = pipelineContext->GetTheme<SwiperIndicatorTheme>();
|
||||
CHECK_NULL_VOID(swiperIndicatorTheme);
|
||||
auto swiperParameters = GetSwiperArcDotParameters();
|
||||
CHECK_NULL_VOID(swiperParameters);
|
||||
layoutProperty->ResetIndicatorLayoutStyle();
|
||||
paintProperty->UpdateArcDirection(swiperParameters->arcDirection.value_or(SwiperArcDirection::SIX_CLOCK_DIRECTION));
|
||||
paintProperty->UpdateColor(swiperParameters->itemColor.value_or(swiperIndicatorTheme->GetArcItemColor()));
|
||||
paintProperty->UpdateSelectedColor(
|
||||
swiperParameters->selectedItemColor.value_or(swiperIndicatorTheme->GetArcSelectedItemColor()));
|
||||
paintProperty->UpdateContainerColor(
|
||||
swiperParameters->containerColor.value_or(swiperIndicatorTheme->GetArcContainerColor()));
|
||||
paintProperty->UpdateMaskColor(swiperParameters->maskColor.value_or(swiperIndicatorTheme->GetArcMaskColor()));
|
||||
MarkDirtyNodeSelf();
|
||||
indicatorNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF);
|
||||
}
|
||||
|
||||
void ArcSwiperPattern::SetSwiperArcDotParameters(const SwiperArcDotParameters& swiperArcDotParameters)
|
||||
{
|
||||
swiperArcDotParameters_ = std::make_shared<SwiperArcDotParameters>(swiperArcDotParameters);
|
||||
}
|
||||
|
||||
std::string ArcSwiperPattern::GetArcDotIndicatorStyle() const
|
||||
{
|
||||
auto swiperParameters = GetSwiperArcDotParameters();
|
||||
CHECK_NULL_RETURN(swiperParameters, "");
|
||||
auto jsonValue = JsonUtil::Create(true);
|
||||
auto pipelineContext = GetHost()->GetContext();
|
||||
CHECK_NULL_RETURN(pipelineContext, "");
|
||||
auto swiperIndicatorTheme = pipelineContext->GetTheme<SwiperIndicatorTheme>();
|
||||
CHECK_NULL_RETURN(swiperIndicatorTheme, "");
|
||||
|
||||
static const char* ARC_DIRECTION[] = { "ArcDirection.THREE_CLOCK_DIRECTION", "ArcDirection.SIX_CLOCK_DIRECTION",
|
||||
"ArcDirection.NINE_CLOCK_DIRECTION" };
|
||||
jsonValue->Put("arcDirection", ARC_DIRECTION[static_cast<int32_t>(swiperParameters->arcDirection.value_or(
|
||||
SwiperArcDirection::SIX_CLOCK_DIRECTION))]);
|
||||
jsonValue->Put("itemColor",
|
||||
swiperParameters->itemColor.value_or(swiperIndicatorTheme->GetArcItemColor()).ColorToString().c_str());
|
||||
jsonValue->Put("selectedItemColor",
|
||||
swiperParameters->selectedItemColor.value_or(swiperIndicatorTheme->GetArcSelectedItemColor())
|
||||
.ColorToString()
|
||||
.c_str());
|
||||
jsonValue->Put(
|
||||
"backgroundColor", swiperParameters->containerColor.value_or(swiperIndicatorTheme->GetArcContainerColor())
|
||||
.ColorToString()
|
||||
.c_str());
|
||||
jsonValue->Put("maskColor",
|
||||
GradientToJson(swiperParameters->maskColor.value_or(swiperIndicatorTheme->GetArcMaskColor())).c_str());
|
||||
|
||||
return jsonValue->ToString();
|
||||
}
|
||||
|
||||
std::shared_ptr<SwiperArcDotParameters> ArcSwiperPattern::GetSwiperArcDotParameters() const
|
||||
{
|
||||
if (swiperArcDotParameters_ == nullptr) {
|
||||
swiperArcDotParameters_ = std::make_shared<SwiperArcDotParameters>();
|
||||
auto pipelineContext = GetHost()->GetContext();
|
||||
CHECK_NULL_RETURN(pipelineContext, swiperArcDotParameters_);
|
||||
auto swiperIndicatorTheme = pipelineContext->GetTheme<SwiperIndicatorTheme>();
|
||||
|
||||
swiperArcDotParameters_->arcDirection = SwiperArcDirection::SIX_CLOCK_DIRECTION;
|
||||
swiperArcDotParameters_->itemColor = swiperIndicatorTheme->GetArcItemColor();
|
||||
swiperArcDotParameters_->selectedItemColor = swiperIndicatorTheme->GetArcSelectedItemColor();
|
||||
swiperArcDotParameters_->containerColor = swiperIndicatorTheme->GetArcContainerColor();
|
||||
swiperArcDotParameters_->maskColor = swiperIndicatorTheme->GetArcMaskColor();
|
||||
}
|
||||
return swiperArcDotParameters_;
|
||||
}
|
||||
|
||||
std::string ArcSwiperPattern::GradientToJson(Gradient colors) const
|
||||
{
|
||||
auto jsonArray = JsonUtil::CreateArray(true);
|
||||
for (size_t index = 0; index < colors.GetColors().size(); ++index) {
|
||||
auto gradientColor = colors.GetColors()[index];
|
||||
auto gradientColorJson = JsonUtil::Create(true);
|
||||
gradientColorJson->Put("color", gradientColor.GetLinearColor().ToColor().ColorToString().c_str());
|
||||
gradientColorJson->Put("offset", std::to_string(gradientColor.GetDimension().Value()).c_str());
|
||||
jsonArray->Put(std::to_string(index).c_str(), gradientColorJson);
|
||||
}
|
||||
return jsonArray->ToString();
|
||||
}
|
||||
} // namespace OHOS::Ace::NG
|
@ -1,35 +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_SWIPER_ARC_SWIPER_PATTERN_H
|
||||
#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SWIPER_ARC_SWIPER_PATTERN_H
|
||||
|
||||
#include "core/components_ng/pattern/swiper/swiper_pattern.h"
|
||||
|
||||
namespace OHOS::Ace::NG {
|
||||
class ArcSwiperPattern : public SwiperPattern {
|
||||
DECLARE_ACE_TYPE(ArcSwiperPattern, SwiperPattern);
|
||||
public:
|
||||
void SaveCircleDotIndicatorProperty(const RefPtr<FrameNode>& indicatorNode) override;
|
||||
void SetSwiperArcDotParameters(const SwiperArcDotParameters& swiperArcDotParameters) override;
|
||||
std::string GetArcDotIndicatorStyle() const override;
|
||||
std::shared_ptr<SwiperArcDotParameters> GetSwiperArcDotParameters() const override;
|
||||
|
||||
private:
|
||||
std::string GradientToJson(Gradient colors) const;
|
||||
mutable std::shared_ptr<SwiperArcDotParameters> swiperArcDotParameters_;
|
||||
};
|
||||
} // namespace OHOS::Ace::NG
|
||||
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SWIPER_ARC_SWIPER_PATTERN_H
|
@ -63,14 +63,6 @@ struct SwiperDigitalParameters {
|
||||
std::optional<FontWeight> selectedFontWeight;
|
||||
};
|
||||
|
||||
struct SwiperArcDotParameters {
|
||||
std::optional<SwiperArcDirection> arcDirection;
|
||||
std::optional<Color> itemColor;
|
||||
std::optional<Color> selectedItemColor;
|
||||
std::optional<Color> containerColor;
|
||||
std::optional<NG::Gradient> maskColor;
|
||||
};
|
||||
|
||||
struct SwiperArrowParameters {
|
||||
std::optional<bool> isShowBackground;
|
||||
std::optional<bool> isSidebarMiddle;
|
||||
@ -104,7 +96,7 @@ public:
|
||||
static SwiperModel* GetInstance();
|
||||
virtual ~SwiperModel() = default;
|
||||
|
||||
virtual RefPtr<SwiperController> Create(bool isCreateArc = false);
|
||||
virtual RefPtr<SwiperController> Create();
|
||||
virtual void SetDirection(Axis axis);
|
||||
virtual void SetIndex(uint32_t index);
|
||||
virtual void SetIndicatorInteractive(bool interactive) {}
|
||||
@ -139,7 +131,6 @@ public:
|
||||
virtual void SetIndicatorType(SwiperIndicatorType indicatorType) {}
|
||||
virtual void SetIsIndicatorCustomSize(bool isCustomSize) {}
|
||||
virtual void SetDotIndicatorStyle(const SwiperParameters& swiperParameters) {}
|
||||
virtual void SetArcDotIndicatorStyle(const SwiperArcDotParameters& swiperArcDotParameters) {}
|
||||
virtual void SetDigitIndicatorStyle(const SwiperDigitalParameters& swiperDigitalParameters) {}
|
||||
virtual void SetPreviousMargin(const Dimension& prevMargin, bool ignoreBlank) {}
|
||||
virtual void SetNextMargin(const Dimension& nextMargin, bool ignoreBlank) {}
|
||||
|
@ -26,7 +26,6 @@
|
||||
#include "core/components/swiper/swiper_component.h"
|
||||
#include "core/components_ng/base/frame_node.h"
|
||||
#include "core/components_ng/base/view_stack_processor.h"
|
||||
#include "core/components_ng/pattern/swiper/arc_swiper_pattern.h"
|
||||
#include "core/components_ng/pattern/swiper/swiper_pattern.h"
|
||||
#include "core/components_ng/pattern/swiper_indicator/indicator_common/swiper_indicator_pattern.h"
|
||||
#include "core/components_ng/pattern/swiper_indicator/indicator_common/swiper_indicator_utils.h"
|
||||
@ -39,20 +38,14 @@ typedef enum {
|
||||
ARKUI_SWIPER_ARROW_SHOW_ON_HOVER,
|
||||
} SwiperArrow;
|
||||
|
||||
RefPtr<SwiperController> SwiperModelNG::Create(bool isCreateArc)
|
||||
RefPtr<SwiperController> SwiperModelNG::Create()
|
||||
{
|
||||
auto* stack = ViewStackProcessor::GetInstance();
|
||||
CHECK_NULL_RETURN(stack, nullptr);
|
||||
auto nodeId = stack->ClaimNodeId();
|
||||
ACE_LAYOUT_SCOPED_TRACE("Create[%s][self:%d]", V2::SWIPER_ETS_TAG, nodeId);
|
||||
RefPtr<FrameNode> swiperNode = nullptr;
|
||||
if (isCreateArc) {
|
||||
swiperNode = FrameNode::GetOrCreateFrameNode(
|
||||
V2::SWIPER_ETS_TAG, nodeId, []() { return AceType::MakeRefPtr<ArcSwiperPattern>(); });
|
||||
} else {
|
||||
swiperNode = FrameNode::GetOrCreateFrameNode(
|
||||
V2::SWIPER_ETS_TAG, nodeId, []() { return AceType::MakeRefPtr<SwiperPattern>(); });
|
||||
}
|
||||
auto swiperNode = FrameNode::GetOrCreateFrameNode(
|
||||
V2::SWIPER_ETS_TAG, nodeId, []() { return AceType::MakeRefPtr<SwiperPattern>(); });
|
||||
|
||||
stack->Push(swiperNode);
|
||||
auto pattern = swiperNode->GetPattern<SwiperPattern>();
|
||||
@ -258,15 +251,6 @@ void SwiperModelNG::SetIndicatorStyle(const SwiperParameters& swiperParameters)
|
||||
pattern->SetSwiperParameters(swiperParameters);
|
||||
};
|
||||
|
||||
void SwiperModelNG::SetArcDotIndicatorStyle(const SwiperArcDotParameters& swiperArcDotParameters)
|
||||
{
|
||||
auto swiperNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
|
||||
CHECK_NULL_VOID(swiperNode);
|
||||
auto pattern = swiperNode->GetPattern<SwiperPattern>();
|
||||
CHECK_NULL_VOID(pattern);
|
||||
pattern->SetSwiperArcDotParameters(swiperArcDotParameters);
|
||||
}
|
||||
|
||||
void SwiperModelNG::SetDotIndicatorStyle(const SwiperParameters& swiperParameters)
|
||||
{
|
||||
auto swiperNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
|
||||
@ -619,14 +603,6 @@ void SwiperModelNG::SetDotIndicatorStyle(FrameNode* frameNode, const SwiperParam
|
||||
pattern->SetSwiperParameters(swiperParameters);
|
||||
}
|
||||
|
||||
void SwiperModelNG::SetArcDotIndicatorStyle(FrameNode* frameNode, const SwiperArcDotParameters& swiperArcDotParameters)
|
||||
{
|
||||
CHECK_NULL_VOID(frameNode);
|
||||
auto pattern = frameNode->GetPattern<SwiperPattern>();
|
||||
CHECK_NULL_VOID(pattern);
|
||||
pattern->SetSwiperArcDotParameters(swiperArcDotParameters);
|
||||
}
|
||||
|
||||
void SwiperModelNG::SetEnabled(FrameNode* frameNode, bool enabled)
|
||||
{
|
||||
ACE_UPDATE_NODE_PAINT_PROPERTY(SwiperPaintProperty, Enabled, enabled, frameNode);
|
||||
|
@ -29,9 +29,9 @@
|
||||
#include "core/components_ng/pattern/swiper/swiper_model.h"
|
||||
|
||||
namespace OHOS::Ace::NG {
|
||||
class ACE_FORCE_EXPORT SwiperModelNG : public OHOS::Ace::SwiperModel {
|
||||
class ACE_EXPORT SwiperModelNG : public OHOS::Ace::SwiperModel {
|
||||
public:
|
||||
RefPtr<SwiperController> Create(bool isCreateArc = false) override;
|
||||
RefPtr<SwiperController> Create() override;
|
||||
void SetDirection(Axis axis) override;
|
||||
void SetIndex(uint32_t index) override;
|
||||
void SetIndicatorInteractive(bool interactive) override;
|
||||
@ -64,7 +64,6 @@ public:
|
||||
void SetMainSwiperSizeHeight() override;
|
||||
void SetIndicatorStyle(const SwiperParameters& swiperParameters) override;
|
||||
void SetDotIndicatorStyle(const SwiperParameters& swiperParameters) override;
|
||||
void SetArcDotIndicatorStyle(const SwiperArcDotParameters& swiperArcDotParameters) override;
|
||||
void SetDigitIndicatorStyle(const SwiperDigitalParameters& swiperDigitalParameters) override;
|
||||
void SetPreviousMargin(const Dimension& prevMargin, bool ignoreBlank) override;
|
||||
void SetNextMargin(const Dimension& nextMargi, bool ignoreBlankn) override;
|
||||
@ -104,7 +103,6 @@ public:
|
||||
static void SetIndicatorIsBoolean(FrameNode* frameNode, bool isBoolean);
|
||||
static void SetDigitIndicatorStyle(FrameNode* frameNode, const SwiperDigitalParameters& swiperDigitalParameters);
|
||||
static void SetDotIndicatorStyle(FrameNode* frameNode, const SwiperParameters& swiperParameters);
|
||||
static void SetArcDotIndicatorStyle(FrameNode* frameNode, const SwiperArcDotParameters& swiperArcDotParameters);
|
||||
static void SetIndicatorType(FrameNode* frameNode, SwiperIndicatorType indicatorType);
|
||||
static void SetIsIndicatorCustomSize(FrameNode* frameNode, bool isCustomSize);
|
||||
static void SetEnabled(FrameNode* frameNode, bool enabled);
|
||||
|
@ -1906,8 +1906,6 @@ void SwiperPattern::InitIndicator()
|
||||
CHECK_NULL_VOID(props);
|
||||
if (props->GetIndicatorTypeValue(SwiperIndicatorType::DOT) == SwiperIndicatorType::DOT) {
|
||||
SwiperHelper::SaveDotIndicatorProperty(indicatorNode, *this);
|
||||
} else if (props->GetIndicatorTypeValue(SwiperIndicatorType::DOT) == SwiperIndicatorType::ARC_DOT) {
|
||||
SaveCircleDotIndicatorProperty(indicatorNode);
|
||||
} else {
|
||||
SwiperHelper::SaveDigitIndicatorProperty(indicatorNode, *this);
|
||||
}
|
||||
@ -5175,10 +5173,6 @@ void SwiperPattern::DumpAdvanceInfo()
|
||||
DumpLog::GetInstance().AddDesc("SwiperIndicatorType:DIGIT");
|
||||
break;
|
||||
}
|
||||
case SwiperIndicatorType::ARC_DOT: {
|
||||
DumpLog::GetInstance().AddDesc("SwiperIndicatorType:ARC_DOT");
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
@ -5768,8 +5762,6 @@ void SwiperPattern::ToJsonValue(std::unique_ptr<JsonValue>& json, const Inspecto
|
||||
const char* indicator = "indicator";
|
||||
if (indicatorType == SwiperIndicatorType::DOT) {
|
||||
json->PutExtAttr(indicator, GetDotIndicatorStyle().c_str(), filter);
|
||||
} else if (indicatorType == SwiperIndicatorType::ARC_DOT) {
|
||||
json->PutExtAttr(indicator, GetArcDotIndicatorStyle().c_str(), filter);
|
||||
} else {
|
||||
json->PutExtAttr(indicator, GetDigitIndicatorStyle().c_str(), filter);
|
||||
}
|
||||
|
@ -101,11 +101,6 @@ public:
|
||||
std::string GetDotIndicatorStyle() const;
|
||||
std::string GetDigitIndicatorStyle() const;
|
||||
|
||||
virtual std::string GetArcDotIndicatorStyle() const
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
int32_t GetCurrentShownIndex() const
|
||||
{
|
||||
return IsLoop() ? currentIndex_ : GetLoopIndex(currentIndex_);
|
||||
@ -269,8 +264,6 @@ public:
|
||||
swiperDigitalParameters_ = std::make_shared<SwiperDigitalParameters>(swiperDigitalParameters);
|
||||
}
|
||||
|
||||
virtual void SetSwiperArcDotParameters(const SwiperArcDotParameters& swiperArcDotParameters) {}
|
||||
|
||||
void ShowNext();
|
||||
void ShowPrevious();
|
||||
void SwipeTo(int32_t index);
|
||||
@ -414,10 +407,6 @@ public:
|
||||
}
|
||||
|
||||
std::shared_ptr<SwiperParameters> GetSwiperParameters() const;
|
||||
virtual std::shared_ptr<SwiperArcDotParameters> GetSwiperArcDotParameters() const
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
std::shared_ptr<SwiperDigitalParameters> GetSwiperDigitalParameters() const;
|
||||
|
||||
void ArrowHover(bool hoverFlag);
|
||||
@ -547,8 +536,6 @@ public:
|
||||
prevMarginIgnoreBlank_ = prevMarginIgnoreBlank;
|
||||
}
|
||||
|
||||
virtual void SaveCircleDotIndicatorProperty(const RefPtr<FrameNode>& indicatorNode) {}
|
||||
|
||||
bool GetPrevMarginIgnoreBlank()
|
||||
{
|
||||
return prevMarginIgnoreBlank_;
|
||||
|
@ -1,49 +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/swiper_indicator/circle_dot_indicator/circle_dot_indicator_layout_algorithm.h"
|
||||
|
||||
#include "core/components_ng/pattern/swiper_indicator/indicator_common/swiper_indicator_pattern.h"
|
||||
|
||||
namespace OHOS::Ace::NG {
|
||||
void CircleDotIndicatorLayoutAlgorithm::Measure(LayoutWrapper* layoutWrapper)
|
||||
{
|
||||
CHECK_NULL_VOID(layoutWrapper);
|
||||
auto frameNode = layoutWrapper->GetHostNode();
|
||||
CHECK_NULL_VOID(frameNode);
|
||||
auto indicatorlayoutProperty = frameNode->GetLayoutProperty<SwiperIndicatorLayoutProperty>();
|
||||
CHECK_NULL_VOID(indicatorlayoutProperty);
|
||||
|
||||
const auto& indicatorLayoutConstraint = indicatorlayoutProperty->GetLayoutConstraint();
|
||||
float swiperWidthIndicator = 0.0f;
|
||||
float swiperHeightIndicator = 0.0f;
|
||||
if (indicatorLayoutConstraint.has_value()) {
|
||||
swiperWidthIndicator = indicatorLayoutConstraint->parentIdealSize.Width().value_or(0.0f);
|
||||
swiperHeightIndicator = indicatorLayoutConstraint->parentIdealSize.Height().value_or(0.0f);
|
||||
}
|
||||
|
||||
SizeF frameSize = { -1.0f, -1.0f };
|
||||
frameSize.SetSizeT(SizeF { swiperWidthIndicator, swiperHeightIndicator });
|
||||
layoutWrapper->GetGeometryNode()->SetFrameSize(frameSize);
|
||||
}
|
||||
|
||||
void CircleDotIndicatorLayoutAlgorithm::Layout(LayoutWrapper* layoutWrapper)
|
||||
{
|
||||
CHECK_NULL_VOID(layoutWrapper);
|
||||
OffsetF currentOffset = { 0.0, 0.0 };
|
||||
|
||||
layoutWrapper->GetGeometryNode()->SetMarginFrameOffset(currentOffset);
|
||||
}
|
||||
} // namespace OHOS::Ace::NG
|
@ -1,34 +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_PATTERN_SWIPER_INDICATOR_CIRCLE_DOT_INDICATOR_LAYOUT_ALGORITHM_H
|
||||
#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SWIPER_INDICATOR_CIRCLE_DOT_INDICATOR_LAYOUT_ALGORITHM_H
|
||||
|
||||
#include "core/components_ng/layout/layout_algorithm.h"
|
||||
#include "core/components_ng/layout/layout_wrapper.h"
|
||||
namespace OHOS::Ace::NG {
|
||||
class ACE_EXPORT CircleDotIndicatorLayoutAlgorithm : public LayoutAlgorithm {
|
||||
DECLARE_ACE_TYPE(CircleDotIndicatorLayoutAlgorithm, LayoutAlgorithm);
|
||||
|
||||
public:
|
||||
CircleDotIndicatorLayoutAlgorithm() = default;
|
||||
~CircleDotIndicatorLayoutAlgorithm() override = default;
|
||||
|
||||
void OnReset() override {}
|
||||
void Measure(LayoutWrapper* layoutWrapper) override;
|
||||
void Layout(LayoutWrapper* layoutWrapper) override;
|
||||
};
|
||||
} // namespace OHOS::Ace::NG
|
||||
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SWIPER_INDICATOR_ROUND_DOT_INDICATOR_LAYOUT_ALGORITHM_H
|
@ -1,501 +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/swiper_indicator/circle_dot_indicator/circle_dot_indicator_modifier.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "base/utils/utils.h"
|
||||
#include "core/animation/spring_curve.h"
|
||||
#include "core/components_ng/render/animation_utils.h"
|
||||
#include "core/components_ng/render/drawing.h"
|
||||
|
||||
namespace OHOS::Ace::NG {
|
||||
namespace {
|
||||
constexpr int32_t COMPONENT_DILATE_ANIMATION_DURATION = 250;
|
||||
constexpr int32_t COMPONENT_SHRINK_ANIMATION_DURATION = 300;
|
||||
|
||||
constexpr float BLACK_POINT_CENTER_BEZIER_CURVE_VELOCITY = 0.4f;
|
||||
constexpr float HEAD_POINT_CENTER_BEZIER_CURVE_VELOCITY = 1.0f;
|
||||
constexpr float TAIL_POINT_CENTER_BEZIER_CURVE_VELOCITY = 0.2f;
|
||||
constexpr float CENTER_BEZIER_CURVE_MASS = 0.0f;
|
||||
constexpr float CENTER_BEZIER_CURVE_STIFFNESS = 1.0f;
|
||||
constexpr float CENTER_BEZIER_CURVE_DAMPING = 1.0f;
|
||||
|
||||
constexpr int32_t BLACK_POINT_DURATION = 400;
|
||||
constexpr int32_t LONG_POINT_DURATION = 400;
|
||||
|
||||
constexpr uint32_t ITEM_RADIUS = 0;
|
||||
constexpr uint32_t SELECTED_ITEM_RADIUS = 1;
|
||||
constexpr uint32_t CONTAINER_RADIUS = 2;
|
||||
constexpr uint32_t ITEM_PADDING = 3;
|
||||
constexpr uint32_t SELECTED_ITEM_PADDING = 4;
|
||||
constexpr uint32_t ACTIVE_ITEM_ANGLE = 5;
|
||||
constexpr Dimension MASK_HEIGHT = 36.0_vp;
|
||||
constexpr double QUARTER_CIRCLE_ANGLE = 90.0;
|
||||
constexpr double HALF_CIRCLE_ANGLE = 180.0;
|
||||
constexpr int32_t ITEM_TWO_NUM = 2;
|
||||
constexpr int32_t ITEM_THREE_NUM = 3;
|
||||
|
||||
constexpr float DEFAULT_DOT_PADDING_ANGLE = 5.0f;
|
||||
constexpr float DEFAULT_DOT_ACTIVE_PADDING_ANGLE = 7.0f;
|
||||
constexpr float DEFAULT_DOT_ACTIVE_ANGLE = 4.0f;
|
||||
constexpr Dimension DEFAULT_CONTAINER_BORDER_WIDTH = 16.0_vp;
|
||||
constexpr Dimension DEFAULT_ITEM_RADIUS = 2.5_vp;
|
||||
constexpr Dimension DEFAULT_ITEM_SELECT_WIDTH = 5.0_vp;
|
||||
} // namespace
|
||||
|
||||
CircleDotIndicatorModifier::CircleDotIndicatorModifier()
|
||||
: backgroundColor_(AceType::MakeRefPtr<AnimatablePropertyColor>(LinearColor::TRANSPARENT)),
|
||||
vectorBlackPointAngle_(AceType::MakeRefPtr<AnimatablePropertyVectorFloat>(LinearVector<float>(0))),
|
||||
unselectedColor_(AceType::MakeRefPtr<PropertyColor>(Color::TRANSPARENT)),
|
||||
selectedColor_(AceType::MakeRefPtr<PropertyColor>(Color::TRANSPARENT)),
|
||||
dotPaddingAngle_(AceType::MakeRefPtr<AnimatablePropertyFloat>(DEFAULT_DOT_PADDING_ANGLE)),
|
||||
dotActiveAngle_(AceType::MakeRefPtr<AnimatablePropertyFloat>(DEFAULT_DOT_ACTIVE_ANGLE)),
|
||||
dotActiveStartAngle_(AceType::MakeRefPtr<AnimatablePropertyFloat>(0.0)),
|
||||
dotActiveEndAngle_(AceType::MakeRefPtr<AnimatablePropertyFloat>(0.0)),
|
||||
dotActivePaddingAngle_(AceType::MakeRefPtr<AnimatablePropertyFloat>(DEFAULT_DOT_ACTIVE_PADDING_ANGLE)),
|
||||
containerBorderWidth_(AceType::MakeRefPtr<AnimatablePropertyFloat>(DEFAULT_CONTAINER_BORDER_WIDTH.ConvertToPx())),
|
||||
itemRadius_(AceType::MakeRefPtr<AnimatablePropertyFloat>(DEFAULT_ITEM_RADIUS.ConvertToPx())),
|
||||
itemSelectWidth_(AceType::MakeRefPtr<AnimatablePropertyFloat>(DEFAULT_ITEM_SELECT_WIDTH.ConvertToPx())),
|
||||
updateMaskColor_(AceType::MakeRefPtr<PropertyBool>(false))
|
||||
{
|
||||
AttachProperty(backgroundColor_);
|
||||
AttachProperty(vectorBlackPointAngle_);
|
||||
AttachProperty(unselectedColor_);
|
||||
AttachProperty(selectedColor_);
|
||||
AttachProperty(dotPaddingAngle_);
|
||||
AttachProperty(dotActiveAngle_);
|
||||
AttachProperty(dotActiveStartAngle_);
|
||||
AttachProperty(dotActiveEndAngle_);
|
||||
AttachProperty(dotActivePaddingAngle_);
|
||||
AttachProperty(containerBorderWidth_);
|
||||
AttachProperty(itemRadius_);
|
||||
AttachProperty(itemSelectWidth_);
|
||||
AttachProperty(updateMaskColor_);
|
||||
}
|
||||
|
||||
void CircleDotIndicatorModifier::onDraw(DrawingContext& context)
|
||||
{
|
||||
ContentProperty contentProperty;
|
||||
contentProperty.backgroundColor = backgroundColor_->Get().ToColor();
|
||||
contentProperty.vectorBlackPointAngle = vectorBlackPointAngle_->Get();
|
||||
contentProperty.dotPaddingAngle = dotPaddingAngle_->Get();
|
||||
contentProperty.dotActiveAngle = dotActiveAngle_->Get();
|
||||
contentProperty.dotActiveStartAngle = dotActiveStartAngle_->Get();
|
||||
contentProperty.dotActiveEndAngle = dotActiveEndAngle_->Get();
|
||||
contentProperty.dotActivePaddingAngle = dotActivePaddingAngle_->Get();
|
||||
contentProperty.containerBorderWidth = containerBorderWidth_->Get();
|
||||
contentProperty.itemRadius = itemRadius_->Get();
|
||||
contentProperty.itemSelectWidth = itemSelectWidth_->Get();
|
||||
|
||||
PaintIndicatorMask(context, contentProperty);
|
||||
PaintBackground(context, contentProperty);
|
||||
PaintContent(context, contentProperty);
|
||||
}
|
||||
|
||||
void CircleDotIndicatorModifier::PaintBackground(DrawingContext& context, const ContentProperty& contentProperty)
|
||||
{
|
||||
RSCanvas& canvas = context.canvas;
|
||||
CHECK_NULL_VOID(contentProperty.backgroundColor.GetAlpha());
|
||||
float dotPaddingAngle = contentProperty.dotPaddingAngle;
|
||||
float dotActivePaddingAngle = contentProperty.dotActivePaddingAngle;
|
||||
float containerBorderWidth = contentProperty.containerBorderWidth;
|
||||
float dotActiveAngle = contentProperty.dotActiveAngle;
|
||||
auto itemSize = contentProperty.vectorBlackPointAngle.size();
|
||||
float allPointArcAngle = 0;
|
||||
// The number 2 represents multiplying by 2 times or dividing equally
|
||||
if (currentIndex_ == 0 || currentIndex_ == itemSize - 1) {
|
||||
if (itemSize >= ITEM_TWO_NUM) {
|
||||
allPointArcAngle = (itemSize - ITEM_TWO_NUM) * dotPaddingAngle + dotActivePaddingAngle + dotActiveAngle / 2;
|
||||
} else {
|
||||
allPointArcAngle = dotActiveAngle;
|
||||
}
|
||||
} else {
|
||||
allPointArcAngle = (itemSize - ITEM_THREE_NUM) * dotPaddingAngle + dotActivePaddingAngle * 2;
|
||||
}
|
||||
RSPen pen;
|
||||
pen.SetAntiAlias(true);
|
||||
pen.SetWidth(containerBorderWidth);
|
||||
pen.SetColor(contentProperty.backgroundColor.GetValue());
|
||||
pen.SetCapStyle(ToRSCapStyle(LineCap::ROUND));
|
||||
float startAngle = 0;
|
||||
PointF startPoint;
|
||||
PointF endPoint;
|
||||
// The number 2 represents multiplying by 2 times or dividing equally
|
||||
if (axis_ == Axis::HORIZONTAL) {
|
||||
startPoint.SetX(centerX_ - circleRadius_ + containerBorderWidth / 2);
|
||||
startPoint.SetY(centerY_ - circleRadius_ + containerBorderWidth / 2);
|
||||
endPoint.SetX(centerX_ + circleRadius_ - (containerBorderWidth / 2));
|
||||
endPoint.SetY(centerY_ + circleRadius_ - (containerBorderWidth / 2));
|
||||
} else {
|
||||
startPoint.SetX(centerY_ - circleRadius_ + containerBorderWidth / 2);
|
||||
startPoint.SetY(centerX_ - circleRadius_ + containerBorderWidth / 2);
|
||||
endPoint.SetX(centerY_ + circleRadius_ - (containerBorderWidth / 2));
|
||||
endPoint.SetY(centerX_ + circleRadius_ - (containerBorderWidth / 2));
|
||||
}
|
||||
if (arcDirection_ == SwiperArcDirection::SIX_CLOCK_DIRECTION) {
|
||||
startAngle = QUARTER_CIRCLE_ANGLE + (allPointArcAngle / 2);
|
||||
} else if (arcDirection_ == SwiperArcDirection::THREE_CLOCK_DIRECTION) {
|
||||
startAngle = allPointArcAngle / 2;
|
||||
} else {
|
||||
startAngle = HALF_CIRCLE_ANGLE + (allPointArcAngle / 2);
|
||||
}
|
||||
canvas.AttachPen(pen);
|
||||
canvas.DrawArc(
|
||||
{ startPoint.GetX(), startPoint.GetY(), endPoint.GetX(), endPoint.GetY() }, startAngle, -allPointArcAngle);
|
||||
canvas.DetachPen();
|
||||
canvas.Restore();
|
||||
}
|
||||
|
||||
std::vector<GradientColor> CircleDotIndicatorModifier::GetMaskColor() const
|
||||
{
|
||||
Gradient gradient = SortGradientColorsByOffset(maskColor_);
|
||||
std::vector<GradientColor> gradientColors = gradient.GetColors();
|
||||
if (gradientColors.empty()) {
|
||||
auto pipeline = PipelineBase::GetCurrentContextSafely();
|
||||
CHECK_NULL_RETURN(pipeline, gradientColors);
|
||||
auto theme = pipeline->GetTheme<SwiperIndicatorTheme>();
|
||||
CHECK_NULL_RETURN(theme, gradientColors);
|
||||
gradientColors = theme->GetArcMaskColor().GetColors();
|
||||
}
|
||||
return gradientColors;
|
||||
}
|
||||
|
||||
Gradient CircleDotIndicatorModifier::SortGradientColorsByOffset(const Gradient& gradient) const
|
||||
{
|
||||
auto srcGradientColors = gradient.GetColors();
|
||||
std::sort(srcGradientColors.begin(), srcGradientColors.end(),
|
||||
[](const GradientColor& left, const GradientColor& right) {
|
||||
return left.GetDimension().Value() < right.GetDimension().Value();
|
||||
});
|
||||
|
||||
Gradient sortedGradient;
|
||||
for (const auto& item : srcGradientColors) {
|
||||
sortedGradient.AddColor(item);
|
||||
}
|
||||
|
||||
return sortedGradient;
|
||||
}
|
||||
|
||||
void CircleDotIndicatorModifier::PaintIndicatorMask(DrawingContext& context, const ContentProperty& contentProperty)
|
||||
{
|
||||
RSCanvas& canvas = context.canvas;
|
||||
RSBrush brush;
|
||||
brush.SetAntiAlias(true);
|
||||
|
||||
std::vector<GradientColor> gradientColors = GetMaskColor();
|
||||
std::vector<RSColorQuad> colors;
|
||||
std::vector<float> pos;
|
||||
for (size_t i = 0; i < gradientColors.size(); i++) {
|
||||
colors.emplace_back(gradientColors[i].GetLinearColor().GetValue());
|
||||
pos.emplace_back(gradientColors[i].GetDimension().Value());
|
||||
}
|
||||
|
||||
float centerX = axis_ == Axis::HORIZONTAL ? centerX_ : centerY_;
|
||||
float centerY = axis_ == Axis::HORIZONTAL ? centerY_ : centerX_;
|
||||
RSPoint startPt = { 0.0, 0.0 };
|
||||
RSPoint endPt = { 0.0, 0.0 };
|
||||
RSPoint gradientStartPt = { 0.0, 0.0 };
|
||||
RSPoint gradientendPt = { 0.0, 0.0 };
|
||||
if (arcDirection_ == SwiperArcDirection::SIX_CLOCK_DIRECTION) {
|
||||
startPt = RSPoint(
|
||||
centerX - circleRadius_, centerY + circleRadius_ - static_cast<float>(MASK_HEIGHT.ConvertToPx()));
|
||||
endPt = RSPoint(centerX + circleRadius_, centerY + circleRadius_);
|
||||
gradientStartPt = RSPoint(centerX, centerY + circleRadius_ - static_cast<float>(MASK_HEIGHT.ConvertToPx()));
|
||||
gradientendPt = RSPoint(centerX, centerY + circleRadius_);
|
||||
} else if (arcDirection_ == SwiperArcDirection::THREE_CLOCK_DIRECTION) {
|
||||
startPt = RSPoint(
|
||||
centerX + circleRadius_ - static_cast<float>(MASK_HEIGHT.ConvertToPx()), centerY - circleRadius_);
|
||||
endPt = RSPoint(centerX + circleRadius_, centerY + circleRadius_);
|
||||
gradientStartPt = RSPoint(centerX + circleRadius_ - static_cast<float>(MASK_HEIGHT.ConvertToPx()), centerY);
|
||||
gradientendPt = RSPoint(centerX + circleRadius_, centerY);
|
||||
} else {
|
||||
startPt = RSPoint(centerX - circleRadius_, centerY - circleRadius_);
|
||||
endPt = RSPoint(
|
||||
centerX - circleRadius_ + static_cast<float>(MASK_HEIGHT.ConvertToPx()), centerY + circleRadius_);
|
||||
gradientStartPt = RSPoint(centerX - circleRadius_ + static_cast<float>(MASK_HEIGHT.ConvertToPx()), centerY);
|
||||
gradientendPt = RSPoint(centerX - circleRadius_, centerY);
|
||||
}
|
||||
|
||||
brush.SetShaderEffect(
|
||||
RSShaderEffect::CreateLinearGradient(gradientStartPt, gradientendPt, colors, pos, RSTileMode::CLAMP));
|
||||
canvas.AttachBrush(brush);
|
||||
canvas.DrawRect({ startPt.GetX(), startPt.GetY(), endPt.GetX(), endPt.GetY() });
|
||||
canvas.DetachBrush();
|
||||
canvas.Restore();
|
||||
}
|
||||
|
||||
void CircleDotIndicatorModifier::PaintContent(DrawingContext& context, ContentProperty& contentProperty)
|
||||
{
|
||||
RSCanvas& canvas = context.canvas;
|
||||
auto totalCount = contentProperty.vectorBlackPointAngle.size();
|
||||
for (size_t i = 0; i < totalCount; ++i) {
|
||||
float itemAngle = contentProperty.vectorBlackPointAngle[i];
|
||||
PaintUnselectedIndicator(canvas, itemAngle, contentProperty, LinearColor(unselectedColor_->Get()));
|
||||
}
|
||||
|
||||
PaintSelectedIndicator(canvas, contentProperty);
|
||||
}
|
||||
|
||||
void CircleDotIndicatorModifier::PaintUnselectedIndicator(
|
||||
RSCanvas& canvas, float itemAngle, ContentProperty& contentProperty, const LinearColor& indicatorColor)
|
||||
{
|
||||
RSBrush brush;
|
||||
brush.SetAntiAlias(true);
|
||||
brush.SetColor(ToRSColor(indicatorColor));
|
||||
canvas.AttachBrush(brush);
|
||||
|
||||
float itemRadius = contentProperty.itemRadius;
|
||||
float containerBorderWidth = contentProperty.containerBorderWidth;
|
||||
|
||||
float itemCenterX = 0.0;
|
||||
float itemCenterY = 0.0;
|
||||
float centerX = axis_ == Axis::HORIZONTAL ? centerX_ : centerY_;
|
||||
float centerY = axis_ == Axis::HORIZONTAL ? centerY_ : centerX_;
|
||||
double radians = std::abs(itemAngle) * M_PI / HALF_CIRCLE_ANGLE;
|
||||
// The number 2 represents multiplying by 2 times or dividing equally
|
||||
if (GreatOrEqualCustomPrecision(itemAngle, 0.0f)) {
|
||||
if (arcDirection_ == SwiperArcDirection::SIX_CLOCK_DIRECTION) {
|
||||
itemCenterX = centerX - (circleRadius_ - (containerBorderWidth / 2)) * sin(radians);
|
||||
itemCenterY = centerY + (circleRadius_ - (containerBorderWidth / 2)) * cos(radians);
|
||||
} else if (arcDirection_ == SwiperArcDirection::THREE_CLOCK_DIRECTION) {
|
||||
itemCenterX = centerX + (circleRadius_ - (containerBorderWidth / 2)) * cos(radians);
|
||||
itemCenterY = centerY + (circleRadius_ - (containerBorderWidth / 2)) * sin(radians);
|
||||
} else {
|
||||
itemCenterX = centerX - (circleRadius_ - (containerBorderWidth / 2)) * cos(radians);
|
||||
itemCenterY = centerY - (circleRadius_ - (containerBorderWidth / 2)) * sin(radians);
|
||||
}
|
||||
} else {
|
||||
if (arcDirection_ == SwiperArcDirection::SIX_CLOCK_DIRECTION) {
|
||||
itemCenterX = centerX + (circleRadius_ - (containerBorderWidth / 2)) * sin(radians);
|
||||
itemCenterY = centerY + (circleRadius_ - (containerBorderWidth / 2)) * cos(radians);
|
||||
} else if (arcDirection_ == SwiperArcDirection::THREE_CLOCK_DIRECTION) {
|
||||
itemCenterX = centerX + (circleRadius_ - (containerBorderWidth / 2)) * cos(radians);
|
||||
itemCenterY = centerY - (circleRadius_ - (containerBorderWidth / 2)) * sin(radians);
|
||||
} else {
|
||||
itemCenterX = centerX - (circleRadius_ - (containerBorderWidth / 2)) * cos(radians);
|
||||
itemCenterY = centerY + (circleRadius_ - (containerBorderWidth / 2)) * sin(radians);
|
||||
}
|
||||
}
|
||||
|
||||
canvas.DrawCircle({ itemCenterX, itemCenterY }, itemRadius);
|
||||
canvas.DetachBrush();
|
||||
}
|
||||
|
||||
void CircleDotIndicatorModifier::PaintSelectedIndicator(RSCanvas& canvas, ContentProperty& contentProperty)
|
||||
{
|
||||
auto totalCount = contentProperty.vectorBlackPointAngle.size();
|
||||
if (totalCount == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
float containerBorderWidth = contentProperty.containerBorderWidth;
|
||||
float itemSelectWidth = contentProperty.itemSelectWidth;
|
||||
float dotActiveStartAngle = contentProperty.dotActiveStartAngle;
|
||||
float dotActiveEndAngle = contentProperty.dotActiveEndAngle;
|
||||
|
||||
RSPen pen;
|
||||
pen.SetAntiAlias(true);
|
||||
pen.SetWidth(itemSelectWidth);
|
||||
pen.SetColor(selectedColor_->Get().GetValue());
|
||||
pen.SetCapStyle(ToRSCapStyle(LineCap::ROUND));
|
||||
|
||||
PointF startPoint;
|
||||
PointF endPoint;
|
||||
if (axis_ == Axis::HORIZONTAL) {
|
||||
startPoint.SetX(centerX_ - circleRadius_ + containerBorderWidth / 2);
|
||||
startPoint.SetY(centerY_ - circleRadius_ + containerBorderWidth / 2);
|
||||
endPoint.SetX(centerX_ + circleRadius_ - (containerBorderWidth / 2));
|
||||
endPoint.SetY(centerY_ + circleRadius_ - (containerBorderWidth / 2));
|
||||
} else {
|
||||
startPoint.SetX(centerY_ - circleRadius_ + containerBorderWidth / 2);
|
||||
startPoint.SetY(centerX_ - circleRadius_ + containerBorderWidth / 2);
|
||||
endPoint.SetX(centerY_ + circleRadius_ - (containerBorderWidth / 2));
|
||||
endPoint.SetY(centerX_ + circleRadius_ - (containerBorderWidth / 2));
|
||||
}
|
||||
|
||||
canvas.AttachPen(pen);
|
||||
canvas.DrawArc(
|
||||
{ startPoint.GetX(), startPoint.GetY(), endPoint.GetX(), endPoint.GetY() },
|
||||
dotActiveStartAngle, dotActiveEndAngle - dotActiveStartAngle);
|
||||
canvas.DetachPen();
|
||||
canvas.Restore();
|
||||
}
|
||||
|
||||
void CircleDotIndicatorModifier::UpdateShrinkPaintProperty(const LinearVector<float>& normalItemSizes,
|
||||
const LinearVector<float>& vectorBlackPointAngle, const std::pair<float, float>& longPointAngle)
|
||||
{
|
||||
dotPaddingAngle_->Set(normalItemSizes[ITEM_PADDING]);
|
||||
dotActiveAngle_->Set(normalItemSizes[ACTIVE_ITEM_ANGLE]);
|
||||
dotActivePaddingAngle_->Set(normalItemSizes[SELECTED_ITEM_PADDING]);
|
||||
containerBorderWidth_->Set(normalItemSizes[CONTAINER_RADIUS] * 2);
|
||||
itemRadius_->Set(normalItemSizes[ITEM_RADIUS]);
|
||||
itemSelectWidth_->Set(normalItemSizes[SELECTED_ITEM_RADIUS] * 2);
|
||||
if (longPointLeftAnimEnd_ && longPointRightAnimEnd_) {
|
||||
dotActiveStartAngle_->Set(longPointAngle.first);
|
||||
dotActiveEndAngle_->Set(longPointAngle.second);
|
||||
}
|
||||
vectorBlackPointAngle_->Set(vectorBlackPointAngle);
|
||||
}
|
||||
|
||||
void CircleDotIndicatorModifier::UpdateDilatePaintProperty(const LinearVector<float>& hoverItemSizes,
|
||||
const LinearVector<float>& vectorBlackPointAngle, const std::pair<float, float>& longPointAngle)
|
||||
{
|
||||
dotPaddingAngle_->Set(hoverItemSizes[ITEM_PADDING]);
|
||||
dotActiveAngle_->Set(hoverItemSizes[ACTIVE_ITEM_ANGLE]);
|
||||
dotActivePaddingAngle_->Set(hoverItemSizes[SELECTED_ITEM_PADDING]);
|
||||
containerBorderWidth_->Set(hoverItemSizes[CONTAINER_RADIUS] * 2);
|
||||
itemRadius_->Set(hoverItemSizes[ITEM_RADIUS]);
|
||||
itemSelectWidth_->Set(hoverItemSizes[SELECTED_ITEM_RADIUS] * 2);
|
||||
if (longPointLeftAnimEnd_ && longPointRightAnimEnd_) {
|
||||
dotActiveStartAngle_->Set(longPointAngle.first);
|
||||
dotActiveEndAngle_->Set(longPointAngle.second);
|
||||
}
|
||||
vectorBlackPointAngle_->Set(vectorBlackPointAngle);
|
||||
}
|
||||
|
||||
void CircleDotIndicatorModifier::UpdateBackgroundColor(const Color& backgroundColor)
|
||||
{
|
||||
backgroundColor_->Set(LinearColor(backgroundColor));
|
||||
}
|
||||
|
||||
void CircleDotIndicatorModifier::UpdateNormalPaintProperty(const LinearVector<float>& normalItemSizes,
|
||||
const LinearVector<float>& vectorBlackPointAngle, const std::pair<float, float>& longPointAngle)
|
||||
{
|
||||
UpdateShrinkPaintProperty(normalItemSizes, vectorBlackPointAngle, longPointAngle);
|
||||
UpdateBackgroundColor(containerColor_.ChangeOpacity(0));
|
||||
}
|
||||
|
||||
void CircleDotIndicatorModifier::UpdatePressPaintProperty(const LinearVector<float>& hoverItemSizes,
|
||||
const LinearVector<float>& vectorBlackPointAngle, const std::pair<float, float>& longPointAngle)
|
||||
{
|
||||
UpdateDilatePaintProperty(hoverItemSizes, vectorBlackPointAngle, longPointAngle);
|
||||
UpdateBackgroundColor(containerColor_);
|
||||
}
|
||||
|
||||
void CircleDotIndicatorModifier::UpdateNormalToPressPaintProperty(const LinearVector<float>& hoverItemSizes,
|
||||
const LinearVector<float>& vectorBlackPointAngle, const std::pair<float, float>& longPointAngle)
|
||||
{
|
||||
AnimationOption option;
|
||||
option.SetDuration(COMPONENT_DILATE_ANIMATION_DURATION);
|
||||
option.SetCurve(Curves::SHARP);
|
||||
longPointLeftAnimEnd_ = true;
|
||||
longPointRightAnimEnd_ = true;
|
||||
AnimationUtils::Animate(option, [weak = WeakClaim(this), hoverItemSizes, vectorBlackPointAngle, longPointAngle]() {
|
||||
auto modifier = weak.Upgrade();
|
||||
CHECK_NULL_VOID(modifier);
|
||||
modifier->UpdatePressPaintProperty(hoverItemSizes, vectorBlackPointAngle, longPointAngle);
|
||||
});
|
||||
}
|
||||
|
||||
void CircleDotIndicatorModifier::UpdatePressToNormalPaintProperty(const LinearVector<float>& normalItemSizes,
|
||||
const LinearVector<float>& vectorBlackPointAngle, const std::pair<float, float>& longPointAngle)
|
||||
{
|
||||
StopAnimation(true);
|
||||
AnimationOption option;
|
||||
option.SetDuration(COMPONENT_SHRINK_ANIMATION_DURATION);
|
||||
option.SetCurve(Curves::SHARP);
|
||||
AnimationUtils::Animate(option, [weak = WeakClaim(this), normalItemSizes, vectorBlackPointAngle, longPointAngle]() {
|
||||
auto modifier = weak.Upgrade();
|
||||
CHECK_NULL_VOID(modifier);
|
||||
modifier->UpdateNormalPaintProperty(normalItemSizes, vectorBlackPointAngle, longPointAngle);
|
||||
});
|
||||
}
|
||||
|
||||
void CircleDotIndicatorModifier::PlayBlackPointsAnimation(const LinearVector<float>& vectorBlackPointAngle)
|
||||
{
|
||||
auto curve = AceType::MakeRefPtr<CubicCurve>(BLACK_POINT_CENTER_BEZIER_CURVE_VELOCITY, CENTER_BEZIER_CURVE_MASS,
|
||||
CENTER_BEZIER_CURVE_STIFFNESS, CENTER_BEZIER_CURVE_DAMPING);
|
||||
AnimationOption option;
|
||||
option.SetCurve(curve);
|
||||
option.SetDuration(BLACK_POINT_DURATION);
|
||||
blackPointsAnimation_ =
|
||||
AnimationUtils::StartAnimation(option, [&]() { vectorBlackPointAngle_->Set(vectorBlackPointAngle); });
|
||||
}
|
||||
|
||||
void CircleDotIndicatorModifier::PlayLongPointAnimation(const std::pair<float, float>& longPointAngle,
|
||||
GestureState gestureState, const LinearVector<float>& vectorBlackPointAngle)
|
||||
{
|
||||
AnimationOption optionHead;
|
||||
optionHead.SetDuration(LONG_POINT_DURATION);
|
||||
optionHead.SetCurve(AceType::MakeRefPtr<CubicCurve>(HEAD_POINT_CENTER_BEZIER_CURVE_VELOCITY,
|
||||
CENTER_BEZIER_CURVE_MASS, CENTER_BEZIER_CURVE_STIFFNESS, CENTER_BEZIER_CURVE_DAMPING));
|
||||
|
||||
AnimationOption optionTail;
|
||||
optionTail.SetDuration(LONG_POINT_DURATION);
|
||||
optionHead.SetCurve(AceType::MakeRefPtr<CubicCurve>(TAIL_POINT_CENTER_BEZIER_CURVE_VELOCITY,
|
||||
CENTER_BEZIER_CURVE_MASS, CENTER_BEZIER_CURVE_STIFFNESS, CENTER_BEZIER_CURVE_DAMPING));
|
||||
|
||||
AnimationOption optionLeft = optionTail;
|
||||
AnimationOption optionRight = optionHead;
|
||||
|
||||
if (gestureState == GestureState::GESTURE_STATE_RELEASE_LEFT) {
|
||||
optionLeft = optionHead;
|
||||
optionRight = optionTail;
|
||||
}
|
||||
|
||||
if (longPointLeftAnimEnd_ && longPointRightAnimEnd_) {
|
||||
longPointLeftAnimEnd_ = false;
|
||||
longPointRightAnimEnd_ = false;
|
||||
auto weak = WeakClaim(this);
|
||||
AnimationUtils::StartAnimation(optionLeft, [weak, longPointAngle]() {
|
||||
auto modifier = weak.Upgrade();
|
||||
CHECK_NULL_VOID(modifier);
|
||||
modifier->dotActiveStartAngle_->Set(longPointAngle.first);
|
||||
}, [weak]() {
|
||||
auto modifier = weak.Upgrade();
|
||||
CHECK_NULL_VOID(modifier);
|
||||
modifier->longPointLeftAnimEnd_ = true;
|
||||
});
|
||||
|
||||
AnimationUtils::StartAnimation(optionRight, [weak, longPointAngle]() {
|
||||
auto modifier = weak.Upgrade();
|
||||
CHECK_NULL_VOID(modifier);
|
||||
modifier->dotActiveEndAngle_->Set(longPointAngle.second);
|
||||
}, [weak]() {
|
||||
auto modifier = weak.Upgrade();
|
||||
CHECK_NULL_VOID(modifier);
|
||||
modifier->longPointRightAnimEnd_ = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void CircleDotIndicatorModifier::PlayIndicatorAnimation(const LinearVector<float>& vectorBlackPointAngle,
|
||||
const std::pair<float, float>& longPointAngle, GestureState gestureState)
|
||||
{
|
||||
StopAnimation();
|
||||
PlayBlackPointsAnimation(vectorBlackPointAngle);
|
||||
PlayLongPointAnimation(longPointAngle, gestureState, vectorBlackPointAngle);
|
||||
}
|
||||
|
||||
void CircleDotIndicatorModifier::StopAnimation(bool ifImmediately)
|
||||
{
|
||||
if (ifImmediately) {
|
||||
AnimationOption option;
|
||||
option.SetDuration(0);
|
||||
option.SetCurve(Curves::LINEAR);
|
||||
AnimationUtils::StartAnimation(option, [weak = WeakClaim(this)]() {
|
||||
auto modifier = weak.Upgrade();
|
||||
CHECK_NULL_VOID(modifier);
|
||||
modifier->dotActiveStartAngle_->Set(modifier->dotActiveStartAngle_->Get());
|
||||
modifier->dotActiveEndAngle_->Set(modifier->dotActiveEndAngle_->Get());
|
||||
});
|
||||
}
|
||||
AnimationUtils::StopAnimation(blackPointsAnimation_);
|
||||
longPointLeftAnimEnd_ = true;
|
||||
longPointRightAnimEnd_ = true;
|
||||
}
|
||||
} // namespace OHOS::Ace::NG
|
@ -1,192 +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_SWIPER_INDICATOR_CIRCLE_DOT_INDICATOR_MODIFIER_H
|
||||
#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SWIPER_INDICATOR_CIRCLE_DOT_INDICATOR_MODIFIER_H
|
||||
|
||||
#include <optional>
|
||||
|
||||
#include "core/components/swiper/swiper_indicator_theme.h"
|
||||
#include "core/components_ng/base/modifier.h"
|
||||
#include "core/components_ng/render/animation_utils.h"
|
||||
#include "core/components_ng/render/drawing_prop_convertor.h"
|
||||
#include "core/components_ng/pattern/swiper_indicator/dot_indicator/dot_indicator_modifier.h"
|
||||
#include "core/components/declaration/swiper/swiper_declaration.h"
|
||||
|
||||
namespace OHOS::Ace::NG {
|
||||
class CircleDotIndicatorModifier : public ContentModifier {
|
||||
DECLARE_ACE_TYPE(CircleDotIndicatorModifier, ContentModifier);
|
||||
public:
|
||||
CircleDotIndicatorModifier();
|
||||
~CircleDotIndicatorModifier() override = default;
|
||||
|
||||
struct ContentProperty {
|
||||
Color backgroundColor = Color::TRANSPARENT;
|
||||
LinearVector<float> vectorBlackPointAngle;
|
||||
float dotPaddingAngle = 0;
|
||||
float dotActiveAngle = 0;
|
||||
float dotActiveStartAngle = 0;
|
||||
float dotActiveEndAngle = 0;
|
||||
|
||||
float dotActivePaddingAngle = 0;
|
||||
float containerBorderWidth = 0;
|
||||
float itemRadius = 0;
|
||||
float itemSelectWidth = 0;
|
||||
};
|
||||
|
||||
void onDraw(DrawingContext& context) override;
|
||||
// paint
|
||||
void PaintContent(DrawingContext& context, ContentProperty& contentProperty);
|
||||
void PaintUnselectedIndicator(RSCanvas& canvas, float itemAngle, ContentProperty& contentProperty,
|
||||
const LinearColor& indicatorColor);
|
||||
void PaintSelectedIndicator(RSCanvas& canvas, ContentProperty& contentProperty);
|
||||
void PaintBackground(DrawingContext& context, const ContentProperty& contentProperty);
|
||||
void PaintIndicatorMask(DrawingContext& context, const ContentProperty& contentProperty);
|
||||
// Update property
|
||||
void UpdateShrinkPaintProperty(const LinearVector<float>& normalItemSizes,
|
||||
const LinearVector<float>& vectorBlackPointAngle, const std::pair<float, float>& longPointAngle);
|
||||
void UpdateDilatePaintProperty(const LinearVector<float>& hoverItemSizes,
|
||||
const LinearVector<float>& vectorBlackPointAngle, const std::pair<float, float>& longPointAngle);
|
||||
void UpdateBackgroundColor(const Color& backgroundColor);
|
||||
|
||||
void UpdateNormalPaintProperty(const LinearVector<float>& normalItemSizes,
|
||||
const LinearVector<float>& vectorBlackPointAngle, const std::pair<float, float>& longPointAngle);
|
||||
void UpdatePressPaintProperty(const LinearVector<float>& hoverItemSizes,
|
||||
const LinearVector<float>& vectorBlackPointAngle, const std::pair<float, float>& longPointAngle);
|
||||
// Update
|
||||
void UpdateNormalToPressPaintProperty(const LinearVector<float>& hoverItemSizes,
|
||||
const LinearVector<float>& vectorBlackPointAngle, const std::pair<float, float>& longPointAngle);
|
||||
void UpdatePressToNormalPaintProperty(const LinearVector<float>& normalItemSizes,
|
||||
const LinearVector<float>& vectorBlackPointAngle, const std::pair<float, float>& longPointAngle);
|
||||
|
||||
void SetAxis(Axis axis)
|
||||
{
|
||||
axis_ = axis;
|
||||
}
|
||||
|
||||
void SetUnselectedColor(const Color& unselectedColor)
|
||||
{
|
||||
if (unselectedColor_) {
|
||||
unselectedColor_->Set(unselectedColor);
|
||||
}
|
||||
}
|
||||
|
||||
void SetSelectedColor(const Color& selectedColor)
|
||||
{
|
||||
if (selectedColor_) {
|
||||
selectedColor_->Set(selectedColor);
|
||||
}
|
||||
}
|
||||
|
||||
void SetCenterY(const float centerY)
|
||||
{
|
||||
centerY_ = centerY;
|
||||
}
|
||||
|
||||
void SetCenterX(const float centerX)
|
||||
{
|
||||
centerX_ = centerX;
|
||||
}
|
||||
|
||||
void SetCircleRadius(const float circleRadius)
|
||||
{
|
||||
circleRadius_ = circleRadius;
|
||||
}
|
||||
|
||||
void SetIsPressed(bool isPressed)
|
||||
{
|
||||
isPressed_ = isPressed;
|
||||
}
|
||||
|
||||
bool GetIsPressed() const
|
||||
{
|
||||
return isPressed_;
|
||||
}
|
||||
|
||||
void PlayIndicatorAnimation(const LinearVector<float>& vectorBlackPointAngle,
|
||||
const std::pair<float, float>& longPointAngle, GestureState gestureState);
|
||||
void StopAnimation(bool ifImmediately = false);
|
||||
|
||||
std::pair<float, float> GetLongPointAngle()
|
||||
{
|
||||
return { dotActiveStartAngle_->Get(), dotActiveEndAngle_->Get() };
|
||||
}
|
||||
|
||||
void SetArcDirection(SwiperArcDirection arcDirection)
|
||||
{
|
||||
arcDirection_ = arcDirection;
|
||||
}
|
||||
|
||||
void SetCurrentIndex(int32_t currentIndex)
|
||||
{
|
||||
currentIndex_ = currentIndex;
|
||||
}
|
||||
|
||||
void SetMaskColor(const NG::Gradient& maskColor)
|
||||
{
|
||||
maskColor_ = maskColor;
|
||||
if (updateMaskColor_) {
|
||||
updateMaskColor_->Set(!updateMaskColor_->Get());
|
||||
}
|
||||
}
|
||||
|
||||
void SetBackgroundColor(const Color& backgroundColor)
|
||||
{
|
||||
containerColor_ = backgroundColor;
|
||||
}
|
||||
|
||||
private:
|
||||
void PlayBlackPointsAnimation(const LinearVector<float>& vectorBlackPointAngle);
|
||||
void PlayLongPointAnimation(const std::pair<float, float>& longPointAngle,
|
||||
GestureState gestureState, const LinearVector<float>& vectorBlackPointAngle);
|
||||
std::vector<GradientColor> GetMaskColor() const;
|
||||
Gradient SortGradientColorsByOffset(const Gradient& gradient) const;
|
||||
|
||||
RefPtr<AnimatablePropertyColor> backgroundColor_;
|
||||
RefPtr<AnimatablePropertyVectorFloat> vectorBlackPointAngle_;
|
||||
RefPtr<PropertyColor> unselectedColor_;
|
||||
RefPtr<PropertyColor> selectedColor_;
|
||||
RefPtr<AnimatablePropertyFloat> dotPaddingAngle_;
|
||||
RefPtr<AnimatablePropertyFloat> dotActiveAngle_;
|
||||
|
||||
RefPtr<AnimatablePropertyFloat> dotActiveStartAngle_;
|
||||
RefPtr<AnimatablePropertyFloat> dotActiveEndAngle_;
|
||||
RefPtr<AnimatablePropertyFloat> dotActivePaddingAngle_;
|
||||
RefPtr<AnimatablePropertyFloat> containerBorderWidth_;
|
||||
RefPtr<AnimatablePropertyFloat> itemRadius_;
|
||||
RefPtr<AnimatablePropertyFloat> itemSelectWidth_;
|
||||
RefPtr<PropertyBool> updateMaskColor_;
|
||||
Gradient maskColor_;
|
||||
|
||||
std::shared_ptr<AnimationUtils::Animation> blackPointsAnimation_;
|
||||
|
||||
Color containerColor_ = Color::TRANSPARENT;
|
||||
|
||||
float centerX_ = 0.0;
|
||||
float centerY_ = 0.0;
|
||||
float circleRadius_ = 0.0;
|
||||
|
||||
SwiperArcDirection arcDirection_ = SwiperArcDirection::SIX_CLOCK_DIRECTION;
|
||||
|
||||
Axis axis_ = Axis::HORIZONTAL;
|
||||
bool isPressed_ = false;
|
||||
bool longPointLeftAnimEnd_ = true;
|
||||
bool longPointRightAnimEnd_ = true;
|
||||
|
||||
int32_t currentIndex_ = 0;
|
||||
ACE_DISALLOW_COPY_AND_MOVE(CircleDotIndicatorModifier);
|
||||
};
|
||||
} // namespace OHOS::Ace::NG
|
||||
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SWIPER_INDICATOR_CIRCLE_DOT_INDICATOR_MODIFIER_H
|
@ -1,338 +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/swiper_indicator/circle_dot_indicator/circle_dot_indicator_paint_method.h"
|
||||
|
||||
#include <valarray>
|
||||
|
||||
#include "core/components/common/layout/constants.h"
|
||||
#include "core/components/common/properties/color.h"
|
||||
#include "core/components/swiper/render_swiper.h"
|
||||
#include "core/components_ng/pattern/swiper/swiper_layout_property.h"
|
||||
#include "core/components_ng/pattern/swiper_indicator/indicator_common/swiper_indicator_utils.h"
|
||||
#include "core/components_ng/render/paint_property.h"
|
||||
#include "core/pipeline/pipeline_base.h"
|
||||
|
||||
namespace OHOS::Ace::NG {
|
||||
namespace {
|
||||
constexpr uint32_t ITEM_PADDING = 3;
|
||||
constexpr uint32_t SELECTED_ITEM_PADDING = 4;
|
||||
constexpr uint32_t ACTIVE_ITEM_ANGLE = 5;
|
||||
|
||||
constexpr Dimension ITEM_SHRINK_DIAMETER = 5.0_vp;
|
||||
constexpr Dimension SLECTED_ITEM_SHRINK_DIAMETER = 5.0_vp;
|
||||
constexpr Dimension CONTAINER_SHRINK_DIAMETER = 16.0_vp;
|
||||
constexpr float ITEM_SHRINK_PADDING = 5.0;
|
||||
constexpr float SELECTED_ITEM_SHRINK_PADDING = 7.0;
|
||||
constexpr float ACTIVE_ITEM_SHRINK_ANGLE = 4.0;
|
||||
|
||||
constexpr Dimension ITEM_DILATE_DIAMETER = 8.0_vp;
|
||||
constexpr Dimension SLECTED_ITEM_DILATE_DIAMETER = 8.0_vp;
|
||||
constexpr Dimension CONTAINER_DILATE_DIAMETER = 24.0_vp;
|
||||
constexpr float ITEM_DILATE_PADDING = 10.0;
|
||||
constexpr float SELECTED_ITEM_DILATE_PADDING = 14.0;
|
||||
constexpr float ACTIVE_ITEM_DILATE_ANGLE = 8.0;
|
||||
constexpr double QUARTER_CIRCLE_ANGLE = 90.0;
|
||||
constexpr double HALF_CIRCLE_ANGLE = 180.0;
|
||||
constexpr int32_t ITEM_TWO_NUM = 2;
|
||||
constexpr int32_t ITEM_THREE_NUM = 3;
|
||||
} // namespace
|
||||
|
||||
void CircleDotIndicatorPaintMethod::UpdateContentModifier(PaintWrapper* paintWrapper)
|
||||
{
|
||||
CHECK_NULL_VOID(circleDotIndicatorModifier_);
|
||||
CHECK_NULL_VOID(paintWrapper);
|
||||
auto pipelineContext = PipelineBase::GetCurrentContextSafely();
|
||||
CHECK_NULL_VOID(pipelineContext);
|
||||
auto swiperTheme = pipelineContext->GetTheme<SwiperIndicatorTheme>();
|
||||
CHECK_NULL_VOID(swiperTheme);
|
||||
const auto& geometryNode = paintWrapper->GetGeometryNode();
|
||||
CHECK_NULL_VOID(geometryNode);
|
||||
auto paintProperty = DynamicCast<CircleDotIndicatorPaintProperty>(paintWrapper->GetPaintProperty());
|
||||
CHECK_NULL_VOID(paintProperty);
|
||||
circleDotIndicatorModifier_->SetAxis(axis_);
|
||||
circleDotIndicatorModifier_->SetCurrentIndex(currentIndex_);
|
||||
arcDirection_ = paintProperty->GetArcDirectionValue(SwiperArcDirection::SIX_CLOCK_DIRECTION);
|
||||
circleDotIndicatorModifier_->SetArcDirection(
|
||||
paintProperty->GetArcDirectionValue(SwiperArcDirection::SIX_CLOCK_DIRECTION));
|
||||
circleDotIndicatorModifier_->SetUnselectedColor(paintProperty->GetColorValue(swiperTheme->GetArcItemColor()));
|
||||
circleDotIndicatorModifier_->SetSelectedColor(
|
||||
paintProperty->GetSelectedColorValue(swiperTheme->GetArcSelectedItemColor()));
|
||||
circleDotIndicatorModifier_->SetBackgroundColor(
|
||||
paintProperty->GetContainerColorValue(swiperTheme->GetArcContainerColor()));
|
||||
circleDotIndicatorModifier_->SetMaskColor(paintProperty->GetMaskColorValue(swiperTheme->GetArcMaskColor()));
|
||||
|
||||
const auto& contentSize = geometryNode->GetFrameSize();
|
||||
//The number 0.5 represents equal division
|
||||
float centerY = (axis_ == Axis::HORIZONTAL ? contentSize.Height() : contentSize.Width()) * 0.5;
|
||||
float centerX = (axis_ == Axis::HORIZONTAL ? contentSize.Width() : contentSize.Height()) * 0.5;
|
||||
float centerR = std::min(centerX, centerY);
|
||||
circleDotIndicatorModifier_->SetCenterX(centerX);
|
||||
circleDotIndicatorModifier_->SetCenterY(centerY);
|
||||
circleDotIndicatorModifier_->SetCircleRadius(centerR);
|
||||
|
||||
if (isLongPressed_) {
|
||||
PaintPressIndicator(paintWrapper);
|
||||
circleDotIndicatorModifier_->SetIsPressed(true);
|
||||
} else {
|
||||
PaintNormalIndicator(paintWrapper);
|
||||
circleDotIndicatorModifier_->SetIsPressed(false);
|
||||
}
|
||||
}
|
||||
|
||||
void CircleDotIndicatorPaintMethod::UpdateNormalIndicator(
|
||||
LinearVector<float>& itemSizes, const PaintWrapper* paintWrapper)
|
||||
{
|
||||
if (gestureState_ == GestureState::GESTURE_STATE_RELEASE_LEFT ||
|
||||
gestureState_ == GestureState::GESTURE_STATE_RELEASE_RIGHT) {
|
||||
circleDotIndicatorModifier_->PlayIndicatorAnimation(vectorBlackPointAngle_, longPointAngle_, gestureState_);
|
||||
} else {
|
||||
circleDotIndicatorModifier_->UpdateNormalPaintProperty(itemSizes, vectorBlackPointAngle_, longPointAngle_);
|
||||
}
|
||||
}
|
||||
|
||||
void CircleDotIndicatorPaintMethod::PaintNormalIndicator(const PaintWrapper* paintWrapper)
|
||||
{
|
||||
auto [longPointAngle, itemSizes] = CalculateLongPointCenterAngle(paintWrapper, true);
|
||||
longPointAngle_ = longPointAngle;
|
||||
if (circleDotIndicatorModifier_->GetIsPressed()) {
|
||||
circleDotIndicatorModifier_->UpdatePressToNormalPaintProperty(
|
||||
itemSizes, vectorBlackPointAngle_, longPointAngle_);
|
||||
} else {
|
||||
UpdateNormalIndicator(itemSizes, paintWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
void CircleDotIndicatorPaintMethod::PaintPressIndicator(const PaintWrapper* paintWrapper)
|
||||
{
|
||||
CHECK_NULL_VOID(paintWrapper);
|
||||
LinearVector<float> itemSizes;
|
||||
// The number 0.5 represents equal division
|
||||
itemSizes.emplace_back(static_cast<float>(ITEM_DILATE_DIAMETER.ConvertToPx()) * 0.5);
|
||||
itemSizes.emplace_back(static_cast<float>(SLECTED_ITEM_DILATE_DIAMETER.ConvertToPx()) * 0.5);
|
||||
itemSizes.emplace_back(static_cast<float>(CONTAINER_DILATE_DIAMETER.ConvertToPx()) * 0.5);
|
||||
itemSizes.emplace_back(ITEM_DILATE_PADDING);
|
||||
itemSizes.emplace_back(SELECTED_ITEM_DILATE_PADDING);
|
||||
itemSizes.emplace_back(ACTIVE_ITEM_DILATE_ANGLE);
|
||||
|
||||
longPointAngle_ = CalculatePointAngle(itemSizes, currentIndex_);
|
||||
if (circleDotIndicatorModifier_->GetIsPressed()) {
|
||||
circleDotIndicatorModifier_->PlayIndicatorAnimation(vectorBlackPointAngle_, longPointAngle_, gestureState_);
|
||||
} else {
|
||||
circleDotIndicatorModifier_->UpdateNormalToPressPaintProperty(
|
||||
itemSizes, vectorBlackPointAngle_, longPointAngle_);
|
||||
}
|
||||
}
|
||||
|
||||
std::pair<float, float> CircleDotIndicatorPaintMethod::CalculatePointAngle(
|
||||
const LinearVector<float>& itemSizes, int32_t currentIndex)
|
||||
{
|
||||
if (itemCount_ == 0) {
|
||||
return {0.0, 0.0};
|
||||
}
|
||||
auto [startCurrentIndex, endCurrentIndex] = GetStartAndEndIndex(currentIndex);
|
||||
vectorBlackPointAngle_.resize(itemCount_);
|
||||
for (int32_t i = 0; i < itemCount_; ++i) {
|
||||
vectorBlackPointAngle_[i] = GetBlackPointAngle(itemSizes, i, endCurrentIndex);
|
||||
}
|
||||
|
||||
return GetLongPointAngle(itemSizes, endCurrentIndex);
|
||||
}
|
||||
|
||||
std::tuple<std::pair<float, float>, LinearVector<float>> CircleDotIndicatorPaintMethod::CalculateLongPointCenterAngle(
|
||||
const PaintWrapper* paintWrapper, bool isNormal)
|
||||
{
|
||||
std::tuple<std::pair<float, float>, LinearVector<float>> tmp;
|
||||
CHECK_NULL_RETURN(paintWrapper, tmp);
|
||||
LinearVector<float> itemSizes;
|
||||
// The number 0.5 represents equal division
|
||||
if (isNormal) {
|
||||
itemSizes.emplace_back(static_cast<float>(ITEM_SHRINK_DIAMETER.ConvertToPx()) * 0.5);
|
||||
itemSizes.emplace_back(static_cast<float>(SLECTED_ITEM_SHRINK_DIAMETER.ConvertToPx()) * 0.5);
|
||||
itemSizes.emplace_back(static_cast<float>(CONTAINER_SHRINK_DIAMETER.ConvertToPx()) * 0.5);
|
||||
itemSizes.emplace_back(ITEM_SHRINK_PADDING);
|
||||
itemSizes.emplace_back(SELECTED_ITEM_SHRINK_PADDING);
|
||||
itemSizes.emplace_back(ACTIVE_ITEM_SHRINK_ANGLE);
|
||||
} else {
|
||||
itemSizes.emplace_back(static_cast<float>(ITEM_DILATE_DIAMETER.ConvertToPx()) * 0.5);
|
||||
itemSizes.emplace_back(static_cast<float>(SLECTED_ITEM_DILATE_DIAMETER.ConvertToPx()) * 0.5);
|
||||
itemSizes.emplace_back(static_cast<float>(CONTAINER_DILATE_DIAMETER.ConvertToPx()) * 0.5);
|
||||
itemSizes.emplace_back(ITEM_DILATE_PADDING);
|
||||
itemSizes.emplace_back(SELECTED_ITEM_DILATE_PADDING);
|
||||
itemSizes.emplace_back(ACTIVE_ITEM_DILATE_ANGLE);
|
||||
}
|
||||
|
||||
auto longPointAngle = CalculatePointAngle(itemSizes, currentIndex_);
|
||||
return { longPointAngle, itemSizes };
|
||||
}
|
||||
|
||||
int32_t CircleDotIndicatorPaintMethod::GetHalfIndex()
|
||||
{
|
||||
if (itemCount_ == 1) {
|
||||
return itemCount_ - 1;
|
||||
}
|
||||
if (itemCount_ % 2 == 0) {
|
||||
return (itemCount_ / 2) - 1;
|
||||
}
|
||||
return (itemCount_ - 1) / 2;
|
||||
}
|
||||
|
||||
std::pair<int32_t, int32_t> CircleDotIndicatorPaintMethod::GetLongPointAngle(
|
||||
const LinearVector<float>& itemSizes, int32_t currentIndex)
|
||||
{
|
||||
float dotActiveAngle = itemSizes[ACTIVE_ITEM_ANGLE];
|
||||
float selectItemAngle = GetBlackPointAngle(itemSizes, currentIndex, currentIndex);
|
||||
float LongPointStartAngle = 0.0;
|
||||
float LongPointEndAngle = 0.0;
|
||||
// The number 2 represents equal division
|
||||
if (arcDirection_ == SwiperArcDirection::SIX_CLOCK_DIRECTION) {
|
||||
LongPointStartAngle = QUARTER_CIRCLE_ANGLE + selectItemAngle + dotActiveAngle / 2;
|
||||
} else if (arcDirection_ == SwiperArcDirection::THREE_CLOCK_DIRECTION) {
|
||||
LongPointStartAngle = selectItemAngle + dotActiveAngle / 2;
|
||||
} else {
|
||||
LongPointStartAngle = HALF_CIRCLE_ANGLE + selectItemAngle + dotActiveAngle / 2;
|
||||
}
|
||||
LongPointEndAngle = LongPointStartAngle - dotActiveAngle;
|
||||
return { LongPointStartAngle, LongPointEndAngle };
|
||||
}
|
||||
|
||||
float CircleDotIndicatorPaintMethod::GetAllPointArcAngle(const LinearVector<float>& itemSizes, int32_t currentIndex)
|
||||
{
|
||||
float dotPaddingAngle = itemSizes[ITEM_PADDING];
|
||||
float dotActivePaddingAngle = itemSizes[SELECTED_ITEM_PADDING];
|
||||
float dotActiveAngle = itemSizes[ACTIVE_ITEM_ANGLE];
|
||||
float allPointArcAngle = 0;
|
||||
// The number 2 represents equal division
|
||||
if (currentIndex == 0 || currentIndex == itemCount_ - 1) {
|
||||
if (itemCount_ >= ITEM_TWO_NUM) {
|
||||
allPointArcAngle =
|
||||
(itemCount_ - ITEM_TWO_NUM) * dotPaddingAngle + dotActivePaddingAngle + dotActiveAngle / 2;
|
||||
} else {
|
||||
allPointArcAngle = dotActiveAngle;
|
||||
}
|
||||
} else {
|
||||
allPointArcAngle = (itemCount_ - ITEM_THREE_NUM) * dotPaddingAngle + dotActivePaddingAngle * 2;
|
||||
}
|
||||
return allPointArcAngle;
|
||||
}
|
||||
|
||||
float CircleDotIndicatorPaintMethod::GetBlackPointAngle(
|
||||
const LinearVector<float>& itemSizes, int32_t index, int32_t currentIndex)
|
||||
{
|
||||
float dotPaddingAngle = itemSizes[ITEM_PADDING];
|
||||
float dotActivePaddingAngle = itemSizes[SELECTED_ITEM_PADDING];
|
||||
float dotActiveAngle = itemSizes[ACTIVE_ITEM_ANGLE];
|
||||
float allPointArcAngle = GetAllPointArcAngle(itemSizes, currentIndex);
|
||||
|
||||
float itemCenterAngle = 0.0;
|
||||
int32_t itemIndex = index;
|
||||
int32_t halIndex = GetHalfIndex();
|
||||
if (itemIndex <= halIndex) {
|
||||
if (itemCount_ == 1) {
|
||||
itemCenterAngle = 0.0;
|
||||
} else if (currentIndex == 0) {
|
||||
if (itemIndex == 0) {
|
||||
itemCenterAngle = (allPointArcAngle / 2) - (dotActiveAngle / 2);
|
||||
} else {
|
||||
itemCenterAngle = (allPointArcAngle / 2) - (dotActiveAngle / 2) -
|
||||
dotActivePaddingAngle - (itemIndex -1) * dotPaddingAngle;
|
||||
}
|
||||
} else if (itemIndex == currentIndex) {
|
||||
itemCenterAngle = (allPointArcAngle / 2) - (itemIndex -1) * dotPaddingAngle - dotActivePaddingAngle;
|
||||
} else if (itemIndex > currentIndex) {
|
||||
itemCenterAngle = (allPointArcAngle / 2) - (itemIndex -2) * dotPaddingAngle - dotActivePaddingAngle * 2;
|
||||
} else {
|
||||
itemCenterAngle = (allPointArcAngle / 2) - itemIndex * dotPaddingAngle;
|
||||
}
|
||||
} else {
|
||||
if (itemIndex == 0) {
|
||||
itemCenterAngle = (dotActiveAngle / 2) + dotActivePaddingAngle +
|
||||
(itemIndex -1) * dotPaddingAngle - (allPointArcAngle / 2);
|
||||
} else if (itemIndex == currentIndex) {
|
||||
itemCenterAngle = (itemIndex - 1) * dotPaddingAngle + dotActivePaddingAngle - (allPointArcAngle / 2);
|
||||
} else if (itemIndex > currentIndex) {
|
||||
itemCenterAngle =
|
||||
(itemIndex - ITEM_TWO_NUM) * dotPaddingAngle + dotActivePaddingAngle * 2 - (allPointArcAngle / 2);
|
||||
} else {
|
||||
itemCenterAngle = itemIndex * dotPaddingAngle - (allPointArcAngle / 2);
|
||||
}
|
||||
itemCenterAngle = -itemCenterAngle;
|
||||
}
|
||||
return itemCenterAngle;
|
||||
}
|
||||
|
||||
std::pair<int32_t, int32_t> CircleDotIndicatorPaintMethod::GetIndex(int32_t index)
|
||||
{
|
||||
if (mouseClickIndex_ || gestureState_ == GestureState::GESTURE_STATE_RELEASE_LEFT ||
|
||||
gestureState_ == GestureState::GESTURE_STATE_RELEASE_RIGHT) {
|
||||
turnPageRate_ = 0;
|
||||
}
|
||||
// item may be invalid in auto linear scene
|
||||
if (nextValidIndex_ >= 0) {
|
||||
int32_t startCurrentIndex = index;
|
||||
int32_t endCurrentIndex = NearEqual(turnPageRate_, 0.0f) || LessOrEqualCustomPrecision(turnPageRate_, -1.0f) ||
|
||||
GreatOrEqualCustomPrecision(turnPageRate_, 1.0f)
|
||||
? index
|
||||
: nextValidIndex_;
|
||||
// reach edge scene
|
||||
if (startCurrentIndex > endCurrentIndex) {
|
||||
startCurrentIndex = currentIndexActual_;
|
||||
endCurrentIndex = currentIndexActual_;
|
||||
}
|
||||
return { startCurrentIndex, endCurrentIndex };
|
||||
}
|
||||
|
||||
int32_t startCurrentIndex = index;
|
||||
int32_t endCurrentIndex = NearEqual(turnPageRate_, 0.0f) || LessOrEqualCustomPrecision(turnPageRate_, -1.0f) ||
|
||||
GreatOrEqualCustomPrecision(turnPageRate_, 1.0f)
|
||||
? endCurrentIndex = index
|
||||
: (LessNotEqualCustomPrecision(turnPageRate_, 0.0f) ? index + 1 : index - 1);
|
||||
if (endCurrentIndex == -1) {
|
||||
endCurrentIndex = itemCount_ - 1;
|
||||
} else if (endCurrentIndex == itemCount_) {
|
||||
endCurrentIndex = 0;
|
||||
}
|
||||
return { startCurrentIndex, endCurrentIndex };
|
||||
}
|
||||
|
||||
std::pair<int32_t, int32_t> CircleDotIndicatorPaintMethod::GetStartAndEndIndex(int32_t index)
|
||||
{
|
||||
auto [startCurrentIndex, endCurrentIndex] = GetIndex(index);
|
||||
|
||||
if (pointAnimationStage_ == PointAnimationStage::STATE_EXPAND_TO_LONG_POINT &&
|
||||
gestureState_ == GestureState::GESTURE_STATE_RELEASE_LEFT &&
|
||||
touchBottomTypeLoop_ == TouchBottomTypeLoop::TOUCH_BOTTOM_TYPE_LOOP_LEFT) {
|
||||
endCurrentIndex = startCurrentIndex;
|
||||
return { startCurrentIndex, endCurrentIndex };
|
||||
} else if (pointAnimationStage_ == PointAnimationStage::STATE_EXPAND_TO_LONG_POINT &&
|
||||
gestureState_ == GestureState::GESTURE_STATE_RELEASE_RIGHT &&
|
||||
touchBottomTypeLoop_ == TouchBottomTypeLoop::TOUCH_BOTTOM_TYPE_LOOP_RIGHT) {
|
||||
endCurrentIndex = startCurrentIndex = 0;
|
||||
return { startCurrentIndex, endCurrentIndex };
|
||||
}
|
||||
|
||||
if (touchBottomTypeLoop_ == TouchBottomTypeLoop::TOUCH_BOTTOM_TYPE_LOOP_LEFT &&
|
||||
!(endCurrentIndex == startCurrentIndex && startCurrentIndex != 0)) {
|
||||
startCurrentIndex = endCurrentIndex = 0;
|
||||
} else if (gestureState_ == GestureState::GESTURE_STATE_RELEASE_RIGHT &&
|
||||
touchBottomTypeLoop_ == TouchBottomTypeLoop::TOUCH_BOTTOM_TYPE_LOOP_RIGHT) {
|
||||
endCurrentIndex = startCurrentIndex = itemCount_ - 1;
|
||||
} else if (touchBottomTypeLoop_ == TouchBottomTypeLoop::TOUCH_BOTTOM_TYPE_LOOP_RIGHT) {
|
||||
endCurrentIndex = startCurrentIndex;
|
||||
}
|
||||
|
||||
return { startCurrentIndex, endCurrentIndex };
|
||||
}
|
||||
} // namespace OHOS::Ace::NG
|
@ -1,141 +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_PATTERN_SWIPER_INDICATOR_CIRCLE_DOT_INDICATOR_PAINT_METHOD_H
|
||||
#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SWIPER_INDICATOR_CIRCLE_DOT_INDICATOR_PAINT_METHOD_H
|
||||
|
||||
#include "core/components/common/properties/swiper_indicator.h"
|
||||
#include "core/components_ng/pattern/swiper_indicator/circle_dot_indicator/circle_dot_indicator_modifier.h"
|
||||
#include "core/components_ng/pattern/swiper_indicator/circle_dot_indicator/circle_dot_indicator_paint_property.h"
|
||||
#include "core/components_ng/render/canvas_image.h"
|
||||
#include "core/components_ng/render/node_paint_method.h"
|
||||
#include "core/components_ng/render/paint_wrapper.h"
|
||||
#include "core/components_ng/render/render_context.h"
|
||||
#include "core/components_ng/pattern/swiper_indicator/dot_indicator/dot_indicator_paint_method.h"
|
||||
#include "core/components/declaration/swiper/swiper_declaration.h"
|
||||
|
||||
namespace OHOS::Ace::NG {
|
||||
class ACE_EXPORT CircleDotIndicatorPaintMethod : public NodePaintMethod {
|
||||
DECLARE_ACE_TYPE(CircleDotIndicatorPaintMethod, NodePaintMethod)
|
||||
public:
|
||||
explicit CircleDotIndicatorPaintMethod(const RefPtr<CircleDotIndicatorModifier>& circleDotIndicatorModifier)
|
||||
: circleDotIndicatorModifier_(circleDotIndicatorModifier)
|
||||
{}
|
||||
~CircleDotIndicatorPaintMethod() override = default;
|
||||
|
||||
RefPtr<Modifier> GetContentModifier(PaintWrapper* paintWrapper) override
|
||||
{
|
||||
CHECK_NULL_RETURN(circleDotIndicatorModifier_, nullptr);
|
||||
return circleDotIndicatorModifier_;
|
||||
}
|
||||
|
||||
void UpdateContentModifier(PaintWrapper* paintWrapper) override;
|
||||
void PaintNormalIndicator(const PaintWrapper* paintWrapper);
|
||||
void PaintPressIndicator(const PaintWrapper* paintWrapper);
|
||||
std::pair<float, float> CalculatePointAngle(const LinearVector<float>& itemSizes, int32_t currentIndex);
|
||||
|
||||
void SetCurrentIndex(int32_t index)
|
||||
{
|
||||
currentIndex_ = index;
|
||||
}
|
||||
|
||||
void SetItemCount(int32_t itemCount)
|
||||
{
|
||||
itemCount_ = itemCount;
|
||||
}
|
||||
|
||||
void SetAxis(Axis axis)
|
||||
{
|
||||
axis_ = axis;
|
||||
}
|
||||
|
||||
Axis GetAxis() const
|
||||
{
|
||||
return axis_;
|
||||
}
|
||||
|
||||
void SetIsLongPressed(bool isLongPressed)
|
||||
{
|
||||
isLongPressed_ = isLongPressed;
|
||||
}
|
||||
|
||||
void SetTurnPageRate(float turnPageRate)
|
||||
{
|
||||
turnPageRate_ = turnPageRate;
|
||||
}
|
||||
|
||||
void SetGestureState(GestureState gestureState)
|
||||
{
|
||||
gestureState_ = gestureState;
|
||||
}
|
||||
|
||||
void SetTouchBottomTypeLoop(TouchBottomTypeLoop touchBottomTypeLoop)
|
||||
{
|
||||
touchBottomTypeLoop_ = touchBottomTypeLoop;
|
||||
}
|
||||
|
||||
void SetMouseClickIndex(const std::optional<int32_t>& mouseClickIndex)
|
||||
{
|
||||
mouseClickIndex_ = mouseClickIndex;
|
||||
}
|
||||
|
||||
void SetPointAnimationStage(PointAnimationStage pointAnimationStage)
|
||||
{
|
||||
pointAnimationStage_ = pointAnimationStage;
|
||||
}
|
||||
|
||||
void SetCurrentIndexActual(int32_t currentIndexActual)
|
||||
{
|
||||
currentIndexActual_ = currentIndexActual;
|
||||
}
|
||||
|
||||
void SetNextValidIndex(int32_t nextValidIndex)
|
||||
{
|
||||
nextValidIndex_ = nextValidIndex;
|
||||
}
|
||||
|
||||
private:
|
||||
std::tuple<std::pair<float, float>, LinearVector<float>> CalculateLongPointCenterAngle(
|
||||
const PaintWrapper* paintWrapper, bool isNormal);
|
||||
void UpdateNormalIndicator(LinearVector<float>& itemSizes, const PaintWrapper* paintWrapper);
|
||||
std::pair<int32_t, int32_t> GetStartAndEndIndex(int32_t index);
|
||||
std::pair<int32_t, int32_t> GetIndex(int32_t index);
|
||||
int32_t GetHalfIndex();
|
||||
float GetBlackPointAngle(const LinearVector<float>& itemSizes, int32_t index, int32_t currentIndex);
|
||||
std::pair<int32_t, int32_t> GetLongPointAngle(const LinearVector<float>& itemSizes, int32_t currentIndex);
|
||||
float GetAllPointArcAngle(const LinearVector<float>& itemSizes, int32_t currentIndex);
|
||||
|
||||
RefPtr<CircleDotIndicatorModifier> circleDotIndicatorModifier_;
|
||||
std::optional<int32_t> mouseClickIndex_ = std::nullopt;
|
||||
Axis axis_ = Axis::HORIZONTAL;
|
||||
int32_t currentIndex_ = 0;
|
||||
int32_t currentIndexActual_ = 0;
|
||||
int32_t nextValidIndex_ = 0;
|
||||
int32_t itemCount_ = 0;
|
||||
float turnPageRate_ = 0.0f;
|
||||
SwiperArcDirection arcDirection_ = SwiperArcDirection::SIX_CLOCK_DIRECTION;
|
||||
GestureState gestureState_ = GestureState::GESTURE_STATE_INIT;
|
||||
TouchBottomTypeLoop touchBottomTypeLoop_ = TouchBottomTypeLoop::TOUCH_BOTTOM_TYPE_LOOP_NONE;
|
||||
PointAnimationStage pointAnimationStage_ = PointAnimationStage::STATE_SHRINKT_TO_BLACK_POINT;
|
||||
bool isLongPressed_ = false;
|
||||
// Animatable properties for updating Modifier
|
||||
LinearVector<float> vectorBlackPointAngle_ = {};
|
||||
std::pair<float, float> longPointAngle_ = { 0, 0 };
|
||||
LinearVector<float> longPointCenter_ = {};
|
||||
ACE_DISALLOW_COPY_AND_MOVE(CircleDotIndicatorPaintMethod);
|
||||
};
|
||||
} // namespace OHOS::Ace::NG
|
||||
|
||||
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SWIPER_INDICATOR_CIRCLE_DOT_INDICATOR_PAINT_METHOD_H
|
@ -1,62 +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_PATTERN_SWIPER_INDICATOR_CIRCLE_DOT_INDICATOR_PAINT_PROPERTY_H
|
||||
#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SWIPER_INDICATOR_CIRCLE_DOT_INDICATOR_PAINT_PROPERTY_H
|
||||
|
||||
#include "core/components/common/layout/constants.h"
|
||||
#include "core/components/common/properties/color.h"
|
||||
#include "core/components_ng/render/paint_property.h"
|
||||
#include "core/components/declaration/swiper/swiper_declaration.h"
|
||||
|
||||
namespace OHOS::Ace::NG {
|
||||
struct CircleDotIndicatorStyle {
|
||||
ACE_DEFINE_PROPERTY_GROUP_ITEM(ArcDirection, SwiperArcDirection);
|
||||
ACE_DEFINE_PROPERTY_GROUP_ITEM(Color, Color);
|
||||
ACE_DEFINE_PROPERTY_GROUP_ITEM(SelectedColor, Color);
|
||||
ACE_DEFINE_PROPERTY_GROUP_ITEM(ContainerColor, Color);
|
||||
ACE_DEFINE_PROPERTY_GROUP_ITEM(MaskColor, Gradient);
|
||||
};
|
||||
class CircleDotIndicatorPaintProperty : public PaintProperty {
|
||||
DECLARE_ACE_TYPE(CircleDotIndicatorPaintProperty, PaintProperty)
|
||||
|
||||
public:
|
||||
CircleDotIndicatorPaintProperty() = default;
|
||||
~CircleDotIndicatorPaintProperty() override = default;
|
||||
|
||||
RefPtr<PaintProperty> Clone() const override
|
||||
{
|
||||
auto paintProperty = MakeRefPtr<CircleDotIndicatorPaintProperty>();
|
||||
paintProperty->UpdatePaintProperty(this);
|
||||
paintProperty->propCircleDotIndicatorStyle_ = CloneCircleDotIndicatorStyle();
|
||||
return paintProperty;
|
||||
}
|
||||
|
||||
void Reset() override
|
||||
{
|
||||
PaintProperty::Reset();
|
||||
ResetCircleDotIndicatorStyle();
|
||||
}
|
||||
ACE_DEFINE_PROPERTY_GROUP(CircleDotIndicatorStyle, CircleDotIndicatorStyle);
|
||||
ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP(
|
||||
CircleDotIndicatorStyle, ArcDirection, SwiperArcDirection, PROPERTY_UPDATE_RENDER);
|
||||
ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP(CircleDotIndicatorStyle, Color, Color, PROPERTY_UPDATE_RENDER);
|
||||
ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP(CircleDotIndicatorStyle, SelectedColor, Color, PROPERTY_UPDATE_RENDER);
|
||||
ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP(CircleDotIndicatorStyle, ContainerColor, Color, PROPERTY_UPDATE_RENDER);
|
||||
ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP(CircleDotIndicatorStyle, MaskColor, Gradient, PROPERTY_UPDATE_RENDER);
|
||||
ACE_DISALLOW_COPY_AND_MOVE(CircleDotIndicatorPaintProperty);
|
||||
};
|
||||
} // namespace OHOS::Ace::NG
|
||||
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SWIPER_INDICATOR_CIRCLE_DOT_INDICATOR_PAINT_PROPERTY_H
|
@ -15,8 +15,6 @@
|
||||
|
||||
#include "core/components_ng/pattern/swiper_indicator/indicator_common/swiper_indicator_pattern.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "base/log/dump_log.h"
|
||||
#include "base/utils/utils.h"
|
||||
#include "core/components_ng/base/frame_node.h"
|
||||
@ -34,18 +32,6 @@ constexpr Dimension INDICATOR_DRAG_MIN_DISTANCE = 4.0_vp;
|
||||
constexpr Dimension INDICATOR_DRAG_MAX_DISTANCE = 18.0_vp;
|
||||
constexpr Dimension INDICATOR_TOUCH_BOTTOM_MAX_DISTANCE = 80.0_vp;
|
||||
constexpr int32_t LONG_PRESS_DELAY = 300;
|
||||
constexpr double QUARTER_CIRCLE_ANGLE = 90.0;
|
||||
constexpr double HALF_CIRCLE_ANGLE = 180.0;
|
||||
constexpr double THREE_QUARTER_CIRCLE_ANGLE = 270.0;
|
||||
constexpr double FULL_CIRCLE_ANGLE = 360.0;
|
||||
constexpr float ITEM_PADDING = 5.0f;
|
||||
constexpr float ACTIVE_ITEM_ANGLE = 4.0f;
|
||||
constexpr float ADD_HOT_REG_ANGLE = 8.0f;
|
||||
constexpr Dimension CONTAINER_BORDER_WIDTH = 24.0_vp;
|
||||
constexpr Dimension CIRCLE_DIAMETER_OFFSET = 16.0_vp;
|
||||
constexpr float INDICATOR_DRAG_MIN_ANGLE = 6.0;
|
||||
constexpr float INDICATOR_DRAG_MAX_ANGLE = 23.0;
|
||||
constexpr float INDICATOR_TOUCH_BOTTOM_MAX_ANGLE = 120.0;
|
||||
constexpr float HALF_FLOAT = 0.5f;
|
||||
} // namespace
|
||||
|
||||
@ -128,12 +114,6 @@ void SwiperIndicatorPattern::OnModifyDone()
|
||||
InitLongPressEvent(gestureHub);
|
||||
InitFocusEvent();
|
||||
}
|
||||
if (swiperLayoutProperty->GetIndicatorTypeValue(SwiperIndicatorType::DOT) == SwiperIndicatorType::ARC_DOT) {
|
||||
auto gestureHub = host->GetOrCreateGestureEventHub();
|
||||
CHECK_NULL_VOID(gestureHub);
|
||||
InitTouchEvent(gestureHub);
|
||||
InitLongPressEvent(gestureHub);
|
||||
}
|
||||
}
|
||||
|
||||
void SwiperIndicatorPattern::InitFocusEvent()
|
||||
@ -205,9 +185,6 @@ void SwiperIndicatorPattern::OnIsFocusActiveUpdate(bool isFocusAcitve)
|
||||
|
||||
bool SwiperIndicatorPattern::OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config)
|
||||
{
|
||||
if (swiperIndicatorType_ == SwiperIndicatorType::ARC_DOT) {
|
||||
return SetArcIndicatorHotRegion(dirty, config);
|
||||
}
|
||||
CHECK_NULL_RETURN(config.frameSizeChange, false);
|
||||
return true;
|
||||
}
|
||||
@ -621,9 +598,6 @@ void SwiperIndicatorPattern::HandleDragEnd(double dragVelocity)
|
||||
swiperPattern->SetIndicatorLongPress(false);
|
||||
swiperPattern->StartAutoPlay();
|
||||
}
|
||||
if (swiperPattern->GetIndicatorType() == SwiperIndicatorType::ARC_DOT) {
|
||||
isLongPressed_ = false;
|
||||
}
|
||||
auto host = GetHost();
|
||||
CHECK_NULL_VOID(host);
|
||||
touchBottomType_ = TouchBottomType::NONE;
|
||||
@ -659,28 +633,21 @@ bool SwiperIndicatorPattern::CheckIsTouchBottom(const GestureEvent& info)
|
||||
auto dragPoint =
|
||||
PointF(static_cast<float>(info.GetLocalLocation().GetX()), static_cast<float>(info.GetLocalLocation().GetY()));
|
||||
auto offset = dragPoint - dragStartPoint_;
|
||||
float touchBottomRate = 0.0;
|
||||
float touchOffset = 0.0;
|
||||
if (swiperIndicatorType_ == SwiperIndicatorType::ARC_DOT) {
|
||||
auto center = GetCenterPointF();
|
||||
float startAngle = GetAngleWithPoint(center, dragStartPoint_);
|
||||
float endAngle = GetAngleWithPoint(center, dragPoint);
|
||||
touchOffset = startAngle - endAngle;
|
||||
touchBottomRate = LessOrEqual(std::abs(touchOffset), INDICATOR_TOUCH_BOTTOM_MAX_ANGLE)
|
||||
? touchOffset / INDICATOR_TOUCH_BOTTOM_MAX_ANGLE : 1;
|
||||
} else {
|
||||
touchOffset = swiperPattern->GetDirection() == Axis::HORIZONTAL ? offset.GetX() : offset.GetY();
|
||||
touchBottomRate = LessOrEqual(std::abs(touchOffset), INDICATOR_TOUCH_BOTTOM_MAX_DISTANCE.ConvertToPx())
|
||||
? touchOffset / INDICATOR_TOUCH_BOTTOM_MAX_DISTANCE.ConvertToPx() : 1;
|
||||
}
|
||||
auto touchOffset = swiperPattern->GetDirection() == Axis::HORIZONTAL ? offset.GetX() : offset.GetY();
|
||||
auto touchBottomRate = LessOrEqual(std::abs(touchOffset), INDICATOR_TOUCH_BOTTOM_MAX_DISTANCE.ConvertToPx())
|
||||
? touchOffset / INDICATOR_TOUCH_BOTTOM_MAX_DISTANCE.ConvertToPx()
|
||||
: 1;
|
||||
|
||||
swiperPattern->SetTurnPageRate(0);
|
||||
swiperPattern->SetTouchBottomRate(std::abs(touchBottomRate));
|
||||
TouchBottomType touchBottomType = TouchBottomType::NONE;
|
||||
|
||||
if ((currentIndex <= 0) && !isLoop) {
|
||||
if (Negative(info.GetMainDelta()) || NonPositive(touchOffset)) {
|
||||
touchBottomType = TouchBottomType::START;
|
||||
}
|
||||
}
|
||||
|
||||
if ((currentIndex >= childrenSize - displayCount) && !isLoop) {
|
||||
if (Positive(info.GetMainDelta()) || NonNegative(touchOffset)) {
|
||||
touchBottomType = TouchBottomType::END;
|
||||
@ -712,21 +679,12 @@ bool SwiperIndicatorPattern::CheckIsTouchBottom(const TouchLocationInfo& info)
|
||||
|
||||
auto dragPoint =
|
||||
PointF(static_cast<float>(info.GetLocalLocation().GetX()), static_cast<float>(info.GetLocalLocation().GetY()));
|
||||
float touchBottomRate = 0.0;
|
||||
float touchOffset = 0.0;
|
||||
if (swiperIndicatorType_ == SwiperIndicatorType::ARC_DOT) {
|
||||
auto center = GetCenterPointF();
|
||||
float startAngle = GetAngleWithPoint(center, dragStartPoint_);
|
||||
float endAngle = GetAngleWithPoint(center, dragPoint);
|
||||
touchOffset = startAngle - endAngle;
|
||||
touchBottomRate = LessOrEqual(std::abs(touchOffset), INDICATOR_TOUCH_BOTTOM_MAX_ANGLE)
|
||||
? touchOffset / INDICATOR_TOUCH_BOTTOM_MAX_ANGLE : 1;
|
||||
} else {
|
||||
auto offset = dragPoint - dragStartPoint_;
|
||||
touchOffset = swiperPattern->GetDirection() == Axis::HORIZONTAL ? offset.GetX() : offset.GetY();
|
||||
touchBottomRate = LessOrEqual(std::abs(touchOffset), INDICATOR_TOUCH_BOTTOM_MAX_DISTANCE.ConvertToPx())
|
||||
? touchOffset / INDICATOR_TOUCH_BOTTOM_MAX_DISTANCE.ConvertToPx() : 1;
|
||||
}
|
||||
auto offset = dragPoint - dragStartPoint_;
|
||||
auto touchOffset = swiperPattern->GetDirection() == Axis::HORIZONTAL ? offset.GetX() : offset.GetY();
|
||||
auto touchBottomRate = LessOrEqual(std::abs(touchOffset), INDICATOR_TOUCH_BOTTOM_MAX_DISTANCE.ConvertToPx())
|
||||
? touchOffset / INDICATOR_TOUCH_BOTTOM_MAX_DISTANCE.ConvertToPx()
|
||||
: 1;
|
||||
|
||||
swiperPattern->SetTurnPageRate(0);
|
||||
swiperPattern->SetTouchBottomRate(std::abs(touchBottomRate));
|
||||
TouchBottomType touchBottomType = TouchBottomType::NONE;
|
||||
@ -742,6 +700,7 @@ bool SwiperIndicatorPattern::CheckIsTouchBottom(const TouchLocationInfo& info)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (currentIndex >= childrenSize - displayCount) {
|
||||
if (swiperPattern->IsHorizontalAndRightToLeft()) {
|
||||
if (NonPositive(touchOffset)) {
|
||||
@ -790,87 +749,6 @@ void SwiperIndicatorPattern::HandleLongPress(GestureEvent& info)
|
||||
swiperPattern->StopSpringAnimation();
|
||||
swiperPattern->StopAutoPlay();
|
||||
}
|
||||
if (swiperPattern->GetIndicatorType() == SwiperIndicatorType::ARC_DOT) {
|
||||
isLongPressed_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
PointF SwiperIndicatorPattern::GetCenterPointF()
|
||||
{
|
||||
auto center = PointF(0.0, 0.0);
|
||||
auto swiperNode = GetSwiperNode();
|
||||
CHECK_NULL_RETURN(swiperNode, center);
|
||||
auto swiperPattern = swiperNode->GetPattern<SwiperPattern>();
|
||||
CHECK_NULL_RETURN(swiperPattern, center);
|
||||
|
||||
const auto& geometryNode = swiperNode->GetGeometryNode();
|
||||
const auto& contentSize = geometryNode->GetFrameSize();
|
||||
float centerY_ = (swiperPattern->GetDirection() == Axis::HORIZONTAL ?
|
||||
contentSize.Height() : contentSize.Width()) * 0.5;
|
||||
float centerX_ = (swiperPattern->GetDirection() == Axis::HORIZONTAL ?
|
||||
contentSize.Width() : contentSize.Height()) * 0.5;
|
||||
center = PointF(centerX_, centerY_);
|
||||
return center;
|
||||
}
|
||||
|
||||
float SwiperIndicatorPattern::ConvertAngleWithArcDirection(SwiperArcDirection arcDirection, const float& angle)
|
||||
{
|
||||
float result = 0.0;
|
||||
if (arcDirection == SwiperArcDirection::SIX_CLOCK_DIRECTION) {
|
||||
result = angle;
|
||||
} else if (arcDirection == SwiperArcDirection::THREE_CLOCK_DIRECTION) {
|
||||
if (angle > QUARTER_CIRCLE_ANGLE) {
|
||||
result = -THREE_QUARTER_CIRCLE_ANGLE + angle;
|
||||
} else {
|
||||
result = angle + QUARTER_CIRCLE_ANGLE;
|
||||
}
|
||||
} else {
|
||||
if (angle < -QUARTER_CIRCLE_ANGLE) {
|
||||
result = THREE_QUARTER_CIRCLE_ANGLE + angle;
|
||||
} else {
|
||||
result = angle - QUARTER_CIRCLE_ANGLE;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
float SwiperIndicatorPattern::GetAngleWithPoint(const PointF& conter, const PointF& point)
|
||||
{
|
||||
float angle = 0.0;
|
||||
auto swiperNode = GetSwiperNode();
|
||||
CHECK_NULL_RETURN(swiperNode, angle);
|
||||
auto swiperPattern = swiperNode->GetPattern<SwiperPattern>();
|
||||
CHECK_NULL_RETURN(swiperPattern, angle);
|
||||
|
||||
float centerX = swiperPattern->GetDirection() == Axis::HORIZONTAL ? conter.GetX() : conter.GetY();
|
||||
float centerY = swiperPattern->GetDirection() == Axis::HORIZONTAL ? conter.GetY() : conter.GetX();
|
||||
float pointX = swiperPattern->GetDirection() == Axis::HORIZONTAL ? point.GetX() : point.GetY();
|
||||
float pointY = swiperPattern->GetDirection() == Axis::HORIZONTAL ? point.GetY() : point.GetX();
|
||||
const auto& arcDotParameters = swiperPattern->GetSwiperArcDotParameters();
|
||||
CHECK_NULL_RETURN(arcDotParameters, angle);
|
||||
std::optional<SwiperArcDirection> swiperArcDirection = arcDotParameters->arcDirection;
|
||||
CHECK_NULL_RETURN(swiperArcDirection.has_value(), angle);
|
||||
auto arcDirection = swiperArcDirection.value();
|
||||
if (NearEqual(centerY, pointY) && LessOrEqual(centerX, pointX)) {
|
||||
angle = -QUARTER_CIRCLE_ANGLE;
|
||||
} else if (NearEqual(centerX, pointX) && pointY > centerY) {
|
||||
angle = 0.0;
|
||||
} else if (NearEqual(centerY, pointY) && pointX < centerX) {
|
||||
angle = QUARTER_CIRCLE_ANGLE;
|
||||
} else if (NearEqual(centerX, pointX) && pointY < centerY) {
|
||||
angle = HALF_CIRCLE_ANGLE;
|
||||
} else if (pointX > centerX && pointY > centerY) {
|
||||
angle = atan((pointY - centerY) / (pointX - centerX)) * HALF_CIRCLE_ANGLE / M_PI - QUARTER_CIRCLE_ANGLE;
|
||||
} else if (pointX < centerX && pointY > centerY) {
|
||||
angle = QUARTER_CIRCLE_ANGLE - atan((pointY - centerY) / (centerX - pointX)) * HALF_CIRCLE_ANGLE / M_PI;
|
||||
} else if (pointX < centerX && pointY < centerY) {
|
||||
angle = QUARTER_CIRCLE_ANGLE + atan((centerY - pointY) / (centerX - pointX)) * HALF_CIRCLE_ANGLE / M_PI;
|
||||
} else {
|
||||
angle = -QUARTER_CIRCLE_ANGLE - atan((centerY - pointY) / (pointX - centerX)) * HALF_CIRCLE_ANGLE / M_PI;
|
||||
}
|
||||
|
||||
return ConvertAngleWithArcDirection(arcDirection, angle);
|
||||
}
|
||||
|
||||
void SwiperIndicatorPattern::HandleLongDragUpdate(const TouchLocationInfo& info)
|
||||
@ -891,30 +769,17 @@ void SwiperIndicatorPattern::HandleLongDragUpdate(const TouchLocationInfo& info)
|
||||
if (CheckIsTouchBottom(info)) {
|
||||
return;
|
||||
}
|
||||
float turnPageRate = 0.0;
|
||||
float turnPageRateOffset = 0.0;
|
||||
auto dragPoint =
|
||||
PointF(static_cast<float>(info.GetLocalLocation().GetX()), static_cast<float>(info.GetLocalLocation().GetY()));
|
||||
if (swiperIndicatorType_ == SwiperIndicatorType::ARC_DOT) {
|
||||
auto center = GetCenterPointF();
|
||||
float startAngle = GetAngleWithPoint(center, dragStartPoint_);
|
||||
float endAngle = GetAngleWithPoint(center, dragPoint);
|
||||
turnPageRateOffset = startAngle - endAngle;
|
||||
if (LessNotEqual(std::abs(turnPageRateOffset), INDICATOR_DRAG_MIN_ANGLE)) {
|
||||
return;
|
||||
}
|
||||
turnPageRate = -(turnPageRateOffset / INDICATOR_DRAG_MAX_ANGLE);
|
||||
} else {
|
||||
auto offset = dragPoint - dragStartPoint_;
|
||||
turnPageRateOffset = swiperPattern->GetDirection() == Axis::HORIZONTAL ? offset.GetX() : offset.GetY();
|
||||
if (LessNotEqual(std::abs(turnPageRateOffset), INDICATOR_DRAG_MIN_DISTANCE.ConvertToPx())) {
|
||||
return;
|
||||
}
|
||||
if (swiperPattern->IsHorizontalAndRightToLeft()) {
|
||||
turnPageRateOffset = -turnPageRateOffset;
|
||||
}
|
||||
turnPageRate = -(turnPageRateOffset / INDICATOR_DRAG_MAX_DISTANCE.ConvertToPx());
|
||||
auto offset = dragPoint - dragStartPoint_;
|
||||
auto turnPageRateOffset = swiperPattern->GetDirection() == Axis::HORIZONTAL ? offset.GetX() : offset.GetY();
|
||||
if (LessNotEqual(std::abs(turnPageRateOffset), INDICATOR_DRAG_MIN_DISTANCE.ConvertToPx())) {
|
||||
return;
|
||||
}
|
||||
if (swiperPattern->IsHorizontalAndRightToLeft()) {
|
||||
turnPageRateOffset = -turnPageRateOffset;
|
||||
}
|
||||
auto turnPageRate = -(turnPageRateOffset / INDICATOR_DRAG_MAX_DISTANCE.ConvertToPx());
|
||||
swiperPattern->SetTurnPageRate(turnPageRate);
|
||||
if (std::abs(turnPageRate) >= 1) {
|
||||
if (Positive(turnPageRateOffset)) {
|
||||
@ -976,130 +841,12 @@ void SwiperIndicatorPattern::DumpAdvanceInfo()
|
||||
DumpLog::GetInstance().AddDesc("SwiperIndicatorType:DIGIT");
|
||||
break;
|
||||
}
|
||||
case SwiperIndicatorType::ARC_DOT: {
|
||||
DumpLog::GetInstance().AddDesc("SwiperIndicatorType:ARC_DOT");
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool SwiperIndicatorPattern::SetArcIndicatorHotRegion(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config)
|
||||
{
|
||||
if (config.skipMeasure && config.skipLayout) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto& indicatorGeometryNode = dirty->GetGeometryNode();
|
||||
CHECK_NULL_RETURN(indicatorGeometryNode, false);
|
||||
const auto& frameRect = indicatorGeometryNode->GetFrameRect();
|
||||
if (NonPositive(frameRect.Width()) || NonPositive(frameRect.Height())) {
|
||||
return false;
|
||||
}
|
||||
return CalculateArcIndicatorHotRegion(frameRect, indicatorGeometryNode->GetContentOffset());
|
||||
}
|
||||
|
||||
bool SwiperIndicatorPattern::CalculateArcIndicatorHotRegion(const RectF& frameRect, const OffsetF& contentOffset)
|
||||
{
|
||||
auto host = GetHost();
|
||||
CHECK_NULL_RETURN(host, false);
|
||||
auto gestureHub = host->GetOrCreateGestureEventHub();
|
||||
CHECK_NULL_RETURN(gestureHub, false);
|
||||
auto swiperNode = DynamicCast<FrameNode>(host->GetParent());
|
||||
CHECK_NULL_RETURN(swiperNode, false);
|
||||
auto swiperPattern = swiperNode->GetPattern<SwiperPattern>();
|
||||
CHECK_NULL_RETURN(swiperPattern, false);
|
||||
int32_t itemCount = swiperPattern->RealTotalCount();
|
||||
if (itemCount <= 0) {
|
||||
return false;
|
||||
}
|
||||
auto allPointArcAngle = (itemCount - 1) * ITEM_PADDING + ACTIVE_ITEM_ANGLE + ADD_HOT_REG_ANGLE;
|
||||
auto centerX = frameRect.Width() * 0.5 + contentOffset.GetX();
|
||||
auto centerY = frameRect.Height() * 0.5 + contentOffset.GetY();
|
||||
auto minEdgeLength = LessNotEqual(frameRect.Width(), frameRect.Height()) ? frameRect.Width() : frameRect.Height();
|
||||
if (LessOrEqual(minEdgeLength, CIRCLE_DIAMETER_OFFSET.ConvertToPx())) {
|
||||
return false;
|
||||
}
|
||||
auto radius = (minEdgeLength - CIRCLE_DIAMETER_OFFSET.ConvertToPx()) * 0.5;
|
||||
const auto& parameter = swiperPattern->GetSwiperArcDotParameters();
|
||||
CHECK_NULL_RETURN(parameter, false);
|
||||
SwiperArcDirection arcDirection = parameter->arcDirection.value_or(SwiperArcDirection::SIX_CLOCK_DIRECTION);
|
||||
std::vector<DimensionRect> responseRegion;
|
||||
int32_t allAngleCount = static_cast<int32_t>(allPointArcAngle);
|
||||
for (int32_t i = 0; i <= allAngleCount; i++) {
|
||||
double angle = 0.0;
|
||||
// The number 0.5 represents equal division
|
||||
if (arcDirection == SwiperArcDirection::THREE_CLOCK_DIRECTION) {
|
||||
angle = - allPointArcAngle * 0.5 + i;
|
||||
} else if (arcDirection == SwiperArcDirection::NINE_CLOCK_DIRECTION) {
|
||||
angle = HALF_CIRCLE_ANGLE - allPointArcAngle * 0.5 + i;
|
||||
} else {
|
||||
angle = QUARTER_CIRCLE_ANGLE - allPointArcAngle * 0.5 + i;
|
||||
}
|
||||
if (LessNotEqual(angle, 0.0)) {
|
||||
angle = FULL_CIRCLE_ANGLE + angle;
|
||||
}
|
||||
|
||||
OffsetF angleOffset = CalculateAngleOffset(centerX, centerY, radius, angle);
|
||||
Dimension width;
|
||||
Dimension height;
|
||||
OffsetF hotRegionOffset = CalculateRectLayout(angle, radius, angleOffset, width, height);
|
||||
|
||||
DimensionRect responseRect(width, height, DimensionOffset(hotRegionOffset));
|
||||
responseRegion.emplace_back(responseRect);
|
||||
}
|
||||
|
||||
gestureHub->SetResponseRegion(responseRegion);
|
||||
return true;
|
||||
}
|
||||
|
||||
OffsetF SwiperIndicatorPattern::CalculateAngleOffset(float centerX, float centerY, float radius, double angle)
|
||||
{
|
||||
double radians = 0.0;
|
||||
OffsetF angleOffset;
|
||||
if (GreatOrEqual(angle, 0.0) && LessNotEqual(angle, QUARTER_CIRCLE_ANGLE)) {
|
||||
radians = std::abs(angle) * M_PI / HALF_CIRCLE_ANGLE;
|
||||
angleOffset.SetX(centerX + cos(radians) * radius);
|
||||
angleOffset.SetY(centerY + sin(radians) * radius);
|
||||
} else if (GreatOrEqual(angle, QUARTER_CIRCLE_ANGLE) && LessNotEqual(angle, HALF_CIRCLE_ANGLE)) {
|
||||
radians = std::abs(HALF_CIRCLE_ANGLE - angle) * M_PI / HALF_CIRCLE_ANGLE;
|
||||
angleOffset.SetX(centerX - cos(radians) * radius);
|
||||
angleOffset.SetY(centerY + sin(radians) * radius);
|
||||
} else if (GreatOrEqual(angle, HALF_CIRCLE_ANGLE) && LessNotEqual(angle, THREE_QUARTER_CIRCLE_ANGLE)) {
|
||||
radians = std::abs(angle - HALF_CIRCLE_ANGLE) * M_PI / HALF_CIRCLE_ANGLE;
|
||||
angleOffset.SetX(centerX - cos(radians) * radius);
|
||||
angleOffset.SetY(centerY - sin(radians) * radius);
|
||||
} else if (GreatOrEqual(angle, THREE_QUARTER_CIRCLE_ANGLE) && LessNotEqual(angle, FULL_CIRCLE_ANGLE)) {
|
||||
radians = std::abs(FULL_CIRCLE_ANGLE - angle) * M_PI / HALF_CIRCLE_ANGLE;
|
||||
angleOffset.SetX(centerX + cos(radians) * radius);
|
||||
angleOffset.SetY(centerY - sin(radians) * radius);
|
||||
}
|
||||
return angleOffset;
|
||||
}
|
||||
|
||||
OffsetF SwiperIndicatorPattern::CalculateRectLayout(
|
||||
double angle, float radius, OffsetF angleOffset, Dimension& width, Dimension& height)
|
||||
{
|
||||
OffsetF hotRegionOffset = angleOffset;
|
||||
Dimension oneAngleLength = Dimension(sin(M_PI / HALF_CIRCLE_ANGLE) * radius, DimensionUnit::PX);
|
||||
// The number 0.5 represents equal division
|
||||
if ((GreatOrEqual(angle, QUARTER_CIRCLE_ANGLE * 0.5) &&
|
||||
LessNotEqual(angle, QUARTER_CIRCLE_ANGLE * 0.5 + QUARTER_CIRCLE_ANGLE)) ||
|
||||
(GreatOrEqual(angle, QUARTER_CIRCLE_ANGLE * 0.5 + HALF_CIRCLE_ANGLE) &&
|
||||
LessNotEqual(angle, QUARTER_CIRCLE_ANGLE * 0.5 + THREE_QUARTER_CIRCLE_ANGLE))) {
|
||||
hotRegionOffset.SetY(angleOffset.GetY() - CONTAINER_BORDER_WIDTH.ConvertToPx() * 0.5);
|
||||
width = oneAngleLength;
|
||||
height = CONTAINER_BORDER_WIDTH;
|
||||
} else {
|
||||
hotRegionOffset.SetX(angleOffset.GetX() - CONTAINER_BORDER_WIDTH.ConvertToPx() * 0.5);
|
||||
width = CONTAINER_BORDER_WIDTH;
|
||||
height = oneAngleLength;
|
||||
}
|
||||
return hotRegionOffset;
|
||||
}
|
||||
|
||||
RefPtr<OverlengthDotIndicatorPaintMethod> SwiperIndicatorPattern::CreateOverlongDotIndicatorPaintMethod(
|
||||
RefPtr<SwiperPattern> swiperPattern)
|
||||
{
|
||||
|
@ -21,8 +21,6 @@
|
||||
#include "core/components_ng/base/frame_node.h"
|
||||
#include "core/components_ng/pattern/pattern.h"
|
||||
#include "core/components_ng/pattern/swiper/swiper_pattern.h"
|
||||
#include "core/components_ng/pattern/swiper_indicator/circle_dot_indicator/circle_dot_indicator_layout_algorithm.h"
|
||||
#include "core/components_ng/pattern/swiper_indicator/circle_dot_indicator/circle_dot_indicator_paint_method.h"
|
||||
#include "core/components_ng/pattern/swiper_indicator/digit_indicator/digit_indicator_layout_algorithm.h"
|
||||
#include "core/components_ng/pattern/swiper_indicator/dot_indicator/overlength_dot_indicator_paint_method.h"
|
||||
#include "core/components_ng/pattern/swiper_indicator/dot_indicator/dot_indicator_layout_algorithm.h"
|
||||
@ -48,8 +46,6 @@ public:
|
||||
{
|
||||
if (SwiperIndicatorUtils::GetSwiperIndicatorType() == SwiperIndicatorType::DOT) {
|
||||
return MakeRefPtr<DotIndicatorPaintProperty>();
|
||||
} else if (SwiperIndicatorUtils::GetSwiperIndicatorType() == SwiperIndicatorType::ARC_DOT) {
|
||||
return MakeRefPtr<CircleDotIndicatorPaintProperty>();
|
||||
} else {
|
||||
return MakeRefPtr<PaintProperty>();
|
||||
}
|
||||
@ -75,9 +71,6 @@ public:
|
||||
maxDisplayCount > 0 ? indicatorLayoutAlgorithm->SetIndicatorDisplayCount(maxDisplayCount)
|
||||
: indicatorLayoutAlgorithm->SetIndicatorDisplayCount(swiperPattern->TotalCount());
|
||||
|
||||
return indicatorLayoutAlgorithm;
|
||||
} else if (swiperPattern->GetIndicatorType() == SwiperIndicatorType::ARC_DOT) {
|
||||
auto indicatorLayoutAlgorithm = MakeRefPtr<CircleDotIndicatorLayoutAlgorithm>();
|
||||
return indicatorLayoutAlgorithm;
|
||||
} else {
|
||||
auto indicatorLayoutAlgorithm = MakeRefPtr<DigitIndicatorLayoutAlgorithm>();
|
||||
@ -115,28 +108,6 @@ public:
|
||||
mouseClickIndex_ = std::nullopt;
|
||||
}
|
||||
|
||||
RefPtr<CircleDotIndicatorPaintMethod> CreateCircleDotIndicatorPaintMethod(RefPtr<SwiperPattern> swiperPattern)
|
||||
{
|
||||
auto swiperLayoutProperty = swiperPattern->GetLayoutProperty<SwiperLayoutProperty>();
|
||||
CHECK_NULL_RETURN(swiperLayoutProperty, nullptr);
|
||||
auto paintMethod = MakeRefPtr<CircleDotIndicatorPaintMethod>(circleDotIndicatorModifier_);
|
||||
paintMethod->SetAxis(swiperPattern->GetDirection());
|
||||
paintMethod->SetCurrentIndex(swiperPattern->GetLoopIndex(swiperPattern->GetCurrentFirstIndex()));
|
||||
paintMethod->SetCurrentIndexActual(swiperPattern->GetLoopIndex(swiperPattern->GetCurrentIndex()));
|
||||
paintMethod->SetNextValidIndex(swiperPattern->GetNextValidIndex());
|
||||
paintMethod->SetItemCount(swiperPattern->RealTotalCount());
|
||||
paintMethod->SetGestureState(swiperPattern->GetGestureState());
|
||||
paintMethod->SetTurnPageRate(swiperPattern->GetTurnPageRate());
|
||||
paintMethod->SetTouchBottomTypeLoop(swiperPattern->GetTouchBottomTypeLoop());
|
||||
paintMethod->SetIsLongPressed(isLongPressed_);
|
||||
if (mouseClickIndex_) {
|
||||
mouseClickIndex_ = swiperPattern->GetLoopIndex(mouseClickIndex_.value());
|
||||
}
|
||||
paintMethod->SetMouseClickIndex(mouseClickIndex_);
|
||||
mouseClickIndex_ = std::nullopt;
|
||||
return paintMethod;
|
||||
}
|
||||
|
||||
RefPtr<NodePaintMethod> CreateNodePaintMethod() override
|
||||
{
|
||||
auto swiperNode = GetSwiperNode();
|
||||
@ -151,12 +122,6 @@ public:
|
||||
|
||||
SetIndicatorInteractive(swiperPattern->IsIndicatorInteractive());
|
||||
return CreateDotIndicatorPaintMethod(swiperPattern);
|
||||
} else if (swiperPattern->GetIndicatorType() == SwiperIndicatorType::ARC_DOT) {
|
||||
if (!circleDotIndicatorModifier_) {
|
||||
circleDotIndicatorModifier_ = AceType::MakeRefPtr<CircleDotIndicatorModifier>();
|
||||
}
|
||||
auto paintMethod = CreateCircleDotIndicatorPaintMethod(swiperPattern);
|
||||
return paintMethod;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
@ -228,16 +193,9 @@ private:
|
||||
bool CheckIsTouchBottom(const GestureEvent& info);
|
||||
void InitLongPressEvent(const RefPtr<GestureEventHub>& gestureHub);
|
||||
void HandleLongPress(GestureEvent& info);
|
||||
PointF GetCenterPointF();
|
||||
float ConvertAngleWithArcDirection(SwiperArcDirection arcDirection, const float& angle);
|
||||
float GetAngleWithPoint(const PointF& conter, const PointF& point);
|
||||
void HandleLongDragUpdate(const TouchLocationInfo& info);
|
||||
bool CheckIsTouchBottom(const TouchLocationInfo& info);
|
||||
float HandleTouchClickMargin();
|
||||
bool SetArcIndicatorHotRegion(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config);
|
||||
bool CalculateArcIndicatorHotRegion(const RectF& frameRect, const OffsetF& contentOffset);
|
||||
OffsetF CalculateAngleOffset(float centerX, float centerY, float radius, double angle);
|
||||
OffsetF CalculateRectLayout(double angle, float radius, OffsetF angleOffset, Dimension& width, Dimension& height);
|
||||
int32_t GetCurrentIndex() const;
|
||||
void InitFocusEvent();
|
||||
void HandleFocusEvent();
|
||||
@ -259,7 +217,6 @@ private:
|
||||
RefPtr<LongPressEvent> longPressEvent_;
|
||||
bool isHover_ = false;
|
||||
bool isPressed_ = false;
|
||||
bool isLongPressed_ = false;
|
||||
PointF hoverPoint_;
|
||||
PointF dragStartPoint_;
|
||||
TouchBottomType touchBottomType_ = TouchBottomType::NONE;
|
||||
@ -271,7 +228,6 @@ private:
|
||||
std::function<void(bool)> isFocusActiveUpdateEvent_;
|
||||
RefPtr<DotIndicatorModifier> dotIndicatorModifier_;
|
||||
RefPtr<OverlengthDotIndicatorModifier> overlongDotIndicatorModifier_;
|
||||
RefPtr<CircleDotIndicatorModifier> circleDotIndicatorModifier_;
|
||||
SwiperIndicatorType swiperIndicatorType_ = SwiperIndicatorType::DOT;
|
||||
|
||||
std::optional<int32_t> jumpIndex_;
|
||||
|
@ -1,20 +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/swiper_indicator/indicator_common/swiper_indicator_utils.h"
|
||||
|
||||
namespace OHOS::Ace::NG {
|
||||
SwiperIndicatorType SwiperIndicatorUtils::swiperIndicatorType = SwiperIndicatorType::DOT;
|
||||
} // namespace OHOS::Ace::NG
|
@ -23,6 +23,7 @@
|
||||
#include "core/components_ng/pattern/swiper_indicator/indicator_common/swiper_indicator_layout_property.h"
|
||||
|
||||
namespace OHOS::Ace::NG {
|
||||
static SwiperIndicatorType swiperIndicatorType = SwiperIndicatorType::DOT;
|
||||
|
||||
inline float GET_PADDING_PROPERTY_VALUE_PX(const std::optional<CalcLength>& value)
|
||||
{
|
||||
@ -173,8 +174,6 @@ private:
|
||||
}
|
||||
return offsetY;
|
||||
}
|
||||
|
||||
static SwiperIndicatorType swiperIndicatorType;
|
||||
};
|
||||
} // namespace OHOS::Ace::NG
|
||||
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SWIPER_INDICATOR_SWIPER_INDICATOR_UTILS_H
|
||||
|
@ -265,7 +265,7 @@ struct ACE_EXPORT SweepGradient {
|
||||
|
||||
class ACE_FORCE_EXPORT Gradient final {
|
||||
public:
|
||||
ACE_FORCE_EXPORT void AddColor(const GradientColor& color);
|
||||
void AddColor(const GradientColor& color);
|
||||
|
||||
void ClearColors();
|
||||
|
||||
|
@ -957,7 +957,6 @@ ohos_source_set("ace_components_pattern") {
|
||||
"$ace_root/frameworks/core/components_ng/pattern/stepper/stepper_model_ng.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/pattern/stepper/stepper_node.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/pattern/stepper/stepper_pattern.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/pattern/swiper/arc_swiper_pattern.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/pattern/swiper/swiper_accessibility_property.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/pattern/swiper/swiper_helper.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/pattern/swiper/swiper_layout_algorithm.cpp",
|
||||
@ -965,9 +964,6 @@ ohos_source_set("ace_components_pattern") {
|
||||
"$ace_root/frameworks/core/components_ng/pattern/swiper/swiper_paint_method.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/pattern/swiper/swiper_paint_property.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/pattern/swiper/swiper_pattern.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/pattern/swiper_indicator/circle_dot_indicator/circle_dot_indicator_layout_algorithm.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/pattern/swiper_indicator/circle_dot_indicator/circle_dot_indicator_modifier.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/pattern/swiper_indicator/circle_dot_indicator/circle_dot_indicator_paint_method.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/pattern/swiper_indicator/digit_indicator/digit_indicator_layout_algorithm.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/pattern/swiper_indicator/dot_indicator/dot_indicator_layout_algorithm.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/pattern/swiper_indicator/dot_indicator/dot_indicator_modifier.cpp",
|
||||
@ -978,7 +974,6 @@ ohos_source_set("ace_components_pattern") {
|
||||
"$ace_root/frameworks/core/components_ng/pattern/swiper_indicator/indicator_common/swiper_arrow_pattern.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/pattern/swiper_indicator/indicator_common/swiper_indicator_accessibility_property.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/pattern/swiper_indicator/indicator_common/swiper_indicator_pattern.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/pattern/swiper_indicator/indicator_common/swiper_indicator_utils.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/pattern/symbol/symbol_effect_options.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/pattern/symbol/symbol_model_ng.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/pattern/symbol/symbol_source_info.cpp",
|
||||
|
@ -544,10 +544,7 @@ HWTEST_F(SwiperAttrTestNg, AttrDisplayCount003, TestSize.Level1)
|
||||
* @tc.cases: Set displayCount to ITEM_NUMBER+1
|
||||
* @tc.expected: DisplayCount is ITEM_NUMBER+1, last item place has placeholder child
|
||||
*/
|
||||
CreateWithItem([](SwiperModelNG model) {
|
||||
model.SetDisplayCount(ITEM_NUMBER + 1);
|
||||
model.SetIndicatorType(SwiperIndicatorType::DOT);
|
||||
});
|
||||
CreateWithItem([](SwiperModelNG model) { model.SetDisplayCount(ITEM_NUMBER + 1); });
|
||||
EXPECT_EQ(pattern_->GetDisplayCount(), 5);
|
||||
EXPECT_EQ(pattern_->TotalCount(), ITEM_NUMBER); // child number still is 4
|
||||
EXPECT_GT(GetChildWidth(frameNode_, 3), 0.f); // item size > 0
|
||||
@ -565,10 +562,7 @@ HWTEST_F(SwiperAttrTestNg, AttrDisplayCount004, TestSize.Level1)
|
||||
* @tc.cases: Set minsize to half of swiper width
|
||||
* @tc.expected: show 2 item in one page
|
||||
*/
|
||||
CreateWithItem([](SwiperModelNG model) {
|
||||
model.SetMinSize(Dimension(SWIPER_WIDTH / 3));
|
||||
model.SetIndicatorType(SwiperIndicatorType::DOT);
|
||||
});
|
||||
CreateWithItem([](SwiperModelNG model) { model.SetMinSize(Dimension(SWIPER_WIDTH / 3)); });
|
||||
EXPECT_TRUE(pattern_->IsAutoFill());
|
||||
EXPECT_EQ(pattern_->GetDisplayCount(), 2);
|
||||
EXPECT_GT(GetChildWidth(frameNode_, 0), 0.f); // item size > 0
|
||||
@ -1179,53 +1173,4 @@ HWTEST_F(SwiperAttrTestNg, SwiperPaintProperty001, TestSize.Level1)
|
||||
paintProperty_->FromJson(jsonFrom);
|
||||
EXPECT_TRUE(jsonFrom);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ArcDotIndicator001
|
||||
* @tc.desc: Test property about indicator
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SwiperAttrTestNg, ArcDotIndicator001, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. create swiper and set parameters.
|
||||
*/
|
||||
SwiperArcDotParameters swiperArcDotParameters;
|
||||
swiperArcDotParameters.arcDirection = SwiperArcDirection::NINE_CLOCK_DIRECTION;
|
||||
swiperArcDotParameters.itemColor = Color::GREEN;
|
||||
swiperArcDotParameters.selectedItemColor = Color::RED;
|
||||
swiperArcDotParameters.containerColor = Color::BLUE;
|
||||
CreateWithItem([=](SwiperModelNG model) {
|
||||
model.Create(true);
|
||||
model.SetIndicatorType(SwiperIndicatorType::ARC_DOT);
|
||||
model.SetArcDotIndicatorStyle(swiperArcDotParameters);
|
||||
});
|
||||
auto paintProperty = indicatorNode_->GetPaintProperty<CircleDotIndicatorPaintProperty>();
|
||||
RefPtr<SwiperPattern> indicatorPattern = frameNode_->GetPattern<SwiperPattern>();
|
||||
indicatorPattern->OnModifyDone();
|
||||
EXPECT_EQ(pattern_->GetIndicatorType(), SwiperIndicatorType::ARC_DOT);
|
||||
EXPECT_EQ(paintProperty->GetArcDirection(), SwiperArcDirection::NINE_CLOCK_DIRECTION);
|
||||
EXPECT_EQ(paintProperty->GetColor(), Color::GREEN);
|
||||
EXPECT_EQ(paintProperty->GetSelectedColor(), Color::RED);
|
||||
EXPECT_EQ(paintProperty->GetContainerColor(), Color::BLUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ArcDotIndicator001
|
||||
* @tc.desc: Test property about indicator
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SwiperAttrTestNg, ArcDotIndicator002, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. create swiper and set parameters.
|
||||
*/
|
||||
CreateWithItem([=](SwiperModelNG model) {
|
||||
model.Create(true);
|
||||
model.SetIndicatorType(SwiperIndicatorType::ARC_DOT);
|
||||
});
|
||||
RefPtr<ArcSwiperPattern> indicatorPattern = frameNode_->GetPattern<ArcSwiperPattern>();
|
||||
indicatorPattern->GetSwiperArcDotParameters();
|
||||
EXPECT_NE(indicatorPattern->swiperArcDotParameters_, nullptr);
|
||||
}
|
||||
} // namespace OHOS::Ace::NG
|
||||
|
@ -30,10 +30,7 @@ public:
|
||||
*/
|
||||
HWTEST_F(SwiperIndicatorLayoutTestNg, SwiperIndicatorLayoutAlgorithmMeasure001, TestSize.Level1)
|
||||
{
|
||||
CreateWithItem([](SwiperModelNG model) {
|
||||
model.SetDirection(Axis::VERTICAL);
|
||||
model.SetIndicatorType(SwiperIndicatorType::DOT);
|
||||
});
|
||||
CreateWithItem([](SwiperModelNG model) {});
|
||||
auto indicatorPattern = indicatorNode_->GetPattern<SwiperIndicatorPattern>();
|
||||
RefPtr<NodePaintMethod> nodePaintMethod = indicatorPattern->CreateNodePaintMethod();
|
||||
auto algorithm = indicatorPattern->CreateLayoutAlgorithm();
|
||||
@ -58,7 +55,6 @@ HWTEST_F(SwiperIndicatorLayoutTestNg, SwiperIndicatorLayoutAlgorithmMeasure002,
|
||||
{
|
||||
CreateWithItem([](SwiperModelNG model) {
|
||||
model.SetDirection(Axis::VERTICAL);
|
||||
model.SetIndicatorType(SwiperIndicatorType::DOT);
|
||||
});
|
||||
layoutProperty_->UpdateDirection(Axis::VERTICAL);
|
||||
auto indicatorPattern = indicatorNode_->GetPattern<SwiperIndicatorPattern>();
|
||||
@ -391,96 +387,4 @@ HWTEST_F(SwiperIndicatorLayoutTestNg, SwiperDigitIndicatorLayoutAlgorithmLayout0
|
||||
auto children = hostNode->GetChildren();
|
||||
EXPECT_FALSE(children.empty());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CircleDotIndicatorLayoutAlgorithmMeasure001
|
||||
* @tc.desc: Test LayoutWrapper CircleDotIndicatorLayoutAlgorithm Measure
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SwiperIndicatorLayoutTestNg, CircleDotIndicatorLayoutAlgorithmMeasure001, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. create swiper and set parameters.
|
||||
*/
|
||||
CreateWithItem([](SwiperModelNG model) {
|
||||
model.Create(true);
|
||||
model.SetDirection(Axis::VERTICAL);
|
||||
model.SetIndicatorType(SwiperIndicatorType::ARC_DOT);
|
||||
});
|
||||
ViewAbstract::SetWidth(AceType::RawPtr(frameNode_), CalcLength(SWIPER_WIDTH));
|
||||
ViewAbstract::SetHeight(AceType::RawPtr(frameNode_), CalcLength(SWIPER_HEIGHT));
|
||||
FlushLayoutTask(frameNode_);
|
||||
auto indicatorPattern = indicatorNode_->GetPattern<SwiperIndicatorPattern>();
|
||||
indicatorPattern->OnModifyDone();
|
||||
auto algorithm = indicatorPattern->CreateLayoutAlgorithm();
|
||||
auto geometryNode = AceType::MakeRefPtr<GeometryNode>();
|
||||
LayoutWrapperNode layoutWrapper =
|
||||
LayoutWrapperNode(indicatorNode_, geometryNode, indicatorNode_->GetLayoutProperty());
|
||||
LayoutConstraintF layoutConstraint;
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. call Measure.
|
||||
*/
|
||||
algorithm->Measure(&layoutWrapper);
|
||||
EXPECT_TRUE(IsEqual(layoutWrapper.GetGeometryNode()->GetFrameSize(), SizeF(SWIPER_WIDTH, SWIPER_HEIGHT)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CircleDotIndicatorLayoutAlgorithmLayout001
|
||||
* @tc.desc: Test CircleDotIndicatorLayoutAlgorithm CircleDotIndicatorLayoutAlgorithmLayout
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SwiperIndicatorLayoutTestNg, CircleDotIndicatorLayoutAlgorithmLayout001, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. create swiper and set parameters.
|
||||
*/
|
||||
CreateWithItem([](SwiperModelNG model) {
|
||||
model.Create(true);
|
||||
model.SetIndicatorType(SwiperIndicatorType::ARC_DOT);
|
||||
});
|
||||
auto indicatorPattern = indicatorNode_->GetPattern<SwiperIndicatorPattern>();
|
||||
auto algorithm = indicatorPattern->CreateLayoutAlgorithm();
|
||||
auto geometryNode = AceType::MakeRefPtr<GeometryNode>();
|
||||
LayoutWrapperNode layoutWrapper =
|
||||
LayoutWrapperNode(indicatorNode_, geometryNode, indicatorNode_->GetLayoutProperty());
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. call Layout.
|
||||
*/
|
||||
algorithm->Layout(&layoutWrapper);
|
||||
EXPECT_TRUE(IsEqual(layoutWrapper.GetGeometryNode()->GetMarginFrameOffset(), OffsetF(0.0f, 0.0f)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CircleDotIndicatorFlushLayoutTask001
|
||||
* @tc.desc: Test CircleDotIndicatorLayoutAlgorithm FlushLayoutTask
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SwiperIndicatorLayoutTestNg, CircleDotIndicatorFlushLayoutTask001, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. create swiper and set parameters.
|
||||
*/
|
||||
CreateWithItem([](SwiperModelNG model) {
|
||||
model.Create(true);
|
||||
model.SetIndicatorType(SwiperIndicatorType::ARC_DOT);
|
||||
});
|
||||
ViewAbstract::SetWidth(AceType::RawPtr(frameNode_), CalcLength(SWIPER_WIDTH));
|
||||
ViewAbstract::SetHeight(AceType::RawPtr(frameNode_), CalcLength(SWIPER_HEIGHT));
|
||||
FlushLayoutTask(frameNode_);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. call FlushLayoutTask.
|
||||
*/
|
||||
FlushLayoutTask(indicatorNode_);
|
||||
EXPECT_TRUE(IsEqual(indicatorNode_->GetGeometryNode()->GetFrameSize(), SizeF(SWIPER_WIDTH, SWIPER_HEIGHT)));
|
||||
ViewAbstract::SetWidth(AceType::RawPtr(frameNode_), CalcLength(300.f));
|
||||
ViewAbstract::SetHeight(AceType::RawPtr(frameNode_), CalcLength(500.f));
|
||||
FlushLayoutTask(frameNode_);
|
||||
EXPECT_TRUE(IsEqual(frameNode_->GetGeometryNode()->GetFrameSize(), SizeF(300.f, 500.f)));
|
||||
FlushLayoutTask(indicatorNode_);
|
||||
EXPECT_TRUE(IsEqual(indicatorNode_->GetGeometryNode()->GetFrameSize(), SizeF(300.f, 500.f)));
|
||||
EXPECT_TRUE(IsEqual(indicatorNode_->GetGeometryNode()->GetMarginFrameOffset(), OffsetF(0.0f, 0.0f)));
|
||||
}
|
||||
} // namespace OHOS::Ace::NG
|
||||
|
@ -1605,506 +1605,4 @@ HWTEST_F(SwiperIndicatorModifierTestNg, UpdateShrinkPaintProperty002, TestSize.L
|
||||
modifier->UpdateShrinkPaintProperty(offset, normalItemHalfSizes, vectorBlackPointCenterX, longPointCenterX);
|
||||
EXPECT_FALSE(modifier->longPointLeftAnimEnd_ && modifier->longPointRightAnimEnd_);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CircleDotIndicatorModifier001
|
||||
* @tc.desc: Test DotIndicatorModifier
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SwiperIndicatorModifierTestNg, CircleDotIndicatorModifier001, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. set parameters.
|
||||
*/
|
||||
CircleDotIndicatorModifier circleDotIndicatorModifier;
|
||||
Testing::MockCanvas canvas;
|
||||
DrawingContext context { canvas, 100.f, 100.f };
|
||||
EXPECT_CALL(canvas, AttachPen(_)).WillRepeatedly(ReturnRef(canvas));
|
||||
EXPECT_CALL(canvas, DetachPen()).WillRepeatedly(ReturnRef(canvas));
|
||||
EXPECT_CALL(canvas, AttachBrush(_)).WillRepeatedly(ReturnRef(canvas));
|
||||
EXPECT_CALL(canvas, DetachBrush()).WillRepeatedly(ReturnRef(canvas));
|
||||
EXPECT_CALL(canvas, DrawArc(_, _, _)).Times(AnyNumber());
|
||||
EXPECT_CALL(canvas, DrawRect(_)).Times(AnyNumber());
|
||||
EXPECT_CALL(canvas, DrawCircle(_, _)).Times(AnyNumber());
|
||||
EXPECT_CALL(canvas, Restore()).Times(AnyNumber());
|
||||
circleDotIndicatorModifier.SetAxis(Axis::HORIZONTAL);
|
||||
circleDotIndicatorModifier.SetArcDirection(SwiperArcDirection::THREE_CLOCK_DIRECTION);
|
||||
circleDotIndicatorModifier.UpdateBackgroundColor(Color::BLUE);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. call onDraw.
|
||||
*/
|
||||
circleDotIndicatorModifier.onDraw(context);
|
||||
EXPECT_EQ(circleDotIndicatorModifier.axis_, Axis::HORIZONTAL);
|
||||
EXPECT_EQ(circleDotIndicatorModifier.arcDirection_, SwiperArcDirection::THREE_CLOCK_DIRECTION);
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. set parameters.
|
||||
*/
|
||||
circleDotIndicatorModifier.SetAxis(Axis::VERTICAL);
|
||||
circleDotIndicatorModifier.SetArcDirection(SwiperArcDirection::SIX_CLOCK_DIRECTION);
|
||||
circleDotIndicatorModifier.UpdateBackgroundColor(Color::RED);
|
||||
LinearVector<float> vectorBlackPointCenterX;
|
||||
vectorBlackPointCenterX.emplace_back(20.f);
|
||||
LinearVector<float> itemHalfSizes;
|
||||
itemHalfSizes.emplace_back(20.f);
|
||||
itemHalfSizes.emplace_back(10.f);
|
||||
itemHalfSizes.emplace_back(30.f);
|
||||
itemHalfSizes.emplace_back(35.f);
|
||||
circleDotIndicatorModifier.UpdatePressPaintProperty(itemHalfSizes, vectorBlackPointCenterX, { 0.f, 0.f });
|
||||
|
||||
/**
|
||||
* @tc.steps: step4. call onDraw.
|
||||
*/
|
||||
circleDotIndicatorModifier.onDraw(context);
|
||||
EXPECT_EQ(circleDotIndicatorModifier.axis_, Axis::VERTICAL);
|
||||
EXPECT_EQ(circleDotIndicatorModifier.arcDirection_, SwiperArcDirection::SIX_CLOCK_DIRECTION);
|
||||
|
||||
/**
|
||||
* @tc.steps: step5. set parameters.
|
||||
*/
|
||||
circleDotIndicatorModifier.SetArcDirection(SwiperArcDirection::NINE_CLOCK_DIRECTION);
|
||||
circleDotIndicatorModifier.UpdateNormalToPressPaintProperty(itemHalfSizes, vectorBlackPointCenterX, { 0.f, 0.f });
|
||||
|
||||
/**
|
||||
* @tc.steps: step6. call onDraw.
|
||||
*/
|
||||
circleDotIndicatorModifier.onDraw(context);
|
||||
EXPECT_EQ(circleDotIndicatorModifier.arcDirection_, SwiperArcDirection::NINE_CLOCK_DIRECTION);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CircleDotPlayIndicatorAnimation001
|
||||
* @tc.desc: play long point animation
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SwiperIndicatorModifierTestNg, CircleDotPlayIndicatorAnimation001, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. create swiper and set parameters.
|
||||
*/
|
||||
CreateWithItem([](SwiperModelNG model) {
|
||||
model.Create(true);
|
||||
model.SetIndicatorType(SwiperIndicatorType::ARC_DOT);
|
||||
});
|
||||
|
||||
RefPtr<CircleDotIndicatorModifier> modifier = AceType::MakeRefPtr<CircleDotIndicatorModifier>();
|
||||
LinearVector<float> vectorBlackPointAngle;
|
||||
vectorBlackPointAngle.push_back(20.0f);
|
||||
vectorBlackPointAngle.push_back(20.0f);
|
||||
std::pair<float, float> longPointCenterX = { 0.0f, 0.0f };
|
||||
auto gestureState = GestureState::GESTURE_STATE_RELEASE_LEFT;
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. call PlayIndicatorAnimation.
|
||||
*/
|
||||
modifier->PlayIndicatorAnimation(vectorBlackPointAngle, longPointCenterX, gestureState);
|
||||
longPointCenterX = { 1.0f, 1.0f };
|
||||
modifier->PlayIndicatorAnimation(vectorBlackPointAngle, longPointCenterX, gestureState);
|
||||
EXPECT_EQ(modifier->longPointLeftAnimEnd_, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CircleDotIndicatorUpdateContentModifier001
|
||||
* @tc.desc: Test CircleDotIndicatorPaintMethod UpdateContentModifier
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SwiperIndicatorModifierTestNg, CircleDotIndicatorUpdateContentModifier001, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. create swiper and set parameters.
|
||||
*/
|
||||
CreateWithItem([](SwiperModelNG model) {
|
||||
model.Create(true);
|
||||
model.SetIndicatorType(SwiperIndicatorType::ARC_DOT);
|
||||
});
|
||||
RefPtr<CircleDotIndicatorModifier> modifier = AceType::MakeRefPtr<CircleDotIndicatorModifier>();
|
||||
RefPtr<CircleDotIndicatorPaintMethod> paintMethod = AceType::MakeRefPtr<CircleDotIndicatorPaintMethod>(modifier);
|
||||
auto geometryNode = AceType::MakeRefPtr<GeometryNode>();
|
||||
auto paintProperty = AceType::MakeRefPtr<CircleDotIndicatorPaintProperty>();
|
||||
paintProperty->Clone();
|
||||
paintProperty->Reset();
|
||||
auto renderContext = frameNode_->GetRenderContext();
|
||||
PaintWrapper paintWrapper(renderContext, geometryNode, paintProperty);
|
||||
EXPECT_FALSE(paintMethod->GetContentModifier(nullptr) == nullptr);
|
||||
paintMethod->circleDotIndicatorModifier_->SetIsPressed(true);
|
||||
paintMethod->isLongPressed_ = true;
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. call UpdateContentModifier.
|
||||
*/
|
||||
paintMethod->UpdateContentModifier(&paintWrapper);
|
||||
paintMethod->circleDotIndicatorModifier_->SetIsPressed(false);
|
||||
paintMethod->isLongPressed_ = true;
|
||||
paintMethod->UpdateContentModifier(&paintWrapper);
|
||||
paintMethod->isLongPressed_ = false;
|
||||
paintMethod->UpdateContentModifier(&paintWrapper);
|
||||
paintMethod->gestureState_ = GestureState::GESTURE_STATE_RELEASE_LEFT;
|
||||
paintMethod->isLongPressed_ = false;
|
||||
paintMethod->UpdateContentModifier(&paintWrapper);
|
||||
paintMethod->circleDotIndicatorModifier_->SetIsPressed(true);
|
||||
paintMethod->isLongPressed_ = false;
|
||||
paintMethod->UpdateContentModifier(&paintWrapper);
|
||||
EXPECT_EQ(paintMethod->circleDotIndicatorModifier_->axis_, Axis::HORIZONTAL);
|
||||
EXPECT_EQ(paintMethod->circleDotIndicatorModifier_->arcDirection_, SwiperArcDirection::SIX_CLOCK_DIRECTION);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CircleDotIndicatorPaintNormalIndicator001
|
||||
* @tc.desc: Test CircleDotIndicatorPaintMethod PaintNormalIndicator
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SwiperIndicatorModifierTestNg, CircleDotIndicatorPaintNormalIndicator001, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. create swiper and set parameters.
|
||||
*/
|
||||
CreateWithItem([](SwiperModelNG model) {
|
||||
model.Create(true);
|
||||
model.SetDirection(Axis::VERTICAL);
|
||||
model.SetIndicatorType(SwiperIndicatorType::ARC_DOT);
|
||||
});
|
||||
RefPtr<CircleDotIndicatorModifier> modifier = AceType::MakeRefPtr<CircleDotIndicatorModifier>();
|
||||
RefPtr<CircleDotIndicatorPaintMethod> paintMethod = AceType::MakeRefPtr<CircleDotIndicatorPaintMethod>(modifier);
|
||||
|
||||
auto geometryNode = AceType::MakeRefPtr<GeometryNode>();
|
||||
geometryNode->SetFrameSize(SizeF(500.f, 500.f));
|
||||
auto paintProperty = AceType::MakeRefPtr<CircleDotIndicatorPaintProperty>();
|
||||
paintProperty->Clone();
|
||||
paintProperty->Reset();
|
||||
paintProperty->UpdateContainerColor(Color::BLUE);
|
||||
paintProperty->UpdateArcDirection(SwiperArcDirection::NINE_CLOCK_DIRECTION);
|
||||
paintProperty->UpdateColor(Color::RED);
|
||||
paintProperty->UpdateSelectedColor(Color::GREEN);
|
||||
auto renderContext = frameNode_->GetRenderContext();
|
||||
PaintWrapper paintWrapper(renderContext, geometryNode, paintProperty);
|
||||
paintMethod->CalculateLongPointCenterAngle(&paintWrapper, false);
|
||||
paintMethod->circleDotIndicatorModifier_->SetIsPressed(true);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. call PaintNormalIndicator.
|
||||
*/
|
||||
paintMethod->PaintNormalIndicator(&paintWrapper);
|
||||
EXPECT_EQ(paintMethod->circleDotIndicatorModifier_->isPressed_, true);
|
||||
|
||||
paintMethod->circleDotIndicatorModifier_->SetIsPressed(false);
|
||||
paintMethod->gestureState_ = GestureState::GESTURE_STATE_RELEASE_LEFT;
|
||||
paintMethod->PaintNormalIndicator(&paintWrapper);
|
||||
EXPECT_EQ(paintMethod->circleDotIndicatorModifier_->isPressed_, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CircleDotIndicatorPaintUnselectedIndicator001
|
||||
* @tc.desc: Test CircleDotIndicatorPaintUnselectedIndicator
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SwiperIndicatorModifierTestNg, CircleDotIndicatorPaintUnselectedIndicator001, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. create swiper and set parameters.
|
||||
*/
|
||||
CreateWithItem([](SwiperModelNG model) {
|
||||
model.Create(true);
|
||||
model.SetDirection(Axis::VERTICAL);
|
||||
model.SetIndicatorType(SwiperIndicatorType::ARC_DOT);
|
||||
});
|
||||
|
||||
RefPtr<CircleDotIndicatorModifier> modifier = AceType::MakeRefPtr<CircleDotIndicatorModifier>();
|
||||
LinearVector<float> itemHalfSizes;
|
||||
itemHalfSizes.push_back(20.0f);
|
||||
itemHalfSizes.push_back(20.0f);
|
||||
|
||||
RSCanvas canvas;
|
||||
float itemAngle = -1.2f;
|
||||
CircleDotIndicatorModifier::ContentProperty contentProperty;
|
||||
LinearVector<float> vectorBlackPointAngle;
|
||||
vectorBlackPointAngle.push_back(20.0f);
|
||||
vectorBlackPointAngle.push_back(20.0f);
|
||||
contentProperty.vectorBlackPointAngle = vectorBlackPointAngle;
|
||||
/**
|
||||
* @tc.steps: step2. Call PaintUnselectedIndicator.
|
||||
*/
|
||||
modifier->arcDirection_ = SwiperArcDirection::SIX_CLOCK_DIRECTION;
|
||||
modifier->PaintUnselectedIndicator(
|
||||
canvas, itemAngle, contentProperty, LinearColor(Color::TRANSPARENT));
|
||||
EXPECT_EQ(modifier->arcDirection_, SwiperArcDirection::SIX_CLOCK_DIRECTION);
|
||||
|
||||
modifier->arcDirection_ = SwiperArcDirection::THREE_CLOCK_DIRECTION;
|
||||
modifier->PaintUnselectedIndicator(
|
||||
canvas, itemAngle, contentProperty, LinearColor(Color::TRANSPARENT));
|
||||
EXPECT_EQ(modifier->arcDirection_, SwiperArcDirection::THREE_CLOCK_DIRECTION);
|
||||
|
||||
modifier->arcDirection_ = SwiperArcDirection::NINE_CLOCK_DIRECTION;
|
||||
modifier->PaintUnselectedIndicator(
|
||||
canvas, itemAngle, contentProperty, LinearColor(Color::TRANSPARENT));
|
||||
EXPECT_EQ(modifier->arcDirection_, SwiperArcDirection::NINE_CLOCK_DIRECTION);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CircleDotIndicatorCalculatePointAngle001
|
||||
* @tc.desc: Test CircleDotIndicatorPaintMethod CalculatePointAngle
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SwiperIndicatorModifierTestNg, CircleDotIndicatorCalculatePointAngle001, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. create swiper and set parameters.
|
||||
*/
|
||||
CreateWithItem([](SwiperModelNG model) {
|
||||
model.Create(true);
|
||||
model.SetDirection(Axis::VERTICAL);
|
||||
model.SetIndicatorType(SwiperIndicatorType::ARC_DOT);
|
||||
});
|
||||
RefPtr<CircleDotIndicatorModifier> modifier = AceType::MakeRefPtr<CircleDotIndicatorModifier>();
|
||||
RefPtr<CircleDotIndicatorPaintMethod> paintMethod = AceType::MakeRefPtr<CircleDotIndicatorPaintMethod>(modifier);
|
||||
paintMethod->itemCount_ = 1;
|
||||
LinearVector<float> vectorBlackPointAngle;
|
||||
vectorBlackPointAngle.push_back(20.0f);
|
||||
vectorBlackPointAngle.push_back(20.0f);
|
||||
paintMethod->vectorBlackPointAngle_ = vectorBlackPointAngle;
|
||||
LinearVector<float> itemSizes;
|
||||
itemSizes.emplace_back(20.f);
|
||||
itemSizes.emplace_back(20.f);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Call CalculatePointAngle.
|
||||
*/
|
||||
paintMethod->CalculatePointAngle(itemSizes, 0);
|
||||
EXPECT_EQ(paintMethod->vectorBlackPointAngle_.size(), 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CircleDotIndicatorGetHalfIndex001
|
||||
* @tc.desc: Test CircleDotIndicatorPaintMethod GetHalfIndex
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SwiperIndicatorModifierTestNg, CircleDotIndicatorGetHalfIndex001, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. create swiper and set parameters.
|
||||
*/
|
||||
CreateWithItem([](SwiperModelNG model) {
|
||||
model.Create(true);
|
||||
model.SetDirection(Axis::VERTICAL);
|
||||
model.SetIndicatorType(SwiperIndicatorType::ARC_DOT);
|
||||
});
|
||||
RefPtr<CircleDotIndicatorModifier> modifier = AceType::MakeRefPtr<CircleDotIndicatorModifier>();
|
||||
RefPtr<CircleDotIndicatorPaintMethod> paintMethod = AceType::MakeRefPtr<CircleDotIndicatorPaintMethod>(modifier);
|
||||
auto geometryNode = AceType::MakeRefPtr<GeometryNode>();
|
||||
auto paintProperty = AceType::MakeRefPtr<CircleDotIndicatorPaintProperty>();
|
||||
paintProperty->Clone();
|
||||
paintProperty->Reset();
|
||||
auto renderContext = frameNode_->GetRenderContext();
|
||||
PaintWrapper paintWrapper(renderContext, geometryNode, paintProperty);
|
||||
paintMethod->itemCount_ = 2;
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Call GetHalfIndex.
|
||||
*/
|
||||
EXPECT_EQ(paintMethod->GetHalfIndex(), 0);
|
||||
paintMethod->itemCount_ = 3;
|
||||
EXPECT_EQ(paintMethod->GetHalfIndex(), 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CircleDotIndicatorGetLongPointAngle001
|
||||
* @tc.desc: Test CircleDotIndicatorPaintMethod GetLongPointAngle
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SwiperIndicatorModifierTestNg, CircleDotIndicatorGetLongPointAngle001, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. create swiper and set parameters.
|
||||
*/
|
||||
CreateWithItem([](SwiperModelNG model) {
|
||||
model.Create(true);
|
||||
model.SetDirection(Axis::VERTICAL);
|
||||
model.SetIndicatorType(SwiperIndicatorType::ARC_DOT);
|
||||
});
|
||||
auto indicatorPattern = indicatorNode_->GetPattern<SwiperIndicatorPattern>();
|
||||
indicatorPattern->CreateCircleDotIndicatorPaintMethod(pattern_);
|
||||
RefPtr<CircleDotIndicatorModifier> modifier = AceType::MakeRefPtr<CircleDotIndicatorModifier>();
|
||||
RefPtr<CircleDotIndicatorPaintMethod> paintMethod = AceType::MakeRefPtr<CircleDotIndicatorPaintMethod>(modifier);
|
||||
paintMethod->arcDirection_ = SwiperArcDirection::THREE_CLOCK_DIRECTION;
|
||||
LinearVector<float> itemSizes;
|
||||
itemSizes.emplace_back(20.f);
|
||||
itemSizes.emplace_back(20.f);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Call GetLongPointAngle.
|
||||
*/
|
||||
paintMethod->GetLongPointAngle(itemSizes, 0);
|
||||
EXPECT_EQ(paintMethod->arcDirection_, SwiperArcDirection::THREE_CLOCK_DIRECTION);
|
||||
paintMethod->arcDirection_ = SwiperArcDirection::NINE_CLOCK_DIRECTION;
|
||||
paintMethod->GetLongPointAngle(itemSizes, 0);
|
||||
EXPECT_EQ(paintMethod->arcDirection_, SwiperArcDirection::NINE_CLOCK_DIRECTION);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CircleDotIndicatorGetBlackPointAngle001
|
||||
* @tc.desc: Test CircleDotIndicatorPaintMethod GetBlackPointAngle
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SwiperIndicatorModifierTestNg, CircleDotIndicatorGetBlackPointAngle001, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. create swiper and set parameters.
|
||||
*/
|
||||
CreateWithItem([](SwiperModelNG model) {
|
||||
model.Create(true);
|
||||
model.SetDirection(Axis::VERTICAL);
|
||||
model.SetIndicatorType(SwiperIndicatorType::ARC_DOT);
|
||||
});
|
||||
auto indicatorPattern = indicatorNode_->GetPattern<SwiperIndicatorPattern>();
|
||||
indicatorPattern->CreateCircleDotIndicatorPaintMethod(pattern_);
|
||||
RefPtr<CircleDotIndicatorModifier> modifier = AceType::MakeRefPtr<CircleDotIndicatorModifier>();
|
||||
RefPtr<CircleDotIndicatorPaintMethod> paintMethod = AceType::MakeRefPtr<CircleDotIndicatorPaintMethod>(modifier);
|
||||
paintMethod->itemCount_ = 5;
|
||||
LinearVector<float> itemSizes;
|
||||
itemSizes.emplace_back(20.f);
|
||||
itemSizes.emplace_back(20.f);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Call GetBlackPointAngle.
|
||||
*/
|
||||
paintMethod->GetBlackPointAngle(itemSizes, 0, 0);
|
||||
paintMethod->GetBlackPointAngle(itemSizes, 1, 0);
|
||||
paintMethod->GetBlackPointAngle(itemSizes, 1, 1);
|
||||
paintMethod->GetBlackPointAngle(itemSizes, 2, 1);
|
||||
paintMethod->GetBlackPointAngle(itemSizes, 1, 2);
|
||||
EXPECT_EQ(paintMethod->GetHalfIndex(), 2);
|
||||
paintMethod->itemCount_ = 1;
|
||||
paintMethod->GetBlackPointAngle(itemSizes, 1, 1);
|
||||
paintMethod->GetBlackPointAngle(itemSizes, 2, 1);
|
||||
paintMethod->GetBlackPointAngle(itemSizes, 1, 2);
|
||||
EXPECT_EQ(paintMethod->GetHalfIndex(), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CircleDotIndicatorGetIndex001
|
||||
* @tc.desc: Test CircleDotIndicatorPaintMethod GetIndex
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SwiperIndicatorModifierTestNg, CircleDotIndicatorGetIndex001, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. create swiper and set parameters.
|
||||
*/
|
||||
CreateWithItem([](SwiperModelNG model) {
|
||||
model.Create(true);
|
||||
model.SetDirection(Axis::VERTICAL);
|
||||
model.SetIndicatorType(SwiperIndicatorType::ARC_DOT);
|
||||
});
|
||||
auto indicatorPattern = indicatorNode_->GetPattern<SwiperIndicatorPattern>();
|
||||
indicatorPattern->CreateCircleDotIndicatorPaintMethod(pattern_);
|
||||
RefPtr<CircleDotIndicatorModifier> modifier = AceType::MakeRefPtr<CircleDotIndicatorModifier>();
|
||||
RefPtr<CircleDotIndicatorPaintMethod> paintMethod = AceType::MakeRefPtr<CircleDotIndicatorPaintMethod>(modifier);
|
||||
paintMethod->nextValidIndex_ = 1;
|
||||
paintMethod->turnPageRate_ = 0.5f;
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Call GetIndex.
|
||||
*/
|
||||
EXPECT_EQ(paintMethod->GetIndex(2).first, paintMethod->currentIndexActual_);
|
||||
paintMethod->nextValidIndex_ = -1;
|
||||
EXPECT_EQ(paintMethod->GetIndex(0).first, 0);
|
||||
paintMethod->turnPageRate_ = 0.0f;
|
||||
EXPECT_EQ(paintMethod->GetIndex(-1).first, -1);
|
||||
paintMethod->itemCount_ = 1;
|
||||
EXPECT_EQ(paintMethod->GetIndex(0).first, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CircleDotIndicatorGetStartAndEndIndex001
|
||||
* @tc.desc: Test CircleDotIndicatorPaintMethod GetStartAndEndIndex
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SwiperIndicatorModifierTestNg, CircleDotIndicatorGetStartAndEndIndex001, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. create swiper and set parameters.
|
||||
*/
|
||||
CreateWithItem([](SwiperModelNG model) {
|
||||
model.Create(true);
|
||||
model.SetDirection(Axis::VERTICAL);
|
||||
model.SetIndicatorType(SwiperIndicatorType::ARC_DOT);
|
||||
});
|
||||
auto indicatorPattern = indicatorNode_->GetPattern<SwiperIndicatorPattern>();
|
||||
indicatorPattern->CreateCircleDotIndicatorPaintMethod(pattern_);
|
||||
RefPtr<CircleDotIndicatorModifier> modifier = AceType::MakeRefPtr<CircleDotIndicatorModifier>();
|
||||
RefPtr<CircleDotIndicatorPaintMethod> paintMethod = AceType::MakeRefPtr<CircleDotIndicatorPaintMethod>(modifier);
|
||||
paintMethod->pointAnimationStage_ = PointAnimationStage::STATE_EXPAND_TO_LONG_POINT;
|
||||
paintMethod->gestureState_ = GestureState::GESTURE_STATE_RELEASE_LEFT;
|
||||
paintMethod->touchBottomTypeLoop_ = TouchBottomTypeLoop::TOUCH_BOTTOM_TYPE_LOOP_LEFT;
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Call GetStartAndEndIndex.
|
||||
*/
|
||||
EXPECT_EQ(paintMethod->GetStartAndEndIndex(0).first, 0);
|
||||
paintMethod->pointAnimationStage_ = PointAnimationStage::STATE_EXPAND_TO_LONG_POINT;
|
||||
paintMethod->gestureState_ = GestureState::GESTURE_STATE_RELEASE_RIGHT;
|
||||
paintMethod->touchBottomTypeLoop_ = TouchBottomTypeLoop::TOUCH_BOTTOM_TYPE_LOOP_RIGHT;
|
||||
EXPECT_EQ(paintMethod->GetStartAndEndIndex(0).first, 0);
|
||||
paintMethod->nextValidIndex_ = 1;
|
||||
paintMethod->turnPageRate_ = 0.5f;
|
||||
paintMethod->pointAnimationStage_ = PointAnimationStage::STATE_SHRINKT_TO_BLACK_POINT;
|
||||
paintMethod->gestureState_ = GestureState::GESTURE_STATE_RELEASE_LEFT;
|
||||
paintMethod->touchBottomTypeLoop_ = TouchBottomTypeLoop::TOUCH_BOTTOM_TYPE_LOOP_LEFT;
|
||||
EXPECT_EQ(paintMethod->GetStartAndEndIndex(-1).first, -1);
|
||||
paintMethod->pointAnimationStage_ = PointAnimationStage::STATE_SHRINKT_TO_BLACK_POINT;
|
||||
paintMethod->gestureState_ = GestureState::GESTURE_STATE_RELEASE_LEFT;
|
||||
paintMethod->touchBottomTypeLoop_ = TouchBottomTypeLoop::TOUCH_BOTTOM_TYPE_LOOP_RIGHT;
|
||||
paintMethod->GetStartAndEndIndex(0);
|
||||
paintMethod->pointAnimationStage_ = PointAnimationStage::STATE_SHRINKT_TO_BLACK_POINT;
|
||||
paintMethod->gestureState_ = GestureState::GESTURE_STATE_RELEASE_RIGHT;
|
||||
paintMethod->touchBottomTypeLoop_ = TouchBottomTypeLoop::TOUCH_BOTTOM_TYPE_LOOP_RIGHT;
|
||||
EXPECT_EQ(paintMethod->GetStartAndEndIndex(0).first, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CircleDotIndicatorSetFunctions001
|
||||
* @tc.desc: Test CircleDotIndicatorPaintMethod Set Functions
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SwiperIndicatorModifierTestNg, CircleDotIndicatorSetFunctions001, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. create swiper and set parameters.
|
||||
*/
|
||||
CreateWithItem([](SwiperModelNG model) {
|
||||
model.Create(true);
|
||||
model.SetDirection(Axis::VERTICAL);
|
||||
model.SetIndicatorType(SwiperIndicatorType::ARC_DOT);
|
||||
});
|
||||
auto indicatorPattern = indicatorNode_->GetPattern<SwiperIndicatorPattern>();
|
||||
layoutProperty_->UpdateIndicatorType(SwiperIndicatorType::ARC_DOT);
|
||||
auto indicatorpaintMethod = indicatorPattern->CreateCircleDotIndicatorPaintMethod(pattern_);
|
||||
auto paintMethod = AceType::DynamicCast<CircleDotIndicatorPaintMethod>(indicatorPattern->CreateNodePaintMethod());
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Call Set Functions.
|
||||
*/
|
||||
indicatorpaintMethod->SetCurrentIndex(1);
|
||||
EXPECT_EQ(indicatorpaintMethod->currentIndex_, 1);
|
||||
indicatorpaintMethod->SetItemCount(1);
|
||||
EXPECT_EQ(indicatorpaintMethod->itemCount_, 1);
|
||||
paintMethod->SetAxis(Axis::HORIZONTAL);
|
||||
EXPECT_EQ(paintMethod->GetAxis(), Axis::HORIZONTAL);
|
||||
paintMethod->SetIsLongPressed(true);
|
||||
EXPECT_EQ(paintMethod->isLongPressed_, true);
|
||||
paintMethod->SetTurnPageRate(1.0f);
|
||||
EXPECT_EQ(paintMethod->turnPageRate_, 1.0f);
|
||||
paintMethod->SetGestureState(GestureState::GESTURE_STATE_RELEASE_LEFT);
|
||||
EXPECT_EQ(paintMethod->gestureState_, GestureState::GESTURE_STATE_RELEASE_LEFT);
|
||||
paintMethod->SetTouchBottomTypeLoop(TouchBottomTypeLoop::TOUCH_BOTTOM_TYPE_LOOP_RIGHT);
|
||||
EXPECT_EQ(paintMethod->touchBottomTypeLoop_, TouchBottomTypeLoop::TOUCH_BOTTOM_TYPE_LOOP_RIGHT);
|
||||
paintMethod->SetMouseClickIndex(1);
|
||||
EXPECT_EQ(paintMethod->mouseClickIndex_, 1);
|
||||
paintMethod->SetPointAnimationStage(PointAnimationStage::STATE_EXPAND_TO_LONG_POINT);
|
||||
EXPECT_EQ(paintMethod->pointAnimationStage_, PointAnimationStage::STATE_EXPAND_TO_LONG_POINT);
|
||||
paintMethod->SetCurrentIndexActual(1);
|
||||
EXPECT_EQ(paintMethod->currentIndexActual_, 1);
|
||||
paintMethod->SetNextValidIndex(1);
|
||||
EXPECT_EQ(paintMethod->nextValidIndex_, 1);
|
||||
}
|
||||
} // namespace OHOS::Ace::NG
|
||||
|
@ -127,9 +127,7 @@ HWTEST_F(SwiperIndicatorTestNg, OnIndicatorChangeEvent001, TestSize.Level1)
|
||||
*/
|
||||
HWTEST_F(SwiperIndicatorTestNg, HandleMouseClick001, TestSize.Level1)
|
||||
{
|
||||
CreateWithItem([](SwiperModelNG model) {
|
||||
model.SetIndicatorType(SwiperIndicatorType::DOT);
|
||||
});
|
||||
CreateWithItem([](SwiperModelNG model) {});
|
||||
|
||||
/**
|
||||
* @tc.steps: step1. Click item(index:1)
|
||||
@ -167,9 +165,7 @@ HWTEST_F(SwiperIndicatorTestNg, HandleMouseClick001, TestSize.Level1)
|
||||
*/
|
||||
HWTEST_F(SwiperIndicatorTestNg, HandleTouchClick001, TestSize.Level1)
|
||||
{
|
||||
CreateWithItem([](SwiperModelNG model) {
|
||||
model.SetIndicatorType(SwiperIndicatorType::DOT);
|
||||
});
|
||||
CreateWithItem([](SwiperModelNG model) {});
|
||||
|
||||
/**
|
||||
* @tc.steps: step1. Click item(index:1)
|
||||
@ -470,7 +466,6 @@ HWTEST_F(SwiperIndicatorTestNg, SwiperIndicatorGetMouseClickIndex001, TestSize.L
|
||||
{
|
||||
CreateWithItem([](SwiperModelNG model) {
|
||||
model.SetDirection(Axis::VERTICAL);
|
||||
model.SetIndicatorType(SwiperIndicatorType::DOT);
|
||||
});
|
||||
RefPtr<SwiperIndicatorPattern> indicatorPattern = indicatorNode_->GetPattern<SwiperIndicatorPattern>();
|
||||
auto paintProperty = indicatorNode_->GetPaintProperty<DotIndicatorPaintProperty>();
|
||||
@ -668,92 +663,4 @@ HWTEST_F(SwiperIndicatorTestNg, SwiperIndicatorPatternTestNg0020, TestSize.Level
|
||||
indicatorPattern->dragStartPoint_.SetX(1.0f);
|
||||
EXPECT_FALSE(indicatorPattern->CheckIsTouchBottom(touchEventInfo.GetTouches().front()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CircleSwiperIndicatorPatternCheckIsTouchBottom001
|
||||
* @tc.desc: CheckIsTouchBottom
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SwiperIndicatorTestNg, CircleSwiperIndicatorPatternCheckIsTouchBottom001, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. create swiper and set parameters.
|
||||
*/
|
||||
CreateWithItem([](SwiperModelNG model) {
|
||||
model.Create(true);
|
||||
model.SetDirection(Axis::VERTICAL);
|
||||
model.SetIndicatorType(SwiperIndicatorType::ARC_DOT);
|
||||
});
|
||||
auto indicatorPattern = indicatorNode_->GetPattern<SwiperIndicatorPattern>();
|
||||
GestureEvent info;
|
||||
TouchLocationInfo touchLocationInfo("down", 0);
|
||||
touchLocationInfo.SetTouchType(TouchType::DOWN);
|
||||
std::list<TouchLocationInfo> infoSwiper;
|
||||
infoSwiper.emplace_back(touchLocationInfo);
|
||||
TouchEventInfo touchEventInfo("down");
|
||||
touchEventInfo.touches_ = infoSwiper;
|
||||
indicatorPattern->swiperIndicatorType_ = SwiperIndicatorType::ARC_DOT;
|
||||
indicatorPattern->HandleLongDragUpdate(touchLocationInfo);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. call CheckIsTouchBottom.
|
||||
*/
|
||||
EXPECT_FALSE(indicatorPattern->CheckIsTouchBottom(info));
|
||||
EXPECT_TRUE(indicatorPattern->CheckIsTouchBottom(touchEventInfo.GetTouches().front()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CircleSwiperIndicatorPatternCheckIsTouchBottom002
|
||||
* @tc.desc: CheckIsTouchBottom
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SwiperIndicatorTestNg, CircleSwiperIndicatorPatternCheckIsTouchBottom002, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. create swiper and set parameters.
|
||||
*/
|
||||
CreateWithItem([](SwiperModelNG model) {
|
||||
model.Create(true);
|
||||
model.SetDirection(Axis::VERTICAL);
|
||||
model.SetIndicatorType(SwiperIndicatorType::ARC_DOT);
|
||||
});
|
||||
auto indicatorPattern = indicatorNode_->GetPattern<SwiperIndicatorPattern>();
|
||||
TouchLocationInfo touchLocationInfo("down", 2);
|
||||
indicatorPattern->swiperIndicatorType_ = SwiperIndicatorType::ARC_DOT;
|
||||
indicatorPattern->HandleLongDragUpdate(touchLocationInfo);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. call CheckIsTouchBottom.
|
||||
*/
|
||||
EXPECT_TRUE(indicatorPattern->CheckIsTouchBottom(touchLocationInfo));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CircleSwiperIndicatorPatternConvertAngleWithArcDirection001
|
||||
* @tc.desc: ConvertAngleWithArcDirection
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SwiperIndicatorTestNg, CircleSwiperIndicatorPatternConvertAngleWithArcDirection001, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. create swiper and set parameters.
|
||||
*/
|
||||
CreateWithItem([](SwiperModelNG model) {
|
||||
model.Create(true);
|
||||
model.SetIndicatorType(SwiperIndicatorType::ARC_DOT);
|
||||
});
|
||||
auto indicatorPattern = indicatorNode_->GetPattern<SwiperIndicatorPattern>();
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. call ConvertAngleWithArcDirection.
|
||||
*/
|
||||
EXPECT_EQ(indicatorPattern->ConvertAngleWithArcDirection(SwiperArcDirection::THREE_CLOCK_DIRECTION, 91.0f),
|
||||
-179.0f);
|
||||
EXPECT_EQ(indicatorPattern->ConvertAngleWithArcDirection(SwiperArcDirection::THREE_CLOCK_DIRECTION, 89.0f),
|
||||
179.0f);
|
||||
EXPECT_EQ(indicatorPattern->ConvertAngleWithArcDirection(SwiperArcDirection::NINE_CLOCK_DIRECTION, -91.0f),
|
||||
179.0f);
|
||||
EXPECT_EQ(indicatorPattern->ConvertAngleWithArcDirection(SwiperArcDirection::NINE_CLOCK_DIRECTION, 1.0f),
|
||||
-89.0f);
|
||||
}
|
||||
} // namespace OHOS::Ace::NG
|
||||
|
@ -1681,9 +1681,7 @@ HWTEST_F(SwiperLayoutTestNg, SwiperPatternAlgorithmMeasure003, TestSize.Level1)
|
||||
*/
|
||||
HWTEST_F(SwiperLayoutTestNg, ItemWidth001, TestSize.Level1)
|
||||
{
|
||||
CreateWithItem([](SwiperModelNG model) {
|
||||
model.SetIndicatorType(SwiperIndicatorType::DOT);
|
||||
});
|
||||
CreateWithItem([](SwiperModelNG model) {});
|
||||
auto indicatorPattern = indicatorNode_->GetPattern<SwiperIndicatorPattern>();
|
||||
RefPtr<NodePaintMethod> nodePaintMethod = indicatorPattern->CreateNodePaintMethod();
|
||||
auto algorithm = indicatorPattern->CreateLayoutAlgorithm();
|
||||
|
@ -161,7 +161,6 @@ HWTEST_F(SwiperTestNg, SwiperPatternOnDirtyLayoutWrapperSwap001, TestSize.Level1
|
||||
model.SetDisplayArrow(true); // show arrow
|
||||
model.SetHoverShow(false);
|
||||
model.SetArrowStyle(ARROW_PARAMETERS);
|
||||
model.SetIndicatorType(SwiperIndicatorType::DOT);
|
||||
});
|
||||
auto firstChild = AccessibilityManager::DynamicCast<FrameNode>(indicatorNode_);
|
||||
RefPtr<GeometryNode> firstGeometryNode = AceType::MakeRefPtr<GeometryNode>();
|
||||
@ -2031,35 +2030,6 @@ HWTEST_F(SwiperTestNg, CheckTargetIndexheckTargetIndex001, TestSize.Level1)
|
||||
EXPECT_EQ(pattern_->CheckTargetIndex(targetIndex, false), targetIndex + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: WearableSwiperOnModifyDone001
|
||||
* @tc.desc: Test OnModifyDone
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SwiperTestNg, WearableSwiperOnModifyDone001, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. create swiper and set parameters.
|
||||
*/
|
||||
CreateWithItem([](SwiperModelNG model) {
|
||||
model.Create(true);
|
||||
model.SetDirection(Axis::VERTICAL);
|
||||
model.SetIndicatorType(SwiperIndicatorType::ARC_DOT);
|
||||
});
|
||||
RefPtr<SwiperPattern> indicatorPattern = frameNode_->GetPattern<SwiperPattern>();
|
||||
EXPECT_NE(indicatorPattern, nullptr);
|
||||
indicatorPattern->GetArcDotIndicatorStyle();
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. call UpdateContentModifier.
|
||||
*/
|
||||
indicatorPattern->OnModifyDone();
|
||||
indicatorPattern->swiperController_->removeSwiperEventCallback_();
|
||||
indicatorPattern->swiperController_->addSwiperEventCallback_();
|
||||
indicatorPattern->OnAfterModifyDone();
|
||||
EXPECT_EQ(indicatorPattern->lastSwiperIndicatorType_, SwiperIndicatorType::ARC_DOT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: SwiperSetFrameRateTest001
|
||||
* @tc.desc: Test SetFrameRate
|
||||
|
@ -41,10 +41,6 @@
|
||||
#include "core/components_ng/pattern/swiper/swiper_event_hub.h"
|
||||
#include "core/components_ng/pattern/swiper/swiper_model_ng.h"
|
||||
#include "core/components_ng/pattern/swiper/swiper_pattern.h"
|
||||
#include "core/components_ng/pattern/swiper/arc_swiper_pattern.h"
|
||||
#include "core/components_ng/pattern/swiper_indicator/circle_dot_indicator/circle_dot_indicator_layout_algorithm.h"
|
||||
#include "core/components_ng/pattern/swiper_indicator/circle_dot_indicator/circle_dot_indicator_paint_method.h"
|
||||
#include "core/components_ng/pattern/swiper_indicator/circle_dot_indicator/circle_dot_indicator_paint_property.h"
|
||||
#include "core/components_ng/pattern/swiper_indicator/dot_indicator/dot_indicator_layout_algorithm.h"
|
||||
#include "core/components_ng/pattern/swiper_indicator/dot_indicator/dot_indicator_paint_method.h"
|
||||
#include "core/components_ng/pattern/swiper_indicator/dot_indicator/dot_indicator_paint_property.h"
|
||||
|
Loading…
Reference in New Issue
Block a user