!40052 dialog适配悬停态

Merge pull request !40052 from zhangjing/master
This commit is contained in:
openharmony_ci 2024-08-29 14:09:50 +00:00 committed by Gitee
commit 6f1a06ed97
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
27 changed files with 367 additions and 51 deletions

View File

@ -1732,6 +1732,7 @@ void FrontendDelegateDeclarative::ShowDialog(const PromptDialogAttr& dialogAttr,
.onLanguageChange = dialogAttr.onLanguageChange,
.isShowInSubWindow = dialogAttr.showInSubWindow,
.isModal = dialogAttr.isModal,
.enableHoverMode = dialogAttr.enableHoverMode,
.maskRect = dialogAttr.maskRect,
};
#if defined(PREVIEW)
@ -1756,6 +1757,9 @@ void FrontendDelegateDeclarative::ShowDialog(const PromptDialogAttr& dialogAttr,
if (dialogAttr.backgroundBlurStyle.has_value()) {
dialogProperties.backgroundBlurStyle = dialogAttr.backgroundBlurStyle.value();
}
if (dialogAttr.hoverModeArea.has_value()) {
dialogProperties.hoverModeArea = dialogAttr.hoverModeArea.value();
}
ShowDialogInner(dialogProperties, std::move(callback), callbacks);
}
@ -1806,6 +1810,7 @@ DialogProperties FrontendDelegateDeclarative::ParsePropertiesFromAttr(const Prom
.borderRadius = dialogAttr.borderRadius,
.isShowInSubWindow = dialogAttr.showInSubWindow,
.isModal = dialogAttr.isModal,
.enableHoverMode = dialogAttr.enableHoverMode,
.customBuilder = dialogAttr.customBuilder,
.borderWidth = dialogAttr.borderWidth,
.borderColor = dialogAttr.borderColor,
@ -1834,6 +1839,9 @@ DialogProperties FrontendDelegateDeclarative::ParsePropertiesFromAttr(const Prom
if (dialogAttr.offset.has_value()) {
dialogProperties.offset = dialogAttr.offset.value();
}
if (dialogAttr.hoverModeArea.has_value()) {
dialogProperties.hoverModeArea = dialogAttr.hoverModeArea.value();
}
if (Container::LessThanAPIVersion(PlatformVersion::VERSION_TWELVE)) {
dialogProperties.isSysBlurStyle = false;
} else {

View File

@ -440,6 +440,7 @@ void JSActionSheet::Show(const JSCallbackInfo& args)
// Parse transition.
properties.transitionEffect = ParseJsTransitionEffect(args);
JSViewAbstract::SetDialogProperties(obj, properties);
JSViewAbstract::SetDialogHoverModeProperties(obj, properties);
ActionSheetModel::GetInstance()->ShowActionSheet(properties);
args.SetReturnValue(args.This());
}

View File

@ -476,6 +476,7 @@ void JSAlertDialog::Show(const JSCallbackInfo& args)
// Parse transition.
properties.transitionEffect = ParseJsTransitionEffect(args);
JSViewAbstract::SetDialogProperties(obj, properties);
JSViewAbstract::SetDialogHoverModeProperties(obj, properties);
AlertDialogModel::GetInstance()->SetShowDialog(properties);
}
}

View File

@ -228,7 +228,9 @@ void JSCustomDialogController::ConstructorCallback(const JSCallbackInfo& info)
if (isModalValue->IsBoolean()) {
instance->dialogProperties_.isModal = isModalValue->ToBoolean();
}
JSViewAbstract::SetDialogProperties(constructorArg, instance->dialogProperties_);
JSViewAbstract::SetDialogHoverModeProperties(constructorArg, instance->dialogProperties_);
instance->IncRefCount();
info.SetReturnValue(AceType::RawPtr(instance));
}

View File

@ -770,6 +770,7 @@ void JSCalendarPickerDialog::CalendarPickerDialogShow(const JSRef<JSObject>& par
if ((shadowValue->IsObject() || shadowValue->IsNumber()) && JSViewAbstract::ParseShadowProps(shadowValue, shadow)) {
properties.shadow = shadow;
}
properties.customStyle = false;
if (Container::LessThanAPIVersion(PlatformVersion::VERSION_TWELVE)) {
properties.offset = DimensionOffset(Offset(0, -theme->GetMarginBottom().ConvertToPx()));
@ -777,6 +778,7 @@ void JSCalendarPickerDialog::CalendarPickerDialogShow(const JSRef<JSObject>& par
dialogRadius.SetRadius(calendarTheme->GetDialogBorderRadius());
properties.borderRadius = dialogRadius;
}
JSViewAbstract::SetDialogHoverModeProperties(paramObj, properties);
auto context = AccessibilityManager::DynamicCast<NG::PipelineContext>(pipelineContext);
auto overlayManager = context ? context->GetOverlayManager() : nullptr;

View File

@ -48,6 +48,8 @@ const std::vector<DialogAlignment> DIALOG_ALIGNMENT = { DialogAlignment::TOP, Di
DialogAlignment::BOTTOM, DialogAlignment::DEFAULT, DialogAlignment::TOP_START, DialogAlignment::TOP_END,
DialogAlignment::CENTER_START, DialogAlignment::CENTER_END, DialogAlignment::BOTTOM_START,
DialogAlignment::BOTTOM_END };
const std::vector<HoverModeAreaType> HOVER_MODE_AREA_TYPE = { HoverModeAreaType::TOP_SCREEN,
HoverModeAreaType::BOTTOM_SCREEN };
const char TIMEPICKER_OPTIONS_HOUR[] = "hour";
const char TIMEPICKER_OPTIONS_MINUTE[] = "minute";
const char TIMEPICKER_OPTIONS_SECOND[] = "second";
@ -264,6 +266,22 @@ std::vector<ButtonInfo> ParseButtonStyles(const JSRef<JSObject>& paramObject)
return buttonInfos;
}
void ParseDatePickerHoverMode(PickerDialogInfo& pickerDialog, const JSRef<JSObject>& paramObject)
{
auto enableHoverModeValue = paramObject->GetProperty("enableHoverMode");
if (enableHoverModeValue->IsBoolean()) {
pickerDialog.enableHoverMode = enableHoverModeValue->ToBoolean();
}
auto hoverModeAreaValue = paramObject->GetProperty("hoverModeArea");
if (hoverModeAreaValue->IsNumber()) {
auto hoverModeArea = hoverModeAreaValue->ToNumber<int32_t>();
if (hoverModeArea >= 0 && hoverModeArea < static_cast<int32_t>(HOVER_MODE_AREA_TYPE.size())) {
pickerDialog.hoverModeArea = HOVER_MODE_AREA_TYPE[hoverModeArea];
}
}
}
} // namespace
void JSDatePicker::JSBind(BindingTarget globalObj)
@ -1045,6 +1063,8 @@ void JSDatePickerDialog::UpdatePickerDialogInfo(const JSRef<JSObject>& paramObje
if ((shadowValue->IsObject() || shadowValue->IsNumber()) && JSViewAbstract::ParseShadowProps(shadowValue, shadow)) {
pickerDialog.shadow = shadow;
}
ParseDatePickerHoverMode(pickerDialog, paramObject);
}
void JSDatePickerDialog::Show(const JSCallbackInfo& info)
@ -1721,6 +1741,8 @@ void JSTimePickerDialog::Show(const JSCallbackInfo& info)
}
}
ParseDatePickerHoverMode(pickerDialog, paramObject);
auto buttonInfos = ParseButtonStyles(paramObject);
auto shadowValue = paramObject->GetProperty("shadow");

