From fe12196017b1c66b0efdacac4548bcd881d56467 Mon Sep 17 00:00:00 2001 From: openharmony_ci <120357966@qq.com> Date: Thu, 20 Jul 2023 16:39:35 +0000 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E9=80=80=20'Pull=20Request=20!16155?= =?UTF-8?q?=20:=20=E6=8C=91=E5=8D=95beta2'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../datepicker_column_layout_algorithm.cpp | 32 +++++++------------ .../datepicker_column_layout_algorithm.h | 1 - .../picker/datepicker_column_pattern.cpp | 13 ++++++-- .../pattern/picker/datepicker_dialog_view.cpp | 9 ++++++ .../pattern/picker/datepicker_model_ng.cpp | 8 +++++ .../picker/datepicker_paint_method.cpp | 5 +++ .../timepicker_column_layout_algorithm.cpp | 28 +++++----------- .../timepicker_column_layout_algorithm.h | 1 - .../time_picker/timepicker_column_pattern.cpp | 7 ++-- .../time_picker/timepicker_dialog_view.cpp | 5 +++ .../time_picker/timepicker_model_ng.cpp | 8 +++++ .../time_picker/timepicker_test_ng.cpp | 2 +- 12 files changed, 71 insertions(+), 48 deletions(-) diff --git a/frameworks/core/components_ng/pattern/picker/datepicker_column_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/picker/datepicker_column_layout_algorithm.cpp index 73145174a85..c9998c782bb 100644 --- a/frameworks/core/components_ng/pattern/picker/datepicker_column_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/picker/datepicker_column_layout_algorithm.cpp @@ -26,8 +26,6 @@ namespace OHOS::Ace::NG { namespace { const int32_t DIVIDER_SIZE = 2; -const int32_t OPTION_COUNT_PHONE_LANDSCAPE = 3; -const float ITEM_HEIGHT_HALF = 2.0f; } // namespace void DatePickerColumnLayoutAlgorithm::Measure(LayoutWrapper* layoutWrapper) { @@ -39,13 +37,8 @@ void DatePickerColumnLayoutAlgorithm::Measure(LayoutWrapper* layoutWrapper) CHECK_NULL_VOID(dialogTheme); SizeF frameSize = { -1.0f, -1.0f }; - uint32_t showCount_ = pickerTheme->GetShowOptionCount(); - if (SystemProperties::GetDeviceType() == DeviceType::PHONE && - SystemProperties::GetDeviceOrientation() == DeviceOrientation::LANDSCAPE) { - showCount_ = OPTION_COUNT_PHONE_LANDSCAPE; - } - auto height = static_cast(pickerTheme->GetGradientHeight().ConvertToPx() * (showCount_ - 1) + - pickerTheme->GetDividerSpacing().ConvertToPx()); + auto height = static_cast( + pickerTheme->GetGradientHeight().ConvertToPx() * 4 + pickerTheme->GetDividerSpacing().ConvertToPx()); auto columnNode = layoutWrapper->GetHostNode(); CHECK_NULL_VOID(columnNode); auto stackNode = DynamicCast(columnNode->GetParent()); @@ -74,15 +67,15 @@ void DatePickerColumnLayoutAlgorithm::Measure(LayoutWrapper* layoutWrapper) dialogTheme->GetDividerPadding().Bottom() + pickerTheme->GetContentMarginVertical() * 2) .ConvertToPx()); pickerMaxHeight -= (dialogTitleHeight + dialogButtonHeight); + auto totalChild = layoutWrapper->GetTotalChildCount(); auto gradientHeight = pickerTheme->GetGradientHeight().ConvertToPx(); auto dividerSpacingHeight = pickerTheme->GetDividerSpacing().ConvertToPx(); - auto columnHeight = gradientHeight * (showCount_ - 1) + dividerSpacingHeight; + auto columnHeight = gradientHeight * (totalChild - 1) + dividerSpacingHeight; datePickerPattern->SetResizePickerItemHeight( dividerSpacingHeight / columnHeight * std::min(height, pickerMaxHeight)); datePickerPattern->SetResizeFlag(true); } - pickerItemHeight_ = std::min(height, pickerMaxHeight); frameSize.SetWidth(pickerWidth); frameSize.SetHeight(std::min(height, pickerMaxHeight)); layoutWrapper->GetGeometryNode()->SetFrameSize(frameSize); @@ -111,12 +104,15 @@ void DatePickerColumnLayoutAlgorithm::ChangeTextStyle(uint32_t index, uint32_t s auto pickerTheme = pipeline->GetTheme(); CHECK_NULL_VOID(pickerTheme); frameSize.SetWidth(size.Width()); + auto gradientHeight = pickerTheme->GetGradientHeight().ConvertToPx(); + auto dividerSpacingHeight = pickerTheme->GetDividerSpacing().ConvertToPx(); + auto columnHeight = gradientHeight * (showOptionCount - 1) + dividerSpacingHeight; auto layoutChildConstraint = layoutWrapper->GetLayoutProperty()->CreateChildConstraint(); uint32_t selectedIndex = showOptionCount / 2; // the center option is selected. if (index == selectedIndex) { - frameSize.SetHeight(static_cast(pickerTheme->GetDividerSpacing().ConvertToPx())); + frameSize.SetHeight(static_cast(dividerSpacingHeight / columnHeight * size.Height())); } else { - frameSize.SetHeight(static_cast(pickerTheme->GetGradientHeight().ConvertToPx())); + frameSize.SetHeight(static_cast(gradientHeight / columnHeight * size.Height())); } layoutChildConstraint.selfIdealSize = { frameSize.Width(), frameSize.Height() }; childLayoutWrapper->Measure(layoutChildConstraint); @@ -125,10 +121,6 @@ void DatePickerColumnLayoutAlgorithm::ChangeTextStyle(uint32_t index, uint32_t s void DatePickerColumnLayoutAlgorithm::Layout(LayoutWrapper* layoutWrapper) { CHECK_NULL_VOID(layoutWrapper); - auto pipeline = PipelineContext::GetCurrentContext(); - CHECK_NULL_VOID(pipeline); - auto pickerTheme = pipeline->GetTheme(); - CHECK_NULL_VOID(pickerTheme); auto layoutProperty = AceType::DynamicCast(layoutWrapper->GetLayoutProperty()); CHECK_NULL_VOID(layoutProperty); auto geometryNode = layoutWrapper->GetGeometryNode(); @@ -138,10 +130,8 @@ void DatePickerColumnLayoutAlgorithm::Layout(LayoutWrapper* layoutWrapper) MinusPaddingToSize(padding, size); auto children = layoutWrapper->GetAllChildrenWithBuild(); - uint32_t halfCount = layoutWrapper->GetTotalChildCount() / 2; - float childStartCoordinate = static_cast(pickerItemHeight_ / ITEM_HEIGHT_HALF - - pickerTheme->GetGradientHeight().ConvertToPx() * halfCount - - pickerTheme->GetDividerSpacing().ConvertToPx() / ITEM_HEIGHT_HALF); + + float childStartCoordinate = 0.0; for (const auto& child : children) { auto childGeometryNode = child->GetGeometryNode(); auto childSize = childGeometryNode->GetMarginFrameSize(); diff --git a/frameworks/core/components_ng/pattern/picker/datepicker_column_layout_algorithm.h b/frameworks/core/components_ng/pattern/picker/datepicker_column_layout_algorithm.h index 4c7569a89e5..d0b832449a6 100644 --- a/frameworks/core/components_ng/pattern/picker/datepicker_column_layout_algorithm.h +++ b/frameworks/core/components_ng/pattern/picker/datepicker_column_layout_algorithm.h @@ -49,7 +49,6 @@ public: private: double currentOffset_ = 0.0; - float pickerItemHeight_ = 0.0f; ACE_DISALLOW_COPY_AND_MOVE(DatePickerColumnLayoutAlgorithm); }; diff --git a/frameworks/core/components_ng/pattern/picker/datepicker_column_pattern.cpp b/frameworks/core/components_ng/pattern/picker/datepicker_column_pattern.cpp index 4e0a9c32075..45d9acf34b5 100644 --- a/frameworks/core/components_ng/pattern/picker/datepicker_column_pattern.cpp +++ b/frameworks/core/components_ng/pattern/picker/datepicker_column_pattern.cpp @@ -42,6 +42,7 @@ namespace { // TODO datepicker style modification constexpr float PADDING_WEIGHT = 10.0f; const Dimension FONT_SIZE = Dimension(2.0); +const uint32_t OPTION_COUNT_PHONE_LANDSCAPE = 3; const float TEXT_HEIGHT_NUMBER = 3.0f; const float TEXT_WEIGHT_NUMBER = 6.0f; const int32_t ANIMATION_ZERO_TO_OUTER = 200; @@ -92,7 +93,11 @@ void DatePickerColumnPattern::InitMouseAndPressEvent() auto host = GetHost(); CHECK_NULL_VOID(host); RefPtr middleChild = nullptr; - middleChild = DynamicCast(host->GetChildAtIndex(MINDDLE_CHILD_INDEX)); + if (GetShowCount() != OPTION_COUNT_PHONE_LANDSCAPE) { + middleChild = DynamicCast(host->GetChildAtIndex(MINDDLE_CHILD_INDEX)); + } else { + middleChild = DynamicCast(host->GetChildAtIndex(1)); + } CHECK_NULL_VOID(middleChild); auto eventHub = middleChild->GetEventHub(); CHECK_NULL_VOID(eventHub); @@ -359,7 +364,11 @@ void DatePickerColumnPattern::SetDividerHeight(uint32_t showOptionCount) CHECK_NULL_VOID(pipeline); auto pickerTheme = pipeline->GetTheme(); CHECK_NULL_VOID(pickerTheme); - gradientHeight_ = static_cast(pickerTheme->GetGradientHeight().Value() * TEXT_HEIGHT_NUMBER); + if (showOptionCount != OPTION_COUNT_PHONE_LANDSCAPE) { + gradientHeight_ = static_cast(pickerTheme->GetGradientHeight().Value() * TEXT_HEIGHT_NUMBER); + } else { + gradientHeight_ = static_cast(pickerTheme->GetGradientHeight().Value()); + } dividerHeight_ = static_cast( gradientHeight_ + pickerTheme->GetDividerSpacing().Value() + pickerTheme->GetGradientHeight().Value()); dividerSpacingWidth_ = static_cast(pickerTheme->GetDividerSpacing().Value() * TEXT_WEIGHT_NUMBER); diff --git a/frameworks/core/components_ng/pattern/picker/datepicker_dialog_view.cpp b/frameworks/core/components_ng/pattern/picker/datepicker_dialog_view.cpp index a1005eed72c..b9b18ea26fb 100644 --- a/frameworks/core/components_ng/pattern/picker/datepicker_dialog_view.cpp +++ b/frameworks/core/components_ng/pattern/picker/datepicker_dialog_view.cpp @@ -37,6 +37,7 @@ 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.4285; constexpr double TIME_WIDTH_PERCENT_ONE = 0.5714; @@ -445,6 +446,10 @@ RefPtr DatePickerDialogView::CreateDateNode(int32_t dateNodeId, auto pickerTheme = pipeline->GetTheme(); 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) { @@ -593,6 +598,10 @@ RefPtr DatePickerDialogView::CreateTimeNode( auto pickerTheme = pipeline->GetTheme(); 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(); diff --git a/frameworks/core/components_ng/pattern/picker/datepicker_model_ng.cpp b/frameworks/core/components_ng/pattern/picker/datepicker_model_ng.cpp index c7e68535e8b..0fb94d98613 100644 --- a/frameworks/core/components_ng/pattern/picker/datepicker_model_ng.cpp +++ b/frameworks/core/components_ng/pattern/picker/datepicker_model_ng.cpp @@ -32,6 +32,10 @@ #include "core/components_v2/inspector/inspector_constants.h" namespace OHOS::Ace::NG { +namespace { +const uint32_t OPTION_COUNT_PHONE_LANDSCAPE = 3; +} // namespace + void DatePickerModelNG::CreateDatePicker(RefPtr pickerTheme) { auto* stack = ViewStackProcessor::GetInstance(); @@ -51,6 +55,10 @@ void DatePickerModelNG::CreateDatePicker(RefPtr pickerTheme) CHECK_NULL_VOID(pickerTheme); 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( diff --git a/frameworks/core/components_ng/pattern/picker/datepicker_paint_method.cpp b/frameworks/core/components_ng/pattern/picker/datepicker_paint_method.cpp index e82ced10e0e..cd1ae816257 100644 --- a/frameworks/core/components_ng/pattern/picker/datepicker_paint_method.cpp +++ b/frameworks/core/components_ng/pattern/picker/datepicker_paint_method.cpp @@ -45,7 +45,12 @@ CanvasDrawFunction DatePickerPaintMethod::GetForegroundDrawFunction(PaintWrapper return [weak = WeakClaim(this), dividerLineWidth = DIVIDER_LINE_WIDTH, frameRect, dividerSpacing, dividerColor, enabled = enabled_, pattern = pattern_](RSCanvas& canvas) { DividerPainter dividerPainter(dividerLineWidth, frameRect.Width(), false, dividerColor, LineCap::SQUARE); + auto datePickerPattern = DynamicCast(pattern.Upgrade()); + CHECK_NULL_VOID_NOLOG(datePickerPattern); auto height = dividerSpacing; + if (datePickerPattern->GetResizeFlag()) { + height = datePickerPattern->GetResizePickerItemHeight(); + } double upperLine = (frameRect.Height() - height) / 2.0; double downLine = (frameRect.Height() + height) / 2.0; diff --git a/frameworks/core/components_ng/pattern/time_picker/timepicker_column_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/time_picker/timepicker_column_layout_algorithm.cpp index 146df0ab16c..804e45d4140 100644 --- a/frameworks/core/components_ng/pattern/time_picker/timepicker_column_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/time_picker/timepicker_column_layout_algorithm.cpp @@ -24,8 +24,6 @@ namespace OHOS::Ace::NG { namespace { const int32_t DIVIDER_SIZE = 2; -const int32_t OPTION_COUNT_PHONE_LANDSCAPE = 3; -const float ITEM_HEIGHT_HALF = 2.0f; } // namespace void TimePickerColumnLayoutAlgorithm::Measure(LayoutWrapper* layoutWrapper) { @@ -35,13 +33,8 @@ void TimePickerColumnLayoutAlgorithm::Measure(LayoutWrapper* layoutWrapper) CHECK_NULL_VOID(pickerTheme); SizeF frameSize = { -1.0f, -1.0f }; - uint32_t showCount_ = pickerTheme->GetShowOptionCount(); - if (SystemProperties::GetDeviceType() == DeviceType::PHONE && - SystemProperties::GetDeviceOrientation() == DeviceOrientation::LANDSCAPE) { - showCount_ = OPTION_COUNT_PHONE_LANDSCAPE; - } - auto height = static_cast(pickerTheme->GetGradientHeight().ConvertToPx() * (showCount_ - 1) + - pickerTheme->GetDividerSpacing().ConvertToPx()); + auto height = static_cast( + pickerTheme->GetGradientHeight().ConvertToPx() * 4 + pickerTheme->GetDividerSpacing().ConvertToPx()); auto layoutConstraint = layoutWrapper->GetLayoutProperty()->GetLayoutConstraint(); CHECK_NULL_VOID(layoutConstraint); auto width = layoutConstraint->parentIdealSize.Width(); @@ -52,7 +45,6 @@ void TimePickerColumnLayoutAlgorithm::Measure(LayoutWrapper* layoutWrapper) pickerWidth = static_cast((pickerTheme->GetDividerSpacing() * DIVIDER_SIZE).ConvertToPx()); } - pickerItemHeight_ = std::min(height, layoutConstraint->maxSize.Height()); frameSize.SetWidth(pickerWidth); frameSize.SetHeight(std::min(height, layoutConstraint->maxSize.Height())); layoutWrapper->GetGeometryNode()->SetFrameSize(frameSize); @@ -81,12 +73,15 @@ void TimePickerColumnLayoutAlgorithm::ChangeAmPmTextStyle(uint32_t index, uint32 auto pickerTheme = pipeline->GetTheme(); CHECK_NULL_VOID(pickerTheme); frameSize.SetWidth(size.Width()); + auto gradientHeight = pickerTheme->GetGradientHeight().ConvertToPx(); + auto dividerSpacingHeight = pickerTheme->GetDividerSpacing().ConvertToPx(); + auto columnHeight = gradientHeight * (showOptionCount - 1) + dividerSpacingHeight; auto layoutChildConstraint = layoutWrapper->GetLayoutProperty()->CreateChildConstraint(); uint32_t selectedIndex = showOptionCount / 2; // the center option is selected. if (index == selectedIndex) { - frameSize.SetHeight(static_cast(pickerTheme->GetDividerSpacing().ConvertToPx())); + frameSize.SetHeight(static_cast(dividerSpacingHeight / columnHeight * size.Height())); } else { - frameSize.SetHeight(static_cast(pickerTheme->GetGradientHeight().ConvertToPx())); + frameSize.SetHeight(static_cast(gradientHeight / columnHeight * size.Height())); } layoutChildConstraint.selfIdealSize = { frameSize.Width(), frameSize.Height() }; childLayoutWrapper->Measure(layoutChildConstraint); @@ -95,10 +90,6 @@ void TimePickerColumnLayoutAlgorithm::ChangeAmPmTextStyle(uint32_t index, uint32 void TimePickerColumnLayoutAlgorithm::Layout(LayoutWrapper* layoutWrapper) { CHECK_NULL_VOID(layoutWrapper); - auto pipeline = PipelineContext::GetCurrentContext(); - CHECK_NULL_VOID(pipeline); - auto pickerTheme = pipeline->GetTheme(); - CHECK_NULL_VOID(pickerTheme); auto layoutProperty = AceType::DynamicCast(layoutWrapper->GetLayoutProperty()); CHECK_NULL_VOID(layoutProperty); auto geometryNode = layoutWrapper->GetGeometryNode(); @@ -107,10 +98,7 @@ void TimePickerColumnLayoutAlgorithm::Layout(LayoutWrapper* layoutWrapper) auto padding = layoutProperty->CreatePaddingAndBorder(); MinusPaddingToSize(padding, size); auto children = layoutWrapper->GetAllChildrenWithBuild(); - uint32_t halfCount = layoutWrapper->GetTotalChildCount() / 2; - float childStartCoordinate = static_cast(pickerItemHeight_ / ITEM_HEIGHT_HALF - - pickerTheme->GetGradientHeight().ConvertToPx() * halfCount - - pickerTheme->GetDividerSpacing().ConvertToPx() / ITEM_HEIGHT_HALF); + float childStartCoordinate = 0.0f; for (const auto& child : children) { auto childGeometryNode = child->GetGeometryNode(); auto childSize = childGeometryNode->GetMarginFrameSize(); diff --git a/frameworks/core/components_ng/pattern/time_picker/timepicker_column_layout_algorithm.h b/frameworks/core/components_ng/pattern/time_picker/timepicker_column_layout_algorithm.h index 25f68450f0a..6fa9c6a4a28 100644 --- a/frameworks/core/components_ng/pattern/time_picker/timepicker_column_layout_algorithm.h +++ b/frameworks/core/components_ng/pattern/time_picker/timepicker_column_layout_algorithm.h @@ -60,7 +60,6 @@ public: private: float currentOffset_ = 0.0f; - float pickerItemHeight_ = 0.0f; bool hour24_ = !Localization::GetInstance()->IsAmPmHour(); ACE_DISALLOW_COPY_AND_MOVE(TimePickerColumnLayoutAlgorithm); diff --git a/frameworks/core/components_ng/pattern/time_picker/timepicker_column_pattern.cpp b/frameworks/core/components_ng/pattern/time_picker/timepicker_column_pattern.cpp index e51bbf92794..bbdfb407dab 100644 --- a/frameworks/core/components_ng/pattern/time_picker/timepicker_column_pattern.cpp +++ b/frameworks/core/components_ng/pattern/time_picker/timepicker_column_pattern.cpp @@ -34,6 +34,7 @@ namespace { // TODO timepicker style modification constexpr Dimension PADDING_WEIGHT = 10.0_vp; const Dimension FONT_SIZE = Dimension(2.0); +const uint32_t OPTION_COUNT_PHONE_LANDSCAPE = 3; const int32_t CHILD_SIZE = 3; const float TEXT_HEIGHT_NUMBER = 3.0f; const float TEXT_HOUR24_HEIGHT_NUMBER = 9.0f; @@ -705,10 +706,12 @@ void TimePickerColumnPattern::SetDividerHeight(uint32_t showOptionCount) auto pipeline = PipelineContext::GetCurrentContext(); auto pickerTheme = pipeline->GetTheme(); auto childSize = host->GetChildren().size(); - if (childSize != CHILD_SIZE) { + if (showOptionCount != OPTION_COUNT_PHONE_LANDSCAPE && childSize != CHILD_SIZE) { gradientHeight_ = static_cast(pickerTheme->GetGradientHeight().Value() * TEXT_HEIGHT_NUMBER); - } else { + } else if (showOptionCount != OPTION_COUNT_PHONE_LANDSCAPE && childSize == CHILD_SIZE) { gradientHeight_ = static_cast(pickerTheme->GetGradientHeight().Value() - TEXT_HOUR24_HEIGHT_NUMBER); + } else { + gradientHeight_ = static_cast(pickerTheme->GetGradientHeight().Value()); } dividerHeight_ = static_cast( gradientHeight_ + pickerTheme->GetDividerSpacing().Value() + pickerTheme->GetGradientHeight().Value()); diff --git a/frameworks/core/components_ng/pattern/time_picker/timepicker_dialog_view.cpp b/frameworks/core/components_ng/pattern/time_picker/timepicker_dialog_view.cpp index e7751e29a03..d111c8dc28a 100644 --- a/frameworks/core/components_ng/pattern/time_picker/timepicker_dialog_view.cpp +++ b/frameworks/core/components_ng/pattern/time_picker/timepicker_dialog_view.cpp @@ -29,6 +29,7 @@ namespace OHOS::Ace::NG { namespace { +const uint32_t OPTION_COUNT_PHONE_LANDSCAPE = 3; const int32_t MARGIN_HALF = 2; } // namespace @@ -52,6 +53,10 @@ RefPtr TimePickerDialogView::Show(const DialogProperties& dialogPrope CHECK_NULL_RETURN(pickerTheme, nullptr); uint32_t showCount = pickerTheme->GetShowOptionCount(); + if (SystemProperties::GetDeviceType() == DeviceType::PHONE && + SystemProperties::GetDeviceOrientation() == DeviceOrientation::LANDSCAPE) { + showCount = OPTION_COUNT_PHONE_LANDSCAPE; + } auto timePickerRowPattern = timePickerNode->GetPattern(); CHECK_NULL_RETURN(timePickerRowPattern, nullptr); timePickerRowPattern->SetShowCount(showCount); diff --git a/frameworks/core/components_ng/pattern/time_picker/timepicker_model_ng.cpp b/frameworks/core/components_ng/pattern/time_picker/timepicker_model_ng.cpp index 764143231c3..f4cb67eaa70 100644 --- a/frameworks/core/components_ng/pattern/time_picker/timepicker_model_ng.cpp +++ b/frameworks/core/components_ng/pattern/time_picker/timepicker_model_ng.cpp @@ -31,6 +31,10 @@ #include "core/pipeline_ng/pipeline_context.h" namespace OHOS::Ace::NG { +namespace { +const uint32_t OPTION_COUNT_PHONE_LANDSCAPE = 3; +} // namespace + void TimePickerModelNG::CreateTimePicker(RefPtr pickerTheme) { auto* stack = ViewStackProcessor::GetInstance(); @@ -40,6 +44,10 @@ void TimePickerModelNG::CreateTimePicker(RefPtr pickerTheme) CHECK_NULL_VOID(pickerTheme); uint32_t showCount = pickerTheme->GetShowOptionCount(); + if (SystemProperties::GetDeviceType() == DeviceType::PHONE && + SystemProperties::GetDeviceOrientation() == DeviceOrientation::LANDSCAPE) { + showCount = OPTION_COUNT_PHONE_LANDSCAPE; + } auto timePickerRowPattern = timePickerNode->GetPattern(); CHECK_NULL_VOID(timePickerRowPattern); timePickerRowPattern->SetShowCount(showCount); diff --git a/frameworks/core/components_ng/test/pattern/time_picker/timepicker_test_ng.cpp b/frameworks/core/components_ng/test/pattern/time_picker/timepicker_test_ng.cpp index f9f9dcdb79d..39dc1cd8c04 100644 --- a/frameworks/core/components_ng/test/pattern/time_picker/timepicker_test_ng.cpp +++ b/frameworks/core/components_ng/test/pattern/time_picker/timepicker_test_ng.cpp @@ -1262,7 +1262,7 @@ HWTEST_F(TimePickerPatternTestNg, TimePickerColumnPattern013, TestSize.Level1) EXPECT_EQ(minuteColumnPattern->gradientHeight_, gradientHeight - TEXT_HOUR24_HEIGHT_NUMBER); minuteColumnPattern->SetDividerHeight(OPTION_COUNT_PHONE_LANDSCAPE); - EXPECT_EQ(minuteColumnPattern->gradientHeight_, gradientHeight - TEXT_HOUR24_HEIGHT_NUMBER); + EXPECT_EQ(minuteColumnPattern->gradientHeight_, gradientHeight); } /** -- Gitee