mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2024-11-23 23:21:05 +00:00
!10542 date picker组件UX规格与特征动效整改(时间日期选择器切换、切换动效)
Merge pull request !10542 from chensi10/datepicker_0302
This commit is contained in:
commit
415a36f1bd
@ -264,6 +264,108 @@ void JSDatePicker::UseMilitaryTime(bool isUseMilitaryTime)
|
||||
DatePickerModel::GetInstance()->SetHour24(isUseMilitaryTime);
|
||||
}
|
||||
|
||||
void JSDatePicker::ParseTextProperties(const JSRef<JSObject>& paramObj, NG::PickerTextProperties& result)
|
||||
{
|
||||
auto disappearProperty = paramObj->GetProperty("disappearTextStyle");
|
||||
auto normalProperty = paramObj->GetProperty("textStyle");
|
||||
auto selectedProperty = paramObj->GetProperty("selectedTextStyle");
|
||||
|
||||
if (!disappearProperty->IsNull() && disappearProperty->IsObject()) {
|
||||
JSRef<JSObject> disappearObj = JSRef<JSObject>::Cast(disappearProperty);
|
||||
NG::PickerTextStyle disappearTextStyle;
|
||||
JSDatePicker::ParseTextStyle(disappearObj, disappearTextStyle);
|
||||
|
||||
if (disappearTextStyle.fontSize.has_value() && disappearTextStyle.fontSize->IsValid()) {
|
||||
result.disappearFontSize_ = disappearTextStyle.fontSize.value();
|
||||
result.hasValueFlag |= NG::FLAG_DISAPPEAR_FONTSIZE;
|
||||
}
|
||||
if (disappearTextStyle.textColor) {
|
||||
result.disappearColor_ = disappearTextStyle.textColor.value();
|
||||
result.hasValueFlag |= NG::FLAG_DISAPPEAR_COLOR;
|
||||
}
|
||||
if (disappearTextStyle.fontWeight) {
|
||||
result.disappearWeight_ = disappearTextStyle.fontWeight.value();
|
||||
result.hasValueFlag |= NG::FLAG_DISAPPEAR_WEIGHT;
|
||||
}
|
||||
}
|
||||
|
||||
if (!normalProperty->IsNull() && normalProperty->IsObject()) {
|
||||
JSRef<JSObject> noramlObj = JSRef<JSObject>::Cast(normalProperty);
|
||||
NG::PickerTextStyle textStyle;
|
||||
JSDatePicker::ParseTextStyle(noramlObj, textStyle);
|
||||
|
||||
if (textStyle.fontSize.has_value() && textStyle.fontSize->IsValid()) {
|
||||
result.fontSize_ = textStyle.fontSize.value();
|
||||
result.hasValueFlag |= NG::FLAG_FONTSIZE;
|
||||
}
|
||||
if (textStyle.textColor) {
|
||||
result.color_ = textStyle.textColor.value();
|
||||
result.hasValueFlag |= NG::FLAG_COLOR;
|
||||
}
|
||||
if (textStyle.fontWeight) {
|
||||
result.weight_ = textStyle.fontWeight.value();
|
||||
result.hasValueFlag |= NG::FLAG_WEIGHT;
|
||||
}
|
||||
}
|
||||
|
||||
if (!selectedProperty->IsNull() && selectedProperty->IsObject()) {
|
||||
JSRef<JSObject> selectedObj = JSRef<JSObject>::Cast(selectedProperty);
|
||||
NG::PickerTextStyle selectedTextStyle;
|
||||
JSDatePicker::ParseTextStyle(selectedObj, selectedTextStyle);
|
||||
|
||||
if (selectedTextStyle.fontSize.has_value() && selectedTextStyle.fontSize->IsValid()) {
|
||||
result.selectedFontSize_ = selectedTextStyle.fontSize.value();
|
||||
result.hasValueFlag |= NG::FLAG_SELECTED_FONTSIZE;
|
||||
}
|
||||
if (selectedTextStyle.textColor) {
|
||||
result.selectedColor_ = selectedTextStyle.textColor.value();
|
||||
result.hasValueFlag |= NG::FLAG_SELECTED_COLOR;
|
||||
}
|
||||
if (selectedTextStyle.fontWeight) {
|
||||
result.selectedWeight_ = selectedTextStyle.fontWeight.value();
|
||||
result.hasValueFlag |= NG::FLAG_SELECTED_WEIGHT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void JSDatePicker::ParseTextStyle(const JSRef<JSObject>& paramObj, NG::PickerTextStyle& textStyle)
|
||||
{
|
||||
auto fontColor = paramObj->GetProperty("color");
|
||||
auto fontStyle = paramObj->GetProperty("font");
|
||||
|
||||
Color textColor;
|
||||
if (JSViewAbstract::ParseJsColor(fontColor, textColor)) {
|
||||
textStyle.textColor = textColor;
|
||||
}
|
||||
|
||||
if (!fontStyle->IsObject()) {
|
||||
return;
|
||||
}
|
||||
JSRef<JSObject> fontObj = JSRef<JSObject>::Cast(fontStyle);
|
||||
auto fontSize = fontObj->GetProperty("size");
|
||||
auto fontWeight = fontObj->GetProperty("weight");
|
||||
if (fontSize->IsNull() || fontSize->IsUndefined()) {
|
||||
textStyle.fontSize = Dimension(-1);
|
||||
} else {
|
||||
Dimension size;
|
||||
if (!ParseJsDimensionFp(fontSize, size) || size.Unit() == DimensionUnit::PERCENT) {
|
||||
textStyle.fontSize = Dimension(-1);
|
||||
LOGW("Parse to dimension FP failed.");
|
||||
} else {
|
||||
textStyle.fontSize = size;
|
||||
}
|
||||
}
|
||||
|
||||
if (!fontWeight->IsNull() && !fontWeight->IsUndefined()) {
|
||||
std::string weight;
|
||||
if (fontWeight->IsNumber()) {
|
||||
weight = std::to_string(fontWeight->ToNumber<int32_t>());
|
||||
} else {
|
||||
ParseJsString(fontWeight, weight);
|
||||
}
|
||||
textStyle.fontWeight = ConvertStrToFontWeight(weight);
|
||||
}
|
||||
}
|
||||
void JSDatePicker::OnChange(const JSCallbackInfo& info)
|
||||
{
|
||||
if (info.Length() < 1 || !info[0]->IsFunction()) {
|
||||
@ -492,11 +594,16 @@ void JSDatePickerDialog::DatePickerDialogShow(const JSRef<JSObject>& paramObj,
|
||||
return;
|
||||
}
|
||||
|
||||
NG::DatePickerSettingData settingData;
|
||||
auto startDate = paramObj->GetProperty("start");
|
||||
auto endDate = paramObj->GetProperty("end");
|
||||
auto selectedDate = paramObj->GetProperty("selected");
|
||||
auto lunar = paramObj->GetProperty("lunar");
|
||||
bool isLunar = lunar->ToBoolean();
|
||||
auto sTime = paramObj->GetProperty("showTime");
|
||||
auto useMilitary = paramObj->GetProperty("useMilitaryTime");
|
||||
settingData.isLunar = lunar->ToBoolean();
|
||||
settingData.showTime = sTime->ToBoolean();
|
||||
settingData.useMilitary = useMilitary->ToBoolean();
|
||||
auto parseStartDate = ParseDate(startDate);
|
||||
auto parseEndDate = ParseDate(endDate);
|
||||
auto parseSelectedDate = ParseDate(selectedDate);
|
||||
@ -524,24 +631,27 @@ void JSDatePickerDialog::DatePickerDialogShow(const JSRef<JSObject>& paramObj,
|
||||
properties.offset = DimensionOffset(Offset(0, -theme->GetMarginBottom().ConvertToPx()));
|
||||
|
||||
std::map<std::string, PickerDate> datePickerProperty;
|
||||
std::map<std::string, PickerTime> timePickerProperty;
|
||||
if (startDate->IsObject()) {
|
||||
datePickerProperty["start"] = parseStartDate;
|
||||
settingData.datePickerProperty["start"] = parseStartDate;
|
||||
}
|
||||
if (endDate->IsObject()) {
|
||||
datePickerProperty["end"] = parseEndDate;
|
||||
settingData.datePickerProperty["end"] = parseEndDate;
|
||||
}
|
||||
if (selectedDate->IsObject()) {
|
||||
datePickerProperty["selected"] = parseSelectedDate;
|
||||
settingData.datePickerProperty["selected"] = parseSelectedDate;
|
||||
settingData.timePickerProperty["selected"] = ParseTime(selectedDate);
|
||||
}
|
||||
|
||||
JSDatePicker::ParseTextProperties(paramObj, settingData.properties);
|
||||
auto context = AccessibilityManager::DynamicCast<NG::PipelineContext>(pipelineContext);
|
||||
auto overlayManager = context ? context->GetOverlayManager() : nullptr;
|
||||
executor->PostTask(
|
||||
[properties, datePickerProperty, isLunar, dialogEvent, dialogCancelEvent,
|
||||
[properties, settingData, dialogEvent, dialogCancelEvent,
|
||||
weak = WeakPtr<NG::OverlayManager>(overlayManager)] {
|
||||
auto overlayManager = weak.Upgrade();
|
||||
CHECK_NULL_VOID(overlayManager);
|
||||
overlayManager->ShowDateDialog(properties, datePickerProperty, isLunar, dialogEvent, dialogCancelEvent);
|
||||
overlayManager->ShowDateDialog(properties, settingData, dialogEvent, dialogCancelEvent);
|
||||
},
|
||||
TaskExecutor::TaskType::UI);
|
||||
}
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "bridge/declarative_frontend/jsview/js_view_abstract.h"
|
||||
#include "core/components/picker/picker_base_component.h"
|
||||
#include "core/components_ng/pattern/picker/datepicker_event_hub.h"
|
||||
#include "core/components_ng/pattern/picker/picker_type_define.h"
|
||||
#include "frameworks/bridge/declarative_frontend/jsview/dialog/js_alert_dialog.h"
|
||||
|
||||
namespace OHOS::Ace::Framework {
|
||||
@ -31,6 +32,8 @@ public:
|
||||
static void SetLunar(bool isLunar);
|
||||
static void OnChange(const JSCallbackInfo& info);
|
||||
static void PickerBackgroundColor(const JSCallbackInfo& info);
|
||||
static void ParseTextStyle(const JSRef<JSObject>& paramObj, NG::PickerTextStyle& textStyle);
|
||||
static void ParseTextProperties(const JSRef<JSObject>& paramObj, NG::PickerTextProperties& result);
|
||||
// keep compatible, need remove after
|
||||
static void UseMilitaryTime(bool isUseMilitaryTime);
|
||||
|
||||
|
@ -213,6 +213,7 @@ build_component_ng("pattern_ng") {
|
||||
"patternlock/patternlock_model_ng.cpp",
|
||||
"patternlock/patternlock_paint_method.cpp",
|
||||
"patternlock/patternlock_pattern.cpp",
|
||||
"picker/date_time_animation_controller.cpp",
|
||||
"picker/datepicker_column_layout_algorithm.cpp",
|
||||
"picker/datepicker_column_pattern.cpp",
|
||||
"picker/datepicker_dialog_view.cpp",
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2022-2023 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
|
||||
@ -707,13 +707,13 @@ RefPtr<FrameNode> OverlayManager::ShowDialog(
|
||||
return dialog;
|
||||
}
|
||||
|
||||
void OverlayManager::ShowDateDialog(const DialogProperties& dialogProps,
|
||||
std::map<std::string, PickerDate> datePickerProperty, bool isLunar,
|
||||
std::map<std::string, NG::DialogEvent> dialogEvent, std::map<std::string, NG::DialogGestureEvent> dialogCancelEvent)
|
||||
void OverlayManager::ShowDateDialog(const DialogProperties& dialogProps, const DatePickerSettingData& settingData,
|
||||
std::map<std::string, NG::DialogEvent> dialogEvent,
|
||||
std::map<std::string, NG::DialogGestureEvent> dialogCancelEvent)
|
||||
{
|
||||
LOGI("OverlayManager::ShowDateDialogPicker");
|
||||
auto dialogNode = DatePickerDialogView::Show(
|
||||
dialogProps, std::move(datePickerProperty), isLunar, std::move(dialogEvent), std::move(dialogCancelEvent));
|
||||
dialogProps, std::move(settingData), std::move(dialogEvent), std::move(dialogCancelEvent));
|
||||
OpenDialogAnimation(dialogNode);
|
||||
}
|
||||
|
||||
@ -761,7 +761,11 @@ bool OverlayManager::RemoveOverlay()
|
||||
// close dialog with animation
|
||||
auto pattern = overlay->GetPattern();
|
||||
if (AceType::DynamicCast<DialogPattern>(pattern)) {
|
||||
if (FireBackPressEvent()) {
|
||||
return true;
|
||||
}
|
||||
CloseDialog(overlay);
|
||||
SetBackPressEvent(nullptr);
|
||||
return true;
|
||||
} else if (AceType::DynamicCast<BubblePattern>(pattern)) {
|
||||
auto popupNode = AceType::DynamicCast<NG::FrameNode>(rootNode->GetChildAtIndex(childrenSize - 1));
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2022-2023 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
|
||||
@ -25,6 +25,7 @@
|
||||
#include "core/components/picker/picker_data.h"
|
||||
#include "core/components_ng/base/ui_node.h"
|
||||
#include "core/components_ng/pattern/picker/datepicker_event_hub.h"
|
||||
#include "core/components_ng/pattern/picker/picker_type_define.h"
|
||||
#include "core/components_ng/pattern/text_picker/textpicker_event_hub.h"
|
||||
#include "core/pipeline_ng/ui_task_scheduler.h"
|
||||
|
||||
@ -79,8 +80,8 @@ public:
|
||||
// customNode only used by customDialog, pass in nullptr if not customDialog
|
||||
RefPtr<FrameNode> ShowDialog(
|
||||
const DialogProperties& dialogProps, const RefPtr<UINode>& customNode, bool isRightToLeft = false);
|
||||
void ShowDateDialog(const DialogProperties& dialogProps, std::map<std::string, PickerDate> datePickerProperty,
|
||||
bool isLunar, std::map<std::string, NG::DialogEvent> dialogEvent,
|
||||
void ShowDateDialog(const DialogProperties& dialogProps, const DatePickerSettingData& settingData,
|
||||
std::map<std::string, NG::DialogEvent> dialogEvent,
|
||||
std::map<std::string, NG::DialogGestureEvent> dialogCancelEvent);
|
||||
void ShowTimeDialog(const DialogProperties& dialogProps, std::map<std::string, PickerTime> timePickerProperty,
|
||||
bool isUseMilitaryTime, std::map<std::string, NG::DialogEvent> dialogEvent,
|
||||
@ -103,6 +104,19 @@ public:
|
||||
onHideMenuCallback_ = callback;
|
||||
}
|
||||
|
||||
void SetBackPressEvent(std::function<bool()> event)
|
||||
{
|
||||
backPressEvent_ = event;
|
||||
}
|
||||
|
||||
bool FireBackPressEvent() const
|
||||
{
|
||||
if (backPressEvent_) {
|
||||
return backPressEvent_();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
void PopToast(int32_t targetId);
|
||||
|
||||
@ -133,6 +147,7 @@ private:
|
||||
|
||||
std::function<void()> onHideMenuCallback_ = nullptr;
|
||||
CancelableCallback<void()> continuousTask_;
|
||||
std::function<bool()> backPressEvent_ = nullptr;
|
||||
|
||||
ACE_DISALLOW_COPY_AND_MOVE(OverlayManager);
|
||||
};
|
||||
|
@ -0,0 +1,392 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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/layout/layout_property.h"
|
||||
#include "date_time_animation_controller.h"
|
||||
|
||||
namespace OHOS::Ace::NG {
|
||||
namespace {
|
||||
constexpr int32_t CHILD_SIZE = 3;
|
||||
constexpr double SEMI_CIRCLE_ANGEL = 180;
|
||||
constexpr double OPACITY_DELAY = 100;
|
||||
constexpr double COLUMN_OPACITY_DELAY = 150;
|
||||
constexpr double OPACITY_DURATION = 150;
|
||||
constexpr double TRIANGLE_DURATION = 300;
|
||||
constexpr double MOVE_DURATION = 500;
|
||||
} // namespace
|
||||
void DateTimeAnimationController::PlayTitleInAnimation()
|
||||
{
|
||||
CHECK_NULL_VOID(buttonIcon_);
|
||||
auto renderContext = buttonIcon_->GetRenderContext();
|
||||
AnimationOption animationOption;
|
||||
animationOption.SetDuration(TRIANGLE_DURATION);
|
||||
animationOption.SetCurve(Curves::SHARP);
|
||||
|
||||
renderContext->UpdateTransformRotate(Vector4F(0, 0, 1, 0));
|
||||
AnimationUtils::Animate(animationOption,
|
||||
[renderContext]() {
|
||||
CHECK_NULL_VOID_NOLOG(renderContext);
|
||||
renderContext->UpdateTransformRotate(Vector4F(0, 0, 1, 0 - SEMI_CIRCLE_ANGEL));
|
||||
});
|
||||
}
|
||||
|
||||
void DateTimeAnimationController::PlayTitleOutAnimation()
|
||||
{
|
||||
CHECK_NULL_VOID(buttonIcon_);
|
||||
auto renderContext = buttonIcon_->GetRenderContext();
|
||||
AnimationOption animationOption;
|
||||
animationOption.SetDuration(TRIANGLE_DURATION);
|
||||
animationOption.SetCurve(Curves::SHARP);
|
||||
|
||||
renderContext->UpdateTransformRotate(Vector4F(0, 0, 1, 0 - SEMI_CIRCLE_ANGEL));
|
||||
AnimationUtils::Animate(animationOption,
|
||||
[renderContext]() {
|
||||
CHECK_NULL_VOID_NOLOG(renderContext);
|
||||
renderContext->UpdateTransformRotate(Vector4F(0, 0, 1, 0));
|
||||
});
|
||||
}
|
||||
|
||||
void DateTimeAnimationController::PlayMovingInAnimation()
|
||||
{
|
||||
CHECK_NULL_VOID(year_);
|
||||
CHECK_NULL_VOID(month_);
|
||||
CHECK_NULL_VOID(day_);
|
||||
auto yearRenderContext = year_->GetRenderContext();
|
||||
auto monthRenderContext = month_->GetRenderContext();
|
||||
auto dayRenderContext = day_->GetRenderContext();
|
||||
AnimationOption animationOption;
|
||||
animationOption.SetDuration(MOVE_DURATION);
|
||||
animationOption.SetCurve(Curves::FRICTION);
|
||||
|
||||
yearRenderContext->UpdateTransformTranslate(Vector3F(yearStart_, 0, 0));
|
||||
monthRenderContext->UpdateTransformTranslate(Vector3F(monthStart_, 0, 0));
|
||||
dayRenderContext->UpdateTransformTranslate(Vector3F(dayStart_, 0, 0));
|
||||
AnimationUtils::Animate(animationOption,
|
||||
[yearRenderContext, monthRenderContext, dayRenderContext, weak = AceType::WeakClaim(this)]() {
|
||||
auto ref = weak.Upgrade();
|
||||
CHECK_NULL_VOID(ref);
|
||||
CHECK_NULL_VOID_NOLOG(yearRenderContext);
|
||||
CHECK_NULL_VOID_NOLOG(monthRenderContext);
|
||||
CHECK_NULL_VOID_NOLOG(dayRenderContext);
|
||||
yearRenderContext->UpdateTransformTranslate(Vector3F(ref->yearEnd_, 0, 0));
|
||||
monthRenderContext->UpdateTransformTranslate(Vector3F(ref->monthEnd_, 0, 0));
|
||||
dayRenderContext->UpdateTransformTranslate(Vector3F(ref->dayEnd_, 0, 0));
|
||||
});
|
||||
}
|
||||
|
||||
void DateTimeAnimationController::PlayMovingOutAnimation()
|
||||
{
|
||||
CHECK_NULL_VOID(year_);
|
||||
CHECK_NULL_VOID(month_);
|
||||
CHECK_NULL_VOID(day_);
|
||||
auto yearRenderContext = year_->GetRenderContext();
|
||||
auto monthRenderContext = month_->GetRenderContext();
|
||||
auto dayRenderContext = day_->GetRenderContext();
|
||||
AnimationOption animationOption;
|
||||
animationOption.SetDuration(MOVE_DURATION);
|
||||
animationOption.SetCurve(Curves::FRICTION);
|
||||
|
||||
yearRenderContext->UpdateTransformTranslate(Vector3F(yearEnd_, 0, 0));
|
||||
monthRenderContext->UpdateTransformTranslate(Vector3F(monthEnd_, 0, 0));
|
||||
dayRenderContext->UpdateTransformTranslate(Vector3F(dayEnd_, 0, 0));
|
||||
AnimationUtils::Animate(animationOption,
|
||||
[yearRenderContext, monthRenderContext, dayRenderContext, weak = AceType::WeakClaim(this)]() {
|
||||
auto ref = weak.Upgrade();
|
||||
CHECK_NULL_VOID(ref);
|
||||
CHECK_NULL_VOID_NOLOG(yearRenderContext);
|
||||
CHECK_NULL_VOID_NOLOG(monthRenderContext);
|
||||
CHECK_NULL_VOID_NOLOG(dayRenderContext);
|
||||
yearRenderContext->UpdateTransformTranslate(Vector3F(ref->yearStart_, 0, 0));
|
||||
monthRenderContext->UpdateTransformTranslate(Vector3F(ref->monthStart_, 0, 0));
|
||||
dayRenderContext->UpdateTransformTranslate(Vector3F(ref->dayStart_, 0, 0));
|
||||
});
|
||||
}
|
||||
|
||||
void DateTimeAnimationController::PlayOldColumnOpacityInAnimation()
|
||||
{
|
||||
CHECK_NULL_VOID(monthDays_);
|
||||
CHECK_NULL_VOID(timePicker_);
|
||||
auto monthDaysRender = monthDays_->GetRenderContext();
|
||||
auto timePickerRender = timePicker_->GetRenderContext();
|
||||
CHECK_NULL_VOID(monthDaysRender);
|
||||
CHECK_NULL_VOID(timePickerRender);
|
||||
if (datePicker_) {
|
||||
auto layoutProperty = datePicker_->GetLayoutProperty<LayoutProperty>();
|
||||
if (layoutProperty) {
|
||||
layoutProperty->UpdateVisibility(VisibleType::VISIBLE);
|
||||
}
|
||||
}
|
||||
AnimationOption animationOption;
|
||||
animationOption.SetDuration(OPACITY_DURATION);
|
||||
animationOption.SetCurve(Curves::LINEAR);
|
||||
animationOption.SetOnFinishEvent([weak = AceType::WeakClaim(this)] {
|
||||
auto ref = weak.Upgrade();
|
||||
CHECK_NULL_VOID(ref);
|
||||
auto monthDaysNode = ref->monthDays_;
|
||||
CHECK_NULL_VOID(monthDaysNode);
|
||||
auto layoutProperty = monthDaysNode->GetLayoutProperty<LayoutProperty>();
|
||||
CHECK_NULL_VOID(layoutProperty);
|
||||
layoutProperty->UpdateVisibility(VisibleType::GONE);
|
||||
|
||||
auto timePickerNode = ref->timePicker_;
|
||||
CHECK_NULL_VOID(timePickerNode);
|
||||
layoutProperty = timePickerNode->GetLayoutProperty<LayoutProperty>();
|
||||
CHECK_NULL_VOID(layoutProperty);
|
||||
layoutProperty->UpdateVisibility(VisibleType::GONE);
|
||||
});
|
||||
monthDaysRender->UpdateOpacity(1);
|
||||
timePickerRender->UpdateOpacity(1);
|
||||
AnimationUtils::Animate(animationOption,
|
||||
[monthDaysRender, timePickerRender]() {
|
||||
CHECK_NULL_VOID_NOLOG(monthDaysRender);
|
||||
CHECK_NULL_VOID_NOLOG(timePickerRender);
|
||||
monthDaysRender->UpdateOpacity(0);
|
||||
timePickerRender->UpdateOpacity(0);
|
||||
}, animationOption.GetOnFinishEvent());
|
||||
}
|
||||
|
||||
void DateTimeAnimationController::PlayNewColumnOpacityInAnimation()
|
||||
{
|
||||
CHECK_NULL_VOID(month_);
|
||||
CHECK_NULL_VOID(day_);
|
||||
auto monthRender = month_->GetRenderContext();
|
||||
auto dayRender = day_->GetRenderContext();
|
||||
CHECK_NULL_VOID(monthRender);
|
||||
CHECK_NULL_VOID(dayRender);
|
||||
|
||||
AnimationOption animationOption;
|
||||
animationOption.SetDuration(OPACITY_DURATION);
|
||||
animationOption.SetCurve(Curves::LINEAR);
|
||||
|
||||
monthRender->UpdateOpacity(0);
|
||||
dayRender->UpdateOpacity(0);
|
||||
AnimationUtils::Animate(animationOption,
|
||||
[monthRender, dayRender]() {
|
||||
CHECK_NULL_VOID_NOLOG(monthRender);
|
||||
CHECK_NULL_VOID_NOLOG(dayRender);
|
||||
monthRender->UpdateOpacity(1);
|
||||
dayRender->UpdateOpacity(1);
|
||||
});
|
||||
}
|
||||
|
||||
void DateTimeAnimationController::PlayYearColumnOpacityInAnimation()
|
||||
{
|
||||
CHECK_NULL_VOID(year_);
|
||||
auto yearRender = year_->GetRenderContext();
|
||||
CHECK_NULL_VOID(yearRender);
|
||||
|
||||
AnimationOption animationOption;
|
||||
animationOption.SetDelay(OPACITY_DELAY);
|
||||
animationOption.SetDuration(OPACITY_DURATION);
|
||||
animationOption.SetCurve(Curves::LINEAR);
|
||||
|
||||
yearRender->OpacityAnimation(animationOption, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
void DateTimeAnimationController::PlayButtonOpacityInAnimation()
|
||||
{
|
||||
CHECK_NULL_VOID(buttonRow_);
|
||||
auto buttonRender = buttonRow_->GetRenderContext();
|
||||
CHECK_NULL_VOID(buttonRender);
|
||||
|
||||
AnimationOption animationOption;
|
||||
animationOption.SetDelay(OPACITY_DELAY);
|
||||
animationOption.SetDuration(OPACITY_DURATION);
|
||||
animationOption.SetCurve(Curves::LINEAR);
|
||||
animationOption.SetOnFinishEvent([weak = AceType::WeakClaim(this)] {
|
||||
auto ref = weak.Upgrade();
|
||||
CHECK_NULL_VOID(ref);
|
||||
auto buttonNode = ref->buttonRow_;
|
||||
CHECK_NULL_VOID(buttonNode);
|
||||
auto layoutProperty = buttonNode->GetLayoutProperty<LayoutProperty>();
|
||||
CHECK_NULL_VOID(layoutProperty);
|
||||
layoutProperty->UpdateVisibility(VisibleType::INVISIBLE);
|
||||
});
|
||||
buttonRender->OpacityAnimation(animationOption, 1.0f, 0.0f);
|
||||
}
|
||||
|
||||
void DateTimeAnimationController::PlayOldColumnOpacityOutAnimation()
|
||||
{
|
||||
CHECK_NULL_VOID(monthDays_);
|
||||
auto monthDaysRender = monthDays_->GetRenderContext();
|
||||
CHECK_NULL_VOID(timePicker_);
|
||||
auto timePickerRender = timePicker_->GetRenderContext();
|
||||
|
||||
auto layoutProperty = monthDays_->GetLayoutProperty<LayoutProperty>();
|
||||
CHECK_NULL_VOID(layoutProperty);
|
||||
layoutProperty->UpdateVisibility(VisibleType::VISIBLE);
|
||||
layoutProperty = timePicker_->GetLayoutProperty<LayoutProperty>();
|
||||
CHECK_NULL_VOID(layoutProperty);
|
||||
layoutProperty->UpdateVisibility(VisibleType::VISIBLE);
|
||||
|
||||
AnimationOption animationOption;
|
||||
animationOption.SetDelay(COLUMN_OPACITY_DELAY);
|
||||
animationOption.SetDuration(OPACITY_DURATION);
|
||||
animationOption.SetCurve(Curves::LINEAR);
|
||||
animationOption.SetOnFinishEvent([weak = AceType::WeakClaim(this)] {
|
||||
auto ref = weak.Upgrade();
|
||||
CHECK_NULL_VOID(ref);
|
||||
auto datePickerNode = ref->datePicker_;
|
||||
CHECK_NULL_VOID(datePickerNode);
|
||||
auto layoutProperty = datePickerNode->GetLayoutProperty<LayoutProperty>();
|
||||
CHECK_NULL_VOID(layoutProperty);
|
||||
layoutProperty->UpdateVisibility(VisibleType::GONE);
|
||||
});
|
||||
|
||||
monthDaysRender->UpdateOpacity(0);
|
||||
timePickerRender->UpdateOpacity(0);
|
||||
AnimationUtils::Animate(animationOption,
|
||||
[monthDaysRender, timePickerRender]() {
|
||||
CHECK_NULL_VOID_NOLOG(monthDaysRender);
|
||||
CHECK_NULL_VOID_NOLOG(timePickerRender);
|
||||
monthDaysRender->UpdateOpacity(1);
|
||||
timePickerRender->UpdateOpacity(1);
|
||||
}, animationOption.GetOnFinishEvent());
|
||||
}
|
||||
|
||||
void DateTimeAnimationController::PlayNewColumnOpacityOutAnimation()
|
||||
{
|
||||
CHECK_NULL_VOID(month_);
|
||||
CHECK_NULL_VOID(day_);
|
||||
auto monthRender = month_->GetRenderContext();
|
||||
auto dayRender = day_->GetRenderContext();
|
||||
CHECK_NULL_VOID(monthRender);
|
||||
CHECK_NULL_VOID(dayRender);
|
||||
|
||||
AnimationOption animationOption;
|
||||
animationOption.SetDelay(OPACITY_DELAY);
|
||||
animationOption.SetDuration(OPACITY_DURATION);
|
||||
animationOption.SetCurve(Curves::LINEAR);
|
||||
|
||||
monthRender->UpdateOpacity(1);
|
||||
dayRender->UpdateOpacity(1);
|
||||
AnimationUtils::Animate(animationOption,
|
||||
[monthRender, dayRender]() {
|
||||
CHECK_NULL_VOID_NOLOG(monthRender);
|
||||
CHECK_NULL_VOID_NOLOG(dayRender);
|
||||
monthRender->UpdateOpacity(0);
|
||||
dayRender->UpdateOpacity(0);
|
||||
});
|
||||
}
|
||||
|
||||
void DateTimeAnimationController::PlayYearColumnOpacityOutAnimation()
|
||||
{
|
||||
CHECK_NULL_VOID(year_);
|
||||
auto yearRender = year_->GetRenderContext();
|
||||
CHECK_NULL_VOID(yearRender);
|
||||
|
||||
AnimationOption animationOption;
|
||||
animationOption.SetDuration(OPACITY_DURATION);
|
||||
animationOption.SetCurve(Curves::LINEAR);
|
||||
|
||||
yearRender->OpacityAnimation(animationOption, 1.0f, 0.0f);
|
||||
}
|
||||
|
||||
void DateTimeAnimationController::PlayButtonOpacityOutAnimation()
|
||||
{
|
||||
CHECK_NULL_VOID(buttonRow_);
|
||||
auto buttonRender = buttonRow_->GetRenderContext();
|
||||
CHECK_NULL_VOID(buttonRender);
|
||||
|
||||
AnimationOption animationOption;
|
||||
animationOption.SetDelay(OPACITY_DELAY);
|
||||
animationOption.SetDuration(OPACITY_DURATION);
|
||||
animationOption.SetCurve(Curves::LINEAR);
|
||||
animationOption.SetOnFinishEvent([weak = AceType::WeakClaim(this)] {
|
||||
auto ref = weak.Upgrade();
|
||||
CHECK_NULL_VOID(ref);
|
||||
auto buttonNode = ref->buttonRow_;
|
||||
CHECK_NULL_VOID(buttonNode);
|
||||
auto layoutProperty = buttonNode->GetLayoutProperty<LayoutProperty>();
|
||||
CHECK_NULL_VOID(layoutProperty);
|
||||
layoutProperty->UpdateVisibility(VisibleType::VISIBLE);
|
||||
});
|
||||
buttonRender->OpacityAnimation(animationOption, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
void DateTimeAnimationController::PlayInAnimation()
|
||||
{
|
||||
PlayTitleInAnimation();
|
||||
PlayMovingInAnimation();
|
||||
|
||||
PlayOldColumnOpacityInAnimation();
|
||||
PlayNewColumnOpacityInAnimation();
|
||||
PlayYearColumnOpacityInAnimation();
|
||||
PlayButtonOpacityInAnimation();
|
||||
}
|
||||
|
||||
void DateTimeAnimationController::PlayOutAnimation()
|
||||
{
|
||||
PlayTitleOutAnimation();
|
||||
PlayMovingOutAnimation();
|
||||
|
||||
PlayOldColumnOpacityOutAnimation();
|
||||
PlayNewColumnOpacityOutAnimation();
|
||||
PlayYearColumnOpacityOutAnimation();
|
||||
PlayButtonOpacityOutAnimation();
|
||||
}
|
||||
|
||||
|
||||
void DateTimeAnimationController::InitMoveRange()
|
||||
{
|
||||
yearEnd_ = 0.0;
|
||||
monthEnd_ = 0.0;
|
||||
dayEnd_ = 0.0;
|
||||
|
||||
auto yearGeometry = year_->GetGeometryNode();
|
||||
CHECK_NULL_VOID(yearGeometry);
|
||||
auto monthGeometry = month_->GetGeometryNode();
|
||||
CHECK_NULL_VOID(monthGeometry);
|
||||
yearStart_ = 0;
|
||||
monthStart_ = 0 - yearGeometry->GetFrameSize().Width();
|
||||
dayStart_ = monthStart_ - monthGeometry->GetFrameSize().Width();
|
||||
}
|
||||
|
||||
|
||||
void DateTimeAnimationController::SetDatePicker(const RefPtr<FrameNode>& value)
|
||||
{
|
||||
datePicker_ = value;
|
||||
auto children = datePicker_->GetChildren();
|
||||
if (children.size() != CHILD_SIZE) {
|
||||
return;
|
||||
}
|
||||
auto iter = children.begin();
|
||||
auto year = (*iter);
|
||||
CHECK_NULL_VOID(year);
|
||||
iter++;
|
||||
auto month = *iter;
|
||||
CHECK_NULL_VOID(month);
|
||||
iter++;
|
||||
auto day = *iter;
|
||||
CHECK_NULL_VOID(day);
|
||||
year_ = DynamicCast<FrameNode>(year->GetChildAtIndex(1));
|
||||
month_ = DynamicCast<FrameNode>(month->GetChildAtIndex(1));
|
||||
day_ = DynamicCast<FrameNode>(day->GetChildAtIndex(1));
|
||||
}
|
||||
|
||||
void DateTimeAnimationController::Play(bool isIn)
|
||||
{
|
||||
if (!created_) {
|
||||
InitMoveRange();
|
||||
created_ = true;
|
||||
}
|
||||
|
||||
if (isIn) {
|
||||
PlayInAnimation();
|
||||
} else {
|
||||
PlayOutAnimation();
|
||||
}
|
||||
}
|
||||
} // namespace OHOS::Ace
|
@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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_DATE_PICKER_DATE_TIME_ANIMATION_CONTROLLER_H
|
||||
#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_DATE_PICKER_DATE_TIME_ANIMATION_CONTROLLER_H
|
||||
|
||||
#include "core/animation/animator.h"
|
||||
#include "core/components/display/render_display.h"
|
||||
#include "core/components/picker/picker_animation.h"
|
||||
#include "core/components/picker/render_picker_column.h"
|
||||
#include "core/components/triangle/render_triangle.h"
|
||||
#include "core/components_ng/pattern/picker/datepicker_pattern.h"
|
||||
#include "core/pipeline/pipeline_context.h"
|
||||
|
||||
namespace OHOS::Ace::NG {
|
||||
class DateTimeAnimationController : public virtual AceType {
|
||||
DECLARE_ACE_TYPE(DateTimeAnimationController, AceType);
|
||||
|
||||
public:
|
||||
~DateTimeAnimationController() = default;
|
||||
|
||||
void SetButtonIcon(const RefPtr<FrameNode>& value)
|
||||
{
|
||||
buttonIcon_ = value;
|
||||
}
|
||||
|
||||
void SetMonthDays(const RefPtr<FrameNode>& value)
|
||||
{
|
||||
monthDays_ = value;
|
||||
}
|
||||
|
||||
void SetTimePicker(const RefPtr<FrameNode>& value)
|
||||
{
|
||||
timePicker_ = value;
|
||||
}
|
||||
|
||||
void SetDatePicker(const RefPtr<FrameNode>& value);
|
||||
|
||||
void SetButtonRow(const RefPtr<FrameNode>& value)
|
||||
{
|
||||
buttonRow_ = value;
|
||||
}
|
||||
|
||||
void Play(bool isIn);
|
||||
|
||||
private:
|
||||
// triangle animation
|
||||
void PlayTitleInAnimation();
|
||||
void PlayTitleOutAnimation();
|
||||
// opacity animation
|
||||
void PlayOldColumnOpacityInAnimation();
|
||||
void PlayOldColumnOpacityOutAnimation();
|
||||
void PlayNewColumnOpacityInAnimation();
|
||||
void PlayYearColumnOpacityInAnimation();
|
||||
void PlayButtonOpacityInAnimation();
|
||||
void PlayNewColumnOpacityOutAnimation();
|
||||
void PlayYearColumnOpacityOutAnimation();
|
||||
void PlayButtonOpacityOutAnimation();
|
||||
// moving animation
|
||||
void PlayMovingInAnimation();
|
||||
void PlayMovingOutAnimation();
|
||||
void InitMoveRange();
|
||||
// play or stop animation
|
||||
void PlayInAnimation();
|
||||
void PlayOutAnimation();
|
||||
|
||||
RefPtr<FrameNode> buttonIcon_;
|
||||
RefPtr<FrameNode> datePicker_;
|
||||
RefPtr<FrameNode> monthDays_;
|
||||
RefPtr<FrameNode> timePicker_;
|
||||
RefPtr<FrameNode> year_;
|
||||
RefPtr<FrameNode> month_;
|
||||
RefPtr<FrameNode> day_;
|
||||
RefPtr<FrameNode> buttonRow_;
|
||||
// move range of date
|
||||
double yearStart_ = 0.0;
|
||||
double yearEnd_ = 0.0;
|
||||
double monthStart_ = 0.0;
|
||||
double monthEnd_ = 0.0;
|
||||
double dayStart_ = 0.0;
|
||||
double dayEnd_ = 0.0;
|
||||
// others
|
||||
bool created_ = false;
|
||||
};
|
||||
} // namespace OHOS::Ace
|
||||
|
||||
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_DATE_PICKER_DATE_TIME_ANIMATION_CONTROLLER_H
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2022-2023 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
|
||||
@ -18,11 +18,14 @@
|
||||
|
||||
#include "base/memory/ace_type.h"
|
||||
#include "base/utils/utils.h"
|
||||
#include "core/components/theme/icon_theme.h"
|
||||
#include "core/components_ng/base/view_stack_processor.h"
|
||||
#include "core/components_ng/pattern/button/button_pattern.h"
|
||||
#include "core/components_ng/pattern/calendar/calendar_paint_property.h"
|
||||
#include "core/components_ng/pattern/dialog/dialog_view.h"
|
||||
#include "core/components_ng/pattern/divider/divider_pattern.h"
|
||||
#include "core/components_ng/pattern/image/image_pattern.h"
|
||||
#include "core/components_ng/pattern/picker/date_time_animation_controller.h"
|
||||
#include "core/components_ng/pattern/picker/datepicker_pattern.h"
|
||||
#include "core/components_ng/pattern/picker/datepicker_row_layout_property.h"
|
||||
#include "core/components_ng/pattern/stack/stack_pattern.h"
|
||||
@ -33,148 +36,135 @@ namespace OHOS::Ace::NG {
|
||||
namespace {
|
||||
const uint32_t OPTION_COUNT_PHONE_LANDSCAPE = 3;
|
||||
const int32_t MARGIN_HALF = 2;
|
||||
constexpr double MONTHDAYS_WIDTH_PERCENT_ONE = 0.3429;
|
||||
constexpr double TIME_WIDTH_PERCENT_ONE = 0.4571;
|
||||
constexpr double MONTHDAYS_WIDTH_PERCENT_TWO = 0.2909;
|
||||
constexpr double TIME_WIDTH_PERCENT_TWO = 0.5091;
|
||||
} // namespace
|
||||
bool DatePickerDialogView::switchFlag_ = false;
|
||||
|
||||
RefPtr<FrameNode> DatePickerDialogView::Show(const DialogProperties& dialogProperties,
|
||||
std::map<std::string, PickerDate> datePickerProperty, bool isLunar,
|
||||
std::map<std::string, NG::DialogEvent> dialogEvent, std::map<std::string, NG::DialogGestureEvent> dialogCancelEvent)
|
||||
|
||||
const DatePickerSettingData& settingData,
|
||||
std::map<std::string, NG::DialogEvent> dialogEvent,
|
||||
std::map<std::string, NG::DialogGestureEvent> dialogCancelEvent)
|
||||
{
|
||||
auto contentColumn = FrameNode::CreateFrameNode(V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
|
||||
AceType::MakeRefPtr<LinearLayoutPattern>(true));
|
||||
auto pickerStack = CreateStackNode();
|
||||
auto dateNodeId = ElementRegister::GetInstance()->MakeUniqueId();
|
||||
auto dateNode = FrameNode::GetOrCreateFrameNode(
|
||||
V2::DATE_PICKER_ETS_TAG, dateNodeId, []() { return AceType::MakeRefPtr<DatePickerPattern>(); });
|
||||
CHECK_NULL_RETURN(dateNode, nullptr);
|
||||
auto monthDaysNodeId = ElementRegister::GetInstance()->MakeUniqueId();
|
||||
auto dateNode = CreateDateNode(
|
||||
dateNodeId, settingData.datePickerProperty, settingData.properties, settingData.isLunar, false);
|
||||
ViewStackProcessor::GetInstance()->Push(dateNode);
|
||||
auto datePickerPattern = dateNode->GetPattern<DatePickerPattern>();
|
||||
CHECK_NULL_RETURN(datePickerPattern, nullptr);
|
||||
dateNode->MountToParent(pickerStack);
|
||||
|
||||
bool hasYearNode = datePickerPattern->HasYearNode();
|
||||
bool hasMonthNode = datePickerPattern->HasMonthNode();
|
||||
bool hasDayNode = datePickerPattern->HasDayNode();
|
||||
|
||||
auto yearId = datePickerPattern->GetYearId();
|
||||
auto monthId = datePickerPattern->GetMonthId();
|
||||
auto dayId = datePickerPattern->GetDayId();
|
||||
|
||||
auto context = dateNode->GetContext();
|
||||
CHECK_NULL_RETURN(context, nullptr);
|
||||
auto themeManager = context->GetThemeManager();
|
||||
CHECK_NULL_RETURN(themeManager, nullptr);
|
||||
auto pickerTheme = themeManager->GetTheme<PickerTheme>();
|
||||
CHECK_NULL_RETURN(pickerTheme, nullptr);
|
||||
uint32_t showCount = pickerTheme->GetShowOptionCount();
|
||||
if (SystemProperties::GetDeviceType() == DeviceType::PHONE &&
|
||||
SystemProperties::GetDeviceOrientation() == DeviceOrientation::LANDSCAPE) {
|
||||
showCount = OPTION_COUNT_PHONE_LANDSCAPE;
|
||||
}
|
||||
datePickerPattern->SetShowCount(showCount);
|
||||
|
||||
auto yearColumnNode = FrameNode::GetOrCreateFrameNode(
|
||||
V2::COLUMN_ETS_TAG, yearId, []() { return AceType::MakeRefPtr<DatePickerColumnPattern>(); });
|
||||
CHECK_NULL_RETURN(yearColumnNode, nullptr);
|
||||
if (!hasYearNode) {
|
||||
for (uint32_t index = 0; index < showCount; index++) {
|
||||
auto textNode = FrameNode::CreateFrameNode(
|
||||
V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
|
||||
CHECK_NULL_RETURN(textNode, nullptr);
|
||||
textNode->MountToParent(yearColumnNode);
|
||||
}
|
||||
yearColumnNode->MarkModifyDone();
|
||||
datePickerPattern->SetColumn(yearColumnNode);
|
||||
}
|
||||
|
||||
auto monthColumnNode = FrameNode::GetOrCreateFrameNode(
|
||||
V2::COLUMN_ETS_TAG, monthId, []() { return AceType::MakeRefPtr<DatePickerColumnPattern>(); });
|
||||
CHECK_NULL_RETURN(monthColumnNode, nullptr);
|
||||
if (!hasMonthNode) {
|
||||
for (uint32_t index = 0; index < showCount; index++) {
|
||||
auto textNode = FrameNode::CreateFrameNode(
|
||||
V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
|
||||
CHECK_NULL_RETURN(textNode, nullptr);
|
||||
textNode->MountToParent(monthColumnNode);
|
||||
}
|
||||
monthColumnNode->MarkModifyDone();
|
||||
datePickerPattern->SetColumn(monthColumnNode);
|
||||
}
|
||||
|
||||
auto dayColumnNode = FrameNode::GetOrCreateFrameNode(
|
||||
V2::COLUMN_ETS_TAG, dayId, []() { return AceType::MakeRefPtr<DatePickerColumnPattern>(); });
|
||||
CHECK_NULL_RETURN(dayColumnNode, nullptr);
|
||||
if (!hasDayNode) {
|
||||
for (uint32_t index = 0; index < showCount; index++) {
|
||||
auto textNode = FrameNode::CreateFrameNode(
|
||||
V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
|
||||
CHECK_NULL_RETURN(textNode, nullptr);
|
||||
textNode->MountToParent(dayColumnNode);
|
||||
}
|
||||
dayColumnNode->MarkModifyDone();
|
||||
datePickerPattern->SetColumn(dayColumnNode);
|
||||
}
|
||||
|
||||
if (!hasYearNode) {
|
||||
auto stackYearNode = CreateStackNode();
|
||||
auto buttonYearNode = CreateButtonNode();
|
||||
buttonYearNode->MountToParent(stackYearNode);
|
||||
yearColumnNode->MountToParent(stackYearNode);
|
||||
auto layoutProperty = stackYearNode->GetLayoutProperty<LayoutProperty>();
|
||||
layoutProperty->UpdateAlignment(Alignment::CENTER);
|
||||
layoutProperty->UpdateLayoutWeight(1);
|
||||
stackYearNode->MountToParent(dateNode);
|
||||
}
|
||||
if (!hasMonthNode) {
|
||||
auto stackMonthNode = CreateStackNode();
|
||||
auto buttonMonthNode = CreateButtonNode();
|
||||
buttonMonthNode->MountToParent(stackMonthNode);
|
||||
monthColumnNode->MountToParent(stackMonthNode);
|
||||
auto layoutProperty = stackMonthNode->GetLayoutProperty<LayoutProperty>();
|
||||
layoutProperty->UpdateAlignment(Alignment::CENTER);
|
||||
layoutProperty->UpdateLayoutWeight(1);
|
||||
stackMonthNode->MountToParent(dateNode);
|
||||
}
|
||||
if (!hasDayNode) {
|
||||
auto stackDayNode = CreateStackNode();
|
||||
auto buttonDayNode = CreateButtonNode();
|
||||
buttonDayNode->MountToParent(stackDayNode);
|
||||
dayColumnNode->MountToParent(stackDayNode);
|
||||
auto layoutProperty = stackDayNode->GetLayoutProperty<LayoutProperty>();
|
||||
layoutProperty->UpdateAlignment(Alignment::CENTER);
|
||||
layoutProperty->UpdateLayoutWeight(1);
|
||||
stackDayNode->MountToParent(dateNode);
|
||||
}
|
||||
dateNode->MarkModifyDone();
|
||||
|
||||
PickerDate parseStartDate;
|
||||
PickerDate parseEndDate;
|
||||
PickerDate parseSelectedDate;
|
||||
SetShowLunar(isLunar);
|
||||
if (datePickerProperty.find("start") != datePickerProperty.end()) {
|
||||
parseStartDate = datePickerProperty["start"];
|
||||
SetStartDate(datePickerPattern, parseStartDate);
|
||||
}
|
||||
if (datePickerProperty.find("end") != datePickerProperty.end()) {
|
||||
parseEndDate = datePickerProperty["end"];
|
||||
SetEndDate(datePickerPattern, parseEndDate);
|
||||
}
|
||||
if (datePickerProperty.find("selected") != datePickerProperty.end()) {
|
||||
parseSelectedDate = datePickerProperty["selected"];
|
||||
SetSelectedDate(datePickerPattern, parseSelectedDate);
|
||||
}
|
||||
|
||||
auto changeEvent = dialogEvent["changeId"];
|
||||
SetDialogChange(dateNode, std::move(changeEvent));
|
||||
auto contentRow = CreateButtonNode(dateNode, dialogEvent, std::move(dialogCancelEvent));
|
||||
CHECK_NULL_RETURN(contentRow, nullptr);
|
||||
// create title node and bind title text id to date picker, then mark picker node modify done
|
||||
auto buttonTitleNode = CreateTitleButtonNode(dateNode);
|
||||
CHECK_NULL_RETURN(buttonTitleNode, nullptr);
|
||||
ViewStackProcessor::GetInstance()->Finish();
|
||||
|
||||
buttonTitleNode->MountToParent(contentColumn);
|
||||
dateNode->MountToParent(contentColumn);
|
||||
RefPtr<FrameNode> acceptNode = dateNode;
|
||||
if (settingData.showTime) {
|
||||
switchFlag_ = false;
|
||||
auto pickerRow = FrameNode::CreateFrameNode(V2::ROW_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
|
||||
AceType::MakeRefPtr<LinearLayoutPattern>(false));
|
||||
CHECK_NULL_RETURN(pickerRow, nullptr);
|
||||
auto layoutProperty = dateNode->GetLayoutProperty<LayoutProperty>();
|
||||
CHECK_NULL_RETURN(layoutProperty, nullptr);
|
||||
layoutProperty->UpdateVisibility(VisibleType::INVISIBLE);
|
||||
auto pickerPattern = dateNode->GetPattern<DatePickerPattern>();
|
||||
CHECK_NULL_RETURN(pickerPattern, nullptr);
|
||||
auto monthDaysNode = CreateDateNode(
|
||||
monthDaysNodeId, settingData.datePickerProperty, settingData.properties, settingData.isLunar, true);
|
||||
auto monthDaysPickerPattern = monthDaysNode->GetPattern<DatePickerPattern>();
|
||||
CHECK_NULL_RETURN(monthDaysPickerPattern, nullptr);
|
||||
monthDaysPickerPattern->SetTitleId(pickerPattern->GetTitleId());
|
||||
auto monthDaysLayoutProperty = monthDaysNode->GetLayoutProperty();
|
||||
CHECK_NULL_RETURN(monthDaysLayoutProperty, nullptr);
|
||||
monthDaysLayoutProperty->UpdateUserDefinedIdealSize(CalcSize(NG::CalcLength(
|
||||
Dimension(settingData.useMilitary ? MONTHDAYS_WIDTH_PERCENT_ONE : MONTHDAYS_WIDTH_PERCENT_TWO,
|
||||
DimensionUnit::PERCENT)), std::nullopt));
|
||||
monthDaysNode->MarkModifyDone();
|
||||
monthDaysNode->MountToParent(pickerRow);
|
||||
auto timeNode = CreateTimeNode(settingData.timePickerProperty, settingData.properties, settingData.useMilitary);
|
||||
auto timeLayoutProperty = timeNode->GetLayoutProperty();
|
||||
CHECK_NULL_RETURN(timeLayoutProperty, nullptr);
|
||||
timeLayoutProperty->UpdateUserDefinedIdealSize(CalcSize(NG::CalcLength(
|
||||
Dimension(settingData.useMilitary ? TIME_WIDTH_PERCENT_ONE : TIME_WIDTH_PERCENT_TWO,
|
||||
DimensionUnit::PERCENT)), std::nullopt));
|
||||
timeNode->MarkModifyDone();
|
||||
timeNode->MountToParent(pickerRow);
|
||||
pickerRow->MountToParent(pickerStack);
|
||||
|
||||
CreateTitleIconNode(buttonTitleNode);
|
||||
buttonTitleNode->MarkModifyDone();
|
||||
RefPtr<DateTimeAnimationController> animationController = AceType::MakeRefPtr<DateTimeAnimationController>();
|
||||
auto titleSwitchEvent = [contentColumn, pickerStack, animationController]() {
|
||||
// switch picker page.
|
||||
auto pickerRow = pickerStack->GetLastChild();
|
||||
CHECK_NULL_VOID(pickerRow);
|
||||
auto dateNode = AceType::DynamicCast<FrameNode>(pickerStack->GetChildAtIndex(0));
|
||||
CHECK_NULL_VOID(dateNode);
|
||||
auto datePickerPattern = dateNode->GetPattern<DatePickerPattern>();
|
||||
CHECK_NULL_VOID(datePickerPattern);
|
||||
auto monthDaysNode = AceType::DynamicCast<FrameNode>(pickerRow->GetChildAtIndex(0));
|
||||
auto timeNode = AceType::DynamicCast<FrameNode>(pickerRow->GetChildAtIndex(1));
|
||||
CHECK_NULL_VOID(monthDaysNode);
|
||||
CHECK_NULL_VOID(timeNode);
|
||||
auto monthDaysPickerPattern = monthDaysNode->GetPattern<DatePickerPattern>();
|
||||
CHECK_NULL_VOID(monthDaysPickerPattern);
|
||||
|
||||
PickerDate selectedDate = switchFlag_ ? datePickerPattern->GetCurrentDate() :
|
||||
monthDaysPickerPattern->GetCurrentDate();
|
||||
SetSelectedDate(switchFlag_ ? monthDaysNode : dateNode, selectedDate);
|
||||
switchFlag_ ? monthDaysNode->MarkModifyDone() : dateNode->MarkModifyDone();
|
||||
|
||||
auto contentRow = AceType::DynamicCast<FrameNode>(contentColumn->GetLastChild());
|
||||
auto titleRow = AceType::DynamicCast<FrameNode>(contentColumn->GetChildAtIndex(0));
|
||||
CHECK_NULL_VOID(titleRow);
|
||||
auto spinnerNode = AceType::DynamicCast<FrameNode>(titleRow->GetLastChild());
|
||||
CHECK_NULL_VOID(spinnerNode);
|
||||
animationController->SetButtonIcon(spinnerNode);
|
||||
animationController->SetMonthDays(monthDaysNode);
|
||||
animationController->SetDatePicker(dateNode);
|
||||
animationController->SetTimePicker(timeNode);
|
||||
animationController->SetButtonRow(contentRow);
|
||||
switchFlag_ = !switchFlag_;
|
||||
|
||||
animationController->Play(switchFlag_);
|
||||
};
|
||||
auto switchEvent = [func = titleSwitchEvent]() {
|
||||
if (switchFlag_) {
|
||||
func();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
SetDialogSwitchEvent(switchEvent);
|
||||
auto titleClickEvent = [func = std::move(titleSwitchEvent)](const GestureEvent& /* info */) {
|
||||
func();
|
||||
};
|
||||
auto titleEventHub = buttonTitleNode->GetOrCreateGestureEventHub();
|
||||
auto onClick = AceType::MakeRefPtr<NG::ClickEvent>(std::move(titleClickEvent));
|
||||
titleEventHub->AddClickEvent(onClick);
|
||||
acceptNode = monthDaysNode;
|
||||
}
|
||||
|
||||
dateNode->MarkModifyDone();
|
||||
|
||||
ViewStackProcessor::GetInstance()->Finish();
|
||||
pickerStack->MountToParent(contentColumn);
|
||||
|
||||
auto dialogNode = DialogView::CreateDialogNode(dialogProperties, contentColumn);
|
||||
CHECK_NULL_RETURN(dialogNode, nullptr);
|
||||
|
||||
// build dialog accept and cancel button
|
||||
auto changeEvent = dialogEvent["changeId"];
|
||||
SetDialogChange(dateNode, std::move(changeEvent));
|
||||
if (settingData.showTime) {
|
||||
SetDialogChange(acceptNode, std::move(changeEvent));
|
||||
}
|
||||
auto contentRow = CreateButtonNode(acceptNode, dialogEvent, std::move(dialogCancelEvent));
|
||||
CHECK_NULL_RETURN(contentRow, nullptr);
|
||||
auto event = [dialogNode](const GestureEvent& /* info */) {
|
||||
auto pipeline = PipelineContext::GetCurrentContext();
|
||||
auto overlayManager = pipeline->GetOverlayManager();
|
||||
@ -214,6 +204,15 @@ RefPtr<FrameNode> DatePickerDialogView::CreateTitleButtonNode(const RefPtr<Frame
|
||||
auto pickerTheme = pipeline->GetTheme<PickerTheme>();
|
||||
auto pickerPattern = dateNode->GetPattern<DatePickerPattern>();
|
||||
CHECK_NULL_RETURN(pickerPattern, nullptr);
|
||||
auto titleRow = FrameNode::CreateFrameNode(V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
|
||||
AceType::MakeRefPtr<LinearLayoutPattern>(false));
|
||||
CHECK_NULL_RETURN(titleRow, nullptr);
|
||||
auto layoutProps = titleRow->GetLayoutProperty<LinearLayoutProperty>();
|
||||
CHECK_NULL_RETURN(layoutProps, nullptr);
|
||||
layoutProps->UpdateMainAxisAlign(FlexAlign::CENTER);
|
||||
layoutProps->UpdateCrossAxisAlign(FlexAlign::CENTER);
|
||||
layoutProps->UpdateMeasureType(MeasureType::MATCH_PARENT_MAIN_AXIS);
|
||||
|
||||
auto buttonTitleNode = FrameNode::GetOrCreateFrameNode(
|
||||
V2::BUTTON_ETS_TAG, pickerPattern->GetButtonTitleId(), []() { return AceType::MakeRefPtr<ButtonPattern>(); });
|
||||
auto textTitleNodeId = pickerPattern->GetTitleId();
|
||||
@ -240,7 +239,35 @@ RefPtr<FrameNode> DatePickerDialogView::CreateTitleButtonNode(const RefPtr<Frame
|
||||
margin.bottom = CalcLength(dialogTheme->GetDividerHeight() / MARGIN_HALF);
|
||||
buttonTitleNode->GetLayoutProperty()->UpdateMargin(margin);
|
||||
textTitleNode->MountToParent(buttonTitleNode);
|
||||
return buttonTitleNode;
|
||||
buttonTitleNode->MountToParent(titleRow);
|
||||
|
||||
return titleRow;
|
||||
}
|
||||
|
||||
void DatePickerDialogView::CreateTitleIconNode(const RefPtr<FrameNode>& titleNode)
|
||||
{
|
||||
auto pipeline = PipelineContext::GetCurrentContext();
|
||||
CHECK_NULL_VOID(pipeline);
|
||||
auto iconTheme = pipeline->GetTheme<IconTheme>();
|
||||
auto pickerTheme = pipeline->GetTheme<PickerTheme>();
|
||||
auto spinnerNode = FrameNode::CreateFrameNode(
|
||||
V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<ImagePattern>());
|
||||
CHECK_NULL_VOID(spinnerNode);
|
||||
ImageSourceInfo imageSourceInfo;
|
||||
auto iconPath = iconTheme->GetIconPath(InternalResource::ResourceId::SPINNER);
|
||||
imageSourceInfo.SetSrc(iconPath);
|
||||
imageSourceInfo.SetFillColor(pickerTheme->GetTitleStyle().GetTextColor());
|
||||
|
||||
auto spinnerLayoutProperty = spinnerNode->GetLayoutProperty<ImageLayoutProperty>();
|
||||
CHECK_NULL_VOID(spinnerLayoutProperty);
|
||||
spinnerLayoutProperty->UpdateImageSourceInfo(imageSourceInfo);
|
||||
CalcSize idealSize = { CalcLength(pickerTheme->GetTitleStyle().GetFontSize()),
|
||||
CalcLength(pickerTheme->GetTitleStyle().GetFontSize()) };
|
||||
MeasureProperty layoutConstraint;
|
||||
layoutConstraint.selfIdealSize = idealSize;
|
||||
spinnerLayoutProperty->UpdateCalcLayoutProperty(layoutConstraint);
|
||||
spinnerNode->MarkModifyDone();
|
||||
spinnerNode->MountToParent(titleNode);
|
||||
}
|
||||
|
||||
RefPtr<FrameNode> DatePickerDialogView::CreateDividerNode(const RefPtr<FrameNode>& dateNode)
|
||||
@ -342,6 +369,217 @@ RefPtr<FrameNode> DatePickerDialogView::CreateConfirmNode(const RefPtr<FrameNode
|
||||
return buttonConfirmNode;
|
||||
}
|
||||
|
||||
RefPtr<FrameNode> DatePickerDialogView::CreateDateNode(int32_t dateNodeId,
|
||||
std::map<std::string, PickerDate> datePickerProperty,
|
||||
const PickerTextProperties& properties, bool isLunar, bool showTime)
|
||||
{
|
||||
auto dateNode = FrameNode::GetOrCreateFrameNode(V2::DATE_PICKER_ETS_TAG,
|
||||
dateNodeId, []() { return AceType::MakeRefPtr<DatePickerPattern>(); });
|
||||
CHECK_NULL_RETURN(dateNode, nullptr);
|
||||
auto datePickerPattern = dateNode->GetPattern<DatePickerPattern>();
|
||||
CHECK_NULL_RETURN(datePickerPattern, nullptr);
|
||||
|
||||
auto context = dateNode->GetContext();
|
||||
CHECK_NULL_RETURN(context, nullptr);
|
||||
auto themeManager = context->GetThemeManager();
|
||||
CHECK_NULL_RETURN(themeManager, nullptr);
|
||||
auto pickerTheme = themeManager->GetTheme<PickerTheme>();
|
||||
CHECK_NULL_RETURN(pickerTheme, nullptr);
|
||||
uint32_t showCount = pickerTheme->GetShowOptionCount();
|
||||
if (SystemProperties::GetDeviceType() == DeviceType::PHONE &&
|
||||
SystemProperties::GetDeviceOrientation() == DeviceOrientation::LANDSCAPE) {
|
||||
showCount = OPTION_COUNT_PHONE_LANDSCAPE;
|
||||
}
|
||||
datePickerPattern->SetShowCount(showCount);
|
||||
|
||||
if (showTime) {
|
||||
CreateSingleDateNode(dateNode, showCount);
|
||||
} else {
|
||||
CreateNormalDateNode(dateNode, showCount);
|
||||
}
|
||||
|
||||
PickerDate parseStartDate;
|
||||
PickerDate parseEndDate;
|
||||
PickerDate parseSelectedDate;
|
||||
SetShowLunar(dateNode, isLunar);
|
||||
SetDateTextProperties(dateNode, properties);
|
||||
if (datePickerProperty.find("start") != datePickerProperty.end()) {
|
||||
parseStartDate = datePickerProperty["start"];
|
||||
SetStartDate(dateNode, parseStartDate);
|
||||
}
|
||||
if (datePickerProperty.find("end") != datePickerProperty.end()) {
|
||||
parseEndDate = datePickerProperty["end"];
|
||||
SetEndDate(dateNode, parseEndDate);
|
||||
}
|
||||
if (datePickerProperty.find("selected") != datePickerProperty.end()) {
|
||||
parseSelectedDate = datePickerProperty["selected"];
|
||||
SetSelectedDate(dateNode, parseSelectedDate);
|
||||
}
|
||||
return dateNode;
|
||||
}
|
||||
|
||||
RefPtr<FrameNode> DatePickerDialogView::CreateColumnNode(int32_t nodeId, uint32_t showCount, bool isDate)
|
||||
{
|
||||
RefPtr<FrameNode> columnNode;
|
||||
if (isDate) {
|
||||
columnNode = FrameNode::GetOrCreateFrameNode(V2::COLUMN_ETS_TAG, nodeId,
|
||||
[]() {return AceType::MakeRefPtr<DatePickerColumnPattern>();});
|
||||
} else {
|
||||
columnNode = FrameNode::GetOrCreateFrameNode(V2::COLUMN_ETS_TAG, nodeId,
|
||||
[]() {return AceType::MakeRefPtr<TimePickerColumnPattern>();});
|
||||
}
|
||||
CHECK_NULL_RETURN(columnNode, nullptr);
|
||||
columnNode->Clean();
|
||||
for (uint32_t index = 0; index < showCount; index++) {
|
||||
auto textNode = FrameNode::CreateFrameNode(
|
||||
V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
|
||||
CHECK_NULL_RETURN(textNode, nullptr);
|
||||
textNode->MountToParent(columnNode);
|
||||
}
|
||||
columnNode->MarkModifyDone();
|
||||
return columnNode;
|
||||
}
|
||||
|
||||
void DatePickerDialogView::CreateNormalDateNode(const RefPtr<FrameNode>& dateNode, uint32_t showCount)
|
||||
{
|
||||
auto datePickerPattern = dateNode->GetPattern<DatePickerPattern>();
|
||||
CHECK_NULL_VOID(datePickerPattern);
|
||||
datePickerPattern->SetShowMonthDaysFlag(false);
|
||||
|
||||
auto yearColumnNode = CreateColumnNode(datePickerPattern->GetYearId(), showCount);
|
||||
auto monthColumnNode = CreateColumnNode(datePickerPattern->GetMonthId(), showCount);
|
||||
auto dayColumnNode = CreateColumnNode(datePickerPattern->GetDayId(), showCount);
|
||||
CHECK_NULL_VOID(yearColumnNode);
|
||||
CHECK_NULL_VOID(monthColumnNode);
|
||||
CHECK_NULL_VOID(dayColumnNode);
|
||||
datePickerPattern->SetColumn(yearColumnNode);
|
||||
datePickerPattern->SetColumn(monthColumnNode);
|
||||
datePickerPattern->SetColumn(dayColumnNode);
|
||||
|
||||
{
|
||||
auto stackYearNode = CreateStackNode();
|
||||
auto buttonYearNode = CreateButtonNode();
|
||||
buttonYearNode->MountToParent(stackYearNode);
|
||||
yearColumnNode->MountToParent(stackYearNode);
|
||||
auto layoutProperty = stackYearNode->GetLayoutProperty<LayoutProperty>();
|
||||
layoutProperty->UpdateAlignment(Alignment::CENTER);
|
||||
stackYearNode->MountToParent(dateNode);
|
||||
}
|
||||
{
|
||||
auto stackMonthNode = CreateStackNode();
|
||||
auto buttonMonthNode = CreateButtonNode();
|
||||
buttonMonthNode->MountToParent(stackMonthNode);
|
||||
monthColumnNode->MountToParent(stackMonthNode);
|
||||
auto layoutProperty = stackMonthNode->GetLayoutProperty<LayoutProperty>();
|
||||
layoutProperty->UpdateAlignment(Alignment::CENTER);
|
||||
stackMonthNode->MountToParent(dateNode);
|
||||
}
|
||||
{
|
||||
auto stackDayNode = CreateStackNode();
|
||||
auto buttonDayNode = CreateButtonNode();
|
||||
buttonDayNode->MountToParent(stackDayNode);
|
||||
dayColumnNode->MountToParent(stackDayNode);
|
||||
auto layoutProperty = stackDayNode->GetLayoutProperty<LayoutProperty>();
|
||||
layoutProperty->UpdateAlignment(Alignment::CENTER);
|
||||
stackDayNode->MountToParent(dateNode);
|
||||
}
|
||||
}
|
||||
|
||||
void DatePickerDialogView::CreateSingleDateNode(const RefPtr<FrameNode>& dateNode, uint32_t showCount)
|
||||
{
|
||||
auto datePickerPattern = dateNode->GetPattern<DatePickerPattern>();
|
||||
CHECK_NULL_VOID(datePickerPattern);
|
||||
datePickerPattern->SetShowMonthDaysFlag(true);
|
||||
|
||||
auto monthDaysColumnNode = CreateColumnNode(datePickerPattern->GetMonthDaysId(), showCount);
|
||||
auto yearColumnNode = CreateColumnNode(datePickerPattern->GetYearId(), showCount);
|
||||
CHECK_NULL_VOID(monthDaysColumnNode);
|
||||
CHECK_NULL_VOID(yearColumnNode);
|
||||
datePickerPattern->SetColumn(monthDaysColumnNode);
|
||||
datePickerPattern->SetColumn(yearColumnNode);
|
||||
|
||||
{
|
||||
auto stackMonthNode = CreateStackNode();
|
||||
auto buttonMonthNode = CreateButtonNode();
|
||||
buttonMonthNode->MountToParent(stackMonthNode);
|
||||
monthDaysColumnNode->MountToParent(stackMonthNode);
|
||||
auto layoutProperty = stackMonthNode->GetLayoutProperty<LayoutProperty>();
|
||||
layoutProperty->UpdateAlignment(Alignment::CENTER);
|
||||
stackMonthNode->MountToParent(dateNode);
|
||||
}
|
||||
|
||||
{
|
||||
auto stackYearNode = CreateStackNode();
|
||||
auto buttonYearNode = CreateButtonNode();
|
||||
buttonYearNode->MountToParent(stackYearNode);
|
||||
yearColumnNode->MountToParent(stackYearNode);
|
||||
auto layoutProperty = stackYearNode->GetLayoutProperty<LayoutProperty>();
|
||||
layoutProperty->UpdateAlignment(Alignment::CENTER);
|
||||
layoutProperty->UpdateVisibility(VisibleType::GONE);
|
||||
stackYearNode->MountToParent(dateNode);
|
||||
}
|
||||
}
|
||||
|
||||
RefPtr<FrameNode> DatePickerDialogView::CreateTimeNode(std::map<std::string, PickerTime> timePickerProperty,
|
||||
const PickerTextProperties& properties, bool useMilitaryTime)
|
||||
{
|
||||
auto timePickerNode = FrameNode::GetOrCreateFrameNode(V2::TIME_PICKER_ETS_TAG,
|
||||
ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<TimePickerRowPattern>(); });
|
||||
CHECK_NULL_RETURN(timePickerNode, nullptr);
|
||||
auto timePickerRowPattern = timePickerNode->GetPattern<TimePickerRowPattern>();
|
||||
CHECK_NULL_RETURN(timePickerRowPattern, nullptr);
|
||||
|
||||
auto context = timePickerNode->GetContext();
|
||||
CHECK_NULL_RETURN(context, nullptr);
|
||||
auto themeManager = context->GetThemeManager();
|
||||
CHECK_NULL_RETURN(themeManager, nullptr);
|
||||
auto pickerTheme = themeManager->GetTheme<PickerTheme>();
|
||||
CHECK_NULL_RETURN(pickerTheme, nullptr);
|
||||
uint32_t showCount = pickerTheme->GetShowOptionCount();
|
||||
if (SystemProperties::GetDeviceType() == DeviceType::PHONE &&
|
||||
SystemProperties::GetDeviceOrientation() == DeviceOrientation::LANDSCAPE) {
|
||||
showCount = OPTION_COUNT_PHONE_LANDSCAPE;
|
||||
}
|
||||
timePickerRowPattern->SetShowCount(showCount);
|
||||
|
||||
auto hasHourNode = timePickerRowPattern->HasHourNode();
|
||||
auto hasMinuteNode = timePickerRowPattern->HasMinuteNode();
|
||||
|
||||
auto hourColumnNode = CreateColumnNode(timePickerRowPattern->GetHourId(), showCount, false);
|
||||
auto minuteColumnNode = CreateColumnNode(timePickerRowPattern->GetMinuteId(), showCount, false);
|
||||
CHECK_NULL_RETURN(hourColumnNode, nullptr);
|
||||
CHECK_NULL_RETURN(minuteColumnNode, nullptr);
|
||||
timePickerRowPattern->SetColumn(hourColumnNode);
|
||||
timePickerRowPattern->SetColumn(minuteColumnNode);
|
||||
|
||||
if (!hasHourNode) {
|
||||
auto stackHourNode = CreateStackNode();
|
||||
auto buttonYearNode = CreateButtonNode();
|
||||
buttonYearNode->MountToParent(stackHourNode);
|
||||
hourColumnNode->MountToParent(stackHourNode);
|
||||
auto layoutProperty = stackHourNode->GetLayoutProperty<LayoutProperty>();
|
||||
layoutProperty->UpdateAlignment(Alignment::CENTER);
|
||||
stackHourNode->MountToParent(timePickerNode);
|
||||
}
|
||||
if (!hasMinuteNode) {
|
||||
auto stackMinuteNode = CreateStackNode();
|
||||
auto buttonYearNode = CreateButtonNode();
|
||||
buttonYearNode->MountToParent(stackMinuteNode);
|
||||
minuteColumnNode->MountToParent(stackMinuteNode);
|
||||
auto layoutProperty = stackMinuteNode->GetLayoutProperty<LayoutProperty>();
|
||||
layoutProperty->UpdateAlignment(Alignment::CENTER);
|
||||
stackMinuteNode->MountToParent(timePickerNode);
|
||||
}
|
||||
if (timePickerProperty.find("selected") != timePickerProperty.end()) {
|
||||
auto selectedTime = timePickerProperty["selected"];
|
||||
timePickerRowPattern->SetSelectedTime(selectedTime);
|
||||
}
|
||||
timePickerRowPattern->SetHour24(useMilitaryTime);
|
||||
|
||||
SetTimeTextProperties(timePickerNode, properties);
|
||||
return timePickerNode;
|
||||
}
|
||||
|
||||
RefPtr<FrameNode> DatePickerDialogView::CreateCancelNode(NG::DialogGestureEvent& cancelEvent)
|
||||
{
|
||||
auto pipeline = PipelineContext::GetCurrentContext();
|
||||
@ -387,27 +625,41 @@ RefPtr<FrameNode> DatePickerDialogView::CreateCancelNode(NG::DialogGestureEvent&
|
||||
return buttonCancelNode;
|
||||
}
|
||||
|
||||
void DatePickerDialogView::SetStartDate(const RefPtr<DatePickerPattern>& datePickerPattern, const PickerDate& value)
|
||||
void DatePickerDialogView::SetStartDate(const RefPtr<FrameNode>& frameNode, const PickerDate& value)
|
||||
{
|
||||
auto datePickerPattern = frameNode->GetPattern<DatePickerPattern>();
|
||||
CHECK_NULL_VOID(datePickerPattern);
|
||||
datePickerPattern->SetStartDate(value);
|
||||
ACE_UPDATE_LAYOUT_PROPERTY(DataPickerRowLayoutProperty, StartDate, datePickerPattern->GetStartDateLunar());
|
||||
auto pickerProperty = frameNode->GetLayoutProperty<DataPickerRowLayoutProperty>();
|
||||
CHECK_NULL_VOID(pickerProperty);
|
||||
pickerProperty->UpdateStartDate(datePickerPattern->GetStartDateLunar());
|
||||
}
|
||||
|
||||
void DatePickerDialogView::SetEndDate(const RefPtr<DatePickerPattern>& datePickerPattern, const PickerDate& value)
|
||||
void DatePickerDialogView::SetEndDate(const RefPtr<FrameNode>& frameNode, const PickerDate& value)
|
||||
{
|
||||
auto datePickerPattern = frameNode->GetPattern<DatePickerPattern>();
|
||||
CHECK_NULL_VOID(datePickerPattern);
|
||||
datePickerPattern->SetEndDate(value);
|
||||
ACE_UPDATE_LAYOUT_PROPERTY(DataPickerRowLayoutProperty, EndDate, datePickerPattern->GetEndDateLunar());
|
||||
auto pickerProperty = frameNode->GetLayoutProperty<DataPickerRowLayoutProperty>();
|
||||
CHECK_NULL_VOID(pickerProperty);
|
||||
pickerProperty->UpdateEndDate(datePickerPattern->GetEndDateLunar());
|
||||
}
|
||||
|
||||
void DatePickerDialogView::SetSelectedDate(const RefPtr<DatePickerPattern>& datePickerPattern, const PickerDate& value)
|
||||
void DatePickerDialogView::SetSelectedDate(const RefPtr<FrameNode>& frameNode, const PickerDate& value)
|
||||
{
|
||||
auto datePickerPattern = frameNode->GetPattern<DatePickerPattern>();
|
||||
CHECK_NULL_VOID(datePickerPattern);
|
||||
datePickerPattern->SetSelectDate(value);
|
||||
ACE_UPDATE_LAYOUT_PROPERTY(DataPickerRowLayoutProperty, SelectedDate, datePickerPattern->GetSelectDate());
|
||||
auto pickerProperty = frameNode->GetLayoutProperty<DataPickerRowLayoutProperty>();
|
||||
CHECK_NULL_VOID(pickerProperty);
|
||||
pickerProperty->UpdateSelectedDate(datePickerPattern->GetSelectDate());
|
||||
}
|
||||
|
||||
void DatePickerDialogView::SetShowLunar(bool lunar)
|
||||
void DatePickerDialogView::SetShowLunar(const RefPtr<FrameNode>& frameNode, bool lunar)
|
||||
{
|
||||
ACE_UPDATE_LAYOUT_PROPERTY(DataPickerRowLayoutProperty, Lunar, lunar);
|
||||
auto pickerProperty = frameNode->GetLayoutProperty<DataPickerRowLayoutProperty>();
|
||||
CHECK_NULL_VOID(pickerProperty);
|
||||
pickerProperty->UpdateLunar(lunar);
|
||||
}
|
||||
|
||||
void DatePickerDialogView::SetDialogChange(const RefPtr<FrameNode>& frameNode, DialogEvent&& onChange)
|
||||
@ -425,4 +677,23 @@ void DatePickerDialogView::SetDialogAcceptEvent(const RefPtr<FrameNode>& frameNo
|
||||
CHECK_NULL_VOID(eventHub);
|
||||
eventHub->SetDialogAcceptEvent(std::move(onChange));
|
||||
}
|
||||
|
||||
void DatePickerDialogView::SetDialogSwitchEvent(std::function<bool()> switchEvent)
|
||||
{
|
||||
auto pipeline = PipelineContext::GetCurrentContext();
|
||||
CHECK_NULL_VOID(pipeline);
|
||||
auto overlayManger = pipeline->GetOverlayManager();
|
||||
CHECK_NULL_VOID(overlayManger);
|
||||
overlayManger->SetBackPressEvent(switchEvent);
|
||||
}
|
||||
|
||||
void DatePickerDialogView::SetDateTextProperties(const RefPtr<FrameNode>& frameNode,
|
||||
const PickerTextProperties& properties)
|
||||
{
|
||||
}
|
||||
|
||||
void DatePickerDialogView::SetTimeTextProperties(const RefPtr<FrameNode>& frameNode,
|
||||
const PickerTextProperties& properties)
|
||||
{
|
||||
}
|
||||
} // namespace OHOS::Ace::NG
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2022-2023 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
|
||||
@ -22,28 +22,41 @@
|
||||
#include "core/components_ng/pattern/picker/datepicker_event_hub.h"
|
||||
#include "core/components_ng/pattern/picker/datepicker_layout_property.h"
|
||||
#include "core/components_ng/pattern/picker/datepicker_pattern.h"
|
||||
#include "core/components_ng/pattern/picker/picker_type_define.h"
|
||||
#include "core/components_ng/pattern/time_picker/timepicker_row_pattern.h"
|
||||
|
||||
namespace OHOS::Ace::NG {
|
||||
class ACE_EXPORT DatePickerDialogView {
|
||||
public:
|
||||
static RefPtr<FrameNode> Show(const DialogProperties& dialogProperties,
|
||||
std::map<std::string, PickerDate> datePickerProperty, bool isLunar,
|
||||
static RefPtr<FrameNode> Show(const DialogProperties& dialogProps, const DatePickerSettingData& settingData,
|
||||
std::map<std::string, NG::DialogEvent> dialogEvent,
|
||||
std::map<std::string, NG::DialogGestureEvent> dialogCancelEvent);
|
||||
static void SetStartDate(const RefPtr<DatePickerPattern>& datePickerPattern, const PickerDate& value);
|
||||
static void SetEndDate(const RefPtr<DatePickerPattern>& datePickerPattern, const PickerDate& value);
|
||||
static void SetSelectedDate(const RefPtr<DatePickerPattern>& datePickerPattern, const PickerDate& value);
|
||||
static void SetShowLunar(bool lunar = false);
|
||||
static void SetStartDate(const RefPtr<FrameNode>& frameNode, const PickerDate& value);
|
||||
static void SetEndDate(const RefPtr<FrameNode>& frameNode, const PickerDate& value);
|
||||
static void SetSelectedDate(const RefPtr<FrameNode>& frameNode, const PickerDate& value);
|
||||
static void SetShowLunar(const RefPtr<FrameNode>& frameNode, bool lunar = false);
|
||||
static void SetDateTextProperties(const RefPtr<FrameNode>& frameNode, const PickerTextProperties& properties);
|
||||
static void SetTimeTextProperties(const RefPtr<FrameNode>& frameNode, const PickerTextProperties& properties);
|
||||
static void SetDialogChange(const RefPtr<FrameNode>& frameNode, DialogEvent&& onChange);
|
||||
static void SetDialogAcceptEvent(const RefPtr<FrameNode>& frameNode, DialogEvent&& onChange);
|
||||
static void SetDialogSwitchEvent(std::function<bool()> switchEvent);
|
||||
static RefPtr<FrameNode> CreateButtonNode(const RefPtr<FrameNode>& frameNode,
|
||||
std::map<std::string, NG::DialogEvent> dialogEvent,
|
||||
std::map<std::string, NG::DialogGestureEvent> dialogCancelEvent);
|
||||
static RefPtr<FrameNode> CreateTitleButtonNode(const RefPtr<FrameNode>& dateNode);
|
||||
static void CreateTitleIconNode(const RefPtr<FrameNode>& titleNode);
|
||||
static RefPtr<FrameNode> CreateDividerNode(const RefPtr<FrameNode>& dateNode);
|
||||
static RefPtr<FrameNode> CreateConfirmNode(const RefPtr<FrameNode>& dateNode, DialogEvent& acceptEvent);
|
||||
static RefPtr<FrameNode> CreateCancelNode(NG::DialogGestureEvent& cancelEvent);
|
||||
static RefPtr<FrameNode> CreateDateNode(int32_t dateNodeId, std::map<std::string, PickerDate> datePickerProperty,
|
||||
const PickerTextProperties& properties, bool isLunar, bool hasTime);
|
||||
static RefPtr<FrameNode> CreateColumnNode(int32_t nodeId, uint32_t showCount, bool isDate = true);
|
||||
static void CreateNormalDateNode(const RefPtr<FrameNode>& dateNode, uint32_t showCount);
|
||||
static void CreateSingleDateNode(const RefPtr<FrameNode>& dateNode, uint32_t showCount);
|
||||
static RefPtr<FrameNode> CreateTimeNode(std::map<std::string, PickerTime> timePickerProperty,
|
||||
const PickerTextProperties& properties, bool useMilitaryTime);
|
||||
|
||||
static bool switchFlag_;
|
||||
private:
|
||||
static RefPtr<FrameNode> CreateStackNode();
|
||||
static RefPtr<FrameNode> CreateButtonNode();
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2022-2023 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
|
||||
@ -31,7 +31,11 @@
|
||||
|
||||
namespace OHOS::Ace::NG {
|
||||
namespace {
|
||||
constexpr int32_t SINGLE_CHILD_SIZE = 1;
|
||||
constexpr int32_t CHILD_SIZE = 3;
|
||||
constexpr uint32_t MIN_MONTH = 1;
|
||||
constexpr uint32_t MAX_MONTH = 12;
|
||||
constexpr uint32_t MIN_DAY = 1;
|
||||
const Dimension PRESS_INTERVAL = 4.0_vp;
|
||||
const Dimension PRESS_RADIUS = 8.0_vp;
|
||||
} // namespace
|
||||
@ -86,7 +90,11 @@ void DatePickerPattern::OnModifyDone()
|
||||
auto host = GetHost();
|
||||
CHECK_NULL_VOID(host);
|
||||
InitDisabled();
|
||||
FlushColumn();
|
||||
if (ShowMonthDays()) {
|
||||
FlushMonthDaysColumn();
|
||||
} else {
|
||||
FlushColumn();
|
||||
}
|
||||
ShowTitle(GetTitleId());
|
||||
SetChangeCallback([weak = WeakClaim(this)](const RefPtr<FrameNode>& tag, bool add, uint32_t index, bool notify) {
|
||||
auto refPtr = weak.Upgrade();
|
||||
@ -122,7 +130,11 @@ void DatePickerPattern::HandleColumnChange(const RefPtr<FrameNode>& tag, bool is
|
||||
{
|
||||
CHECK_NULL_VOID(GetHost());
|
||||
std::vector<RefPtr<FrameNode>> tags;
|
||||
OnDataLinking(tag, isAdd, index, tags);
|
||||
if (ShowMonthDays()) {
|
||||
HandleMonthDaysChange(tag, isAdd, index, tags);
|
||||
} else {
|
||||
OnDataLinking(tag, isAdd, index, tags);
|
||||
}
|
||||
for (const auto& tag : tags) {
|
||||
auto iter = std::find_if(datePickerColumns_.begin(), datePickerColumns_.end(),
|
||||
[&tag](const RefPtr<FrameNode>& column) { return column->GetId() == tag->GetId(); });
|
||||
@ -358,6 +370,48 @@ void DatePickerPattern::FlushColumn()
|
||||
dayColumnPattern->FlushCurrentOptions();
|
||||
}
|
||||
|
||||
void DatePickerPattern::FlushMonthDaysColumn()
|
||||
{
|
||||
auto host = GetHost();
|
||||
CHECK_NULL_VOID(host);
|
||||
|
||||
auto children = host->GetChildren();
|
||||
if (children.size() <= SINGLE_CHILD_SIZE) {
|
||||
return;
|
||||
}
|
||||
auto iter = children.begin();
|
||||
auto monthDays = (*iter);
|
||||
CHECK_NULL_VOID(monthDays);
|
||||
iter++;
|
||||
auto year = *iter;
|
||||
CHECK_NULL_VOID(year);
|
||||
auto stackMonthDays = DynamicCast<FrameNode>(monthDays);
|
||||
auto monthDaysNode = DynamicCast<FrameNode>(stackMonthDays->GetChildAtIndex(1));
|
||||
auto stackYear = DynamicCast<FrameNode>(year);
|
||||
auto yearDaysNode = DynamicCast<FrameNode>(stackYear->GetChildAtIndex(1));
|
||||
CHECK_NULL_VOID(monthDaysNode);
|
||||
CHECK_NULL_VOID(yearDaysNode);
|
||||
auto dataPickerRowLayoutProperty = host->GetLayoutProperty<DataPickerRowLayoutProperty>();
|
||||
CHECK_NULL_VOID(dataPickerRowLayoutProperty);
|
||||
if (dataPickerRowLayoutProperty->GetLunar().value_or(false)) {
|
||||
LunarMonthDaysColumnBuilding(
|
||||
dataPickerRowLayoutProperty->GetSelectedDate().value_or(SolarToLunar(GetSelectedDate())));
|
||||
} else {
|
||||
SolarMonthDaysColumnsBuilding(
|
||||
LunarToSolar(dataPickerRowLayoutProperty->GetSelectedDate().value_or(SolarToLunar(GetSelectedDate()))));
|
||||
}
|
||||
|
||||
auto monthDaysColumnPattern = monthDaysNode->GetPattern<DatePickerColumnPattern>();
|
||||
auto yearColumnPattern = yearDaysNode->GetPattern<DatePickerColumnPattern>();
|
||||
CHECK_NULL_VOID(monthDaysColumnPattern);
|
||||
CHECK_NULL_VOID(yearColumnPattern);
|
||||
|
||||
monthDaysColumnPattern->SetShowCount(GetShowCount());
|
||||
yearColumnPattern->SetShowCount(GetShowCount());
|
||||
monthDaysColumnPattern->FlushCurrentOptions();
|
||||
yearColumnPattern->FlushCurrentOptions();
|
||||
}
|
||||
|
||||
void DatePickerPattern::FireChangeEvent(bool refresh) const
|
||||
{
|
||||
if (refresh) {
|
||||
@ -411,6 +465,36 @@ void DatePickerPattern::OnDataLinking(
|
||||
LOGE("unknown tag[%{private}d] of column.", tag->GetId());
|
||||
}
|
||||
|
||||
void DatePickerPattern::HandleMonthDaysChange(
|
||||
const RefPtr<FrameNode>& tag, bool isAdd, uint32_t index, std::vector<RefPtr<FrameNode>>& resultTags)
|
||||
{
|
||||
auto host = GetHost();
|
||||
CHECK_NULL_VOID(host);
|
||||
|
||||
auto children = host->GetChildren();
|
||||
if (children.size() <= SINGLE_CHILD_SIZE) {
|
||||
return;
|
||||
}
|
||||
auto iter = children.begin();
|
||||
auto monthDays = (*iter);
|
||||
CHECK_NULL_VOID(monthDays);
|
||||
|
||||
auto stackMonthDays = DynamicCast<FrameNode>(monthDays);
|
||||
auto monthDaysNode = DynamicCast<FrameNode>(stackMonthDays->GetChildAtIndex(1));
|
||||
if (tag != monthDaysNode) {
|
||||
LOGE("unknown tag[%{private}d] of column.", tag->GetId());
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsShowLunar()) {
|
||||
HandleLunarMonthDaysChange(isAdd, index);
|
||||
} else {
|
||||
HandleSolarMonthDaysChange(isAdd, index);
|
||||
}
|
||||
|
||||
resultTags.emplace_back(monthDaysNode);
|
||||
}
|
||||
|
||||
void DatePickerPattern::HandleDayChange(bool isAdd, uint32_t index, std::vector<RefPtr<FrameNode>>& resultTags)
|
||||
{
|
||||
auto allChildNode = GetAllChildNode();
|
||||
@ -584,6 +668,148 @@ void DatePickerPattern::HandleAddLunarDayChange(uint32_t index)
|
||||
LunarColumnsBuilding(lunarDate);
|
||||
}
|
||||
|
||||
void DatePickerPattern::HandleSolarMonthDaysChange(bool isAdd, uint32_t index)
|
||||
{
|
||||
auto host = GetHost();
|
||||
CHECK_NULL_VOID(host);
|
||||
|
||||
auto children = host->GetChildren();
|
||||
if (children.size() <= SINGLE_CHILD_SIZE) {
|
||||
return;
|
||||
}
|
||||
auto iter = children.begin();
|
||||
auto monthDays = (*iter);
|
||||
CHECK_NULL_VOID(monthDays);
|
||||
auto stackMonthDays = DynamicCast<FrameNode>(monthDays);
|
||||
CHECK_NULL_VOID(stackMonthDays);
|
||||
auto monthDaysNode = DynamicCast<FrameNode>(stackMonthDays->GetChildAtIndex(1));
|
||||
CHECK_NULL_VOID(monthDaysNode);
|
||||
auto monthDaysDatePickerColumnPattern = monthDaysNode->GetPattern<DatePickerColumnPattern>();
|
||||
CHECK_NULL_VOID(monthDaysDatePickerColumnPattern);
|
||||
|
||||
auto date = GetCurrentDate();
|
||||
|
||||
if (isAdd && index == 0) {
|
||||
// add to next year
|
||||
date.SetYear(date.GetYear() + 1); // add to next year
|
||||
if (date.GetYear() > endDateSolar_.GetYear()) {
|
||||
date.SetYear(startDateSolar_.GetYear());
|
||||
}
|
||||
}
|
||||
if (!isAdd &&
|
||||
monthDaysDatePickerColumnPattern->GetCurrentIndex() == GetOptionCount(monthDaysNode) - 1) {
|
||||
// reduce to previous year
|
||||
date.SetYear(date.GetYear() - 1);
|
||||
if (date.GetYear() < startDateSolar_.GetYear()) {
|
||||
date.SetYear(endDateSolar_.GetYear());
|
||||
}
|
||||
// reduce to previous year's last day
|
||||
date.SetMonth(MAX_MONTH);
|
||||
date.SetDay(PickerDate::GetMaxDay(date.GetYear(), date.GetMonth()));
|
||||
}
|
||||
uint32_t maxDay = PickerDate::GetMaxDay(date.GetYear(), date.GetMonth());
|
||||
if (date.GetDay() > maxDay) {
|
||||
date.SetDay(maxDay);
|
||||
}
|
||||
AdjustSolarDate(date);
|
||||
SolarMonthDaysColumnsBuilding(date);
|
||||
}
|
||||
|
||||
void DatePickerPattern::HandleLunarMonthDaysChange(bool isAdd, uint32_t index)
|
||||
{
|
||||
if (isAdd) {
|
||||
HandleAddLunarMonthDaysChange(index);
|
||||
} else {
|
||||
HandleReduceLunarMonthDaysChange(index);
|
||||
}
|
||||
}
|
||||
|
||||
void DatePickerPattern::HandleAddLunarMonthDaysChange(uint32_t index)
|
||||
{
|
||||
auto host = GetHost();
|
||||
CHECK_NULL_VOID(host);
|
||||
|
||||
auto children = host->GetChildren();
|
||||
if (children.size() <= SINGLE_CHILD_SIZE) {
|
||||
return;
|
||||
}
|
||||
auto iter = children.begin();
|
||||
auto monthDays = (*iter);
|
||||
CHECK_NULL_VOID(monthDays);
|
||||
iter++;
|
||||
auto year = *iter;
|
||||
CHECK_NULL_VOID(year);
|
||||
auto stackMonthDays = DynamicCast<FrameNode>(monthDays);
|
||||
auto monthDaysNode = DynamicCast<FrameNode>(stackMonthDays->GetChildAtIndex(1));
|
||||
auto stackYear = DynamicCast<FrameNode>(year);
|
||||
auto yearDaysNode = DynamicCast<FrameNode>(stackYear->GetChildAtIndex(1));
|
||||
CHECK_NULL_VOID(monthDaysNode);
|
||||
CHECK_NULL_VOID(yearDaysNode);
|
||||
|
||||
auto monthDaysDatePickerColumnPattern = monthDaysNode->GetPattern<DatePickerColumnPattern>();
|
||||
auto yearDatePickerColumnPattern = yearDaysNode->GetPattern<DatePickerColumnPattern>();
|
||||
|
||||
uint32_t nowLunarYear = startDateLunar_.year + yearDatePickerColumnPattern->GetCurrentIndex();
|
||||
auto lunarDate = GetCurrentLunarDateByMonthDaysColumn(nowLunarYear);
|
||||
if (index == 0) {
|
||||
lunarDate.year = lunarDate.year + 1; // add to next year
|
||||
if (lunarDate.year > endDateLunar_.year) {
|
||||
lunarDate.year = startDateLunar_.year;
|
||||
}
|
||||
lunarDate.month = 1;
|
||||
lunarDate.isLeapMonth = false;
|
||||
}
|
||||
|
||||
AdjustLunarDate(lunarDate);
|
||||
LunarMonthDaysColumnBuilding(lunarDate);
|
||||
}
|
||||
|
||||
void DatePickerPattern::HandleReduceLunarMonthDaysChange(uint32_t index)
|
||||
{
|
||||
auto host = GetHost();
|
||||
CHECK_NULL_VOID(host);
|
||||
|
||||
auto children = host->GetChildren();
|
||||
if (children.size() <= SINGLE_CHILD_SIZE) {
|
||||
return;
|
||||
}
|
||||
auto iter = children.begin();
|
||||
auto monthDays = (*iter);
|
||||
CHECK_NULL_VOID(monthDays);
|
||||
iter++;
|
||||
auto year = *iter;
|
||||
CHECK_NULL_VOID(year);
|
||||
auto stackMonthDays = DynamicCast<FrameNode>(monthDays);
|
||||
auto monthDaysNode = DynamicCast<FrameNode>(stackMonthDays->GetChildAtIndex(1));
|
||||
auto stackYear = DynamicCast<FrameNode>(year);
|
||||
auto yearDaysNode = DynamicCast<FrameNode>(stackYear->GetChildAtIndex(1));
|
||||
CHECK_NULL_VOID(monthDaysNode);
|
||||
CHECK_NULL_VOID(yearDaysNode);
|
||||
|
||||
auto monthDaysDatePickerColumnPattern = monthDaysNode->GetPattern<DatePickerColumnPattern>();
|
||||
auto yearDatePickerColumnPattern = yearDaysNode->GetPattern<DatePickerColumnPattern>();
|
||||
CHECK_NULL_VOID(monthDaysDatePickerColumnPattern);
|
||||
CHECK_NULL_VOID(yearDatePickerColumnPattern);
|
||||
|
||||
uint32_t nowLunarYear = startDateLunar_.year + yearDatePickerColumnPattern->GetCurrentIndex();
|
||||
auto lunarDate = GetCurrentLunarDateByMonthDaysColumn(nowLunarYear);
|
||||
if (monthDaysDatePickerColumnPattern->GetCurrentIndex() == GetOptionCount(monthDaysNode) - 1) {
|
||||
lunarDate.year = lunarDate.year - 1; // reduce to previous year
|
||||
if (lunarDate.year < startDateLunar_.year) {
|
||||
lunarDate.year = endDateLunar_.year;
|
||||
}
|
||||
lunarDate.month = MAX_MONTH; // set to be previous year's max month
|
||||
lunarDate.isLeapMonth = false;
|
||||
if (LunarCalculator::GetLunarLeapMonth(lunarDate.year) == 12) { // leap 12th month
|
||||
lunarDate.isLeapMonth = true;
|
||||
}
|
||||
lunarDate.day = GetLunarMaxDay(lunarDate.year, lunarDate.month, lunarDate.isLeapMonth);
|
||||
}
|
||||
|
||||
AdjustLunarDate(lunarDate);
|
||||
LunarMonthDaysColumnBuilding(lunarDate);
|
||||
}
|
||||
|
||||
void DatePickerPattern::HandleYearChange(bool isAdd, uint32_t index, std::vector<RefPtr<FrameNode>>& resultTags)
|
||||
{
|
||||
auto allChildNode = GetAllChildNode();
|
||||
@ -788,6 +1014,15 @@ void DatePickerPattern::HandleSolarYearChange(bool isAdd, uint32_t index)
|
||||
}
|
||||
|
||||
PickerDate DatePickerPattern::GetCurrentDate() const
|
||||
{
|
||||
if (ShowMonthDays()) {
|
||||
return GetCurrentDateByMonthDaysColumn();
|
||||
} else {
|
||||
return GetCurrentDateByYearMonthDayColumn();
|
||||
}
|
||||
}
|
||||
|
||||
PickerDate DatePickerPattern::GetCurrentDateByYearMonthDayColumn() const
|
||||
{
|
||||
PickerDate currentDate;
|
||||
auto host = GetHost();
|
||||
@ -835,6 +1070,112 @@ PickerDate DatePickerPattern::GetCurrentDate() const
|
||||
return LunarToSolar(GetCurrentLunarDate(lunarYear));
|
||||
}
|
||||
|
||||
PickerDate DatePickerPattern::GetCurrentDateByMonthDaysColumn() const
|
||||
{
|
||||
PickerDate currentDate;
|
||||
auto host = GetHost();
|
||||
CHECK_NULL_RETURN(host, currentDate);
|
||||
|
||||
auto children = host->GetChildren();
|
||||
if (children.size() <= SINGLE_CHILD_SIZE) {
|
||||
return currentDate;
|
||||
}
|
||||
auto iter = children.begin();
|
||||
auto monthDays = (*iter);
|
||||
CHECK_NULL_RETURN(monthDays, currentDate);
|
||||
iter++;
|
||||
auto year = *iter;
|
||||
CHECK_NULL_RETURN(year, currentDate);
|
||||
auto stackMonthDays = DynamicCast<FrameNode>(monthDays);
|
||||
auto monthDaysNode = DynamicCast<FrameNode>(stackMonthDays->GetChildAtIndex(1));
|
||||
auto stackYear = DynamicCast<FrameNode>(year);
|
||||
auto yearDaysNode = DynamicCast<FrameNode>(stackYear->GetChildAtIndex(1));
|
||||
CHECK_NULL_RETURN_NOLOG(monthDaysNode, currentDate);
|
||||
CHECK_NULL_RETURN_NOLOG(yearDaysNode, currentDate);
|
||||
|
||||
auto monthDaysDatePickerColumnPattern = monthDaysNode->GetPattern<DatePickerColumnPattern>();
|
||||
auto yearDatePickerColumnPattern = yearDaysNode->GetPattern<DatePickerColumnPattern>();
|
||||
if (!yearDatePickerColumnPattern || !monthDaysDatePickerColumnPattern) {
|
||||
LOGE("year or monthDays pattern is null.");
|
||||
return currentDate;
|
||||
}
|
||||
|
||||
if (!IsShowLunar()) {
|
||||
currentDate.SetYear(startDateSolar_.GetYear() + yearDatePickerColumnPattern->GetCurrentIndex());
|
||||
auto monthDaysIndex = monthDaysDatePickerColumnPattern->GetCurrentIndex();
|
||||
|
||||
uint32_t month = 1;
|
||||
for (; month <= 12; ++month) { // month start from 1 to 12
|
||||
uint32_t daysInMonth = PickerDate::GetMaxDay(currentDate.GetYear(), month);
|
||||
if (monthDaysIndex < daysInMonth) {
|
||||
break;
|
||||
} else {
|
||||
monthDaysIndex -= daysInMonth;
|
||||
}
|
||||
}
|
||||
currentDate.SetMonth(month);
|
||||
currentDate.SetDay(monthDaysIndex + 1); // days is index start form 0 and day start form 1.
|
||||
return currentDate;
|
||||
}
|
||||
|
||||
uint32_t lunarYear = startDateLunar_.year + yearDatePickerColumnPattern->GetCurrentIndex();
|
||||
return LunarToSolar(GetCurrentLunarDateByMonthDaysColumn(lunarYear));
|
||||
}
|
||||
|
||||
LunarDate DatePickerPattern::GetCurrentLunarDateByMonthDaysColumn(uint32_t lunarYear) const
|
||||
{
|
||||
LunarDate lunarResult;
|
||||
auto host = GetHost();
|
||||
CHECK_NULL_RETURN(host, lunarResult);
|
||||
|
||||
auto children = host->GetChildren();
|
||||
if (children.size() <= SINGLE_CHILD_SIZE) {
|
||||
return lunarResult;
|
||||
}
|
||||
auto iter = children.begin();
|
||||
auto monthDays = (*iter);
|
||||
CHECK_NULL_RETURN(monthDays, lunarResult);
|
||||
iter++;
|
||||
auto year = *iter;
|
||||
CHECK_NULL_RETURN(year, lunarResult);
|
||||
auto stackMonthDays = DynamicCast<FrameNode>(monthDays);
|
||||
auto monthDaysNode = DynamicCast<FrameNode>(stackMonthDays->GetChildAtIndex(1));
|
||||
auto stackYear = DynamicCast<FrameNode>(year);
|
||||
auto yearDaysNode = DynamicCast<FrameNode>(stackYear->GetChildAtIndex(1));
|
||||
CHECK_NULL_RETURN_NOLOG(monthDaysNode, lunarResult);
|
||||
CHECK_NULL_RETURN_NOLOG(yearDaysNode, lunarResult);
|
||||
|
||||
auto monthDaysDatePickerColumnPattern = monthDaysNode->GetPattern<DatePickerColumnPattern>();
|
||||
auto yearDatePickerColumnPattern = yearDaysNode->GetPattern<DatePickerColumnPattern>();
|
||||
if (!yearDatePickerColumnPattern || !monthDaysDatePickerColumnPattern) {
|
||||
LOGE("year or month or day pattern is null.");
|
||||
return lunarResult;
|
||||
}
|
||||
|
||||
uint32_t lunarLeapMonth = 0;
|
||||
bool hasLeapMonth = GetLunarLeapMonth(lunarYear, lunarLeapMonth);
|
||||
auto monthDaysIndex = monthDaysDatePickerColumnPattern->GetCurrentIndex();
|
||||
uint32_t month = 1;
|
||||
for (; month <= 12; ++month) { // month start from 1 to 12
|
||||
auto flag = hasLeapMonth && lunarLeapMonth == month;
|
||||
uint32_t daysInMonth = GetLunarMaxDay(lunarYear, month, flag && lunarResult.isLeapMonth);
|
||||
if (monthDaysIndex < daysInMonth) {
|
||||
break;
|
||||
} else {
|
||||
monthDaysIndex -= daysInMonth;
|
||||
}
|
||||
if (flag && !lunarResult.isLeapMonth) {
|
||||
--month;
|
||||
lunarResult.isLeapMonth = true;
|
||||
}
|
||||
}
|
||||
lunarResult.month = month;
|
||||
lunarResult.day = monthDaysIndex + 1; // day start form 1, index start from 0
|
||||
lunarResult.year = startDateLunar_.year + yearDatePickerColumnPattern->GetCurrentIndex();
|
||||
|
||||
return lunarResult;
|
||||
}
|
||||
|
||||
void DatePickerPattern::AdjustLunarDate(LunarDate& date) const
|
||||
{
|
||||
if (LunarDateCompare(date, startDateLunar_) < 0) {
|
||||
@ -901,24 +1242,8 @@ void DatePickerPattern::LunarColumnsBuilding(const LunarDate& current)
|
||||
CHECK_NULL_VOID(yearColumn);
|
||||
CHECK_NULL_VOID(monthColumn);
|
||||
CHECK_NULL_VOID(dayColumn);
|
||||
auto dataPickerRowLayoutProperty = host->GetLayoutProperty<DataPickerRowLayoutProperty>();
|
||||
CHECK_NULL_VOID(dataPickerRowLayoutProperty);
|
||||
startDateLunar_ = dataPickerRowLayoutProperty->GetStartDate().value_or(SolarToLunar(startDateSolar_));
|
||||
endDateLunar_ = dataPickerRowLayoutProperty->GetEndDate().value_or(SolarToLunar(endDateSolar_));
|
||||
|
||||
if (GetStartDateLunar().year > GetEndDateLunar().year) {
|
||||
startDateLunar_ = SolarToLunar(startDefaultDateSolar_);
|
||||
endDateLunar_ = SolarToLunar(endDefaultDateSolar_);
|
||||
}
|
||||
if (GetStartDateLunar().year == GetEndDateLunar().year && GetStartDateLunar().month > GetEndDateLunar().month) {
|
||||
startDateLunar_ = SolarToLunar(startDefaultDateSolar_);
|
||||
endDateLunar_ = SolarToLunar(endDefaultDateSolar_);
|
||||
}
|
||||
if (GetStartDateLunar().year == GetEndDateLunar().year && GetStartDateLunar().month == GetEndDateLunar().month &&
|
||||
GetStartDateLunar().day > GetEndDateLunar().day) {
|
||||
startDateLunar_ = SolarToLunar(startDefaultDateSolar_);
|
||||
endDateLunar_ = SolarToLunar(endDefaultDateSolar_);
|
||||
}
|
||||
AdjustLunarStartEndDate();
|
||||
auto startYear = startDateLunar_.year;
|
||||
auto endYear = endDateLunar_.year;
|
||||
auto startMonth = startDateLunar_.month;
|
||||
@ -1021,24 +1346,8 @@ void DatePickerPattern::SolarColumnsBuilding(const PickerDate& current)
|
||||
CHECK_NULL_VOID(yearColumn);
|
||||
CHECK_NULL_VOID(monthColumn);
|
||||
CHECK_NULL_VOID(dayColumn);
|
||||
auto dataPickerRowLayoutProperty = host->GetLayoutProperty<DataPickerRowLayoutProperty>();
|
||||
CHECK_NULL_VOID(dataPickerRowLayoutProperty);
|
||||
startDateSolar_ = LunarToSolar(dataPickerRowLayoutProperty->GetStartDate().value_or(SolarToLunar(startDateSolar_)));
|
||||
endDateSolar_ = LunarToSolar(dataPickerRowLayoutProperty->GetEndDate().value_or(SolarToLunar(endDateSolar_)));
|
||||
|
||||
if (startDateSolar_.GetYear() > endDateSolar_.GetYear()) {
|
||||
startDateSolar_ = startDefaultDateSolar_;
|
||||
endDateSolar_ = endDefaultDateSolar_;
|
||||
}
|
||||
if (startDateSolar_.GetYear() == endDateSolar_.GetYear() && startDateSolar_.GetMonth() > endDateSolar_.GetMonth()) {
|
||||
startDateSolar_ = startDefaultDateSolar_;
|
||||
endDateSolar_ = endDefaultDateSolar_;
|
||||
}
|
||||
if (startDateSolar_.GetYear() == endDateSolar_.GetYear() &&
|
||||
startDateSolar_.GetMonth() == endDateSolar_.GetMonth() && startDateSolar_.GetDay() > endDateSolar_.GetDay()) {
|
||||
startDateSolar_ = startDefaultDateSolar_;
|
||||
endDateSolar_ = endDefaultDateSolar_;
|
||||
}
|
||||
AdjustSolarStartEndDate();
|
||||
auto startYear = startDateSolar_.GetYear();
|
||||
auto endYear = endDateSolar_.GetYear();
|
||||
auto startMonth = startDateSolar_.GetMonth();
|
||||
@ -1107,6 +1416,223 @@ void DatePickerPattern::SolarColumnsBuilding(const PickerDate& current)
|
||||
SetShowLunar(false);
|
||||
}
|
||||
|
||||
void DatePickerPattern::LunarMonthDaysColumnBuilding(const LunarDate& current)
|
||||
{
|
||||
RefPtr<FrameNode> monthDaysColumn;
|
||||
RefPtr<FrameNode> yearColumn;
|
||||
auto host = GetHost();
|
||||
CHECK_NULL_VOID(host);
|
||||
|
||||
auto children = host->GetChildren();
|
||||
if (children.size() <= SINGLE_CHILD_SIZE) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto iter = children.begin();
|
||||
auto monthDays = (*iter);
|
||||
CHECK_NULL_VOID(monthDays);
|
||||
iter++;
|
||||
auto year = *iter;
|
||||
CHECK_NULL_VOID(year);
|
||||
auto stackMonthDays = DynamicCast<FrameNode>(monthDays);
|
||||
auto monthDaysNode = DynamicCast<FrameNode>(stackMonthDays->GetChildAtIndex(1));
|
||||
auto stackYear = DynamicCast<FrameNode>(year);
|
||||
auto yearDaysNode = DynamicCast<FrameNode>(stackYear->GetChildAtIndex(1));
|
||||
CHECK_NULL_VOID(monthDaysNode);
|
||||
CHECK_NULL_VOID(yearDaysNode);
|
||||
|
||||
monthDaysColumn = GetColumn(monthDaysNode->GetId());
|
||||
yearColumn = GetColumn(yearDaysNode->GetId());
|
||||
CHECK_NULL_VOID(monthDaysColumn);
|
||||
CHECK_NULL_VOID(yearColumn);
|
||||
|
||||
AdjustLunarStartEndDate();
|
||||
|
||||
auto startYear = startDateLunar_.year;
|
||||
auto endYear = endDateLunar_.year;
|
||||
|
||||
options_[yearColumn].clear();
|
||||
for (uint32_t index = startYear; index <= endYear; ++index) {
|
||||
if (current.year == index) {
|
||||
auto datePickerColumnPattern = yearColumn->GetPattern<DatePickerColumnPattern>();
|
||||
CHECK_NULL_VOID(datePickerColumnPattern);
|
||||
datePickerColumnPattern->SetCurrentIndex(options_[yearColumn].size());
|
||||
}
|
||||
auto yearTextValue = GetYearFormatString(index);
|
||||
options_[yearColumn].emplace_back(yearTextValue);
|
||||
}
|
||||
|
||||
FillLunarMonthDaysOptions(current, monthDaysColumn);
|
||||
|
||||
auto yearColumnPattern = yearColumn->GetPattern<DatePickerColumnPattern>();
|
||||
auto monthDaysColumnPattern = monthDaysColumn->GetPattern<DatePickerColumnPattern>();
|
||||
CHECK_NULL_VOID(yearColumnPattern);
|
||||
CHECK_NULL_VOID(monthDaysColumnPattern);
|
||||
yearColumnPattern->SetOptions(GetOptions());
|
||||
monthDaysColumnPattern->SetOptions(GetOptions());
|
||||
|
||||
SetShowLunar(true);
|
||||
}
|
||||
|
||||
void DatePickerPattern::SolarMonthDaysColumnsBuilding(const PickerDate& current)
|
||||
{
|
||||
RefPtr<FrameNode> monthDaysColumn;
|
||||
RefPtr<FrameNode> yearColumn;
|
||||
auto host = GetHost();
|
||||
CHECK_NULL_VOID(host);
|
||||
|
||||
auto children = host->GetChildren();
|
||||
if (children.size() <= SINGLE_CHILD_SIZE) {
|
||||
return;
|
||||
}
|
||||
auto iter = children.begin();
|
||||
auto monthDays = (*iter);
|
||||
CHECK_NULL_VOID(monthDays);
|
||||
iter++;
|
||||
auto year = *iter;
|
||||
CHECK_NULL_VOID(year);
|
||||
auto stackMonthDays = DynamicCast<FrameNode>(monthDays);
|
||||
auto monthDaysNode = DynamicCast<FrameNode>(stackMonthDays->GetChildAtIndex(1));
|
||||
auto stackYear = DynamicCast<FrameNode>(year);
|
||||
auto yearDaysNode = DynamicCast<FrameNode>(stackYear->GetChildAtIndex(1));
|
||||
monthDaysColumn = GetColumn(monthDaysNode->GetId());
|
||||
yearColumn = GetColumn(yearDaysNode->GetId());
|
||||
CHECK_NULL_VOID(monthDaysColumn);
|
||||
CHECK_NULL_VOID(yearColumn);
|
||||
|
||||
AdjustSolarStartEndDate();
|
||||
FillSolarYearOptions(current, yearColumn);
|
||||
|
||||
options_[monthDaysColumn].clear();
|
||||
for (uint32_t index = MIN_MONTH; index <= MAX_MONTH; ++index) {
|
||||
uint32_t maxDay = PickerDate::GetMaxDay(current.GetYear(), index);
|
||||
auto monthTextValue = GetMonthFormatString(index, false, false);
|
||||
for (uint32_t dayIndex = MIN_DAY; dayIndex <= maxDay; ++dayIndex) {
|
||||
if (index == current.GetMonth() && dayIndex == current.GetDay()) {
|
||||
auto datePickerColumnPattern = monthDaysColumn->GetPattern<DatePickerColumnPattern>();
|
||||
CHECK_NULL_VOID(datePickerColumnPattern);
|
||||
datePickerColumnPattern->SetCurrentIndex(options_[monthDaysColumn].size());
|
||||
}
|
||||
auto dayTextValue = GetDayFormatString(dayIndex, false);
|
||||
options_[monthDaysColumn].emplace_back(monthTextValue + dayTextValue);
|
||||
}
|
||||
}
|
||||
|
||||
auto yearColumnPattern = yearColumn->GetPattern<DatePickerColumnPattern>();
|
||||
auto monthDaysColumnPattern = monthDaysColumn->GetPattern<DatePickerColumnPattern>();
|
||||
CHECK_NULL_VOID(yearColumnPattern);
|
||||
CHECK_NULL_VOID(monthDaysColumnPattern);
|
||||
yearColumnPattern->SetOptions(GetOptions());
|
||||
monthDaysColumnPattern->SetOptions(GetOptions());
|
||||
|
||||
SetShowLunar(false);
|
||||
}
|
||||
|
||||
void DatePickerPattern::FillSolarYearOptions(const PickerDate& current, RefPtr<FrameNode>& yearColumn)
|
||||
{
|
||||
options_[yearColumn].clear();
|
||||
for (uint32_t year = startDateSolar_.GetYear(); year <= endDateSolar_.GetYear(); ++year) {
|
||||
if (year == current.GetYear()) {
|
||||
auto datePickerColumnPattern = yearColumn->GetPattern<DatePickerColumnPattern>();
|
||||
CHECK_NULL_VOID(datePickerColumnPattern);
|
||||
datePickerColumnPattern->SetCurrentIndex(options_[yearColumn].size());
|
||||
}
|
||||
auto yearTextValue = GetYearFormatString(year);
|
||||
options_[yearColumn].emplace_back(yearTextValue);
|
||||
}
|
||||
}
|
||||
|
||||
void DatePickerPattern::FillLunarMonthDaysOptions(const LunarDate& current, RefPtr<FrameNode>& monthDaysColumn)
|
||||
{
|
||||
uint32_t startMonth = 1;
|
||||
uint32_t endMonth = 12;
|
||||
uint32_t startDay = 1;
|
||||
|
||||
uint32_t lunarLeapMonth = 0;
|
||||
bool hasLeapMonth = GetLunarLeapMonth(current.year, lunarLeapMonth);
|
||||
options_[monthDaysColumn].clear();
|
||||
|
||||
for (uint32_t index = startMonth; index <= endMonth; ++index) {
|
||||
uint32_t maxDay = GetLunarMaxDay(current.year, index, false);
|
||||
auto monthTextValue = GetMonthFormatString(index, true, false);
|
||||
for (uint32_t dayIndex = startDay; dayIndex <= maxDay; ++dayIndex) {
|
||||
if (!current.isLeapMonth && current.month == index && current.day == dayIndex) {
|
||||
auto datePickerColumnPattern = monthDaysColumn->GetPattern<DatePickerColumnPattern>();
|
||||
CHECK_NULL_VOID(datePickerColumnPattern);
|
||||
datePickerColumnPattern->SetCurrentIndex(options_[monthDaysColumn].size());
|
||||
}
|
||||
auto dayTextValue = GetDayFormatString(dayIndex, true);
|
||||
options_[monthDaysColumn].emplace_back(monthTextValue + dayTextValue);
|
||||
}
|
||||
|
||||
if (!hasLeapMonth || lunarLeapMonth != index) {
|
||||
continue;
|
||||
}
|
||||
|
||||
maxDay = GetLunarMaxDay(current.year, index, true);
|
||||
monthTextValue = GetMonthFormatString(index, true, true);
|
||||
for (uint32_t dayIndex = startDay; dayIndex <= maxDay; ++dayIndex) {
|
||||
if (current.isLeapMonth && current.month == index && current.day == dayIndex) {
|
||||
auto datePickerColumnPattern = monthDaysColumn->GetPattern<DatePickerColumnPattern>();
|
||||
CHECK_NULL_VOID(datePickerColumnPattern);
|
||||
datePickerColumnPattern->SetCurrentIndex(options_[monthDaysColumn].size());
|
||||
}
|
||||
auto dayTextValue = GetDayFormatString(dayIndex, true);
|
||||
options_[monthDaysColumn].emplace_back(monthTextValue + dayTextValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DatePickerPattern::AdjustSolarStartEndDate()
|
||||
{
|
||||
auto host = GetHost();
|
||||
CHECK_NULL_VOID(host);
|
||||
|
||||
auto dataPickerRowLayoutProperty = host->GetLayoutProperty<DataPickerRowLayoutProperty>();
|
||||
CHECK_NULL_VOID(dataPickerRowLayoutProperty);
|
||||
startDateSolar_ = LunarToSolar(dataPickerRowLayoutProperty->GetStartDate().value_or(SolarToLunar(startDateSolar_)));
|
||||
endDateSolar_ = LunarToSolar(dataPickerRowLayoutProperty->GetEndDate().value_or(SolarToLunar(endDateSolar_)));
|
||||
|
||||
if (startDateSolar_.GetYear() > endDateSolar_.GetYear()) {
|
||||
startDateSolar_ = startDefaultDateSolar_;
|
||||
endDateSolar_ = endDefaultDateSolar_;
|
||||
}
|
||||
if (startDateSolar_.GetYear() == endDateSolar_.GetYear() && startDateSolar_.GetMonth() > endDateSolar_.GetMonth()) {
|
||||
startDateSolar_ = startDefaultDateSolar_;
|
||||
endDateSolar_ = endDefaultDateSolar_;
|
||||
}
|
||||
if (startDateSolar_.GetYear() == endDateSolar_.GetYear() &&
|
||||
startDateSolar_.GetMonth() == endDateSolar_.GetMonth() && startDateSolar_.GetDay() > endDateSolar_.GetDay()) {
|
||||
startDateSolar_ = startDefaultDateSolar_;
|
||||
endDateSolar_ = endDefaultDateSolar_;
|
||||
}
|
||||
}
|
||||
|
||||
void DatePickerPattern::AdjustLunarStartEndDate()
|
||||
{
|
||||
auto host = GetHost();
|
||||
CHECK_NULL_VOID(host);
|
||||
|
||||
auto dataPickerRowLayoutProperty = host->GetLayoutProperty<DataPickerRowLayoutProperty>();
|
||||
CHECK_NULL_VOID(dataPickerRowLayoutProperty);
|
||||
startDateLunar_ = dataPickerRowLayoutProperty->GetStartDate().value_or(SolarToLunar(startDateSolar_));
|
||||
endDateLunar_ = dataPickerRowLayoutProperty->GetEndDate().value_or(SolarToLunar(endDateSolar_));
|
||||
|
||||
if (GetStartDateLunar().year > GetEndDateLunar().year) {
|
||||
startDateLunar_ = SolarToLunar(startDefaultDateSolar_);
|
||||
endDateLunar_ = SolarToLunar(endDefaultDateSolar_);
|
||||
}
|
||||
if (GetStartDateLunar().year == GetEndDateLunar().year && GetStartDateLunar().month > GetEndDateLunar().month) {
|
||||
startDateLunar_ = SolarToLunar(startDefaultDateSolar_);
|
||||
endDateLunar_ = SolarToLunar(endDefaultDateSolar_);
|
||||
}
|
||||
if (GetStartDateLunar().year == GetEndDateLunar().year && GetStartDateLunar().month == GetEndDateLunar().month &&
|
||||
GetStartDateLunar().day > GetEndDateLunar().day) {
|
||||
startDateLunar_ = SolarToLunar(startDefaultDateSolar_);
|
||||
endDateLunar_ = SolarToLunar(endDefaultDateSolar_);
|
||||
}
|
||||
}
|
||||
|
||||
bool DatePickerPattern::GetLunarLeapMonth(uint32_t year, uint32_t& outLeapMonth) const
|
||||
{
|
||||
auto leapMonth = LunarCalculator::GetLunarLeapMonth(year);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2022-2023 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
|
||||
@ -79,6 +79,10 @@ public:
|
||||
|
||||
void LunarColumnsBuilding(const LunarDate& current);
|
||||
|
||||
void SolarMonthDaysColumnsBuilding(const PickerDate& current);
|
||||
|
||||
void LunarMonthDaysColumnBuilding(const LunarDate& current);
|
||||
|
||||
void HandleYearChange(bool isAdd, uint32_t index, std::vector<RefPtr<FrameNode>>& resultTags);
|
||||
|
||||
void HandleMonthChange(bool isAdd, uint32_t index, std::vector<RefPtr<FrameNode>>& resultTags);
|
||||
@ -103,6 +107,16 @@ public:
|
||||
|
||||
void HandleSolarDayChange(bool isAdd, uint32_t index);
|
||||
|
||||
void HandleSolarMonthDaysChange(bool isAdd, uint32_t index);
|
||||
|
||||
void HandleLunarMonthDaysChange(bool isAdd, uint32_t index);
|
||||
|
||||
void HandleAddLunarMonthDaysChange(uint32_t index);
|
||||
|
||||
void HandleReduceLunarMonthDaysChange(uint32_t index);
|
||||
|
||||
LunarDate GetCurrentLunarDateByMonthDaysColumn(uint32_t lunarYear) const;
|
||||
|
||||
PickerDate GetCurrentDate() const;
|
||||
|
||||
void SetEventCallback(EventCallback&& value);
|
||||
@ -111,6 +125,8 @@ public:
|
||||
|
||||
void FlushColumn();
|
||||
|
||||
void FlushMonthDaysColumn();
|
||||
|
||||
void AdjustLunarDate(LunarDate& date) const;
|
||||
|
||||
int LunarDateCompare(const LunarDate& left, const LunarDate& right) const;
|
||||
@ -129,6 +145,11 @@ public:
|
||||
datePickerColumns_.emplace_back(value);
|
||||
}
|
||||
|
||||
void ClearColumn()
|
||||
{
|
||||
datePickerColumns_.clear();
|
||||
}
|
||||
|
||||
void SetShowLunar(bool value)
|
||||
{
|
||||
lunar_ = value;
|
||||
@ -139,6 +160,16 @@ public:
|
||||
return lunar_;
|
||||
}
|
||||
|
||||
void SetShowMonthDaysFlag(bool value)
|
||||
{
|
||||
showMonthDays_ = value;
|
||||
}
|
||||
|
||||
bool ShowMonthDays() const
|
||||
{
|
||||
return showMonthDays_;
|
||||
}
|
||||
|
||||
const EventMarker& GetDialogAcceptEvent() const
|
||||
{
|
||||
return OnDialogAccept_;
|
||||
@ -234,6 +265,9 @@ public:
|
||||
void OnDataLinking(
|
||||
const RefPtr<FrameNode>& tag, bool isAdd, uint32_t index, std::vector<RefPtr<FrameNode>>& resultTags);
|
||||
|
||||
void HandleMonthDaysChange(
|
||||
const RefPtr<FrameNode>& tag, bool isAdd, uint32_t index, std::vector<RefPtr<FrameNode>>& resultTags);
|
||||
|
||||
std::string GetSelectedObject(bool isColumnChange, int status = -1) const
|
||||
{
|
||||
auto date = selectedDate_;
|
||||
@ -367,11 +401,33 @@ public:
|
||||
return dayId_.value();
|
||||
}
|
||||
|
||||
bool HasMonthDaysNode() const
|
||||
{
|
||||
return monthDaysId_.has_value();
|
||||
}
|
||||
|
||||
int32_t GetMonthDaysId()
|
||||
{
|
||||
if (!monthDaysId_.has_value()) {
|
||||
monthDaysId_ = ElementRegister::GetInstance()->MakeUniqueId();
|
||||
}
|
||||
return monthDaysId_.value();
|
||||
}
|
||||
|
||||
bool HasTitleNode() const
|
||||
{
|
||||
return titleId_.has_value();
|
||||
}
|
||||
|
||||
bool SetTitleId(const int32_t id)
|
||||
{
|
||||
if (HasTitleNode()) {
|
||||
return false;
|
||||
}
|
||||
titleId_ = id;
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t GetTitleId()
|
||||
{
|
||||
if (!titleId_.has_value()) {
|
||||
@ -446,6 +502,13 @@ private:
|
||||
bool OnKeyEvent(const KeyEvent& event);
|
||||
bool HandleDirectionKey(KeyCode code);
|
||||
|
||||
PickerDate GetCurrentDateByMonthDaysColumn() const;
|
||||
PickerDate GetCurrentDateByYearMonthDayColumn() const;
|
||||
void FillSolarYearOptions(const PickerDate& current, RefPtr<FrameNode>& yearColumn);
|
||||
void FillLunarMonthDaysOptions(const LunarDate& current, RefPtr<FrameNode>& monthDaysColumn);
|
||||
void AdjustSolarStartEndDate();
|
||||
void AdjustLunarStartEndDate();
|
||||
|
||||
RefPtr<ClickEvent> clickEventListener_;
|
||||
bool enabled_ = true;
|
||||
int32_t focusKeyID_ = 0;
|
||||
@ -453,9 +516,11 @@ private:
|
||||
uint32_t showCount_ = 0;
|
||||
std::vector<RefPtr<FrameNode>> datePickerColumns_;
|
||||
bool lunar_ = false;
|
||||
bool showMonthDays_ = false;
|
||||
std::optional<int32_t> yearId_;
|
||||
std::optional<int32_t> monthId_;
|
||||
std::optional<int32_t> dayId_;
|
||||
std::optional<int32_t> monthDaysId_;
|
||||
std::optional<int32_t> dateNodeId_;
|
||||
std::optional<int32_t> titleId_;
|
||||
std::optional<int32_t> ButtonTitleId_;
|
||||
|
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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_PICKER_PICKER_TYPE_DEFINE_H
|
||||
#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_PICKER_PICKER_TYPE_DEFINE_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "core/components/picker/picker_data.h"
|
||||
|
||||
namespace OHOS::Ace::NG {
|
||||
// update flag of text properties
|
||||
const uint32_t FLAG_DISAPPEAR_COLOR = 0x0001;
|
||||
const uint32_t FLAG_COLOR = 0x0002;
|
||||
const uint32_t FLAG_SELECTED_COLOR = 0x0004;
|
||||
const uint32_t FLAG_DISAPPEAR_FONTSIZE = 0x0008;
|
||||
const uint32_t FLAG_FONTSIZE = 0x0010;
|
||||
const uint32_t FLAG_SELECTED_FONTSIZE = 0x0020;
|
||||
const uint32_t FLAG_DISAPPEAR_WEIGHT = 0x0040;
|
||||
const uint32_t FLAG_WEIGHT = 0x0080;
|
||||
const uint32_t FLAG_SELECTED_WEIGHT = 0x0100;
|
||||
struct PickerTextStyle {
|
||||
std::optional<Color> textColor;
|
||||
std::optional<Dimension> fontSize;
|
||||
std::optional<FontWeight> fontWeight;
|
||||
};
|
||||
struct PickerTextProperties {
|
||||
Color disappearColor_;
|
||||
Color color_;
|
||||
Color selectedColor_;
|
||||
Dimension disappearFontSize_;
|
||||
Dimension fontSize_;
|
||||
Dimension selectedFontSize_;
|
||||
FontWeight disappearWeight_;
|
||||
FontWeight weight_;
|
||||
FontWeight selectedWeight_;
|
||||
uint32_t hasValueFlag = 0;
|
||||
};
|
||||
|
||||
// textpicker column kind
|
||||
const uint32_t ICON = 0x01;
|
||||
const uint32_t TEXT = 0x02;
|
||||
const uint32_t MIXTURE = 0x03;
|
||||
|
||||
struct RangeContent {
|
||||
std::string icon_;
|
||||
std::string text_;
|
||||
};
|
||||
|
||||
struct DatePickerSettingData {
|
||||
bool isLunar;
|
||||
bool showTime;
|
||||
bool useMilitary;
|
||||
std::map<std::string, PickerDate> datePickerProperty;
|
||||
std::map<std::string, PickerTime> timePickerProperty;
|
||||
PickerTextProperties properties;
|
||||
};
|
||||
|
||||
struct TextPickerSettingData {
|
||||
std::vector<RangeContent> rangeVector;
|
||||
uint32_t selected;
|
||||
uint32_t columnKind;
|
||||
Dimension height;
|
||||
PickerTextProperties properties;
|
||||
};
|
||||
|
||||
struct TimePickerSettingData {
|
||||
bool isUseMilitaryTime;
|
||||
PickerTextProperties properties;
|
||||
};
|
||||
} // namespace OHOS::Ace::NG
|
||||
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_PICKER_PICKER_TYPE_DEFINE_H
|
@ -32,6 +32,7 @@ group("pattern_unittest") {
|
||||
"dragBar:dragBar_pattern_test_ng",
|
||||
"flex:flex_pattern_unit_test",
|
||||
"focusHub:focusHub_pattern_test_ng",
|
||||
"form:form_pattern_test_ng",
|
||||
"gauge:gauge_pattern_test_ng",
|
||||
"gesture:gesture_pattern_test_ng",
|
||||
"grid:grid_pattern_test_ng",
|
||||
@ -54,9 +55,7 @@ group("pattern_unittest") {
|
||||
"overlay:overlay_manager_test_ng",
|
||||
"panel:panel_pattern_test_ng",
|
||||
"patternlock:patternlock_pattern_test_ng",
|
||||
|
||||
# "picker:picker_pattern_test_ng",
|
||||
"form:form_pattern_test_ng",
|
||||
"picker:picker_pattern_test_ng",
|
||||
"plugin:plugin_pattern_test_ng",
|
||||
"progress:progress_pattern_test_ng",
|
||||
"qrcode:qrcode_pattern_test_ng",
|
||||
|
@ -85,7 +85,6 @@ ohos_unittest("picker_pattern_test_ng") {
|
||||
"$ace_root/frameworks/core/components_ng/pattern/picker/datepicker_dialog_view.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/pattern/picker/datepicker_paint_method.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/pattern/picker/datepicker_pattern.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/pattern/picker/datepicker_view.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/pattern/picker/toss_animation_controller.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/pattern/select_overlay/select_overlay_layout_algorithm.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/pattern/select_overlay/select_overlay_paint_method.cpp",
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -56,9 +56,9 @@ RefPtr<FrameNode> OverlayManager::ShowDialog(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void OverlayManager::ShowDateDialog(const DialogProperties& dialogProps,
|
||||
std::map<std::string, PickerDate> datePickerProperty, bool isLunar,
|
||||
std::map<std::string, NG::DialogEvent> dialogEvent, std::map<std::string, NG::DialogGestureEvent> dialogCancelEvent)
|
||||
void OverlayManager::ShowDateDialog(const DialogProperties& dialogProps, const DatePickerSettingData& settingData,
|
||||
std::map<std::string, NG::DialogEvent> dialogEvent,
|
||||
std::map<std::string, NG::DialogGestureEvent> dialogCancelEvent)
|
||||
{}
|
||||
|
||||
void OverlayManager::ShowTimeDialog(const DialogProperties& dialogProps,
|
||||
|
Loading…
Reference in New Issue
Block a user