View File

@ -44,6 +44,8 @@ const std::vector<DialogAlignment> DIALOG_ALIGNMENT = { DialogAlignment::TOP, Di
DialogAlignment::BOTTOM, DialogAlignment::DEFAULT, DialogAlignment::TOP_START, DialogAlignment::TOP_END,
DialogAlignment::CENTER_START, DialogAlignment::CENTER_END, DialogAlignment::BOTTOM_START,
DialogAlignment::BOTTOM_END };
const std::vector<HoverModeAreaType> HOVER_MODE_AREA_TYPE = { HoverModeAreaType::TOP_SCREEN,
HoverModeAreaType::BOTTOM_SCREEN };
const std::regex DIMENSION_REGEX(R"(^[-+]?\d+(?:\.\d+)?(?:px|vp|fp|lpx)?$)", std::regex::icase);
}
@ -1477,6 +1479,19 @@ void JSTextPickerDialog::Show(const JSCallbackInfo& info)
textPickerDialog.shadow = shadow;
}
auto enableHoverModeValue = paramObject->GetProperty("enableHoverMode");
if (enableHoverModeValue->IsBoolean()) {
textPickerDialog.enableHoverMode = enableHoverModeValue->ToBoolean();
}
auto hoverModeAreaValue = paramObject->GetProperty("hoverModeArea");
if (hoverModeAreaValue->IsNumber()) {
auto hoverModeArea = hoverModeAreaValue->ToNumber<int32_t>();
if (hoverModeArea >= 0 && hoverModeArea < static_cast<int32_t>(HOVER_MODE_AREA_TYPE.size())) {
textPickerDialog.hoverModeArea = HOVER_MODE_AREA_TYPE[hoverModeArea];
}
}
auto buttonInfos = ParseButtonStyles(paramObject);
TextPickerDialogEvent textPickerDialogEvent { nullptr, nullptr, nullptr, nullptr };

View File

