mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2024-11-23 07:01:24 +00:00
commit
ffcc854f4e
@ -99,7 +99,15 @@ size_t GetLineCount(const RefPtr<LayoutWrapper>& textWrapper, LayoutConstraintF&
|
||||
|
||||
void ToastLayoutAlgorithm::Measure(LayoutWrapper* layoutWrapper)
|
||||
{
|
||||
CHECK_NULL_VOID(layoutWrapper);
|
||||
auto layoutConstraint = layoutWrapper->GetLayoutProperty()->CreateChildConstraint();
|
||||
auto toastProps = DynamicCast<ToastLayoutProperty>(layoutWrapper->GetLayoutProperty());
|
||||
CHECK_NULL_VOID(toastProps);
|
||||
auto toastNode = layoutWrapper->GetHostNode();
|
||||
CHECK_NULL_VOID(toastNode);
|
||||
auto toastPattern = toastNode->GetPattern<ToastPattern>();
|
||||
CHECK_NULL_VOID(toastPattern);
|
||||
toastPattern->InitWrapperRect(layoutWrapper, toastProps);
|
||||
auto text = layoutWrapper->GetOrCreateChildByIndex(0);
|
||||
// TextAlign should be START when lines of text are greater than 1
|
||||
if (GetLineCount(text, layoutConstraint) > 1) {
|
||||
|
@ -27,6 +27,10 @@ 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;
|
||||
@ -39,6 +43,8 @@ struct ToastInfo {
|
||||
std::optional<Color> textColor;
|
||||
std::optional<int32_t> backgroundBlurStyle;
|
||||
std::optional<Shadow> shadow;
|
||||
bool enableHoverMode = false;
|
||||
HoverModeAreaType hoverModeArea = HoverModeAreaType::BOTTOM_SCREEN;
|
||||
};
|
||||
class ACE_EXPORT ToastLayoutProperty : public LayoutProperty {
|
||||
DECLARE_ACE_TYPE(ToastLayoutProperty, LayoutProperty);
|
||||
@ -53,6 +59,8 @@ public:
|
||||
props->LayoutProperty::UpdateLayoutProperty(DynamicCast<LayoutProperty>(this));
|
||||
props->propBottom_ = CloneBottom();
|
||||
props->propShowMode_ = CloneShowMode();
|
||||
props->propEnableHoverMode_ = CloneEnableHoverMode();
|
||||
props->propHoverModeArea_ = CloneHoverModeArea();
|
||||
return props;
|
||||
}
|
||||
|
||||
@ -61,6 +69,8 @@ public:
|
||||
LayoutProperty::Reset();
|
||||
ResetBottom();
|
||||
ResetShowMode();
|
||||
ResetEnableHoverMode();
|
||||
ResetHoverModeArea();
|
||||
}
|
||||
|
||||
enum class SelectStatus {
|
||||
@ -83,6 +93,8 @@ public:
|
||||
ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(ToastOffset, DimensionOffset, PROPERTY_UPDATE_MEASURE);
|
||||
ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Bottom, Dimension, PROPERTY_UPDATE_MEASURE);
|
||||
ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(ShowMode, ToastShowMode, PROPERTY_UPDATE_LAYOUT);
|
||||
ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(EnableHoverMode, bool, PROPERTY_UPDATE_LAYOUT);
|
||||
ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(HoverModeArea, HoverModeAreaType, PROPERTY_UPDATE_LAYOUT);
|
||||
|
||||
void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override
|
||||
{
|
||||
@ -102,6 +114,10 @@ public:
|
||||
offsetValue->Put("dX", propToastOffset_.value_or(DimensionOffset()).GetX().ConvertToVp());
|
||||
offsetValue->Put("dY", propToastOffset_.value_or(DimensionOffset()).GetY().ConvertToVp());
|
||||
json->PutExtAttr("offset", offsetValue, 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:
|
||||
|
@ -43,12 +43,83 @@ RefPtr<PipelineContext> GetMainPipelineContext()
|
||||
CHECK_NULL_RETURN(parentContainer, nullptr);
|
||||
context = AceType::DynamicCast<PipelineContext>(parentContainer->GetPipelineContext());
|
||||
} else {
|
||||
context = PipelineContext::GetCurrentContext();
|
||||
context = PipelineContext::GetCurrentContextSafelyWithCheck();
|
||||
}
|
||||
return context;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void ToastPattern::InitWrapperRect(LayoutWrapper* layoutWrapper, const RefPtr<ToastLayoutProperty>& toastProps)
|
||||
{
|
||||
// init toast wrapper rect with different settings.
|
||||
auto pipelineContext =
|
||||
IsDefaultToast() ? PipelineContext::GetCurrentContextSafelyWithCheck() : GetMainPipelineContext();
|
||||
CHECK_NULL_VOID(pipelineContext);
|
||||
auto safeAreaManager = pipelineContext->GetSafeAreaManager();
|
||||
CHECK_NULL_VOID(safeAreaManager);
|
||||
float safeAreaTop = safeAreaManager->GetSystemSafeArea().top_.Length();
|
||||
const auto& safeArea = toastProps->GetSafeAreaInsets();
|
||||
// Default Toast need to avoid keyboard, but the Top mode doesn't need.
|
||||
float safeAreaBottom =
|
||||
safeArea ? safeArea->bottom_.Length() : safeAreaManager->GetSafeAreaWithoutProcess().bottom_.Length();
|
||||
wrapperRect_ = pipelineContext->GetDisplayWindowRectInfo();
|
||||
wrapperRect_.SetRect(wrapperRect_.Left(), safeAreaTop,
|
||||
pipelineContext->GetRootWidth(), pipelineContext->GetRootHeight() - safeAreaTop - safeAreaBottom);
|
||||
isHoverMode_ = pipelineContext->IsHalfFoldHoverStatus();
|
||||
if (isHoverMode_ && toastInfo_.enableHoverMode) {
|
||||
UpdateHoverModeRect(toastProps, safeAreaManager, safeAreaTop, safeAreaBottom);
|
||||
}
|
||||
}
|
||||
|
||||
void ToastPattern::UpdateHoverModeRect(const RefPtr<ToastLayoutProperty>& toastProps,
|
||||
const RefPtr<SafeAreaManager>& safeAreaManager, float safeAreaTop, float safeAreaBottom)
|
||||
{
|
||||
auto hoverModeArea = toastProps->GetHoverModeAreaValue(HoverModeAreaType::TOP_SCREEN);
|
||||
auto container = Container::CurrentSafelyWithCheck();
|
||||
auto displayInfo = container->GetDisplayInfo();
|
||||
auto foldCreaseRects = displayInfo->GetCurrentFoldCreaseRegion();
|
||||
float foldCreaseTop = 0.0f;
|
||||
float foldCreaseBottom = 0.0f;
|
||||
if (!foldCreaseRects.empty()) {
|
||||
auto foldCrease = foldCreaseRects.front();
|
||||
foldCreaseTop = foldCrease.Top();
|
||||
foldCreaseBottom = foldCrease.Bottom();
|
||||
}
|
||||
bool isKeyboardShow = false;
|
||||
switch (hoverModeArea) {
|
||||
case HoverModeAreaType::TOP_SCREEN:
|
||||
wrapperRect_.SetRect(wrapperRect_.Left(), safeAreaTop, wrapperRect_.Width(), foldCreaseTop - safeAreaTop);
|
||||
break;
|
||||
case HoverModeAreaType::BOTTOM_SCREEN:
|
||||
isKeyboardShow = safeAreaManager->GetKeyboardInset().IsValid();
|
||||
// if keyboard is show, wrapper rect change to the up half screen.
|
||||
if (isKeyboardShow && IsDefaultToast()) {
|
||||
wrapperRect_.SetRect(wrapperRect_.Left(), safeAreaTop,
|
||||
wrapperRect_.Width(), foldCreaseTop - safeAreaTop);
|
||||
} else {
|
||||
wrapperRect_.SetRect(wrapperRect_.Left(), foldCreaseBottom,
|
||||
wrapperRect_.Width(), wrapperRect_.Height() - foldCreaseBottom + safeAreaTop);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
void ToastPattern::FoldStatusChangedAnimation()
|
||||
{
|
||||
auto host = GetHost();
|
||||
CHECK_NULL_VOID(host);
|
||||
AnimationOption option;
|
||||
auto curve = AceType::MakeRefPtr<ResponsiveSpringMotion>(0.35f, 1.0f, 0.0f);
|
||||
option.SetCurve(curve);
|
||||
auto context = host->GetContext();
|
||||
CHECK_NULL_VOID(context);
|
||||
AnimationUtils::Animate(option, [host, context]() {
|
||||
host->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
|
||||
context->FlushUITasks();
|
||||
});
|
||||
}
|
||||
|
||||
bool ToastPattern::OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& changeConfig)
|
||||
{
|
||||
CHECK_NULL_RETURN(dirty, false);
|
||||
@ -74,7 +145,7 @@ Dimension ToastPattern::GetOffsetX(const RefPtr<LayoutWrapper>& layoutWrapper)
|
||||
CHECK_NULL_RETURN(context, Dimension(0.0));
|
||||
auto text = layoutWrapper->GetOrCreateChildByIndex(0);
|
||||
CHECK_NULL_RETURN(text, Dimension(0.0));
|
||||
auto rootWidth = context->GetRootWidth();
|
||||
auto rootWidth = wrapperRect_.Width();
|
||||
auto toastProp = DynamicCast<ToastLayoutProperty>(layoutWrapper->GetLayoutProperty());
|
||||
CHECK_NULL_RETURN(toastProp, Dimension(0.0));
|
||||
auto textWidth = text->GetGeometryNode()->GetMarginFrameSize().Width();
|
||||
@ -98,24 +169,16 @@ Dimension ToastPattern::GetOffsetY(const RefPtr<LayoutWrapper>& layoutWrapper)
|
||||
CHECK_NULL_RETURN(context, Dimension(0.0));
|
||||
auto text = layoutWrapper->GetOrCreateChildByIndex(0);
|
||||
CHECK_NULL_RETURN(text, Dimension(0.0));
|
||||
auto rootHeight = context->GetRootHeight();
|
||||
auto rootHeight = wrapperRect_.Height();
|
||||
auto toastProp = DynamicCast<ToastLayoutProperty>(layoutWrapper->GetLayoutProperty());
|
||||
CHECK_NULL_RETURN(toastProp, Dimension(0.0));
|
||||
auto textHeight = text->GetGeometryNode()->GetMarginFrameSize().Height();
|
||||
Dimension offsetY;
|
||||
auto safeAreaManager = context->GetSafeAreaManager();
|
||||
auto safeAreaOffset = safeAreaManager ? safeAreaManager->GetSafeAreaWithoutProcess().bottom_.Length() : 0;
|
||||
auto showMode = toastProp->GetShowModeValue(ToastShowMode::DEFAULT);
|
||||
if (showMode == ToastShowMode::DEFAULT) {
|
||||
auto keyboardInset = safeAreaManager ? safeAreaManager->GetKeyboardInset().Length() : 0;
|
||||
auto keyboardOffset = GreatNotEqual(keyboardInset, 0) ? keyboardInset : 0;
|
||||
safeAreaOffset = safeAreaOffset + keyboardOffset;
|
||||
}
|
||||
if (!toastProp->HasToastAlignment()) {
|
||||
auto toastBottom = GetBottomValue(layoutWrapper);
|
||||
toastBottom_ = toastBottom;
|
||||
if (context->GetMinPlatformVersion() > API_VERSION_9) {
|
||||
offsetY = Dimension(rootHeight - toastBottom - textHeight - safeAreaOffset);
|
||||
offsetY = Dimension(rootHeight - toastBottom - textHeight);
|
||||
} else {
|
||||
offsetY = Dimension(rootHeight - toastBottom);
|
||||
}
|
||||
@ -123,17 +186,16 @@ Dimension ToastPattern::GetOffsetY(const RefPtr<LayoutWrapper>& layoutWrapper)
|
||||
Alignment alignment = toastProp->GetToastAlignmentValue(Alignment::BOTTOM_CENTER);
|
||||
if (alignment == Alignment::TOP_LEFT || alignment == Alignment::TOP_CENTER ||
|
||||
alignment == Alignment::TOP_RIGHT) {
|
||||
// Top Needs Avoid System Navigation Bar
|
||||
auto safeAreaManager = context->GetSafeAreaManager();
|
||||
auto sysTop = safeAreaManager ? safeAreaManager->GetSystemSafeArea().top_.Length() : 0.0f;
|
||||
offsetY = Dimension(sysTop);
|
||||
offsetY = Dimension(0.0f);
|
||||
} else if (alignment == Alignment::CENTER_LEFT || alignment == Alignment::CENTER ||
|
||||
alignment == Alignment::CENTER_RIGHT) {
|
||||
offsetY = Dimension((rootHeight - textHeight - safeAreaOffset) / 2.0f);
|
||||
offsetY = Dimension((rootHeight - textHeight) / 2.0f);
|
||||
} else {
|
||||
offsetY = Dimension(rootHeight - textHeight - safeAreaOffset);
|
||||
offsetY = Dimension(rootHeight - textHeight);
|
||||
}
|
||||
}
|
||||
// add toast wrapper rect's offsetY.
|
||||
offsetY += Dimension(wrapperRect_.Top());
|
||||
return offsetY + toastProp->GetToastOffsetValue(DimensionOffset()).GetY();
|
||||
}
|
||||
|
||||
@ -142,7 +204,7 @@ double ToastPattern::GetBottomValue(const RefPtr<LayoutWrapper>& layoutWrapper)
|
||||
// Obtain the height relative to the main window
|
||||
auto pipeline = IsDefaultToast() ? PipelineContext::GetCurrentContext() : GetMainPipelineContext();
|
||||
CHECK_NULL_RETURN(pipeline, 0.0);
|
||||
auto rootHeight = Dimension(pipeline->GetRootHeight());
|
||||
auto rootHeight = Dimension(wrapperRect_.Height());
|
||||
auto toastTheme = pipeline->GetTheme<ToastTheme>();
|
||||
CHECK_NULL_RETURN(toastTheme, 0.0);
|
||||
|
||||
@ -178,9 +240,7 @@ void ToastPattern::UpdateToastSize(const RefPtr<FrameNode>& toast)
|
||||
CHECK_NULL_VOID(toast);
|
||||
auto toastProperty = toast->GetLayoutProperty<ToastLayoutProperty>();
|
||||
CHECK_NULL_VOID(toastProperty);
|
||||
auto context = PipelineBase::GetCurrentContext();
|
||||
CHECK_NULL_VOID(context);
|
||||
auto rootWidth = Dimension(context->GetRootWidth());
|
||||
auto rootWidth = Dimension(wrapperRect_.Width());
|
||||
if (Container::GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_TWELVE)) {
|
||||
auto limitWidth = Dimension(GetTextMaxWidth());
|
||||
toastProperty->UpdateUserDefinedIdealSize(CalcSize(NG::CalcLength(limitWidth), std::nullopt));
|
||||
@ -264,6 +324,11 @@ void ToastPattern::OnAttachToFrameNode()
|
||||
}
|
||||
});
|
||||
UpdateFoldDisplayModeChangedCallbackId(callbackId);
|
||||
auto halfFoldHoverCallbackId =
|
||||
pipeline->RegisterHalfFoldHoverChangedCallback([weak = WeakClaim(this), this](bool isHoverMode) {
|
||||
this->FoldStatusChangedAnimation();
|
||||
});
|
||||
UpdateHalfFoldHoverChangedCallbackId(halfFoldHoverCallbackId);
|
||||
}
|
||||
|
||||
void ToastPattern::OnDetachFromFrameNode(FrameNode* node)
|
||||
@ -276,6 +341,9 @@ void ToastPattern::OnDetachFromFrameNode(FrameNode* node)
|
||||
if (HasFoldDisplayModeChangedCallbackId()) {
|
||||
pipeline->UnRegisterFoldDisplayModeChangedCallback(foldDisplayModeChangedCallbackId_.value_or(-1));
|
||||
}
|
||||
if (HasHalfFoldHoverChangedCallbackId()) {
|
||||
pipeline->UnRegisterHalfFoldHoverChangedCallback(halfFoldHoverChangedCallbackId_.value_or(-1));
|
||||
}
|
||||
}
|
||||
|
||||
double ToastPattern::GetTextMaxHeight()
|
||||
@ -372,6 +440,11 @@ void ToastPattern::DumpInfo()
|
||||
auto offset = toastProp->GetToastOffsetValue(DimensionOffset());
|
||||
DumpLog::GetInstance().AddDesc(
|
||||
"Offset: { dx: " + offset.GetX().ToString() + " dy: " + offset.GetY().ToString() + " }");
|
||||
std::string enableHoverMode = toastInfo_.enableHoverMode ? "true" : "false";
|
||||
DumpLog::GetInstance().AddDesc("EnableHoverMode: " + enableHoverMode);
|
||||
std::string hoverModeAreaType =
|
||||
toastInfo_.hoverModeArea == HoverModeAreaType::TOP_SCREEN ? "TOP_SCREEN" : "BOTTOM_SCREEN";
|
||||
DumpLog::GetInstance().AddDesc("HoverModeArea: " + hoverModeAreaType);
|
||||
}
|
||||
|
||||
void ToastPattern::DumpInfo(std::unique_ptr<JsonValue>& json)
|
||||
|
@ -58,6 +58,8 @@ public:
|
||||
return AceType::MakeRefPtr<ToastLayoutAlgorithm>();
|
||||
}
|
||||
|
||||
void InitWrapperRect(LayoutWrapper* layoutWrapper, const RefPtr<ToastLayoutProperty>& toastProps);
|
||||
|
||||
void OnAttachToFrameNode() override;
|
||||
|
||||
void OnDetachFromFrameNode(FrameNode* node) override;
|
||||
@ -96,6 +98,16 @@ public:
|
||||
{
|
||||
return foldDisplayModeChangedCallbackId_.has_value();
|
||||
}
|
||||
|
||||
void UpdateHalfFoldHoverChangedCallbackId(std::optional<int32_t> id)
|
||||
{
|
||||
halfFoldHoverChangedCallbackId_ = id;
|
||||
}
|
||||
|
||||
bool HasHalfFoldHoverChangedCallbackId()
|
||||
{
|
||||
return halfFoldHoverChangedCallbackId_.has_value();
|
||||
}
|
||||
|
||||
void SetToastInfo(const ToastInfo& toastInfo)
|
||||
{
|
||||
@ -111,6 +123,9 @@ private:
|
||||
void BeforeCreateLayoutWrapper() override;
|
||||
void UpdateToastSize(const RefPtr<FrameNode>& toast);
|
||||
void UpdateTextSizeConstraint(const RefPtr<FrameNode>& text);
|
||||
void FoldStatusChangedAnimation();
|
||||
void UpdateHoverModeRect(const RefPtr<ToastLayoutProperty>& toastProps,
|
||||
const RefPtr<SafeAreaManager>& safeAreaManager, float safeAreaTop, float safeAreaBottom);
|
||||
Dimension GetOffsetX(const RefPtr<LayoutWrapper>& layoutWrapper);
|
||||
Dimension GetOffsetY(const RefPtr<LayoutWrapper>& layoutWrapper);
|
||||
|
||||
@ -121,9 +136,12 @@ private:
|
||||
|
||||
RefPtr<FrameNode> textNode_;
|
||||
std::optional<int32_t> foldDisplayModeChangedCallbackId_;
|
||||
std::optional<int32_t> halfFoldHoverChangedCallbackId_;
|
||||
ToastInfo toastInfo_;
|
||||
ACE_DISALLOW_COPY_AND_MOVE(ToastPattern);
|
||||
double toastBottom_;
|
||||
Rect wrapperRect_;
|
||||
bool isHoverMode_ = false;
|
||||
};
|
||||
} // namespace OHOS::Ace::NG
|
||||
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TOAST_TOAST_PATTERN_H
|
||||
|
@ -77,6 +77,7 @@ RefPtr<FrameNode> ToastView::CreateToastNode(const ToastInfo& toastInfo)
|
||||
toastProperty->UpdateBottom(
|
||||
StringUtils::StringToDimensionWithThemeValue(toastInfo.bottom, true, toastTheme->GetBottom()));
|
||||
toastProperty->UpdateShowMode(toastInfo.showMode);
|
||||
toastProperty->UpdateHoverModeArea(toastInfo.hoverModeArea);
|
||||
toastNode->GetEventHub<EventHub>()->GetOrCreateGestureEventHub()->SetHitTestMode(HitTestMode::HTMTRANSPARENT);
|
||||
toastNode->MarkModifyDone();
|
||||
return toastNode;
|
||||
|
@ -359,6 +359,40 @@ void GetToastShadow(napi_env env, napi_value shadowNApi, std::optional<Shadow>&
|
||||
shadow = shadowProps;
|
||||
}
|
||||
|
||||
void GetToastEnableHoverMode(napi_env env, napi_value enableHoverModeNApi, bool& enableHoverMode)
|
||||
{
|
||||
napi_valuetype valueType = napi_undefined;
|
||||
napi_typeof(env, enableHoverModeNApi, &valueType);
|
||||
if (valueType == napi_boolean) {
|
||||
napi_get_value_bool(env, enableHoverModeNApi, &enableHoverMode);
|
||||
}
|
||||
}
|
||||
|
||||
void GetToastHoverModeArea(napi_env env, napi_value hoverModeAreaNApi, NG::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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GetToastHoverModeParams(napi_env env, napi_value argv, NG::ToastInfo& toastInfo)
|
||||
{
|
||||
napi_value enableHoverModeNApi = nullptr;
|
||||
napi_value hoverModeAreaNApi = nullptr;
|
||||
|
||||
napi_get_named_property(env, argv, "enableHoverMode", &enableHoverModeNApi);
|
||||
napi_get_named_property(env, argv, "hoverModeArea", &hoverModeAreaNApi);
|
||||
|
||||
GetToastEnableHoverMode(env, enableHoverModeNApi, toastInfo.enableHoverMode);
|
||||
GetToastHoverModeArea(env, hoverModeAreaNApi, toastInfo.hoverModeArea);
|
||||
}
|
||||
|
||||
bool GetToastParams(napi_env env, napi_value argv, NG::ToastInfo& toastInfo)
|
||||
{
|
||||
napi_value messageNApi = nullptr;
|
||||
@ -402,6 +436,7 @@ bool GetToastParams(napi_env env, napi_value argv, NG::ToastInfo& toastInfo)
|
||||
!GetToastOffset(env, offsetApi, toastInfo.offset)) {
|
||||
return false;
|
||||
}
|
||||
GetToastHoverModeParams(env, argv, toastInfo);
|
||||
GetToastBackgroundColor(env, backgroundColorNApi, toastInfo.backgroundColor);
|
||||
GetToastTextColor(env, textColorNApi, toastInfo.textColor);
|
||||
GetToastBackgroundBlurStyle(env, backgroundBlurStyleNApi, toastInfo.backgroundBlurStyle);
|
||||
|
@ -1257,8 +1257,8 @@ HWTEST_F(OverlayTestNg, ToastShowModeTest001, TestSize.Level1)
|
||||
ASSERT_NE(toastContext, nullptr);
|
||||
EXPECT_FALSE(pattern->IsDefaultToast());
|
||||
EXPECT_TRUE(pattern->OnDirtyLayoutWrapperSwap(toastNode->CreateLayoutWrapper(), DirtySwapConfig()));
|
||||
EXPECT_EQ(toastContext->GetOffset()->GetX().ConvertToPx(), 360.0);
|
||||
EXPECT_EQ(toastContext->GetOffset()->GetY().ConvertToPx(), 1280.0);
|
||||
EXPECT_EQ(toastContext->GetOffset()->GetX().ConvertToPx(), 0.0);
|
||||
EXPECT_EQ(toastContext->GetOffset()->GetY().ConvertToPx(), 0.0);
|
||||
/**
|
||||
* @tc.steps: step3. PopToast.
|
||||
*/
|
||||
@ -1530,6 +1530,76 @@ HWTEST_F(OverlayTestNg, ToastTest008, TestSize.Level1)
|
||||
EXPECT_EQ(showedSelectStatus, ToastLayoutProperty::SelectStatus::ON);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ToastTest009
|
||||
* @tc.desc: Test ShowToast hoverModeArea default and enableHoverMode default
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(OverlayTestNg, ToastTest009, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. create toast and toastNode.
|
||||
*/
|
||||
auto toastId = ElementRegister::GetInstance()->MakeUniqueId();
|
||||
auto toastNode =
|
||||
FrameNode::CreateFrameNode(V2::TOAST_ETS_TAG, toastId, AceType::MakeRefPtr<ToastPattern>());
|
||||
ASSERT_NE(toastNode, nullptr);
|
||||
auto rootNode = FrameNode::CreateFrameNode(V2::ROOT_ETS_TAG, 1, AceType::MakeRefPtr<RootPattern>());
|
||||
MockPipelineContext::GetCurrent()->rootNode_ = rootNode;
|
||||
auto overlayManager = AceType::MakeRefPtr<OverlayManager>(rootNode);
|
||||
toastNode->MountToParent(rootNode);
|
||||
rootNode->MarkDirtyNode();
|
||||
auto toastInfo = NG::ToastInfo { .message = MESSAGE,
|
||||
.duration = DURATION,
|
||||
.bottom = BOTTOMSTRING,
|
||||
.isRightToLeft = true };
|
||||
/**
|
||||
* @tc.steps: step2. create overlayManager and call ShowToast when rootElement is nullptr.
|
||||
* @tc.expected: toastMap_ is empty
|
||||
*/
|
||||
overlayManager->ShowToast(toastInfo, nullptr);
|
||||
EXPECT_TRUE(overlayManager->toastMap_.empty());
|
||||
/**
|
||||
* @tc.steps: step3. Test Toast showMode and hoverModeArea.
|
||||
*/
|
||||
auto toastPattern = toastNode->GetPattern<ToastPattern>();
|
||||
ASSERT_NE(toastPattern, nullptr);
|
||||
EXPECT_TRUE(toastPattern->IsDefaultToast());
|
||||
EXPECT_FALSE(toastPattern->toastInfo_.enableHoverMode);
|
||||
EXPECT_EQ(toastPattern->toastInfo_.hoverModeArea, NG::HoverModeAreaType::BOTTOM_SCREEN);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ToastTest010
|
||||
* @tc.desc: Test ShowToast hoverModeArea TOP_SCREEN and enableHoverMode true
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(OverlayTestNg, ToastTest010, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. ready toastInfo and update hoverModeArea enableHoverMode.
|
||||
*/
|
||||
auto toastInfo = NG::ToastInfo { .message = MESSAGE,
|
||||
.duration = DURATION,
|
||||
.bottom = BOTTOMSTRING,
|
||||
.isRightToLeft = true };
|
||||
toastInfo.enableHoverMode = true;
|
||||
toastInfo.hoverModeArea = NG::HoverModeAreaType::TOP_SCREEN;
|
||||
/**
|
||||
* @tc.steps: step2. create ToastNode toastPattern.
|
||||
*/
|
||||
auto toastNode = ToastView::CreateToastNode(toastInfo);
|
||||
ASSERT_NE(toastNode, nullptr);
|
||||
auto toastPattern = toastNode->GetPattern<ToastPattern>();
|
||||
ASSERT_NE(toastPattern, nullptr);
|
||||
/**
|
||||
* @tc.steps: step3. Test Toast showMode and hoverModeArea.
|
||||
*/
|
||||
EXPECT_TRUE(toastPattern->IsDefaultToast());
|
||||
EXPECT_TRUE(toastPattern->toastInfo_.enableHoverMode);
|
||||
EXPECT_EQ(toastPattern->toastInfo_.hoverModeArea, NG::HoverModeAreaType::TOP_SCREEN);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: DialogTest001
|
||||
* @tc.desc: Test OverlayManager::ShowCustomDialog->CloseDialog.
|
||||
|
@ -98,6 +98,7 @@ const Dimension ADAPT_TOAST_NEG_FONT_SIZE = -12.0_fp;
|
||||
const Dimension DISAPPEAR_FONT_SIZE = 0.0_fp;
|
||||
const Dimension NORMAL_FONT_SIZE = 10.0_fp;
|
||||
const Dimension SELECT_FONT_SIZE = 15.0_fp;
|
||||
constexpr float KEYBOARD_HEIGHT = 600.0f;
|
||||
} // namespace
|
||||
class OverlayTestUpdate : public testing::Test {
|
||||
public:
|
||||
@ -1697,4 +1698,263 @@ HWTEST_F(OverlayTestUpdate, ToastTest029, TestSize.Level1)
|
||||
auto textMaxHeight = pattern->GetTextMaxHeight();
|
||||
EXPECT_EQ(textMaxHeight, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ToastTest030
|
||||
* @tc.desc: Test ToastPattern::InitWrapperRect.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(OverlayTestUpdate, ToastTest030, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. CreateToastNode.
|
||||
*/
|
||||
ToastInfo toastInfo = { MESSAGE, 0, BOTTOMSTRING, true, ToastShowMode::DEFAULT, 0 };
|
||||
auto toastNode = ToastView::CreateToastNode(toastInfo);
|
||||
ASSERT_NE(toastNode, nullptr);
|
||||
auto pattern = toastNode->GetPattern<ToastPattern>();
|
||||
ASSERT_NE(pattern, nullptr);
|
||||
auto toastProps = toastNode->GetLayoutProperty<ToastLayoutProperty>();
|
||||
ASSERT_NE(toastProps, nullptr);
|
||||
auto layoutWrapper =
|
||||
AceType::MakeRefPtr<LayoutWrapperNode>(toastNode, toastNode->GetGeometryNode(), toastNode->GetLayoutProperty());
|
||||
ASSERT_NE(layoutWrapper, nullptr);
|
||||
auto pipelineContext = PipelineContext::GetCurrentContext();
|
||||
ASSERT_NE(pipelineContext, nullptr);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Init wrapper rect.
|
||||
*/
|
||||
pattern->InitWrapperRect(layoutWrapper.rawPtr_, toastProps);
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. Test not in hover mode, toast's wrapper rect.
|
||||
*/
|
||||
auto safeAreaManager = pipelineContext->GetSafeAreaManager();
|
||||
ASSERT_NE(safeAreaManager, nullptr);
|
||||
float safeAreaTop = safeAreaManager->GetSystemSafeArea().top_.Length();
|
||||
const auto& safeArea = toastProps->GetSafeAreaInsets();
|
||||
float safeAreaBottom =
|
||||
safeArea ? safeArea->bottom_.Length() : safeAreaManager->GetSafeAreaWithoutProcess().bottom_.Length();
|
||||
EXPECT_EQ(pattern->wrapperRect_.Width(), pipelineContext->GetRootWidth());
|
||||
EXPECT_EQ(pattern->wrapperRect_.Height(), pipelineContext->GetRootHeight()- safeAreaTop - safeAreaBottom);
|
||||
EXPECT_EQ(pattern->wrapperRect_.Top(), safeAreaTop);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ToastTest031
|
||||
* @tc.desc: Test ToastPattern::InitWrapperRect ToastPattern::UpdateHoverModeRect.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(OverlayTestUpdate, ToastTest031, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. CreateToastNode, enable hover mode, hover mode area is default.
|
||||
*/
|
||||
ToastInfo toastInfo = { MESSAGE, 0, BOTTOMSTRING, true, ToastShowMode::DEFAULT, 0 };
|
||||
toastInfo.enableHoverMode = true;
|
||||
auto toastNode = ToastView::CreateToastNode(toastInfo);
|
||||
ASSERT_NE(toastNode, nullptr);
|
||||
auto pattern = toastNode->GetPattern<ToastPattern>();
|
||||
ASSERT_NE(pattern, nullptr);
|
||||
auto toastProps = toastNode->GetLayoutProperty<ToastLayoutProperty>();
|
||||
ASSERT_NE(toastProps, nullptr);
|
||||
auto layoutWrapper =
|
||||
AceType::MakeRefPtr<LayoutWrapperNode>(toastNode, toastNode->GetGeometryNode(), toastNode->GetLayoutProperty());
|
||||
ASSERT_NE(layoutWrapper, nullptr);
|
||||
auto pipelineContext = PipelineContext::GetCurrentContext();
|
||||
ASSERT_NE(pipelineContext, nullptr);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Set in hover mode.
|
||||
*/
|
||||
pipelineContext->isHalfFoldHoverStatus_ = true;
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. Set fold crease region.
|
||||
*/
|
||||
auto container = Container::Current();
|
||||
ASSERT_NE(container, nullptr);
|
||||
auto displayInfo = container->GetDisplayInfo();
|
||||
std::vector<Rect> rects;
|
||||
Rect rect;
|
||||
rect.SetRect(0, 1064, 2294, 171);
|
||||
rects.insert(rects.end(), rect);
|
||||
displayInfo->SetCurrentFoldCreaseRegion(rects);
|
||||
float foldCreaseBottom = 1235.0f;
|
||||
|
||||
/**
|
||||
* @tc.steps: step4. Init wrapper rect.
|
||||
*/
|
||||
pattern->InitWrapperRect(layoutWrapper.rawPtr_, toastProps);
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. Test in hover mode, hover mode area is default, toast's wrapper rect.
|
||||
*/
|
||||
auto safeAreaManager = pipelineContext->GetSafeAreaManager();
|
||||
ASSERT_NE(safeAreaManager, nullptr);
|
||||
const auto& safeArea = toastProps->GetSafeAreaInsets();
|
||||
float safeAreaBottom =
|
||||
safeArea ? safeArea->bottom_.Length() : safeAreaManager->GetSafeAreaWithoutProcess().bottom_.Length();
|
||||
EXPECT_EQ(pattern->wrapperRect_.Width(), pipelineContext->GetRootWidth());
|
||||
EXPECT_EQ(pattern->wrapperRect_.Height(), pipelineContext->GetRootHeight()- foldCreaseBottom - safeAreaBottom);
|
||||
EXPECT_EQ(pattern->wrapperRect_.Top(), foldCreaseBottom);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ToastTest032
|
||||
* @tc.desc: Test ToastPattern::InitWrapperRect ToastPattern::UpdateHoverModeRect.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(OverlayTestUpdate, ToastTest032, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. CreateToastNode, enable hover mode, hover mode area is default.
|
||||
*/
|
||||
ToastInfo toastInfo = { MESSAGE, 0, BOTTOMSTRING, true, ToastShowMode::DEFAULT, 0 };
|
||||
toastInfo.enableHoverMode = true;
|
||||
auto toastNode = ToastView::CreateToastNode(toastInfo);
|
||||
ASSERT_NE(toastNode, nullptr);
|
||||
auto pattern = toastNode->GetPattern<ToastPattern>();
|
||||
ASSERT_NE(pattern, nullptr);
|
||||
auto toastProps = toastNode->GetLayoutProperty<ToastLayoutProperty>();
|
||||
ASSERT_NE(toastProps, nullptr);
|
||||
auto layoutWrapper =
|
||||
AceType::MakeRefPtr<LayoutWrapperNode>(toastNode, toastNode->GetGeometryNode(), toastNode->GetLayoutProperty());
|
||||
ASSERT_NE(layoutWrapper, nullptr);
|
||||
auto pipelineContext = PipelineContext::GetCurrentContext();
|
||||
ASSERT_NE(pipelineContext, nullptr);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Set in hover mode.
|
||||
*/
|
||||
pipelineContext->isHalfFoldHoverStatus_ = true;
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. Set fold crease region and keyboard safe area.
|
||||
*/
|
||||
auto container = Container::Current();
|
||||
ASSERT_NE(container, nullptr);
|
||||
auto displayInfo = container->GetDisplayInfo();
|
||||
std::vector<Rect> rects;
|
||||
Rect rect;
|
||||
rect.SetRect(0, 1064, 2294, 171);
|
||||
rects.insert(rects.end(), rect);
|
||||
displayInfo->SetCurrentFoldCreaseRegion(rects);
|
||||
float foldCreaseTop = 1064.0f;
|
||||
auto safeAreaManager = pipelineContext->GetSafeAreaManager();
|
||||
ASSERT_NE(safeAreaManager, nullptr);
|
||||
auto ret = safeAreaManager->UpdateKeyboardSafeArea(KEYBOARD_HEIGHT);
|
||||
EXPECT_EQ(ret, true);
|
||||
|
||||
/**
|
||||
* @tc.steps: step4. Init wrapper rect.
|
||||
*/
|
||||
pattern->InitWrapperRect(layoutWrapper.rawPtr_, toastProps);
|
||||
|
||||
/**
|
||||
* @tc.steps: step5. Test in hover mode, hover mode area is default, avoid keyboard toast's wrapper rect.
|
||||
*/
|
||||
float safeAreaTop = safeAreaManager->GetSystemSafeArea().top_.Length();
|
||||
EXPECT_EQ(pattern->wrapperRect_.Width(), pipelineContext->GetRootWidth());
|
||||
EXPECT_EQ(pattern->wrapperRect_.Height(), foldCreaseTop - safeAreaTop);
|
||||
EXPECT_EQ(pattern->wrapperRect_.Top(), safeAreaTop);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ToastTest033
|
||||
* @tc.desc: Test ToastPattern::InitWrapperRect ToastPattern::UpdateHoverModeRect.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(OverlayTestUpdate, ToastTest033, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. CreateToastNode, enable hover mode, hover mode area is default.
|
||||
*/
|
||||
ToastInfo toastInfo = { MESSAGE, 0, BOTTOMSTRING, true, ToastShowMode::DEFAULT, 0 };
|
||||
toastInfo.enableHoverMode = true;
|
||||
auto toastNode = ToastView::CreateToastNode(toastInfo);
|
||||
ASSERT_NE(toastNode, nullptr);
|
||||
auto pattern = toastNode->GetPattern<ToastPattern>();
|
||||
ASSERT_NE(pattern, nullptr);
|
||||
auto toastProps = toastNode->GetLayoutProperty<ToastLayoutProperty>();
|
||||
ASSERT_NE(toastProps, nullptr);
|
||||
auto layoutWrapper =
|
||||
AceType::MakeRefPtr<LayoutWrapperNode>(toastNode, toastNode->GetGeometryNode(), toastNode->GetLayoutProperty());
|
||||
ASSERT_NE(layoutWrapper, nullptr);
|
||||
auto pipelineContext = PipelineContext::GetCurrentContext();
|
||||
ASSERT_NE(pipelineContext, nullptr);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Set in hover mode.
|
||||
*/
|
||||
pipelineContext->isHalfFoldHoverStatus_ = true;
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. Set fold crease region.
|
||||
*/
|
||||
auto container = Container::Current();
|
||||
ASSERT_NE(container, nullptr);
|
||||
auto displayInfo = container->GetDisplayInfo();
|
||||
std::vector<Rect> rects;
|
||||
Rect rect;
|
||||
rect.SetRect(0, 1064, 2294, 171);
|
||||
rects.insert(rects.end(), rect);
|
||||
displayInfo->SetCurrentFoldCreaseRegion(rects);
|
||||
float foldCreaseTop = 1064.0f;
|
||||
auto safeAreaManager = pipelineContext->GetSafeAreaManager();
|
||||
ASSERT_NE(safeAreaManager, nullptr);
|
||||
|
||||
/**
|
||||
* @tc.steps: step4. Init wrapper rect.
|
||||
*/
|
||||
pattern->InitWrapperRect(layoutWrapper.rawPtr_, toastProps);
|
||||
|
||||
/**
|
||||
* @tc.steps: step5. Test in hover mode, hover mode area is TOP_SCREEN.
|
||||
*/
|
||||
float safeAreaTop = safeAreaManager->GetSystemSafeArea().top_.Length();
|
||||
EXPECT_EQ(pattern->wrapperRect_.Width(), pipelineContext->GetRootWidth());
|
||||
EXPECT_EQ(pattern->wrapperRect_.Height(), foldCreaseTop - safeAreaTop);
|
||||
EXPECT_EQ(pattern->wrapperRect_.Top(), safeAreaTop);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ToastTest035
|
||||
* @tc.desc: Test Toast offset.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(OverlayTestUpdate, ToastTest035, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. CreateToastNode.
|
||||
*/
|
||||
ToastInfo toastInfo = { MESSAGE, 0, BOTTOMSTRING, true, ToastShowMode::DEFAULT, 0 };
|
||||
auto toastNode = ToastView::CreateToastNode(toastInfo);
|
||||
ASSERT_NE(toastNode, nullptr);
|
||||
auto pattern = toastNode->GetPattern<ToastPattern>();
|
||||
ASSERT_NE(pattern, nullptr);
|
||||
auto toastProps = toastNode->GetLayoutProperty<ToastLayoutProperty>();
|
||||
ASSERT_NE(toastProps, nullptr);
|
||||
auto layoutWrapper =
|
||||
AceType::MakeRefPtr<LayoutWrapperNode>(toastNode, toastNode->GetGeometryNode(), toastNode->GetLayoutProperty());
|
||||
ASSERT_NE(layoutWrapper, nullptr);
|
||||
auto pipelineContext = PipelineContext::GetCurrentContext();
|
||||
ASSERT_NE(pipelineContext, nullptr);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Init wrapper rect.
|
||||
*/
|
||||
pattern->InitWrapperRect(layoutWrapper.rawPtr_, toastProps);
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. Toast showMode and offset.
|
||||
*/
|
||||
auto toastContext = toastNode->GetRenderContext();
|
||||
ASSERT_NE(toastContext, nullptr);
|
||||
EXPECT_TRUE(pattern->IsDefaultToast());
|
||||
EXPECT_TRUE(pattern->OnDirtyLayoutWrapperSwap(toastNode->CreateLayoutWrapper(), DirtySwapConfig()));
|
||||
EXPECT_EQ(toastContext->GetOffset()->GetX().ConvertToPx(), 360.0);
|
||||
EXPECT_EQ(toastContext->GetOffset()->GetY().ConvertToPx(), 1280.0);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user