mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2025-01-08 09:53:20 +00:00
!34801 CalendarPicker适老化适配UX修改以及TDD
Merge pull request !34801 from sunjiakun/CalendarPicker
This commit is contained in:
commit
de847fd586
@ -26,6 +26,7 @@ namespace OHOS::Ace::NG {
|
||||
namespace {
|
||||
constexpr int32_t CALENDAR_WEEK_DAYS = 7;
|
||||
constexpr Dimension CALENDAR_DISTANCE_ADJUST_FOCUSED_EVENT = 4.0_vp;
|
||||
constexpr double DEVICE_HEIGHT_LIMIT = 640.0;
|
||||
} // namespace
|
||||
void CalendarMonthPattern::OnAttachToFrameNode()
|
||||
{
|
||||
@ -48,7 +49,8 @@ Dimension CalendarMonthPattern::GetDaySize(const RefPtr<CalendarTheme>& theme)
|
||||
auto pipeline = GetHost()->GetContext();
|
||||
CHECK_NULL_RETURN(pipeline, theme->GetCalendarPickerDayWidthOrHeight());
|
||||
auto fontSizeScale = pipeline->GetFontScale();
|
||||
if (fontSizeScale < theme->GetCalendarPickerLargeScale()) {
|
||||
if (fontSizeScale < theme->GetCalendarPickerLargeScale() ||
|
||||
Dimension(SystemProperties::GetDeviceHeight()).ConvertToVp() < DEVICE_HEIGHT_LIMIT) {
|
||||
return theme->GetCalendarPickerDayWidthOrHeight();
|
||||
} else {
|
||||
return theme->GetCalendarPickerDayLargeWidthOrHeight();
|
||||
@ -88,12 +90,6 @@ void CalendarMonthPattern::SetColRowSpace()
|
||||
}
|
||||
|
||||
auto rowCount = dataSize / CALENDAR_WEEK_DAYS;
|
||||
|
||||
auto pipeline = GetHost()->GetContext();
|
||||
CHECK_NULL_VOID(pipeline);
|
||||
if (pipeline->GetFontScale() >= theme->GetCalendarPickerLargerScale()) {
|
||||
calendarDaySize = theme->GetCalendarPickerDayLargerHeight();
|
||||
}
|
||||
space = (height - calendarDaySize.ConvertToPx() * (rowCount + 1)) / rowCount;
|
||||
if (!Positive(space)) {
|
||||
return;
|
||||
|
@ -31,6 +31,9 @@
|
||||
#include "core/components_ng/pattern/text/text_pattern.h"
|
||||
|
||||
namespace OHOS::Ace::NG {
|
||||
namespace {
|
||||
constexpr double DEVICE_HEIGHT_LIMIT = 640.0;
|
||||
} // namespace
|
||||
void CalendarPattern::OnAttachToFrameNode()
|
||||
{
|
||||
auto host = GetHost();
|
||||
@ -381,7 +384,8 @@ void CalendarPattern::UpdateTitleNode()
|
||||
RefPtr<CalendarTheme> theme = pipelineContext->GetTheme<CalendarTheme>();
|
||||
CHECK_NULL_VOID(theme);
|
||||
auto fontSizeScale = pipelineContext->GetFontScale();
|
||||
if (fontSizeScale < theme->GetCalendarPickerLargeScale()) {
|
||||
if (fontSizeScale < theme->GetCalendarPickerLargeScale() ||
|
||||
Dimension(SystemProperties::GetDeviceHeight()).ConvertToVp() < DEVICE_HEIGHT_LIMIT) {
|
||||
textLayoutProperty->UpdateFontSize(theme->GetCalendarTitleFontSize());
|
||||
} else {
|
||||
textLayoutProperty->UpdateMaxLines(2);
|
||||
|
@ -49,6 +49,7 @@ constexpr size_t CANCEL_BUTTON_FONT_COLOR_INDEX = 0;
|
||||
constexpr size_t CANCEL_BUTTON_BACKGROUND_COLOR_INDEX = 1;
|
||||
constexpr size_t ACCEPT_BUTTON_FONT_COLOR_INDEX = 2;
|
||||
constexpr size_t ACCEPT_BUTTON_BACKGROUND_COLOR_INDEX = 3;
|
||||
constexpr double DEVICE_HEIGHT_LIMIT = 640.0;
|
||||
} // namespace
|
||||
RefPtr<FrameNode> CalendarDialogView::Show(const DialogProperties& dialogProperties,
|
||||
const CalendarSettingData& settingData, const std::vector<ButtonInfo>& buttonInfos,
|
||||
@ -159,7 +160,8 @@ void CalendarDialogView::SetTitleIdealSize(
|
||||
auto pipeline = PipelineBase::GetCurrentContext();
|
||||
CHECK_NULL_VOID(pipeline);
|
||||
auto fontSizeScale = pipeline->GetFontScale();
|
||||
if (fontSizeScale < theme->GetCalendarPickerLargeScale()) {
|
||||
if (fontSizeScale < theme->GetCalendarPickerLargeScale() ||
|
||||
Dimension(SystemProperties::GetDeviceHeight()).ConvertToVp() < DEVICE_HEIGHT_LIMIT) {
|
||||
layoutProps->UpdateUserDefinedIdealSize(CalcSize(std::nullopt, CalcLength(theme->GetCalendarTitleRowHeight())));
|
||||
} else if (fontSizeScale >= theme->GetCalendarPickerLargerScale()) {
|
||||
layoutProps->UpdateUserDefinedIdealSize(
|
||||
@ -295,7 +297,8 @@ void CalendarDialogView::SetCalendarIdealSize(
|
||||
auto pipeline = PipelineBase::GetCurrentContext();
|
||||
CHECK_NULL_VOID(pipeline);
|
||||
auto fontSizeScale = pipeline->GetFontScale();
|
||||
if (fontSizeScale < theme->GetCalendarPickerLargeScale()) {
|
||||
if (fontSizeScale < theme->GetCalendarPickerLargeScale() ||
|
||||
Dimension(SystemProperties::GetDeviceHeight()).ConvertToVp() < DEVICE_HEIGHT_LIMIT) {
|
||||
calendarLayoutProperty->UpdateUserDefinedIdealSize(CalcSize(
|
||||
std::nullopt, CalcLength(theme->GetCalendarContainerHeight() + CALENDAR_DISTANCE_ADJUST_FOCUSED_EVENT)));
|
||||
} else if (fontSizeScale >= theme->GetCalendarPickerLargerScale()) {
|
||||
@ -463,7 +466,8 @@ RefPtr<FrameNode> CalendarDialogView::CreateButtonNode(bool isConfirm, const std
|
||||
Localization::GetInstance()->GetEntryLetters(isConfirm ? "common.ok" : "common.cancel"));
|
||||
|
||||
auto fontSizeScale = pipeline->GetFontScale();
|
||||
if (fontSizeScale < calendarTheme->GetCalendarPickerLargeScale()) {
|
||||
if (fontSizeScale < calendarTheme->GetCalendarPickerLargeScale() ||
|
||||
Dimension(SystemProperties::GetDeviceHeight()).ConvertToVp() < DEVICE_HEIGHT_LIMIT) {
|
||||
textLayoutProperty->UpdateFontSize(pickerTheme->GetOptionStyle(false, false).GetFontSize());
|
||||
} else if (fontSizeScale >= calendarTheme->GetCalendarPickerLargerScale()) {
|
||||
textLayoutProperty->UpdateFontSize(calendarTheme->GetCalendarDayLargerFontSize());
|
||||
@ -521,15 +525,13 @@ void CalendarDialogView::UpdateButtonLayoutProperty(const RefPtr<FrameNode>& but
|
||||
}
|
||||
|
||||
auto fontSizeScale = pipeline->GetFontScale();
|
||||
if (fontSizeScale < calendarTheme->GetCalendarPickerLargeScale()) {
|
||||
buttonLayoutProperty->UpdateUserDefinedIdealSize(CalcSize(
|
||||
width, CalcLength(calendarTheme->GetCalendarActionRowHeight())));
|
||||
} else if (fontSizeScale >= calendarTheme->GetCalendarPickerLargerScale()) {
|
||||
buttonLayoutProperty->UpdateUserDefinedIdealSize(CalcSize(
|
||||
width, CalcLength(calendarTheme->GetCalendarActionLargeRowHeight())));
|
||||
if (fontSizeScale >= calendarTheme->GetCalendarPickerLargerScale() &&
|
||||
Dimension(SystemProperties::GetDeviceHeight()).ConvertToVp() >= DEVICE_HEIGHT_LIMIT) {
|
||||
buttonLayoutProperty->UpdateUserDefinedIdealSize(
|
||||
CalcSize(width, CalcLength(calendarTheme->GetCalendarActionLargeRowHeight())));
|
||||
} else {
|
||||
buttonLayoutProperty->UpdateUserDefinedIdealSize(CalcSize(
|
||||
width, CalcLength(calendarTheme->GetCalendarActionRowHeight())));
|
||||
buttonLayoutProperty->UpdateUserDefinedIdealSize(
|
||||
CalcSize(width, CalcLength(calendarTheme->GetCalendarActionRowHeight())));
|
||||
}
|
||||
}
|
||||
|
||||
@ -757,7 +759,8 @@ void CalendarDialogView::SetCalendarPaintProperties(const CalendarSettingData& s
|
||||
|
||||
auto fontSizeScale = pipelineContext->GetFontScale();
|
||||
Dimension defaultDayRadius;
|
||||
if (fontSizeScale < theme->GetCalendarPickerLargeScale()) {
|
||||
if (fontSizeScale < theme->GetCalendarPickerLargeScale() ||
|
||||
Dimension(SystemProperties::GetDeviceHeight()).ConvertToVp() < DEVICE_HEIGHT_LIMIT) {
|
||||
ACE_UPDATE_PAINT_PROPERTY(CalendarPaintProperty, DayHeight, theme->GetCalendarPickerDayWidthOrHeight());
|
||||
ACE_UPDATE_PAINT_PROPERTY(CalendarPaintProperty, DayWidth, theme->GetCalendarPickerDayWidthOrHeight());
|
||||
ACE_UPDATE_PAINT_PROPERTY(CalendarPaintProperty, DayFontSize, theme->GetCalendarDayFontSize());
|
||||
@ -765,22 +768,19 @@ void CalendarDialogView::SetCalendarPaintProperties(const CalendarSettingData& s
|
||||
ACE_UPDATE_PAINT_PROPERTY(CalendarPaintProperty, WeekWidth, theme->GetCalendarPickerDayWidthOrHeight());
|
||||
ACE_UPDATE_PAINT_PROPERTY(CalendarPaintProperty, WeekFontSize, theme->GetCalendarDayFontSize());
|
||||
defaultDayRadius = theme->GetCalendarDayRadius();
|
||||
} else if (fontSizeScale >= theme->GetCalendarPickerLargerScale()) {
|
||||
ACE_UPDATE_PAINT_PROPERTY(CalendarPaintProperty, DayHeight, theme->GetCalendarPickerDayLargerHeight());
|
||||
ACE_UPDATE_PAINT_PROPERTY(CalendarPaintProperty, DayWidth, theme->GetCalendarPickerDayLargeWidthOrHeight());
|
||||
ACE_UPDATE_PAINT_PROPERTY(CalendarPaintProperty, DayFontSize, theme->GetCalendarDayLargerFontSize());
|
||||
ACE_UPDATE_PAINT_PROPERTY(CalendarPaintProperty, WeekHeight, theme->GetCalendarPickerDayLargerHeight());
|
||||
ACE_UPDATE_PAINT_PROPERTY(CalendarPaintProperty, WeekWidth, theme->GetCalendarPickerDayLargeWidthOrHeight());
|
||||
ACE_UPDATE_PAINT_PROPERTY(CalendarPaintProperty, WeekFontSize, theme->GetCalendarDayLargerFontSize());
|
||||
defaultDayRadius = theme->GetCalendarPickerDayLargerHeight() / 2;
|
||||
} else {
|
||||
ACE_UPDATE_PAINT_PROPERTY(CalendarPaintProperty, DayHeight, theme->GetCalendarPickerDayLargeWidthOrHeight());
|
||||
ACE_UPDATE_PAINT_PROPERTY(CalendarPaintProperty, DayWidth, theme->GetCalendarPickerDayLargeWidthOrHeight());
|
||||
ACE_UPDATE_PAINT_PROPERTY(CalendarPaintProperty, DayFontSize, theme->GetCalendarDayLargeFontSize());
|
||||
ACE_UPDATE_PAINT_PROPERTY(CalendarPaintProperty, WeekHeight, theme->GetCalendarPickerDayLargeWidthOrHeight());
|
||||
ACE_UPDATE_PAINT_PROPERTY(CalendarPaintProperty, WeekWidth, theme->GetCalendarPickerDayLargeWidthOrHeight());
|
||||
ACE_UPDATE_PAINT_PROPERTY(CalendarPaintProperty, WeekFontSize, theme->GetCalendarDayLargeFontSize());
|
||||
defaultDayRadius = theme->GetCalendarPickerDayLargeWidthOrHeight() / 2;
|
||||
if (fontSizeScale >= theme->GetCalendarPickerLargerScale()) {
|
||||
ACE_UPDATE_PAINT_PROPERTY(CalendarPaintProperty, DayFontSize, theme->GetCalendarDayLargerFontSize());
|
||||
ACE_UPDATE_PAINT_PROPERTY(CalendarPaintProperty, WeekFontSize, theme->GetCalendarDayLargerFontSize());
|
||||
} else {
|
||||
ACE_UPDATE_PAINT_PROPERTY(CalendarPaintProperty, DayFontSize, theme->GetCalendarDayLargeFontSize());
|
||||
ACE_UPDATE_PAINT_PROPERTY(CalendarPaintProperty, WeekFontSize, theme->GetCalendarDayLargeFontSize());
|
||||
}
|
||||
}
|
||||
|
||||
if (settingData.dayRadius.has_value() && NonNegative(settingData.dayRadius.value().ConvertToPx()) &&
|
||||
|
@ -1246,6 +1246,23 @@ HWTEST_F(CalendarTestNg, CalendarMonthPatternTest003, TestSize.Level1)
|
||||
EXPECT_EQ(calendarMonthPattern->JudgeArea(Offset(OFFSET_X, OFFSET_Y)), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CalendarMonthPatternTest004
|
||||
* @tc.desc: Test CalendarMonthPattern GetDaySize
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(CalendarTestNg, CalendarMonthPatternTest004, TestSize.Level1)
|
||||
{
|
||||
auto* stack = ViewStackProcessor::GetInstance();
|
||||
auto frameNode = FrameNode::GetOrCreateFrameNode(
|
||||
V2::CALENDAR_ETS_TAG, stack->ClaimNodeId(), []() { return AceType::MakeRefPtr<CalendarMonthPattern>(); });
|
||||
auto calendarMonthPattern = frameNode->GetPattern<CalendarMonthPattern>();
|
||||
ASSERT_NE(calendarMonthPattern, nullptr);
|
||||
|
||||
RefPtr<CalendarTheme> theme = MockPipelineContext::GetCurrent()->GetTheme<CalendarTheme>();
|
||||
EXPECT_EQ(calendarMonthPattern->GetDaySize(theme).ConvertToVp(), 0.0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CalendarLayoutAlgorithmTest001
|
||||
* @tc.desc: Test CalendarLayoutAlgorithm MeasureContent
|
||||
|
Loading…
Reference in New Issue
Block a user