@ -115,6 +115,8 @@ const std::string RESOURCE_NAME_PATTERN = "\\[(.+?)\\]";
constexpr int32_t DIRECTION_COUNT = 4;
constexpr char JS_TEXT_MENU_ID_CLASS_NAME[] = "TextMenuItemId";
constexpr int NUM1 = 1;
const std::vector<HoverModeAreaType> HOVER_MODE_AREA_TYPE = { HoverModeAreaType::TOP_SCREEN,
HoverModeAreaType::BOTTOM_SCREEN };
} // namespace
std::unique_ptr<ViewAbstractModel> ViewAbstractModel::instance_ = nullptr;
@ -10437,6 +10439,23 @@ void JSViewAbstract::SetDialogProperties(const JSRef<JSObject>& obj, DialogPrope
}
}
void JSViewAbstract::SetDialogHoverModeProperties(const JSRef<JSObject>& obj, DialogProperties& properties)
{
auto enableHoverModeValue = obj->GetProperty("enableHoverMode");
if (enableHoverModeValue->IsBoolean()) {
properties.enableHoverMode = enableHoverModeValue->ToBoolean();
}
// Parse hoverModeArea
auto hoverModeAreaValue = obj->GetProperty("hoverModeArea");
if (hoverModeAreaValue->IsNumber()) {
auto hoverModeArea = hoverModeAreaValue->ToNumber<int32_t>();
if (hoverModeArea >= 0 && hoverModeArea < static_cast<int32_t>(HOVER_MODE_AREA_TYPE.size())) {
properties.hoverModeArea = HOVER_MODE_AREA_TYPE[hoverModeArea];
}
}
}
std::function<void(NG::DrawingContext& context)> JSViewAbstract::GetDrawCallback(
const RefPtr<JsFunction>& jsDraw, const JSExecutionContext& execCtx)
{

View File

@ -605,6 +605,7 @@ public:
static bool ParseEditMenuOptions(const JSCallbackInfo& info, NG::OnCreateMenuCallback& onCreateMenuCallback,
NG::OnMenuItemClickCallback& onMenuItemClick);
static void SetDialogProperties(const JSRef<JSObject>& obj, DialogProperties& properties);
static void SetDialogHoverModeProperties(const JSRef<JSObject>& obj, DialogProperties& properties);
static std::function<void(NG::DrawingContext& context)> GetDrawCallback(
const RefPtr<JsFunction>& jsDraw, const JSExecutionContext& execCtx);

View File

@ -688,6 +688,7 @@ void FrontendDelegateDeclarativeNG::ShowDialog(const PromptDialogAttr& dialogAtt
.buttons = buttons,
.isShowInSubWindow = dialogAttr.showInSubWindow,
.isModal = dialogAttr.isModal,
.enableHoverMode = dialogAttr.enableHoverMode,
.maskRect = dialogAttr.maskRect,
};
if (dialogAttr.alignment.has_value()) {
@ -705,6 +706,9 @@ void FrontendDelegateDeclarativeNG::ShowDialog(const PromptDialogAttr& dialogAtt
if (dialogAttr.backgroundBlurStyle.has_value()) {
dialogProperties.backgroundBlurStyle = dialogAttr.backgroundBlurStyle.value();
}
if (dialogAttr.hoverModeArea.has_value()) {
dialogProperties.hoverModeArea = dialogAttr.hoverModeArea.value();
}
ShowDialogInner(dialogProperties, std::move(callback), callbacks);
}
@ -743,6 +747,7 @@ DialogProperties FrontendDelegateDeclarativeNG::ParsePropertiesFromAttr(const Pr
.borderRadius = dialogAttr.borderRadius,
.isShowInSubWindow = dialogAttr.showInSubWindow,
.isModal = dialogAttr.isModal,
.enableHoverMode = dialogAttr.enableHoverMode,
.customBuilder = dialogAttr.customBuilder,
.borderWidth = dialogAttr.borderWidth,
.borderColor = dialogAttr.borderColor,
@ -771,6 +776,9 @@ DialogProperties FrontendDelegateDeclarativeNG::ParsePropertiesFromAttr(const Pr
if (dialogAttr.offset.has_value()) {
dialogProperties.offset = dialogAttr.offset.value();
}
if (dialogAttr.hoverModeArea.has_value()) {
dialogProperties.hoverModeArea = dialogAttr.hoverModeArea.value();
}
if (Container::LessThanAPIVersion(PlatformVersion::VERSION_TWELVE)) {
dialogProperties.isSysBlurStyle = false;
} else {

View File

@ -54,6 +54,12 @@ enum class RectHeightStyle {
STRUT,
};
// Type of hover mode area.
enum class HoverModeAreaType {
TOP_SCREEN = 0,
BOTTOM_SCREEN = 1,
};
enum class ButtonStyleMode { NORMAL, EMPHASIZE, TEXT };
enum class ControlSize { SMALL, NORMAL };

View File

@ -235,6 +235,7 @@ struct DialogProperties {
DialogButtonDirection buttonDirection = DialogButtonDirection::AUTO;
bool isMask = false;
bool isModal = true;
bool enableHoverMode = false;
bool isScenceBoardDialog = false;
bool isSysBlurStyle = true; // init use sysBlurStyle
std::function<void()> customBuilder;
@ -245,6 +246,7 @@ struct DialogProperties {
std::optional<Shadow> shadow;
std::optional<CalcDimension> width;
std::optional<CalcDimension> height;
std::optional<HoverModeAreaType> hoverModeArea;
#ifndef NG_BUILD
std::unordered_map<std::string, EventMarker> callbacks; // <callback type(success, cancel, complete), eventId>
@ -282,6 +284,7 @@ struct PromptDialogAttr {
bool autoCancel = true;
bool showInSubWindow = false;
bool isModal = false;
bool enableHoverMode = false;
std::function<void()> customBuilder;
std::function<void(const int32_t& info)> customOnWillDismiss;
@ -297,6 +300,7 @@ struct PromptDialogAttr {
std::optional<Shadow> shadow;
std::optional<CalcDimension> width;
std::optional<CalcDimension> height;
std::optional<HoverModeAreaType> hoverModeArea;
WeakPtr<NG::UINode> contentNode;
bool customStyle = false;

View File

@ -85,6 +85,12 @@ void DialogLayoutAlgorithm::Measure(LayoutWrapper* layoutWrapper)
gridCount_ = dialogProp->GetGridCount().value_or(-1);
isShowInSubWindow_ = dialogProp->GetShowInSubWindowValue(false);
isModal_ = dialogProp->GetIsModal().value_or(true);
auto enableHoverMode = dialogProp->GetEnableHoverMode().value_or(false);
hoverModeArea_ = dialogProp->GetHoverModeArea().value_or(HoverModeAreaType::BOTTOM_SCREEN);
auto safeAreaManager = pipeline->GetSafeAreaManager();
auto keyboardInsert = safeAreaManager->GetKeyboardInset();
isKeyBoardShow_ = keyboardInsert.IsValid();
isHoverMode_ = enableHoverMode ? pipeline->IsHalfFoldHoverStatus() : false;
auto windowManager = pipeline->GetWindowManager();
CHECK_NULL_VOID(windowManager);
dialogPattern->UpdateFontScale();
@ -121,10 +127,7 @@ void DialogLayoutAlgorithm::Measure(LayoutWrapper* layoutWrapper)
maxSize.SetWidth(pipeline->GetRootWidth());
maxSize.SetHeight(pipeline->GetRootHeight());
}
maxSize.MinusPadding(0, 0, safeAreaInsets_.top_.Length(), 0);
if (Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_TWELVE) && LessNotEqual(gridCount_, 0)) {
maxSize.MinusPadding(0, 0, 0, safeAreaInsets_.bottom_.Length());
}
UpdateChildMaxSizeHeight(maxSize);
childLayoutConstraint.UpdateMaxSizeWithCheck(maxSize);
ComputeInnerLayoutParam(childLayoutConstraint, dialogProp);
UpdateChildLayoutConstraint(dialogProp, childLayoutConstraint, child);
@ -143,6 +146,23 @@ void DialogLayoutAlgorithm::Measure(LayoutWrapper* layoutWrapper)
}
}
void DialogLayoutAlgorithm::UpdateChildMaxSizeHeight(SizeT<float>& maxSize)
{
if (!isHoverMode_) {
maxSize.MinusPadding(0, 0, safeAreaInsets_.top_.Length(), 0);
if (Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_TWELVE) && LessNotEqual(gridCount_, 0)) {
maxSize.MinusPadding(0, 0, 0, safeAreaInsets_.bottom_.Length());
}
return;
}
alignBottomScreen_ = !isKeyBoardShow_ && hoverModeArea_ == HoverModeAreaType::BOTTOM_SCREEN;
if (alignBottomScreen_) {
maxSize.MinusPadding(0, 0, foldCreaseRect.Bottom(), safeAreaInsets_.bottom_.Length());
return;
}
maxSize.SetHeight(foldCreaseRect.Top() - safeAreaInsets_.top_.Length());
}
void DialogLayoutAlgorithm::UpdateChildLayoutConstraint(const RefPtr<DialogLayoutProperty>& dialogProp,
LayoutConstraintF& childLayoutConstraint, RefPtr<LayoutWrapper>& childLayoutWrapper)
{
@ -686,9 +706,6 @@ OffsetF DialogLayoutAlgorithm::ComputeChildPosition(
OffsetF dialogOffset = OffsetF(dialogOffsetX.value_or(0.0), dialogOffsetY.value_or(0.0));
auto isHostWindowAlign = isUIExtensionSubWindow_ && expandDisplay_ && hostWindowRect_.GetSize().IsPositive();
auto maxSize = isHostWindowAlign ? hostWindowRect_.GetSize() : layoutConstraint->maxSize;
if (!customSize_ && !IsAlignmentByWholeScreen()) {
maxSize.MinusHeight(safeAreaInsets_.bottom_.Length());
}
if (!SetAlignmentSwitch(maxSize, childSize, topLeftPoint)) {
topLeftPoint = OffsetF(maxSize.Width() - childSize.Width(), maxSize.Height() - childSize.Height()) / HALF;
}
@ -726,8 +743,25 @@ bool DialogLayoutAlgorithm::IsAlignmentByWholeScreen()
}
}
bool DialogLayoutAlgorithm::SetAlignmentSwitch(const SizeF& maxSize, const SizeF& childSize, OffsetF& topLeftPoint)
void DialogLayoutAlgorithm::CaculateMaxSize(SizeF& maxSize)
{
auto halfScreenHeight = maxSize.Height() / HALF;
if (!customSize_ && isHoverMode_) {
maxSize.SetHeight(halfScreenHeight);
}
if (!customSize_ && !IsAlignmentByWholeScreen()) {
if (isHoverMode_ && hoverModeArea_ == HoverModeAreaType::TOP_SCREEN) {
maxSize.SetHeight(foldCreaseRect.Top());
return;
}
maxSize.MinusHeight(safeAreaInsets_.bottom_.Length());
}
}
bool DialogLayoutAlgorithm::SetAlignmentSwitch(SizeF& maxSize, const SizeF& childSize, OffsetF& topLeftPoint)
{
auto halfScreenHeight = maxSize.Height() / HALF;
CaculateMaxSize(maxSize);
if (alignment_ != DialogAlignment::DEFAULT || Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_TWELVE)) {
switch (alignment_) {
case DialogAlignment::TOP:
@ -765,6 +799,9 @@ bool DialogLayoutAlgorithm::SetAlignmentSwitch(const SizeF& maxSize, const SizeF
OffsetF(maxSize.Width() - childSize.Width(), maxSize.Height() - childSize.Height()) / HALF;
break;
}
if (alignBottomScreen_) {
topLeftPoint.SetY(topLeftPoint.GetY() + halfScreenHeight);
}
return true;
}
@ -823,6 +860,13 @@ OffsetF DialogLayoutAlgorithm::AdjustChildPosition(
if (!customSize_ && topLeftPoint.GetY() < safeAreaInsets_.top_.end) {
topLeftPoint.SetY(safeAreaInsets_.top_.end);
}
if (alignBottomScreen_) {
bool alignTop = alignment_ == DialogAlignment::TOP || alignment_ == DialogAlignment::TOP_START ||
alignment_ == DialogAlignment::TOP_END;
if (topLeftPoint.GetY() < foldCreaseRect.Bottom() || alignTop) {
topLeftPoint.SetY(foldCreaseRect.Bottom());
}
}
auto childOffset = topLeftPoint + dialogOffset;
auto manager = pipelineContext->GetSafeAreaManager();
@ -860,6 +904,12 @@ void DialogLayoutAlgorithm::UpdateSafeArea()
auto context = AceType::DynamicCast<NG::PipelineContext>(pipelineContext);
CHECK_NULL_VOID(context);
safeAreaInsets_ = context->GetSafeAreaWithoutProcess();
auto displayInfo = container->GetDisplayInfo();
CHECK_NULL_VOID(displayInfo);
auto foldCreaseRects = displayInfo->GetCurrentFoldCreaseRegion();
if (!foldCreaseRects.empty()) {
foldCreaseRect = foldCreaseRects.front();
}
}
void DialogLayoutAlgorithm::ClipUIExtensionSubWindowContent(const RefPtr<FrameNode>& dialog, bool isClip)

View File

@ -67,9 +67,10 @@ private:
int32_t GetDeviceColumns(GridSizeType type, DeviceType deviceType);
OffsetF ComputeChildPosition(
const SizeF& childSize, const RefPtr<DialogLayoutProperty>& prop, const SizeF& slefSize);
bool SetAlignmentSwitch(const SizeF& maxSize, const SizeF& childSize, OffsetF& topLeftPoint);
bool SetAlignmentSwitch(SizeF& maxSize, const SizeF& childSize, OffsetF& topLeftPoint);
bool SetAlignmentSwitchLessThanAPITwelve(const SizeF& maxSize, const SizeF& childSize, OffsetF& topLeftPoint);
bool IsAlignmentByWholeScreen();
void CaculateMaxSize(SizeF& maxSize);
bool IsDialogTouchingBoundary(OffsetF topLeftPoint, SizeF childSize, SizeF selfSize);
void MultipleDialog(const RefPtr<DialogLayoutProperty>& dialogProp, const SizeF& childSize, const SizeF& selfSize,
const RefPtr<OverlayManager> subOverlayManager);
@ -92,6 +93,7 @@ private:
void ClipUIExtensionSubWindowContent(const RefPtr<FrameNode>& dialog, bool isClip);
void AdjustHeightForKeyboard(LayoutWrapper* layoutWrapper, const RefPtr<LayoutWrapper>& child);
void UpdateIsScrollHeightNegative(LayoutWrapper* layoutWrapper, float height);
void UpdateChildMaxSizeHeight(SizeT<float>& maxSize);
RectF touchRegion_;
OffsetF topLeftPoint_;
@ -115,6 +117,11 @@ private:
SizeF dialogChildSize_;
bool resizeFlag_ = false;
bool isHoverMode_ = false;
bool isKeyBoardShow_ = false;
bool alignBottomScreen_ = false;
Rect foldCreaseRect = Rect(0.0, 0.0, 0.0, 0.0);
HoverModeAreaType hoverModeArea_ = HoverModeAreaType::BOTTOM_SCREEN;
KeyboardAvoidMode keyboardAvoidMode_ = KeyboardAvoidMode::DEFAULT;

View File

@ -46,6 +46,8 @@ public:
props->propDialogButtonDirection_ = CloneDialogButtonDirection();
props->propWidth_ = CloneWidth();
props->propHeight_ = CloneHeight();
props->propEnableHoverMode_ = CloneEnableHoverMode();
props->propHoverModeArea_ = CloneHoverModeArea();
return props;
}
@ -61,6 +63,8 @@ public:
ResetIsModal();
ResetWidth();
ResetHeight();
ResetEnableHoverMode();
ResetHoverModeArea();
}
ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(DialogAlignment, DialogAlignment, PROPERTY_UPDATE_MEASURE);
@ -75,6 +79,8 @@ public:
ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Width, CalcDimension, PROPERTY_UPDATE_MEASURE);
ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Height, CalcDimension, PROPERTY_UPDATE_MEASURE);
ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(EnableHoverMode, bool, PROPERTY_UPDATE_MEASURE);
ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(HoverModeArea, HoverModeAreaType, PROPERTY_UPDATE_MEASURE);
void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override
{
LayoutProperty::ToJsonValue(json, filter);
@ -102,6 +108,9 @@ public:
.c_str(), filter);
json->PutExtAttr("width", propWidth_.value_or(CalcDimension(Dimension(-1))).Value(), filter);
json->PutExtAttr("height", propHeight_.value_or(CalcDimension(Dimension(-1))).Value(), filter);
json->PutExtAttr("enableHoverMode", propEnableHoverMode_.value_or(false) ? "true" : "false", filter);
json->PutExtAttr("HoverModeAreaType", GetHoverModeAreaValue(HoverModeAreaType::BOTTOM_SCREEN) ==
HoverModeAreaType::BOTTOM_SCREEN ? "BOTTOM_SCREEN" : "TOP_SCREEN", filter);
}
private:

