mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2024-11-27 17:21:11 +00:00
提供单独导航点组件
Signed-off-by: jiangzhijun8 <jiangzhijun7@huawei.com>
This commit is contained in:
parent
daf0847f6e
commit
ea0e25edc0
@ -1082,6 +1082,8 @@ frameworks/bridge/declarative_frontend/jsview/js_image_span.cpp @huawei_g_five
|
||||
frameworks/bridge/declarative_frontend/jsview/js_image_span.h @huawei_g_five
|
||||
frameworks/bridge/declarative_frontend/jsview/js_indexer.cpp @arkuiscroll
|
||||
frameworks/bridge/declarative_frontend/jsview/js_indexer.h @arkuiscroll
|
||||
frameworks/bridge/declarative_frontend/jsview/js_indicator.cpp @arkuiscroll
|
||||
frameworks/bridge/declarative_frontend/jsview/js_indicator.h @arkuiscroll
|
||||
frameworks/bridge/declarative_frontend/jsview/js_interactable_view.cpp @arkuievent
|
||||
frameworks/bridge/declarative_frontend/jsview/js_interactable_view.h @arkuievent
|
||||
frameworks/bridge/declarative_frontend/jsview/js_isolated_component.cpp @arkuiabilitygroup
|
||||
|
@ -291,6 +291,7 @@ template("declarative_js_engine") {
|
||||
"jsview/js_image_animator.cpp",
|
||||
"jsview/js_image_span.cpp",
|
||||
"jsview/js_indexer.cpp",
|
||||
"jsview/js_indicator.cpp",
|
||||
"jsview/js_interactable_view.cpp",
|
||||
"jsview/js_keyboard_avoid.cpp",
|
||||
"jsview/js_layout_manager.cpp",
|
||||
@ -829,6 +830,7 @@ template("declarative_js_engine_ng") {
|
||||
"jsview/js_image_animator.cpp",
|
||||
"jsview/js_image_span.cpp",
|
||||
"jsview/js_indexer.cpp",
|
||||
"jsview/js_indicator.cpp",
|
||||
"jsview/js_interactable_view.cpp",
|
||||
"jsview/js_keyboard_avoid.cpp",
|
||||
"jsview/js_layout_manager.cpp",
|
||||
|
@ -72,6 +72,7 @@
|
||||
#include "bridge/declarative_frontend/jsview/js_image_animator.h"
|
||||
#include "bridge/declarative_frontend/jsview/js_image_span.h"
|
||||
#include "bridge/declarative_frontend/jsview/js_indexer.h"
|
||||
#include "bridge/declarative_frontend/jsview/js_indicator.h"
|
||||
#include "bridge/declarative_frontend/jsview/js_isolated_component.h"
|
||||
#include "bridge/declarative_frontend/jsview/js_keyboard_avoid.h"
|
||||
#include "bridge/declarative_frontend/jsview/js_layout_manager.h"
|
||||
@ -534,6 +535,7 @@ static const std::unordered_map<std::string, std::function<void(BindingTarget)>>
|
||||
{ "Gauge", JSGauge::JSBind },
|
||||
{ "Marquee", JSMarquee::JSBind },
|
||||
{ "Swiper", JSSwiper::JSBind },
|
||||
{ "Indicator", JSIndicator::JSBind },
|
||||
{ "SwiperController", JSSwiperController::JSBind },
|
||||
{ "CalendarController", JSCalendarController::JSBind },
|
||||
{ "CanvasRenderingContext2D", JSRenderingContext::JSBind },
|
||||
@ -603,6 +605,7 @@ static const std::unordered_map<std::string, std::function<void(BindingTarget)>>
|
||||
{ "ForEach", JSForEach::JSBind },
|
||||
{ "Divider", JSDivider::JSBind },
|
||||
{ "Swiper", JSSwiper::JSBind },
|
||||
{ "Indicator", JSIndicator::JSBind },
|
||||
{ "Panel", JSSlidingPanel::JSBind },
|
||||
{ "RepeatNative", JSRepeat::JSBind },
|
||||
{ "RepeatVirtualScrollNative", JSRepeatVirtualScroll::JSBind },
|
||||
@ -721,6 +724,7 @@ static const std::unordered_map<std::string, std::function<void(BindingTarget)>>
|
||||
{ "Scroller", JSScroller::JSBind },
|
||||
{ "ListScroller", JSListScroller::JSBind },
|
||||
{ "SwiperController", JSSwiperController::JSBind },
|
||||
{ "IndicatorController", JSIndicatorController::JSBind },
|
||||
{ "TabsController", JSTabsController::JSBind },
|
||||
{ "CalendarController", JSCalendarController::JSBind },
|
||||
#ifdef ABILITY_COMPONENT_SUPPORTED
|
||||
@ -842,6 +846,7 @@ void RegisterAllModule(BindingTarget globalObj, void* nativeEngine)
|
||||
JSColumn::JSBind(globalObj);
|
||||
JSCommonView::JSBind(globalObj);
|
||||
JSSwiperController::JSBind(globalObj);
|
||||
JSIndicatorController::JSBind(globalObj);
|
||||
JSTabsController::JSBind(globalObj);
|
||||
JSScroller::JSBind(globalObj);
|
||||
JSListScroller::JSBind(globalObj);
|
||||
@ -893,6 +898,7 @@ void RegisterAllFormModule(BindingTarget globalObj, void* nativeEngine)
|
||||
JSColumn::JSBind(globalObj);
|
||||
JSCommonView::JSBind(globalObj);
|
||||
JSSwiperController::JSBind(globalObj);
|
||||
JSIndicatorController::JSBind(globalObj);
|
||||
JSScroller::JSBind(globalObj);
|
||||
JSListScroller::JSBind(globalObj);
|
||||
JSCalendarController::JSBind(globalObj);
|
||||
|
390
frameworks/bridge/declarative_frontend/jsview/js_indicator.cpp
Normal file
390
frameworks/bridge/declarative_frontend/jsview/js_indicator.cpp
Normal file
@ -0,0 +1,390 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "frameworks/bridge/declarative_frontend/jsview/js_indicator.h"
|
||||
|
||||
#include "bridge/declarative_frontend/engine/jsi/js_ui_index.h"
|
||||
#include "core/components/swiper/swiper_indicator_theme.h"
|
||||
#include "core/components_ng/base/view_stack_processor.h"
|
||||
#include "core/components_ng/pattern/swiper_indicator/indicator_common/indicator_model.h"
|
||||
#include "core/components_ng/pattern/swiper_indicator/indicator_common/indicator_model_ng.h"
|
||||
|
||||
namespace OHOS::Ace {
|
||||
namespace {
|
||||
constexpr int32_t DEFAULT_INDICATOR_COUNT = 2;
|
||||
} // namespace
|
||||
std::unique_ptr<IndicatorModel> IndicatorModel::instance_ = nullptr;
|
||||
std::mutex IndicatorModel::mutex_;
|
||||
|
||||
IndicatorModel* IndicatorModel::GetInstance()
|
||||
{
|
||||
if (!instance_) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (!instance_) {
|
||||
instance_.reset(new NG::IndicatorModelNG());
|
||||
}
|
||||
}
|
||||
return instance_.get();
|
||||
}
|
||||
|
||||
} // namespace OHOS::Ace
|
||||
namespace OHOS::Ace::Framework {
|
||||
namespace {
|
||||
JSRef<JSVal> SwiperChangeEventToJSValue(const SwiperChangeEvent& eventInfo)
|
||||
{
|
||||
return JSRef<JSVal>::Make(ToJSValue(eventInfo.GetIndex()));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void JSIndicator::Create(const JSCallbackInfo& info)
|
||||
{
|
||||
auto indicatorController = IndicatorModel::GetInstance()->Create();
|
||||
if (info[0]->IsObject()) {
|
||||
auto* jsController = JSRef<JSObject>::Cast(info[0])->Unwrap<JSIndicatorController>();
|
||||
if (jsController) {
|
||||
jsController->SetInstanceId(Container::CurrentId());
|
||||
WeakPtr<NG::UINode> indicatorNode =
|
||||
AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
|
||||
jsController->SetController(indicatorController, indicatorNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void JSIndicator::JSBind(BindingTarget globalObj)
|
||||
{
|
||||
JSClass<JSIndicator>::Declare("IndicatorComponent");
|
||||
MethodOptions opt = MethodOptions::NONE;
|
||||
JSClass<JSIndicator>::StaticMethod("create", &JSIndicator::Create, opt);
|
||||
JSClass<JSIndicator>::StaticMethod("count", &JSIndicator::SetCount, opt);
|
||||
JSClass<JSIndicator>::StaticMethod("loop", &JSIndicator::SetLoop, opt);
|
||||
JSClass<JSIndicator>::StaticMethod("vertical", &JSIndicator::SetVertical, opt);
|
||||
JSClass<JSIndicator>::StaticMethod("style", &JSIndicator::SetIndicator, opt);
|
||||
JSClass<JSIndicator>::StaticMethod("initialIndex", &JSIndicator::SetIndex, opt);
|
||||
JSClass<JSIndicator>::StaticMethod("onChange", &JSIndicator::SetOnChange);
|
||||
JSClass<JSIndicator>::InheritAndBind<JSViewAbstract>(globalObj);
|
||||
}
|
||||
|
||||
void JSIndicator::SetCount(const JSCallbackInfo& info)
|
||||
{
|
||||
if (!info[0]->IsNumber()) {
|
||||
IndicatorModel::GetInstance()->SetCount(DEFAULT_INDICATOR_COUNT);
|
||||
return;
|
||||
}
|
||||
|
||||
auto count = std::max(DEFAULT_INDICATOR_COUNT, info[0]->ToNumber<int32_t>());
|
||||
IndicatorModel::GetInstance()->SetCount(count);
|
||||
}
|
||||
|
||||
void JSIndicator::SetLoop(const JSCallbackInfo& info)
|
||||
{
|
||||
if (!info[0]->IsBoolean()) {
|
||||
IndicatorModel::GetInstance()->SetLoop(true);
|
||||
return;
|
||||
}
|
||||
|
||||
IndicatorModel::GetInstance()->SetLoop(info[0]->ToBoolean());
|
||||
}
|
||||
|
||||
void JSIndicator::SetVertical(const JSCallbackInfo& info)
|
||||
{
|
||||
if (!info[0]->IsBoolean()) {
|
||||
IndicatorModel::GetInstance()->SetDirection(Axis::HORIZONTAL);
|
||||
return;
|
||||
}
|
||||
|
||||
IndicatorModel::GetInstance()->SetDirection(info[0]->ToBoolean() ? Axis::VERTICAL : Axis::HORIZONTAL);
|
||||
}
|
||||
|
||||
void JSIndicator::GetFontContent(const JSRef<JSVal>& font, bool isSelected, SwiperDigitalParameters& digitalParameters)
|
||||
{
|
||||
JSRef<JSObject> obj = JSRef<JSObject>::Cast(font);
|
||||
JSRef<JSVal> size = obj->GetProperty("size");
|
||||
auto pipelineContext = PipelineBase::GetCurrentContext();
|
||||
CHECK_NULL_VOID(pipelineContext);
|
||||
auto swiperIndicatorTheme = pipelineContext->GetTheme<SwiperIndicatorTheme>();
|
||||
CHECK_NULL_VOID(swiperIndicatorTheme);
|
||||
// set font size, unit FP
|
||||
CalcDimension fontSize;
|
||||
if (!size->IsUndefined() && !size->IsNull() && ParseJsDimensionFpNG(size, fontSize)) {
|
||||
if (LessOrEqual(fontSize.Value(), 0.0) || LessOrEqual(size->ToNumber<double>(), 0.0) ||
|
||||
fontSize.Unit() == DimensionUnit::PERCENT) {
|
||||
fontSize = swiperIndicatorTheme->GetDigitalIndicatorTextStyle().GetFontSize();
|
||||
}
|
||||
} else {
|
||||
fontSize = swiperIndicatorTheme->GetDigitalIndicatorTextStyle().GetFontSize();
|
||||
}
|
||||
if (isSelected) {
|
||||
digitalParameters.selectedFontSize = fontSize;
|
||||
} else {
|
||||
digitalParameters.fontSize = fontSize;
|
||||
}
|
||||
JSRef<JSVal> weight = obj->GetProperty("weight");
|
||||
if (!weight->IsNull()) {
|
||||
std::string weightValue;
|
||||
if (weight->IsNumber()) {
|
||||
weightValue = std::to_string(weight->ToNumber<int32_t>());
|
||||
} else {
|
||||
ParseJsString(weight, weightValue);
|
||||
}
|
||||
if (isSelected) {
|
||||
digitalParameters.selectedFontWeight = ConvertStrToFontWeight(weightValue);
|
||||
} else {
|
||||
digitalParameters.fontWeight = ConvertStrToFontWeight(weightValue);
|
||||
}
|
||||
} else {
|
||||
if (isSelected) {
|
||||
digitalParameters.selectedFontWeight = swiperIndicatorTheme->GetDigitalIndicatorTextStyle().GetFontWeight();
|
||||
} else {
|
||||
digitalParameters.fontWeight = swiperIndicatorTheme->GetDigitalIndicatorTextStyle().GetFontWeight();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<Dimension> JSIndicator::ParseIndicatorDimension(const JSRef<JSVal>& value)
|
||||
{
|
||||
std::optional<Dimension> indicatorDimension;
|
||||
if (value->IsUndefined()) {
|
||||
return indicatorDimension;
|
||||
}
|
||||
CalcDimension dimPosition;
|
||||
auto parseOk = ParseJsDimensionVpNG(value, dimPosition);
|
||||
indicatorDimension = parseOk && dimPosition.ConvertToPx() >= 0.0f ? dimPosition : 0.0_vp;
|
||||
return indicatorDimension;
|
||||
}
|
||||
|
||||
SwiperParameters JSIndicator::GetDotIndicatorInfo(const JSRef<JSObject>& obj)
|
||||
{
|
||||
JSRef<JSVal> leftValue = obj->GetProperty(static_cast<int32_t>(ArkUIIndex::LEFT_VALUE));
|
||||
JSRef<JSVal> topValue = obj->GetProperty(static_cast<int32_t>(ArkUIIndex::TOP_VALUE));
|
||||
JSRef<JSVal> rightValue = obj->GetProperty(static_cast<int32_t>(ArkUIIndex::RIGHT_VALUE));
|
||||
JSRef<JSVal> bottomValue = obj->GetProperty(static_cast<int32_t>(ArkUIIndex::BOTTOM_VALUE));
|
||||
JSRef<JSVal> startValue = obj->GetProperty(static_cast<int32_t>(ArkUIIndex::START_VALUE));
|
||||
JSRef<JSVal> endValue = obj->GetProperty(static_cast<int32_t>(ArkUIIndex::END_VALUE));
|
||||
JSRef<JSVal> itemWidthValue = obj->GetProperty(static_cast<int32_t>(ArkUIIndex::ITEM_WIDTH_VALUE));
|
||||
JSRef<JSVal> itemHeightValue = obj->GetProperty(static_cast<int32_t>(ArkUIIndex::ITEM_HEIGHT_VALUE));
|
||||
JSRef<JSVal> selectedItemWidthValue = obj->GetProperty(static_cast<int32_t>(ArkUIIndex::SELECTED_ITEM_WIDTH_VALUE));
|
||||
JSRef<JSVal> selectedItemHeightValue =
|
||||
obj->GetProperty(static_cast<int32_t>(ArkUIIndex::SELECTED_ITEM_HEIGHT_VALUE));
|
||||
auto pipelineContext = PipelineBase::GetCurrentContext();
|
||||
CHECK_NULL_RETURN(pipelineContext, SwiperParameters());
|
||||
auto swiperIndicatorTheme = pipelineContext->GetTheme<SwiperIndicatorTheme>();
|
||||
CHECK_NULL_RETURN(swiperIndicatorTheme, SwiperParameters());
|
||||
SwiperParameters swiperParameters;
|
||||
swiperParameters.dimLeft = ParseIndicatorDimension(leftValue);
|
||||
swiperParameters.dimTop = ParseIndicatorDimension(topValue);
|
||||
swiperParameters.dimRight = ParseIndicatorDimension(rightValue);
|
||||
swiperParameters.dimBottom = ParseIndicatorDimension(bottomValue);
|
||||
CalcDimension dimStart;
|
||||
CalcDimension dimEnd;
|
||||
std::optional<Dimension> indicatorDimension;
|
||||
swiperParameters.dimStart = ParseLengthMetricsToDimension(startValue, dimStart) ? dimStart : indicatorDimension;
|
||||
swiperParameters.dimEnd = ParseLengthMetricsToDimension(endValue, dimEnd) ? dimEnd : indicatorDimension;
|
||||
|
||||
CalcDimension dimPosition;
|
||||
bool parseItemWOk =
|
||||
ParseJsDimensionVpNG(itemWidthValue, dimPosition) && (dimPosition.Unit() != DimensionUnit::PERCENT);
|
||||
auto defaultSize = swiperIndicatorTheme->GetSize();
|
||||
swiperParameters.itemWidth = parseItemWOk && dimPosition > 0.0_vp ? dimPosition : defaultSize;
|
||||
bool parseItemHOk =
|
||||
ParseJsDimensionVpNG(itemHeightValue, dimPosition) && (dimPosition.Unit() != DimensionUnit::PERCENT);
|
||||
swiperParameters.itemHeight = parseItemHOk && dimPosition > 0.0_vp ? dimPosition : defaultSize;
|
||||
bool parseSelectedItemWOk =
|
||||
ParseJsDimensionVpNG(selectedItemWidthValue, dimPosition) && (dimPosition.Unit() != DimensionUnit::PERCENT);
|
||||
swiperParameters.selectedItemWidth = parseSelectedItemWOk && dimPosition > 0.0_vp ? dimPosition : defaultSize;
|
||||
bool parseSelectedItemHOk =
|
||||
ParseJsDimensionVpNG(selectedItemHeightValue, dimPosition) && (dimPosition.Unit() != DimensionUnit::PERCENT);
|
||||
swiperParameters.selectedItemHeight = parseSelectedItemHOk && dimPosition > 0.0_vp ? dimPosition : defaultSize;
|
||||
SwiperModel::GetInstance()->SetIsIndicatorCustomSize(
|
||||
parseSelectedItemWOk || parseSelectedItemHOk || parseItemWOk || parseItemHOk);
|
||||
SetDotIndicatorInfo(obj, swiperParameters, swiperIndicatorTheme);
|
||||
return swiperParameters;
|
||||
}
|
||||
void JSIndicator::SetDotIndicatorInfo(const JSRef<JSObject>& obj, SwiperParameters& swiperParameters,
|
||||
const RefPtr<SwiperIndicatorTheme>& swiperIndicatorTheme)
|
||||
{
|
||||
JSRef<JSVal> maskValue = obj->GetProperty(static_cast<int32_t>(ArkUIIndex::MASK_VALUE));
|
||||
JSRef<JSVal> colorValue = obj->GetProperty(static_cast<int32_t>(ArkUIIndex::COLOR_VALUE));
|
||||
JSRef<JSVal> selectedColorValue = obj->GetProperty(static_cast<int32_t>(ArkUIIndex::SELECTED_COLOR_VALUE));
|
||||
JSRef<JSVal> maxDisplayCountVal = obj->GetProperty(static_cast<int32_t>(ArkUIIndex::MAX_DISPLAY_COUNT_VALUE));
|
||||
if (maskValue->IsBoolean()) {
|
||||
auto mask = maskValue->ToBoolean();
|
||||
swiperParameters.maskValue = mask;
|
||||
}
|
||||
Color colorVal;
|
||||
auto parseOk = ParseJsColor(colorValue, colorVal);
|
||||
swiperParameters.colorVal = parseOk ? colorVal : swiperIndicatorTheme->GetColor();
|
||||
parseOk = ParseJsColor(selectedColorValue, colorVal);
|
||||
swiperParameters.selectedColorVal = parseOk ? colorVal : swiperIndicatorTheme->GetSelectedColor();
|
||||
if (maxDisplayCountVal->IsUndefined()) {
|
||||
return;
|
||||
}
|
||||
uint32_t result = 0;
|
||||
auto setMaxDisplayCountVal = ParseJsInteger(maxDisplayCountVal, result);
|
||||
swiperParameters.maxDisplayCountVal = setMaxDisplayCountVal && result > 0 ? result : 0;
|
||||
}
|
||||
|
||||
SwiperDigitalParameters JSIndicator::GetDigitIndicatorInfo(const JSRef<JSObject>& obj)
|
||||
{
|
||||
JSRef<JSVal> dotLeftValue = obj->GetProperty("leftValue");
|
||||
JSRef<JSVal> dotTopValue = obj->GetProperty("topValue");
|
||||
JSRef<JSVal> dotRightValue = obj->GetProperty("rightValue");
|
||||
JSRef<JSVal> dotBottomValue = obj->GetProperty("bottomValue");
|
||||
JSRef<JSVal> fontColorValue = obj->GetProperty("fontColorValue");
|
||||
JSRef<JSVal> selectedFontColorValue = obj->GetProperty("selectedFontColorValue");
|
||||
JSRef<JSVal> digitFontValue = obj->GetProperty("digitFontValue");
|
||||
JSRef<JSVal> selectedDigitFontValue = obj->GetProperty("selectedDigitFontValue");
|
||||
auto pipelineContext = PipelineBase::GetCurrentContext();
|
||||
CHECK_NULL_RETURN(pipelineContext, SwiperDigitalParameters());
|
||||
auto swiperIndicatorTheme = pipelineContext->GetTheme<SwiperIndicatorTheme>();
|
||||
CHECK_NULL_RETURN(swiperIndicatorTheme, SwiperDigitalParameters());
|
||||
SwiperDigitalParameters digitalParameters;
|
||||
digitalParameters.dimLeft = ParseIndicatorDimension(dotLeftValue);
|
||||
digitalParameters.dimTop = ParseIndicatorDimension(dotTopValue);
|
||||
digitalParameters.dimRight = ParseIndicatorDimension(dotRightValue);
|
||||
digitalParameters.dimBottom = ParseIndicatorDimension(dotBottomValue);
|
||||
Color fontColor;
|
||||
auto parseOk = JSViewAbstract::ParseJsColor(fontColorValue, fontColor);
|
||||
digitalParameters.fontColor =
|
||||
parseOk ? fontColor : swiperIndicatorTheme->GetDigitalIndicatorTextStyle().GetTextColor();
|
||||
parseOk = JSViewAbstract::ParseJsColor(selectedFontColorValue, fontColor);
|
||||
digitalParameters.selectedFontColor =
|
||||
parseOk ? fontColor : swiperIndicatorTheme->GetDigitalIndicatorTextStyle().GetTextColor();
|
||||
if (!digitFontValue->IsNull() && digitFontValue->IsObject()) {
|
||||
GetFontContent(digitFontValue, false, digitalParameters);
|
||||
}
|
||||
if (!selectedDigitFontValue->IsNull() && selectedDigitFontValue->IsObject()) {
|
||||
GetFontContent(selectedDigitFontValue, true, digitalParameters);
|
||||
}
|
||||
return digitalParameters;
|
||||
}
|
||||
|
||||
void JSIndicator::SetIndicator(const JSCallbackInfo& info)
|
||||
{
|
||||
if (info[0]->IsEmpty()) {
|
||||
IndicatorModel::GetInstance()->SetShowIndicator(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (info[0]->IsObject()) {
|
||||
auto obj = JSRef<JSObject>::Cast(info[0]);
|
||||
|
||||
JSRef<JSVal> typeParam = obj->GetProperty("type");
|
||||
if (typeParam->IsString()) {
|
||||
auto type = typeParam->ToString();
|
||||
if (type == "DigitIndicator") {
|
||||
SwiperDigitalParameters digitalParameters = GetDigitIndicatorInfo(obj);
|
||||
IndicatorModel::GetInstance()->SetDigitIndicatorStyle(digitalParameters);
|
||||
IndicatorModel::GetInstance()->SetIndicatorType(SwiperIndicatorType::DIGIT);
|
||||
} else {
|
||||
SwiperParameters swiperParameters = GetDotIndicatorInfo(obj);
|
||||
IndicatorModel::GetInstance()->SetDotIndicatorStyle(swiperParameters);
|
||||
IndicatorModel::GetInstance()->SetIndicatorType(SwiperIndicatorType::DOT);
|
||||
}
|
||||
} else {
|
||||
SwiperParameters swiperParameters = GetDotIndicatorInfo(obj);
|
||||
IndicatorModel::GetInstance()->SetDotIndicatorStyle(swiperParameters);
|
||||
IndicatorModel::GetInstance()->SetIndicatorType(SwiperIndicatorType::DOT);
|
||||
}
|
||||
} else {
|
||||
SwiperParameters swiperParameters = GetDotIndicatorInfo(JSRef<JSObject>::New());
|
||||
IndicatorModel::GetInstance()->SetDotIndicatorStyle(swiperParameters);
|
||||
IndicatorModel::GetInstance()->SetIndicatorType(SwiperIndicatorType::DOT);
|
||||
}
|
||||
if (info[0]->IsBoolean()) {
|
||||
bool showIndicator = false;
|
||||
ParseJsBool(info[0], showIndicator);
|
||||
IndicatorModel::GetInstance()->SetShowIndicator(showIndicator);
|
||||
} else {
|
||||
IndicatorModel::GetInstance()->SetShowIndicator(true);
|
||||
}
|
||||
}
|
||||
|
||||
void JSIndicator::SetOnChange(const JSCallbackInfo& info)
|
||||
{
|
||||
if (!info[0]->IsFunction()) {
|
||||
return;
|
||||
}
|
||||
auto changeHandler = AceType::MakeRefPtr<JsEventFunction<SwiperChangeEvent, 1>>(
|
||||
JSRef<JSFunc>::Cast(info[0]), SwiperChangeEventToJSValue);
|
||||
WeakPtr<NG::FrameNode> targetNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
|
||||
auto onChange = [executionContext = info.GetExecutionContext(), func = std::move(changeHandler), node = targetNode](
|
||||
const BaseEventInfo* info) {
|
||||
JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(executionContext);
|
||||
const auto* swiperInfo = TypeInfoHelper::DynamicCast<SwiperChangeEvent>(info);
|
||||
if (!swiperInfo) {
|
||||
TAG_LOGW(AceLogTag::ACE_INDICATOR, "Indicator onChange callback execute failed.");
|
||||
return;
|
||||
}
|
||||
PipelineContext::SetCallBackNode(node);
|
||||
func->Execute(*swiperInfo);
|
||||
};
|
||||
|
||||
IndicatorModel::GetInstance()->SetOnChange(std::move(onChange));
|
||||
}
|
||||
|
||||
void JSIndicator::SetIndex(const JSCallbackInfo& info)
|
||||
{
|
||||
if (!info[0]->IsNumber()) {
|
||||
IndicatorModel::GetInstance()->SetIndex(0);
|
||||
return;
|
||||
}
|
||||
|
||||
auto index = std::max(0, info[0]->ToNumber<int32_t>());
|
||||
IndicatorModel::GetInstance()->SetIndex(index);
|
||||
}
|
||||
|
||||
void JSIndicatorController::JSBind(BindingTarget globalObj)
|
||||
{
|
||||
JSClass<JSIndicatorController>::Declare("IndicatorComponentController");
|
||||
JSClass<JSIndicatorController>::CustomMethod("showNext", &JSIndicatorController::ShowNext);
|
||||
JSClass<JSIndicatorController>::CustomMethod("showPrevious", &JSIndicatorController::ShowPrevious);
|
||||
JSClass<JSIndicatorController>::CustomMethod("changeIndex", &JSIndicatorController::ChangeIndex);
|
||||
|
||||
JSClass<JSIndicatorController>::Bind(
|
||||
globalObj, JSIndicatorController::Constructor, JSIndicatorController::Destructor);
|
||||
}
|
||||
|
||||
void JSIndicatorController::Constructor(const JSCallbackInfo& args)
|
||||
{
|
||||
auto scroller = Referenced::MakeRefPtr<JSIndicatorController>();
|
||||
scroller->IncRefCount();
|
||||
args.SetReturnValue(Referenced::RawPtr(scroller));
|
||||
}
|
||||
|
||||
void JSIndicatorController::Destructor(JSIndicatorController* scroller)
|
||||
{
|
||||
if (scroller != nullptr) {
|
||||
scroller->DecRefCount();
|
||||
}
|
||||
}
|
||||
|
||||
void JSIndicatorController::ChangeIndex(const JSCallbackInfo& args)
|
||||
{
|
||||
if (!controller_) {
|
||||
return;
|
||||
}
|
||||
if (!args[0]->IsNumber()) {
|
||||
return;
|
||||
}
|
||||
bool useAnimation = false;
|
||||
if (args.Length() > 1 && args[1]->IsBoolean()) {
|
||||
useAnimation = args[1]->ToBoolean();
|
||||
}
|
||||
auto index = args[0]->ToNumber<int32_t>();
|
||||
controller_->ChangeIndex(index, useAnimation);
|
||||
}
|
||||
|
||||
} // namespace OHOS::Ace::Framework
|
110
frameworks/bridge/declarative_frontend/jsview/js_indicator.h
Normal file
110
frameworks/bridge/declarative_frontend/jsview/js_indicator.h
Normal file
@ -0,0 +1,110 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_INDICATOR_H
|
||||
#define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_INDICATOR_H
|
||||
|
||||
#include "frameworks/bridge/declarative_frontend/jsview/js_view_abstract.h"
|
||||
#include "frameworks/core/components_ng/base/ui_node.h"
|
||||
#include "frameworks/core/components_ng/pattern/swiper_indicator/indicator_common/indicator_controller.h"
|
||||
|
||||
namespace OHOS::Ace::Framework {
|
||||
|
||||
class JSIndicator : public JSViewAbstract {
|
||||
public:
|
||||
static void JSBind(BindingTarget globalObj);
|
||||
static void Create(const JSCallbackInfo& info);
|
||||
|
||||
protected:
|
||||
static void SetLoop(const JSCallbackInfo& info);
|
||||
static void SetOnChange(const JSCallbackInfo& info);
|
||||
static void SetIndex(const JSCallbackInfo& info);
|
||||
static void SetIndicator(const JSCallbackInfo& info);
|
||||
static void SetCount(const JSCallbackInfo& info);
|
||||
static void SetVertical(const JSCallbackInfo& info);
|
||||
static SwiperParameters GetDotIndicatorInfo(const JSRef<JSObject>& obj);
|
||||
static SwiperDigitalParameters GetDigitIndicatorInfo(const JSRef<JSObject>& obj);
|
||||
static std::optional<Dimension> ParseIndicatorDimension(const JSRef<JSVal>& value);
|
||||
static void GetFontContent(const JSRef<JSVal>& font, bool isSelected, SwiperDigitalParameters& digitalParameters);
|
||||
static void SetDotIndicatorInfo(const JSRef<JSObject>& obj, SwiperParameters& swiperParameters,
|
||||
const RefPtr<SwiperIndicatorTheme>& swiperIndicatorTheme);
|
||||
};
|
||||
|
||||
class JSIndicatorController final : public Referenced {
|
||||
public:
|
||||
JSIndicatorController() = default;
|
||||
~JSIndicatorController() override = default;
|
||||
static void JSBind(BindingTarget globalObj);
|
||||
static void Constructor(const JSCallbackInfo& args);
|
||||
static void Destructor(JSIndicatorController* scroller);
|
||||
|
||||
void ShowNext(const JSCallbackInfo& args)
|
||||
{
|
||||
ContainerScope scope(instanceId_);
|
||||
if (controller_) {
|
||||
controller_->ShowNext();
|
||||
}
|
||||
}
|
||||
|
||||
void ShowPrevious(const JSCallbackInfo& args)
|
||||
{
|
||||
ContainerScope scope(instanceId_);
|
||||
if (controller_) {
|
||||
controller_->ShowPrevious();
|
||||
}
|
||||
}
|
||||
|
||||
void ChangeIndex(const JSCallbackInfo& args);
|
||||
void SetController(const RefPtr<NG::IndicatorController>& controller, WeakPtr<NG::UINode>& indicatorNode)
|
||||
{
|
||||
controller_ = controller;
|
||||
indicatorNode_ = indicatorNode;
|
||||
hasController_ = true;
|
||||
if (hasSwiperNode_) {
|
||||
controller_->SetSwiperNode(swiperNode_, indicatorNode_);
|
||||
}
|
||||
}
|
||||
|
||||
RefPtr<NG::IndicatorController> GetController()
|
||||
{
|
||||
return controller_;
|
||||
}
|
||||
|
||||
void SetInstanceId(int32_t id)
|
||||
{
|
||||
instanceId_ = id;
|
||||
}
|
||||
|
||||
void SetSwiperNode(WeakPtr<NG::UINode>& node)
|
||||
{
|
||||
swiperNode_ = node;
|
||||
hasSwiperNode_ = true;
|
||||
if (hasController_) {
|
||||
controller_->SetSwiperNode(swiperNode_, indicatorNode_);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
int32_t instanceId_ = INSTANCE_ID_UNDEFINED;
|
||||
RefPtr<NG::IndicatorController> controller_;
|
||||
bool hasSwiperNode_ = false;
|
||||
bool hasController_ = false;
|
||||
WeakPtr<NG::UINode> swiperNode_;
|
||||
WeakPtr<NG::UINode> indicatorNode_;
|
||||
ACE_DISALLOW_COPY_AND_MOVE(JSIndicatorController);
|
||||
};
|
||||
|
||||
} // namespace OHOS::Ace::Framework
|
||||
#endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_INDICATOR_H
|
@ -41,6 +41,7 @@
|
||||
#include "core/components_ng/pattern/swiper/swiper_model.h"
|
||||
#include "core/components_ng/pattern/swiper/swiper_model_ng.h"
|
||||
#include "bridge/declarative_frontend/engine/jsi/js_ui_index.h"
|
||||
#include "bridge/declarative_frontend/jsview/js_indicator.h"
|
||||
|
||||
namespace OHOS::Ace {
|
||||
namespace {
|
||||
@ -688,6 +689,23 @@ void JSSwiper::SetDisplayArrow(const JSCallbackInfo& info)
|
||||
SwiperModel::GetInstance()->SetHoverShow(false);
|
||||
}
|
||||
}
|
||||
|
||||
void JSSwiper::SetIndicatorController(const JSCallbackInfo& info)
|
||||
{
|
||||
if (info.Length() < 1 || !info[0]->IsObject()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto* jsIndicatorController = JSRef<JSObject>::Cast(info[0])->Unwrap<JSIndicatorController>();
|
||||
if (!jsIndicatorController) {
|
||||
return;
|
||||
}
|
||||
|
||||
WeakPtr<NG::UINode> targetNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
|
||||
jsIndicatorController->SetSwiperNode(targetNode);
|
||||
SwiperModel::GetInstance()->SetBindIndicator(true);
|
||||
}
|
||||
|
||||
void JSSwiper::SetIndicator(const JSCallbackInfo& info)
|
||||
{
|
||||
if (info.Length() < 1) {
|
||||
@ -698,6 +716,7 @@ void JSSwiper::SetIndicator(const JSCallbackInfo& info)
|
||||
SwiperModel::GetInstance()->SetShowIndicator(true);
|
||||
return;
|
||||
}
|
||||
SwiperModel::GetInstance()->SetBindIndicator(false);
|
||||
if (info[0]->IsObject()) {
|
||||
auto obj = JSRef<JSObject>::Cast(info[0]);
|
||||
SwiperModel::GetInstance()->SetIndicatorIsBoolean(false);
|
||||
@ -716,6 +735,8 @@ void JSSwiper::SetIndicator(const JSCallbackInfo& info)
|
||||
SwiperModel::GetInstance()->SetDotIndicatorStyle(swiperParameters);
|
||||
SwiperModel::GetInstance()->SetIndicatorType(SwiperIndicatorType::DOT);
|
||||
}
|
||||
} else if (typeParam->IsUndefined()) {
|
||||
SetIndicatorController(info);
|
||||
} else {
|
||||
SwiperParameters swiperParameters = GetDotIndicatorInfo(obj);
|
||||
JSSwiperTheme::ApplyThemeToDotIndicatorForce(swiperParameters);
|
||||
|
@ -70,6 +70,7 @@ protected:
|
||||
static void SetCustomContentTransition(const JSCallbackInfo& info);
|
||||
static void SetOnContentDidScroll(const JSCallbackInfo& info);
|
||||
static bool ParseLengthMetricsToDimension(const JSRef<JSVal>& jsValue, CalcDimension& result);
|
||||
static void SetIndicatorController(const JSCallbackInfo& info);
|
||||
};
|
||||
|
||||
class JSSwiperController final : public Referenced {
|
||||
|
@ -85,7 +85,7 @@ void DigitIndicatorLayoutAlgorithm::Layout(LayoutWrapper* layoutWrapper)
|
||||
auto indicatorPattern = frameNode->GetPattern<SwiperIndicatorPattern>();
|
||||
CHECK_NULL_VOID(indicatorPattern);
|
||||
SizeF frameSize = { 0.0f, 0.0f };
|
||||
auto success = indicatorPattern->GetDigitFrameSize(frameSize);
|
||||
auto success = indicatorPattern->GetDigitFrameSize(layoutGeometryNode, frameSize);
|
||||
CHECK_NULL_VOID(success);
|
||||
auto height = frameSize.Height();
|
||||
auto frontCurrentOffset = OffsetF { INDICATOR_PADDING.ConvertToPx(),
|
||||
|
@ -264,11 +264,10 @@ bool IndicatorPattern::GetDotCurrentOffset(OffsetF& offset, float indicatorWidth
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IndicatorPattern::GetDigitFrameSize(SizeF& frameSize) const
|
||||
bool IndicatorPattern::GetDigitFrameSize(RefPtr<GeometryNode>& geoNode, SizeF& frameSize) const
|
||||
{
|
||||
auto indicatorNode = GetHost();
|
||||
CHECK_NULL_RETURN(indicatorNode, false);
|
||||
frameSize = indicatorNode->GetGeometryNode()->GetFrameSize();
|
||||
CHECK_NULL_RETURN(geoNode, false);
|
||||
frameSize = geoNode->GetFrameSize();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -70,7 +70,7 @@ public:
|
||||
}
|
||||
|
||||
void SetSwiperDigitalParameters(const SwiperDigitalParameters& swiperDigitalParameters);
|
||||
bool GetDigitFrameSize(SizeF& frameSize) const override;
|
||||
bool GetDigitFrameSize(RefPtr<GeometryNode>& geoNode, SizeF& frameSize) const override;
|
||||
bool GetDotCurrentOffset(OffsetF& offset, float indicatorWidth, float indicatorHeight) override;
|
||||
|
||||
RefPtr<FrameNode> WeakUINode2RefFrameNode(WeakPtr<NG::UINode>& weakUINode) const
|
||||
|
@ -1154,11 +1154,10 @@ void SwiperIndicatorPattern::IndicatorOnChange()
|
||||
pipeline->RequestFrame();
|
||||
}
|
||||
|
||||
bool SwiperIndicatorPattern::GetDigitFrameSize(SizeF& frameSize) const
|
||||
bool SwiperIndicatorPattern::GetDigitFrameSize(RefPtr<GeometryNode>& geoNode, SizeF& frameSize) const
|
||||
{
|
||||
auto indicatorNode = GetHost();
|
||||
CHECK_NULL_RETURN(indicatorNode, false);
|
||||
frameSize = indicatorNode->GetGeometryNode()->GetMarginFrameSize();
|
||||
CHECK_NULL_RETURN(geoNode, false);
|
||||
frameSize = geoNode->GetMarginFrameSize();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -177,7 +177,7 @@ public:
|
||||
void OnModifyDone() override;
|
||||
void SetIndicatorOnChange();
|
||||
void IndicatorOnChange();
|
||||
virtual bool GetDigitFrameSize(SizeF& frameSize) const;
|
||||
virtual bool GetDigitFrameSize(RefPtr<GeometryNode>& geoNode, SizeF& frameSize) const;
|
||||
virtual int32_t RealTotalCount() const;
|
||||
virtual int32_t GetCurrentIndex() const;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user