[bugfix] pickerdialog can not show totally in small window

Signed-off-by: z30053720 <zhaoyong70@huawei.com>
This commit is contained in:
z30053720 2024-09-03 15:15:37 +08:00
parent 86911c6c7f
commit c76107f1b4
8 changed files with 102 additions and 17 deletions

View File

@ -32,6 +32,8 @@ const int32_t BUFFER_NODE_NUMBER = 2;
const int32_t HIDENODE = 3;
constexpr double PERCENT_100 = 100.0;
constexpr double PERCENT_120 = 1.2f;
constexpr double SPACE_CALC_TIME = 2.0;
constexpr Dimension LUNARSWITCH_HEIGHT = 48.0_vp;
GradientColor CreatePercentGradientColor(float percent, Color color)
{
NG::GradientColor gredient = GradientColor(color);
@ -47,6 +49,8 @@ void DatePickerColumnLayoutAlgorithm::Measure(LayoutWrapper* layoutWrapper)
CHECK_NULL_VOID(pickerTheme);
auto dialogTheme = pipeline->GetTheme<DialogTheme>();
CHECK_NULL_VOID(dialogTheme);
auto buttonTheme = pipeline->GetTheme<ButtonTheme>();
CHECK_NULL_VOID(buttonTheme);
SizeF frameSize = { -1.0f, -1.0f };
uint32_t showCount_ = pickerTheme->GetShowCountPortrait() + BUFFER_NODE_NUMBER;
@ -85,14 +89,14 @@ void DatePickerColumnLayoutAlgorithm::Measure(LayoutWrapper* layoutWrapper)
auto pickerMaxHeight = layoutConstraint->maxSize.Height();
if (datePickerPattern->GetIsShowInDialog()) {
float dialogTitleHeight =
static_cast<float>((pickerTheme->GetTitleStyle().GetFontSize() + dialogTheme->GetDividerHeight() +
pickerTheme->GetContentMarginVertical() * 2).ConvertToPx());
float dialogButtonHeight =
static_cast<float>((pickerTheme->GetButtonHeight() + dialogTheme->GetDividerHeight() +
dialogTheme->GetDividerPadding().Bottom() + pickerTheme->GetContentMarginVertical() * 2)
.ConvertToPx());
float dialogTitleHeight = static_cast<float>(
(buttonTheme->GetHeight() + dialogTheme->GetButtonSpacingVertical() * SPACE_CALC_TIME).ConvertToPx());
float dialogButtonHeight = static_cast<float>(
(buttonTheme->GetHeight() + dialogTheme->GetButtonPaddingBottom() * SPACE_CALC_TIME).ConvertToPx());
pickerMaxHeight -= (dialogTitleHeight + dialogButtonHeight);
if (datePickerPattern->GetShowLunarSwitch()) {
pickerMaxHeight -= static_cast<float>(LUNARSWITCH_HEIGHT.ConvertToPx());
}
auto gradientHeight = pickerTheme->GetGradientHeight().ConvertToPx() * gradientFontScale_;
auto dividerSpacingHeight = pickerTheme->GetDividerSpacing().ConvertToPx() * dividerSpacingFontScale_;
datePickerPattern->SetPaintDividerSpacing(dividerSpacingFontScale_);

View File

@ -91,6 +91,7 @@ RefPtr<FrameNode> DatePickerDialogView::Show(const DialogProperties& dialogPrope
pickerPattern->SetDateOrder(dateOrder);
}
pickerPattern->SetIsShowInDialog(true);
pickerPattern->SetShowLunarSwitch(settingData.lunarswitch);
pickerPattern->SetTextProperties(settingData.properties);
auto buttonTitleNode = CreateAndMountButtonTitleNode(dateNode, contentColumn);
CHECK_NULL_RETURN(buttonTitleNode, nullptr);
@ -951,7 +952,7 @@ RefPtr<FrameNode> DatePickerDialogView::CreateDateNode(int32_t dateNodeId,
CHECK_NULL_RETURN(pickerTheme, nullptr);
uint32_t showCount = pickerTheme->GetShowOptionCount() + BUFFER_NODE_NUMBER;
datePickerPattern->SetShowCount(showCount);
datePickerPattern->SetIsShowInDialog(true);
if (showTime) {
CreateSingleDateNode(dateNode, showCount);
} else {
@ -1089,6 +1090,7 @@ RefPtr<FrameNode> DatePickerDialogView::CreateTimeNode(
CHECK_NULL_RETURN(pickerTheme, nullptr);
uint32_t showCount = pickerTheme->GetShowOptionCount() + BUFFER_NODE_NUMBER;
timePickerRowPattern->SetShowCount(showCount);
timePickerRowPattern->SetIsShowInDialog(true);
auto hasHourNode = timePickerRowPattern->HasHourNode();
auto hasMinuteNode = timePickerRowPattern->HasMinuteNode();
@ -1547,6 +1549,7 @@ RefPtr<FrameNode> DatePickerDialogView::CreateAndMountMonthDaysNode(const DatePi
CHECK_NULL_RETURN(pickerPattern, nullptr);
monthDaysPickerPattern->SetTitleId(pickerPattern->GetTitleId());
monthDaysPickerPattern->SetShowTimeFlag(true);
monthDaysPickerPattern->SetShowLunarSwitch(settingData.lunarswitch);
pickerPattern->SetShowTimeFlag(true);
auto monthDaysLayoutProperty = monthDaysNode->GetLayoutProperty();
CHECK_NULL_RETURN(monthDaysLayoutProperty, nullptr);
@ -1572,6 +1575,7 @@ RefPtr<FrameNode> DatePickerDialogView::CreateAndMountTimeNode(const DatePickerS
auto timePickerRowPattern = timeNode->GetPattern<TimePickerRowPattern>();
CHECK_NULL_RETURN(timePickerRowPattern, nullptr);
timePickerRowPattern->SetTextProperties(settingData.properties);
timePickerRowPattern->SetShowLunarSwitch(settingData.lunarswitch);
auto timePickerLayout = timeNode->GetLayoutProperty<TimePickerLayoutProperty>();
if (Container::GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_TWELVE)) {
ZeroPrefixType hourOptions = settingData.dateTimeOptions.hourType;

View File

@ -84,21 +84,33 @@ bool DatePickerPattern::OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& di
auto pickerTheme = context->GetTheme<PickerTheme>();
CHECK_NULL_RETURN(pickerTheme, false);
auto children = host->GetChildren();
auto heigth = pickerTheme->GetDividerSpacing();
auto height = pickerTheme->GetDividerSpacing();
for (const auto& child : children) {
auto columnNode = DynamicCast<FrameNode>(child->GetLastChild()->GetLastChild());
auto width = columnNode->GetGeometryNode()->GetFrameSize().Width();
auto datePickerColumnNode = DynamicCast<FrameNode>(child->GetLastChild());
CHECK_NULL_RETURN(datePickerColumnNode, false);
auto columnNodeHeight = datePickerColumnNode->GetGeometryNode()->GetFrameSize().Height();
auto buttonNode = DynamicCast<FrameNode>(child->GetFirstChild());
auto buttonConfirmLayoutProperty = buttonNode->GetLayoutProperty<ButtonLayoutProperty>();
buttonConfirmLayoutProperty->UpdateMeasureType(MeasureType::MATCH_PARENT_MAIN_AXIS);
buttonConfirmLayoutProperty->UpdateType(ButtonType::NORMAL);
buttonConfirmLayoutProperty->UpdateBorderRadius(BorderRadiusProperty(PRESS_RADIUS));
auto standardButtonHeight = static_cast<float>((height - PRESS_INTERVAL).ConvertToPx());
auto maxButtonHeight = static_cast<float>(columnNodeHeight);
auto buttonHeight = Dimension(std::min(standardButtonHeight, maxButtonHeight), DimensionUnit::PX);
buttonConfirmLayoutProperty->UpdateUserDefinedIdealSize(
CalcSize(CalcLength(width - PRESS_INTERVAL.ConvertToPx()), CalcLength(heigth - PRESS_INTERVAL)));
CalcSize(CalcLength(width - PRESS_INTERVAL.ConvertToPx()), CalcLength(buttonHeight)));
auto buttonConfirmRenderContext = buttonNode->GetRenderContext();
buttonConfirmRenderContext->UpdateBackgroundColor(Color::TRANSPARENT);
buttonNode->MarkModifyDone();
buttonNode->MarkDirtyNode();
if (GetIsShowInDialog() && GreatNotEqual(standardButtonHeight, maxButtonHeight) &&
GreatNotEqual(maxButtonHeight, 0.0f)) {
auto parentNode = DynamicCast<FrameNode>(host->GetParent());
CHECK_NULL_RETURN(parentNode, false);
parentNode->MarkDirtyNode(PROPERTY_UPDATE_BY_CHILD_REQUEST);
}
}
return true;
}

View File

@ -219,6 +219,16 @@ public:
showTime_ = value;
}
void SetShowLunarSwitch(bool value)
{
showLunarSwitch_ = value;
}
bool GetShowLunarSwitch()
{
return showLunarSwitch_;
}
const EventMarker& GetDialogAcceptEvent() const
{
return OnDialogAccept_;
@ -729,6 +739,7 @@ private:
bool lunar_ = false;
bool showMonthDays_ = false;
bool showTime_ = false;
bool showLunarSwitch_ = false;
Color backgroundColor_ = Color::WHITE;
std::optional<int32_t> yearId_;
std::optional<int32_t> monthId_;

View File

@ -30,6 +30,8 @@ constexpr int32_t BUFFER_NODE_NUMBER = 2;
constexpr int32_t HIDENODE = 3;
constexpr double PERCENT_100 = 100.0;
constexpr double PERCENT_120 = 1.2f;
constexpr double SPACE_CALC_TIME = 2.0;
constexpr Dimension LUNARSWITCH_HEIGHT = 48.0_vp;
GradientColor CreatePercentGradientColor(float percent, Color color)
{
@ -73,16 +75,15 @@ void TimePickerColumnLayoutAlgorithm::Measure(LayoutWrapper* layoutWrapper)
auto layoutConstraint = blendNode->GetLayoutProperty()->GetLayoutConstraint();
CHECK_NULL_VOID(layoutConstraint);
auto width = layoutConstraint->parentIdealSize.Width();
float pickerWidth = 0.0f;
auto pickerMaxHeight = GetPickerMaxHeight(layoutConstraint, pickerNode);
float pickerWidth = static_cast<float>((pickerTheme->GetDividerSpacing() * DIVIDER_SIZE).ConvertToPx());
if (width.has_value()) {
pickerWidth = width.value();
} else {
pickerWidth = static_cast<float>((pickerTheme->GetDividerSpacing() * DIVIDER_SIZE).ConvertToPx());
}
pickerItemHeight_ = std::min(height, layoutConstraint->maxSize.Height());
pickerItemHeight_ = std::min(height, pickerMaxHeight);
frameSize.SetWidth(pickerWidth);
frameSize.SetHeight(std::min(height, layoutConstraint->maxSize.Height()));
frameSize.SetHeight(std::min(height, pickerMaxHeight));
layoutWrapper->GetGeometryNode()->SetFrameSize(frameSize);
auto layoutChildConstraint = blendNode->GetLayoutProperty()->CreateChildConstraint();
for (auto&& child : layoutWrapper->GetAllChildrenWithBuild()) {
@ -94,6 +95,34 @@ void TimePickerColumnLayoutAlgorithm::Measure(LayoutWrapper* layoutWrapper)
InitGradient(gradientPercent, blendNode, columnNode);
}
float TimePickerColumnLayoutAlgorithm::GetPickerMaxHeight(
const std::optional<LayoutConstraintF>& layoutConstraint, const RefPtr<FrameNode>& pickerNode)
{
auto pickerMaxHeight = layoutConstraint->maxSize.Height();
auto pipeline = pickerNode->GetContext();
CHECK_NULL_RETURN(pipeline, pickerMaxHeight);
auto pickerTheme = pipeline->GetTheme<PickerTheme>();
CHECK_NULL_RETURN(pickerTheme, pickerMaxHeight);
auto dialogTheme = pipeline->GetTheme<DialogTheme>();
CHECK_NULL_RETURN(dialogTheme, pickerMaxHeight);
auto buttonTheme = pipeline->GetTheme<ButtonTheme>();
CHECK_NULL_RETURN(buttonTheme, pickerMaxHeight);
auto timePickerPattern = pickerNode->GetPattern<TimePickerRowPattern>();
if (timePickerPattern->GetIsShowInDialog()) {
float dialogTitleHeight = static_cast<float>(
(buttonTheme->GetHeight() + dialogTheme->GetButtonSpacingVertical() * SPACE_CALC_TIME).ConvertToPx());
float dialogButtonHeight = static_cast<float>(
(buttonTheme->GetHeight() + dialogTheme->GetButtonPaddingBottom() * SPACE_CALC_TIME).ConvertToPx());
pickerMaxHeight -= (dialogTitleHeight + dialogButtonHeight);
if (timePickerPattern->GetShowLunarSwitch()) {
pickerMaxHeight -= static_cast<float>(LUNARSWITCH_HEIGHT.ConvertToPx());
}
}
return pickerMaxHeight;
}
void TimePickerColumnLayoutAlgorithm::InitGradient(const float& gradientPercent, const RefPtr<FrameNode> blendNode,
const RefPtr<FrameNode> columnNode)
{

View File

@ -68,7 +68,8 @@ private:
bool hour24_ = SystemProperties::Is24HourClock();
void InitGradient(const float& gradientPercent, const RefPtr<FrameNode> blendNode,
const RefPtr<FrameNode> columnNode);
float GetPickerMaxHeight(
const std::optional<LayoutConstraintF>& layoutConstraint, const RefPtr<FrameNode>& pickerNode);
ACE_DISALLOW_COPY_AND_MOVE(TimePickerColumnLayoutAlgorithm);
};
} // namespace OHOS::Ace::NG

View File

@ -82,17 +82,29 @@ void TimePickerRowPattern::SetButtonIdeaSize()
if (width > defaultWidth) {
width = static_cast<float>(defaultWidth);
}
auto timePickerColumnNode = DynamicCast<FrameNode>(childNode->GetLastChild());
CHECK_NULL_VOID(timePickerColumnNode);
auto columnNodeHeight = timePickerColumnNode->GetGeometryNode()->GetFrameSize().Height();
auto buttonNode = DynamicCast<FrameNode>(child->GetFirstChild());
auto buttonLayoutProperty = buttonNode->GetLayoutProperty<ButtonLayoutProperty>();
buttonLayoutProperty->UpdateMeasureType(MeasureType::MATCH_PARENT_MAIN_AXIS);
buttonLayoutProperty->UpdateType(ButtonType::NORMAL);
buttonLayoutProperty->UpdateBorderRadius(BorderRadiusProperty(PRESS_RADIUS));
auto standardButtonHeight = static_cast<float>((height - PRESS_INTERVAL).ConvertToPx());
auto maxButtonHeight = static_cast<float>(columnNodeHeight);
auto buttonHeight = Dimension(std::min(standardButtonHeight, maxButtonHeight), DimensionUnit::PX);
buttonLayoutProperty->UpdateUserDefinedIdealSize(
CalcSize(CalcLength(width - PRESS_INTERVAL.ConvertToPx()), CalcLength(height - PRESS_INTERVAL)));
CalcSize(CalcLength(width - PRESS_INTERVAL.ConvertToPx()), CalcLength(buttonHeight)));
auto buttonConfirmRenderContext = buttonNode->GetRenderContext();
buttonConfirmRenderContext->UpdateBackgroundColor(Color::TRANSPARENT);
buttonNode->MarkModifyDone();
buttonNode->MarkDirtyNode();
if (GetIsShowInDialog() && GreatNotEqual(standardButtonHeight, maxButtonHeight) &&
GreatNotEqual(maxButtonHeight, 0.0f)) {
auto parentNode = DynamicCast<FrameNode>(host->GetParent());
CHECK_NULL_VOID(parentNode);
parentNode->MarkDirtyNode(PROPERTY_UPDATE_BY_CHILD_REQUEST);
}
}
}

View File

@ -87,6 +87,17 @@ public:
{
return isShowInDialog_;
}
void SetShowLunarSwitch(bool value)
{
showLunarSwitch_ = value;
}
bool GetShowLunarSwitch() const
{
return showLunarSwitch_;
}
void SetCancelNode(WeakPtr<FrameNode> buttonCancelNode)
{
weakButtonCancel_ = buttonCancelNode;
@ -637,6 +648,7 @@ private:
bool isAmPmTimeOrderUpdate_ = false;
bool isPreLanguageUg_ = false;
bool isShowInDialog_ = false;
bool showLunarSwitch_ = false;
bool isUserSetDividerSpacingFont_ = false;
bool isUserSetGradientFont_ = false;
Dimension gradientHeight_;