View File

@ -132,6 +132,31 @@ void DialogPattern::OnAttachToFrameNode()
};
auto callbackId = pipelineContext->RegisterFoldDisplayModeChangedCallback(std::move(foldModeChangeCallback));
UpdateFoldDisplayModeChangedCallbackId(callbackId);
RegisterHoverModeChangeCallback();
}
void DialogPattern::RegisterHoverModeChangeCallback()
{
auto host = GetHost();
CHECK_NULL_VOID(host);
auto context = host->GetContext();
CHECK_NULL_VOID(context);
auto hoverModeChangeCallback = [weak = WeakClaim(this), context](bool isHalfFoldHover) {
auto pattern = weak.Upgrade();
CHECK_NULL_VOID(pattern);
auto host = pattern->GetHost();
CHECK_NULL_VOID(host);
AnimationOption optionPosition;
auto motion = AceType::MakeRefPtr<ResponsiveSpringMotion>(0.35f, 1.0f, 0.0f);
optionPosition.SetCurve(motion);
context->FlushUITasks();
context->Animate(optionPosition, motion, [host, context]() {
host->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
context->FlushUITasks();
});
};
auto hoverModeCallId = context->RegisterHalfFoldHoverChangedCallback(std::move(hoverModeChangeCallback));
UpdateHoverModeChangedCallbackId(hoverModeCallId);
}
void DialogPattern::OnDetachFromFrameNode(FrameNode* frameNode)
@ -142,6 +167,9 @@ void DialogPattern::OnDetachFromFrameNode(FrameNode* frameNode)
if (HasFoldDisplayModeChangedCallbackId()) {
pipeline->UnRegisterFoldDisplayModeChangedCallback(foldDisplayModeChangedCallbackId_.value_or(-1));
}
if (HasHoverModeChangedCallbackId()) {
pipeline->UnRegisterHalfFoldHoverChangedCallback(hoverModeChangedCallbackId_.value_or(-1));
}
}
void DialogPattern::OnFontConfigurationUpdate()

View File

@ -260,6 +260,16 @@ public:
return foldDisplayModeChangedCallbackId_.has_value();
}
void UpdateHoverModeChangedCallbackId(std::optional<int32_t> id)
{
hoverModeChangedCallbackId_ = id;
}
bool HasHoverModeChangedCallbackId()
{
return hoverModeChangedCallbackId_.has_value();
}
bool GetIsSuitableForAging()
{
return isSuitableForElderly_;
@ -308,6 +318,7 @@ private:
void OnAttachToFrameNode() override;
void OnDetachFromFrameNode(FrameNode* frameNode) override;
void RegisterHoverModeChangeCallback();
void OnWindowSizeChanged(int32_t width, int32_t height, WindowSizeChangeReason type) override;
void InitClickEvent(const RefPtr<GestureEventHub>& gestureHub);
void HandleClick(const GestureEvent& info);
@ -374,6 +385,7 @@ private:
std::optional<AnimationOption> openAnimation_;
std::optional<AnimationOption> closeAnimation_;
std::optional<int32_t> foldDisplayModeChangedCallbackId_;
std::optional<int32_t> hoverModeChangedCallbackId_;
bool isFoldStatusChanged_ = false;
// XTS inspector values

View File

@ -69,6 +69,7 @@ RefPtr<FrameNode> DialogView::CreateDialogNode(
dialogLayoutProp->UpdateDialogButtonDirection(param.buttonDirection);
dialogLayoutProp->UpdateIsModal(param.isModal);
dialogLayoutProp->UpdateIsScenceBoardDialog(param.isScenceBoardDialog);
dialogLayoutProp->UpdateEnableHoverMode(param.enableHoverMode);
if (param.width.has_value() && NonNegative(param.width.value().Value())) {
dialogLayoutProp->UpdateWidth(param.width.value());
} else {
@ -77,6 +78,9 @@ RefPtr<FrameNode> DialogView::CreateDialogNode(
if (param.height.has_value() && NonNegative(param.height.value().Value())) {
dialogLayoutProp->UpdateHeight(param.height.value());
}
if (param.hoverModeArea.has_value()) {
dialogLayoutProp->UpdateHoverModeArea(param.hoverModeArea.value());
}
// create gray background
auto dialogContext = dialog->GetRenderContext();
CHECK_NULL_RETURN(dialogContext, dialog);

View File

@ -659,7 +659,10 @@ void DatePickerDialogModelNG::SetDatePickerDialogShow(PickerDialogInfo& pickerDi
if (pickerDialog.shadow.has_value()) {
properties.shadow = pickerDialog.shadow.value();
}
if (pickerDialog.hoverModeArea.has_value()) {
properties.hoverModeArea = pickerDialog.hoverModeArea.value();
}
properties.enableHoverMode = pickerDialog.enableHoverMode;
properties.customStyle = false;
if (Container::LessThanAPIVersion(PlatformVersion::VERSION_ELEVEN)) {
properties.offset = DimensionOffset(Offset(0, -theme->GetMarginBottom().ConvertToPx()));

View File

@ -35,12 +35,14 @@ struct PickerDialogInfo {
bool isStartDate;
bool isEndDate;
bool isSelectedDate;
bool enableHoverMode;
std::optional<DialogAlignment> alignment;
std::optional<DimensionOffset> offset;
std::optional<DimensionRect> maskRect;
std::optional<Color> backgroundColor;
std::optional<int32_t> backgroundBlurStyle;
std::optional<Shadow> shadow;
std::optional<HoverModeAreaType> hoverModeArea;
};
struct PickerDialogEvent {
std::function<void()> onDidAppear;

View File

@ -29,12 +29,14 @@ struct TextPickerDialog {
uint32_t selectedValue;
std::vector<std::string> getRangeVector;
bool isDefaultHeight;
bool enableHoverMode;
std::optional<DialogAlignment> alignment;
std::optional<DimensionOffset> offset;
std::optional<DimensionRect> maskRect;
std::optional<Color> backgroundColor;
std::optional<int32_t> backgroundBlurStyle;
std::optional<Shadow> shadow;
std::optional<HoverModeAreaType> hoverModeArea;
};
struct TextPickerDialogEvent {
std::function<void()> onDidAppear;

View File

@ -67,6 +67,10 @@ void SetDialogProperties(DialogProperties& properties, TextPickerDialog& textPic
}
properties.maskRect = textPickerDialog.maskRect;
properties.enableHoverMode = textPickerDialog.enableHoverMode;
if (textPickerDialog.hoverModeArea.has_value()) {
properties.hoverModeArea = textPickerDialog.hoverModeArea.value();
}
}
}

View File

@ -449,6 +449,10 @@ void TimePickerDialogModelNG::SetTimePickerDialogShow(PickerDialogInfo& pickerDi
}
properties.maskRect = pickerDialog.maskRect;
properties.enableHoverMode = pickerDialog.enableHoverMode;
if (pickerDialog.hoverModeArea.has_value()) {
properties.hoverModeArea = pickerDialog.hoverModeArea.value();
}
std::map<std::string, PickerTime> timePickerProperty;
if (pickerDialog.isSelectedTime == true) {

View File

@ -27,10 +27,6 @@ enum class ToastShowMode {
TOP_MOST = 1,
SYSTEM_TOP_MOST = 2,
};
enum class HoverModeAreaType {
TOP_SCREEN = 0,
BOTTOM_SCREEN = 1,
};
struct ToastInfo {
std::string message;
int32_t duration = 0;

View File

@ -36,6 +36,8 @@ const std::vector<DialogAlignment> DIALOG_ALIGNMENT = { DialogAlignment::TOP, Di
DialogAlignment::CENTER_START, DialogAlignment::CENTER_END, DialogAlignment::BOTTOM_START,
DialogAlignment::BOTTOM_END };
const std::vector<KeyboardAvoidMode> KEYBOARD_AVOID_MODE = { KeyboardAvoidMode::DEFAULT, KeyboardAvoidMode::NONE };
const std::vector<HoverModeAreaType> HOVER_MODE_AREA_TYPE = { HoverModeAreaType::TOP_SCREEN,
HoverModeAreaType::BOTTOM_SCREEN };
#ifdef OHOS_STANDARD_SYSTEM
bool ContainerIsService()
@ -369,15 +371,15 @@ void GetToastEnableHoverMode(napi_env env, napi_value enableHoverModeNApi, bool&
}
}
void GetToastHoverModeArea(napi_env env, napi_value hoverModeAreaNApi, NG::HoverModeAreaType& hoverModeArea)
void GetToastHoverModeArea(napi_env env, napi_value hoverModeAreaNApi, HoverModeAreaType& hoverModeArea)
{
napi_valuetype valueType = napi_undefined;
napi_typeof(env, hoverModeAreaNApi, &valueType);
if (valueType == napi_number) {
int32_t num = -1;
napi_get_value_int32(env, hoverModeAreaNApi, &num);
if (num >= 0 && num <= static_cast<int32_t>(NG::HoverModeAreaType::BOTTOM_SCREEN)) {
hoverModeArea = static_cast<NG::HoverModeAreaType>(num);
if (num >= 0 && num <= static_cast<int32_t>(HoverModeAreaType::BOTTOM_SCREEN)) {
hoverModeArea = static_cast<HoverModeAreaType>(num);
}
}
}
@ -608,6 +610,8 @@ struct PromptAsyncContext {
napi_value onWillDismiss = nullptr;
napi_value backgroundColorApi = nullptr;
napi_value backgroundBlurStyleApi = nullptr;
napi_value enableHoverMode = nullptr;
napi_value hoverModeAreaApi = nullptr;
napi_value borderWidthApi = nullptr;
napi_value borderColorApi = nullptr;
napi_value borderStyleApi = nullptr;
@ -629,6 +633,7 @@ struct PromptAsyncContext {
std::string messageString;
std::vector<ButtonInfo> buttons;
bool autoCancelBool = true;
bool enableHoverModeBool = false;
bool showInSubWindowBool = false;
bool isModalBool = true;
std::set<std::string> callbacks;
@ -820,20 +825,30 @@ void GetNapiDialogProps(napi_env env, const std::shared_ptr<PromptAsyncContext>&
}
}
void GetNapiDialogbackgroundBlurStyleProps(napi_env env, const std::shared_ptr<PromptAsyncContext>& asyncContext,
std::optional<int32_t>& backgroundBlurStyle)
void GetNapiBlurStyleAndHoverModeProps(napi_env env, const std::shared_ptr<PromptAsyncContext>& asyncContext,
std::optional<int32_t>& backgroundBlurStyle, std::optional<HoverModeAreaType>& hoverModeArea)
{
TAG_LOGD(AceLogTag::ACE_DIALOG, "get napi dialog backgroundBlurStyle props enter");
napi_valuetype valueType = napi_undefined;
TAG_LOGD(AceLogTag::ACE_DIALOG, "get napi dialog backgroundBlurStyle and hoverModeArea props enter");
napi_valuetype blurStyleValueType = napi_undefined;
napi_typeof(env, asyncContext->backgroundBlurStyleApi, &valueType);
if (valueType == napi_number) {
napi_typeof(env, asyncContext->backgroundBlurStyleApi, &blurStyleValueType);
if (blurStyleValueType == napi_number) {
int32_t num;
napi_get_value_int32(env, asyncContext->backgroundBlurStyleApi, &num);
if (num >= 0 && num < BG_BLUR_STYLE_MAX_INDEX) {
backgroundBlurStyle = num;
}
}
napi_valuetype hoverModeValueType = napi_undefined;
napi_typeof(env, asyncContext->hoverModeAreaApi, &hoverModeValueType);
if (hoverModeValueType == napi_number) {
int32_t num;
napi_get_value_int32(env, asyncContext->hoverModeAreaApi, &num);
if (num >= 0 && num < static_cast<int32_t>(HOVER_MODE_AREA_TYPE.size())) {
hoverModeArea = HOVER_MODE_AREA_TYPE[num];
}
}
}
void CheckNapiDimension(CalcDimension value)
@ -1165,6 +1180,27 @@ int32_t GetDialogKeyboardAvoidMode(napi_env env, napi_value keyboardAvoidModeApi
return 0;
}
void GetNapiNamedBoolProperties(napi_env env, std::shared_ptr<PromptAsyncContext>& asyncContext)
{
napi_valuetype valueType = napi_undefined;
napi_typeof(env, asyncContext->autoCancel, &valueType);
if (valueType == napi_boolean) {
napi_get_value_bool(env, asyncContext->autoCancel, &asyncContext->autoCancelBool);
}
napi_typeof(env, asyncContext->enableHoverMode, &valueType);
if (valueType == napi_boolean) {
napi_get_value_bool(env, asyncContext->enableHoverMode, &asyncContext->enableHoverModeBool);
}
napi_typeof(env, asyncContext->showInSubWindow, &valueType);
if (valueType == napi_boolean) {
napi_get_value_bool(env, asyncContext->showInSubWindow, &asyncContext->showInSubWindowBool);
}
napi_typeof(env, asyncContext->isModal, &valueType);
if (valueType == napi_boolean) {
napi_get_value_bool(env, asyncContext->isModal, &asyncContext->isModalBool);
}
}
void GetNapiNamedProperties(napi_env env, napi_value* argv, size_t index,
std::shared_ptr<PromptAsyncContext>& asyncContext)
{
@ -1174,6 +1210,7 @@ void GetNapiNamedProperties(napi_env env, napi_value* argv, size_t index,
napi_get_named_property(env, argv[index], "builder", &asyncContext->builder);
napi_get_named_property(env, argv[index], "backgroundColor", &asyncContext->backgroundColorApi);
napi_get_named_property(env, argv[index], "backgroundBlurStyle", &asyncContext->backgroundBlurStyleApi);
napi_get_named_property(env, argv[index], "hoverModeArea", &asyncContext->hoverModeAreaApi);
napi_get_named_property(env, argv[index], "cornerRadius", &asyncContext->borderRadiusApi);
napi_get_named_property(env, argv[index], "borderWidth", &asyncContext->borderWidthApi);
napi_get_named_property(env, argv[index], "borderColor", &asyncContext->borderColorApi);
@ -1187,6 +1224,7 @@ void GetNapiNamedProperties(napi_env env, napi_value* argv, size_t index,
napi_create_reference(env, asyncContext->builder, 1, &asyncContext->builderRef);
}
}
napi_get_named_property(env, argv[index], "enableHoverMode", &asyncContext->enableHoverMode);
napi_get_named_property(env, argv[index], "showInSubWindow", &asyncContext->showInSubWindow);
napi_get_named_property(env, argv[index], "isModal", &asyncContext->isModal);
napi_get_named_property(env, argv[index], "alignment", &asyncContext->alignmentApi);
@ -1202,18 +1240,7 @@ void GetNapiNamedProperties(napi_env env, napi_value* argv, size_t index,
napi_get_named_property(env, argv[index], "onWillDisappear", &asyncContext->onWillDisappear);
napi_get_named_property(env, argv[index], "keyboardAvoidMode", &asyncContext->keyboardAvoidModeApi);
napi_typeof(env, asyncContext->autoCancel, &valueType);
if (valueType == napi_boolean) {
napi_get_value_bool(env, asyncContext->autoCancel, &asyncContext->autoCancelBool);
}
napi_typeof(env, asyncContext->showInSubWindow, &valueType);
if (valueType == napi_boolean) {
napi_get_value_bool(env, asyncContext->showInSubWindow, &asyncContext->showInSubWindowBool);
}
napi_typeof(env, asyncContext->isModal, &valueType);
if (valueType == napi_boolean) {
napi_get_value_bool(env, asyncContext->isModal, &asyncContext->isModalBool);
}
GetNapiNamedBoolProperties(env, asyncContext);
}
bool JSPromptParseParam(napi_env env, size_t argc, napi_value* argv, std::shared_ptr<PromptAsyncContext>& asyncContext)
@ -1338,6 +1365,7 @@ napi_value JSPromptShowDialog(napi_env env, napi_callback_info info)
std::optional<Shadow> shadowProps;
std::optional<Color> backgroundColor;
std::optional<int32_t> backgroundBlurStyle;
std::optional<HoverModeAreaType> hoverModeArea;
for (size_t i = 0; i < argc; i++) {
napi_valuetype valueType = napi_undefined;
@ -1359,15 +1387,21 @@ napi_value JSPromptShowDialog(napi_env env, napi_callback_info info)
napi_get_named_property(env, argv[0], "shadow", &asyncContext->shadowApi);
napi_get_named_property(env, argv[0], "backgroundColor", &asyncContext->backgroundColorApi);
napi_get_named_property(env, argv[0], "backgroundBlurStyle", &asyncContext->backgroundBlurStyleApi);
napi_get_named_property(env, argv[0], "enableHoverMode", &asyncContext->enableHoverMode);
napi_get_named_property(env, argv[0], "hoverModeArea", &asyncContext->hoverModeAreaApi);
GetNapiString(env, asyncContext->titleNApi, asyncContext->titleString, valueType);
GetNapiString(env, asyncContext->messageNApi, asyncContext->messageString, valueType);
GetNapiDialogProps(env, asyncContext, alignment, offset, maskRect);
GetNapiDialogbackgroundBlurStyleProps(env, asyncContext, backgroundBlurStyle);
backgroundColor = GetColorProps(env, asyncContext->backgroundColorApi);
shadowProps = GetShadowProps(env, asyncContext);
GetNapiBlurStyleAndHoverModeProps(env, asyncContext, backgroundBlurStyle, hoverModeArea);
if (!ParseButtonsPara(env, asyncContext, SHOW_DIALOG_BUTTON_NUM_MAX, false)) {
return nullptr;
}
napi_typeof(env, asyncContext->enableHoverMode, &valueType);
if (valueType == napi_boolean) {
napi_get_value_bool(env, asyncContext->enableHoverMode, &asyncContext->enableHoverModeBool);
}
napi_typeof(env, asyncContext->autoCancel, &valueType);
if (valueType == napi_boolean) {
napi_get_value_bool(env, asyncContext->autoCancel, &asyncContext->autoCancelBool);
@ -1510,6 +1544,8 @@ napi_value JSPromptShowDialog(napi_env env, napi_callback_info info)
.backgroundColor = backgroundColor,
.backgroundBlurStyle = backgroundBlurStyle,
.shadow = shadowProps,
.enableHoverMode = asyncContext->enableHoverModeBool,
.hoverModeArea = hoverModeArea,
.onLanguageChange = onLanguageChange,
};
@ -1904,20 +1940,16 @@ PromptDialogAttr GetPromptActionDialog(napi_env env, const std::shared_ptr<Promp
std::optional<DimensionOffset> offset;
std::optional<DimensionRect> maskRect;
std::optional<int32_t> backgroundBlurStyle;
std::optional<HoverModeAreaType> hoverModeArea;
GetNapiDialogProps(env, asyncContext, alignment, offset, maskRect);
GetNapiBlurStyleAndHoverModeProps(env, asyncContext, backgroundBlurStyle, hoverModeArea);
auto borderWidthProps = GetBorderWidthProps(env, asyncContext);
std::optional<NG::BorderColorProperty> borderColorProps;
std::optional<NG::BorderStyleProperty> borderStyleProps;
GetNapiDialogbackgroundBlurStyleProps(env, asyncContext, backgroundBlurStyle);
ParseBorderColorAndStyle(env, asyncContext, borderWidthProps, borderColorProps, borderStyleProps);
auto borderRadiusProps = GetBorderRadiusProps(env, asyncContext);
auto backgroundColorProps = GetColorProps(env, asyncContext->backgroundColorApi);
auto widthProps = GetNapiDialogWidthProps(env, asyncContext);
auto heightProps = GetNapiDialogHeightProps(env, asyncContext);
auto shadowProps = GetShadowProps(env, asyncContext);
auto builder = GetCustomBuilder(env, asyncContext);
auto* nodePtr = reinterpret_cast<OHOS::Ace::NG::UINode*>(asyncContext->nativePtr);
auto frameNodeWeak = AceType::WeakClaim(nodePtr);
auto maskColorProps = GetColorProps(env, asyncContext->maskColorApi);
auto transitionEffectProps = GetTransitionProps(env, asyncContext);
PromptDialogAttr lifeCycleAttr = GetDialogLifeCycleCallback(env, asyncContext);
@ -1935,18 +1967,20 @@ PromptDialogAttr GetPromptActionDialog(napi_env env, const std::shared_ptr<Promp
.borderWidth = borderWidthProps,
.borderColor = borderColorProps,
.borderStyle = borderStyleProps,
.borderRadius = borderRadiusProps,
.shadow = shadowProps,
.width = widthProps,
.height = heightProps,
.contentNode = frameNodeWeak,
.borderRadius = GetBorderRadiusProps(env, asyncContext),
.shadow = GetShadowProps(env, asyncContext),
.width = GetNapiDialogWidthProps(env, asyncContext),
.height = GetNapiDialogHeightProps(env, asyncContext),
.contentNode = AceType::WeakClaim(nodePtr),
.maskColor = maskColorProps,
.transitionEffect = transitionEffectProps,
.onDidAppear = lifeCycleAttr.onDidAppear,
.onDidDisappear = lifeCycleAttr.onDidDisappear,
.onWillAppear = lifeCycleAttr.onWillAppear,
.onWillDisappear = lifeCycleAttr.onWillDisappear,
.keyboardAvoidMode = KEYBOARD_AVOID_MODE[mode]};
.keyboardAvoidMode = KEYBOARD_AVOID_MODE[mode],
.enableHoverMode = asyncContext->enableHoverModeBool,
.hoverModeArea = hoverModeArea };
return promptDialogAttr;
}

View File

@ -62,6 +62,7 @@ const Dimension DIMENSION_RADIUS(10.0, DimensionUnit::PX);
const Dimension DIMENSION_NEGATIVE(-1.0, DimensionUnit::PX);
const Dimension DIMENSION_SIZE(100.0, DimensionUnit::PX);
const SafeAreaInsets::Inset KEYBOARD_INSET = { .start = 500.f, .end = 1000.f };
const Rect FOLD_CREASE_RECT = Rect(0.0, 300.0, 720.0, 80.0);
} // namespace
class DialogModelTestNg : public testing::Test {
@ -1313,4 +1314,75 @@ HWTEST_F(DialogModelTestNg, DialogModelTestNg032, TestSize.Level1)
EXPECT_EQ(maskRect.value().GetWidth(), Dimension(CHILD_SIZE, DimensionUnit::PX));
EXPECT_EQ(maskRect.value().GetHeight(), Dimension(CHILD_SIZE, DimensionUnit::PX));
}
/**
* @tc.name: DialogModelTestNg033
* @tc.desc: Test DialogLayoutAlgorithm::UpdateChildMaxSizeHeight function
* @tc.type: FUNC
*/
HWTEST_F(DialogModelTestNg, DialogModelTestNg033, TestSize.Level1)
{
/**
* @tc.steps: step1. create DialogLayoutAlgorithm instance.
*/
MockPipelineContext::GetCurrent()->SetMinPlatformVersion(static_cast<int32_t>(PlatformVersion::VERSION_THIRTEEN));
auto dialogLayoutAlgorithm = AceType::MakeRefPtr<DialogLayoutAlgorithm>();
ASSERT_NE(dialogLayoutAlgorithm, nullptr);
auto maxSize = CONTAINER_SIZE;
SafeAreaInsets::Inset insetLeftAndRight = {};
SafeAreaInsets::Inset insetTopAndBottom = { .end = 100.f };
SafeAreaInsets SYSTEM_SAFE_AREA_INSET = { insetLeftAndRight, insetTopAndBottom,
insetLeftAndRight, insetTopAndBottom };
dialogLayoutAlgorithm->foldCreaseRect = FOLD_CREASE_RECT;
dialogLayoutAlgorithm->safeAreaInsets_ = SYSTEM_SAFE_AREA_INSET;
dialogLayoutAlgorithm->isHoverMode_ = false;
dialogLayoutAlgorithm->UpdateChildMaxSizeHeight(maxSize);
EXPECT_EQ(maxSize.Height(), 936);
dialogLayoutAlgorithm->isHoverMode_ = true;
dialogLayoutAlgorithm->hoverModeArea_ = HoverModeAreaType::TOP_SCREEN;
maxSize = CONTAINER_SIZE;
dialogLayoutAlgorithm->UpdateChildMaxSizeHeight(maxSize);
EXPECT_EQ(maxSize.Height(), 200);
dialogLayoutAlgorithm->isKeyBoardShow_ = false;
dialogLayoutAlgorithm->hoverModeArea_ = HoverModeAreaType::BOTTOM_SCREEN;
maxSize = CONTAINER_SIZE;
dialogLayoutAlgorithm->UpdateChildMaxSizeHeight(maxSize);
EXPECT_EQ(maxSize.Height(), 656);
}
/**
* @tc.name: DialogModelTestNg034
* @tc.desc: Test DialogLayoutAlgorithm::SetAlignmentSwitch function
* @tc.type: FUNC
*/
HWTEST_F(DialogModelTestNg, DialogModelTestNg034, TestSize.Level1)
{
/**
* @tc.steps: step1. create DialogLayoutAlgorithm instance.
*/
MockPipelineContext::GetCurrent()->SetMinPlatformVersion(static_cast<int32_t>(PlatformVersion::VERSION_THIRTEEN));
auto dialogLayoutAlgorithm = AceType::MakeRefPtr<DialogLayoutAlgorithm>();
ASSERT_NE(dialogLayoutAlgorithm, nullptr);
auto maxSize = CONTAINER_SIZE;
auto childSize = SizeF(CHILD_SIZE, CHILD_SIZE);
dialogLayoutAlgorithm->alignment_ = DialogAlignment::TOP;
dialogLayoutAlgorithm->isHoverMode_ = true;
dialogLayoutAlgorithm->foldCreaseRect = FOLD_CREASE_RECT;
OffsetF topLeftPoint;
/**
* @tc.steps: step2. call SetAlignmentSwitch function.
* @tc.expected: the results are correct.
*/
dialogLayoutAlgorithm->alignBottomScreen_ = true;
dialogLayoutAlgorithm->SetAlignmentSwitch(maxSize, childSize, topLeftPoint);
dialogLayoutAlgorithm->AdjustChildPosition(topLeftPoint, topLeftPoint, childSize, true);
EXPECT_EQ(topLeftPoint.GetY(), FOLD_CREASE_RECT.Bottom());
dialogLayoutAlgorithm->alignBottomScreen_ = false;
dialogLayoutAlgorithm->SetAlignmentSwitch(maxSize, childSize, topLeftPoint);
dialogLayoutAlgorithm->AdjustChildPosition(topLeftPoint, topLeftPoint, childSize, true);
EXPECT_EQ(topLeftPoint.GetY(), 0);
}
} // namespace OHOS::Ace::NG

View File

@ -1566,7 +1566,7 @@ HWTEST_F(OverlayTestNg, ToastTest009, TestSize.Level1)
ASSERT_NE(toastPattern, nullptr);
EXPECT_TRUE(toastPattern->IsDefaultToast());
EXPECT_FALSE(toastPattern->toastInfo_.enableHoverMode);
EXPECT_EQ(toastPattern->toastInfo_.hoverModeArea, NG::HoverModeAreaType::BOTTOM_SCREEN);
EXPECT_EQ(toastPattern->toastInfo_.hoverModeArea, HoverModeAreaType::BOTTOM_SCREEN);
}
/**
@ -1584,7 +1584,7 @@ HWTEST_F(OverlayTestNg, ToastTest010, TestSize.Level1)
.bottom = BOTTOMSTRING,
.isRightToLeft = true };
toastInfo.enableHoverMode = true;
toastInfo.hoverModeArea = NG::HoverModeAreaType::TOP_SCREEN;
toastInfo.hoverModeArea = HoverModeAreaType::TOP_SCREEN;
/**
* @tc.steps: step2. create ToastNode toastPattern.
*/
@ -1597,7 +1597,7 @@ HWTEST_F(OverlayTestNg, ToastTest010, TestSize.Level1)
*/
EXPECT_TRUE(toastPattern->IsDefaultToast());
EXPECT_TRUE(toastPattern->toastInfo_.enableHoverMode);
EXPECT_EQ(toastPattern->toastInfo_.hoverModeArea, NG::HoverModeAreaType::TOP_SCREEN);
EXPECT_EQ(toastPattern->toastInfo_.hoverModeArea, HoverModeAreaType::TOP_SCREEN);
}
/**