diff --git a/frameworks/bridge/declarative_frontend/frontend_delegate_declarative.cpp b/frameworks/bridge/declarative_frontend/frontend_delegate_declarative.cpp index 4a215247516f70625086b1b65c91ae35f41c47c6..78a382d4b192bc9333be30cc2b35526e37fc0c62 100644 --- a/frameworks/bridge/declarative_frontend/frontend_delegate_declarative.cpp +++ b/frameworks/bridge/declarative_frontend/frontend_delegate_declarative.cpp @@ -1970,6 +1970,10 @@ DialogProperties FrontendDelegateDeclarative::ParsePropertiesFromAttr(const Prom .borderWidth = dialogAttr.borderWidth, .borderColor = dialogAttr.borderColor, .borderStyle = dialogAttr.borderStyle, .shadow = dialogAttr.shadow, .width = dialogAttr.width, .height = dialogAttr.height, + .hasCustomMaskColor = dialogAttr.hasCustomMaskColor, + .hasCustomShadowColor = dialogAttr.hasCustomShadowColor, + .hasCustomBackgroundColor = dialogAttr.hasCustomBackgroundColor, + .customBorderColorProps = dialogAttr.customBorderColorProps, .isUserCreatedDialog = dialogAttr.isUserCreatedDialog, .maskRect = dialogAttr.maskRect, .transitionEffect = dialogAttr.transitionEffect, .dialogTransitionEffect = dialogAttr.dialogTransitionEffect, diff --git a/frameworks/bridge/declarative_frontend/jsview/dialog/js_custom_dialog_controller.cpp b/frameworks/bridge/declarative_frontend/jsview/dialog/js_custom_dialog_controller.cpp index 424c497d538a12599add71a0979d56940a354959..e82cf4570b441229e658dec1838ee394d2bf934a 100644 --- a/frameworks/bridge/declarative_frontend/jsview/dialog/js_custom_dialog_controller.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/dialog/js_custom_dialog_controller.cpp @@ -108,6 +108,40 @@ void ParseCustomDialogFocusable(DialogProperties& properties, JSRef ob properties.focusable = focusableValue->ToBoolean(); } +void ParseCustomDialogBackgroundColor(DialogProperties& properties, JSRef obj) +{ + // Parse backgroundColor. + if (obj->IsEmpty()) { + return; + } + auto backgroundColorValue = obj->GetProperty("backgroundColor"); + Color backgroundColor; + RefPtr resObj; + if (JSViewAbstract::ParseJsColor(backgroundColorValue, backgroundColor, resObj)) { + if (SystemProperties::ConfigChangePerform() && JSViewAbstract::CheckDarkResource(resObj)) { + properties.hasCustomBackgroundColor = true; + } + properties.backgroundColor = backgroundColor; + } +} + +void ParseCustomDialogMaskColor(DialogProperties& properties, JSRef obj) +{ + // Parse backgroundColor. + if (obj->IsEmpty()) { + return; + } + auto maskColorValue = obj->GetProperty("maskColor"); + Color maskColor; + RefPtr resObj; + if (JSViewAbstract::ParseJsColor(maskColorValue, maskColor, resObj)) { + if (SystemProperties::ConfigChangePerform() && !JSViewAbstract::CheckDarkResource(resObj)) { + properties.hasCustomMaskColor = true; + } + properties.maskColor = maskColor; + } +} + static std::atomic controllerId = 0; void JSCustomDialogController::ConstructorCallback(const JSCallbackInfo& info) @@ -238,11 +272,7 @@ void JSCustomDialogController::ConstructorCallback(const JSCallbackInfo& info) } // Parse maskColor. - auto maskColorValue = constructorArg->GetProperty("maskColor"); - Color maskColor; - if (JSViewAbstract::ParseJsColor(maskColorValue, maskColor)) { - instance->dialogProperties_.maskColor = maskColor; - } + ParseCustomDialogMaskColor(instance->dialogProperties_, constructorArg ); // Parse maskRect. auto maskRectValue = constructorArg->GetProperty("maskRect"); @@ -250,13 +280,9 @@ void JSCustomDialogController::ConstructorCallback(const JSCallbackInfo& info) if (JSViewAbstract::ParseJsDimensionRect(maskRectValue, maskRect)) { instance->dialogProperties_.maskRect = maskRect; } - // Parse backgroundColor. - auto backgroundColorValue = constructorArg->GetProperty("backgroundColor"); - Color backgroundColor; - if (JSViewAbstract::ParseJsColor(backgroundColorValue, backgroundColor)) { - instance->dialogProperties_.backgroundColor = backgroundColor; - } + ParseCustomDialogBackgroundColor(instance->dialogProperties_, constructorArg); + // Parse backgroundBlurStyle. auto backgroundBlurStyle = constructorArg->GetProperty("backgroundBlurStyle"); diff --git a/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.cpp b/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.cpp index 280c48f19853c3ccfd78f03e89ece98aa0c2dc73..dcddae216be7b50292ca6befae99820493029b62 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.cpp @@ -11562,6 +11562,77 @@ bool JSViewAbstract::ParseBorderColorProps(const JSRef& args, return false; } +bool JSViewAbstract::CheckDarkResource(std::optional& color) +{ + if (!color.has_value()) { + return false; + } + + uint32_t resId = color.GetResourceId(); + if (resId != 0) { + auto colorMode = Container::CurrentColorMode(); + if (colorMode != ColorMode::DARK) { + return true; + } + auto resourceAdapter = ResourceManager::GetInstance().GetResourceAdapter(Container::CurrentIdSafely()); + CHECK_NULL_RETURN(resourceAdapter, false); + return resourceAdapter->ExistDarkResById(std::to_string(resId)); + } + return false; +} + +bool JSViewAbstract::ParseDialogBorderColorProps(const JSRef& args, NG::BorderColorProperty& colorProperty, + RefPtr& resourceObj, std::optional& props) +{ + if (!args->IsObject() && !args->IsNumber() && !args->IsString()) { + return false; + } + CHECK_NULL_VOID(props, false); + Color borderColor; + if (ParseJsColor(args, borderColor, resourceObj)) { + colorProperty.SetColor(borderColor); + if (SystemProperties::ConfigChangePerform() && !CheckDarkResource(resourceObj)) { + props->hasCustomBorderColor = true; + } + return true; + } else if (args->IsObject()) { + JSRef obj = JSRef::Cast(args); + CommonColor commonColor; + auto isLocalizedEdgeColor = ParseCommonEdgeColors(obj, commonColor); + colorProperty.topColor = commonColor.top; + colorProperty.bottomColor = commonColor.bottom; + if (isLocalizedEdgeColor) { + colorProperty.startColor = commonColor.left; + colorProperty.endColor = commonColor.right; + } else { + colorProperty.leftColor = commonColor.left; + colorProperty.rightColor = commonColor.right; + } + if (SystemProperties::ConfigChangePerform() && !CheckDarkResource(colorProperty.topColor)) { + props->hasCustomTopBorderColor = true; + } + if (SystemProperties::ConfigChangePerform() && !CheckDarkResource(colorProperty.bottomColor)) { + props->hasCustomBottomBorderColor = true; + } + if (SystemProperties::ConfigChangePerform() && !CheckDarkResource(colorProperty.startColor)) { + props->hasCustomStartBorderColor = true; + } + if (SystemProperties::ConfigChangprops.customBorderColorPropsePerform() && !CheckDarkResource(colorProperty.endColor)) { + props->hasCustomEndBorderColor = true; + } + if (SystemProperties::ConfigChangePerform() && !CheckDarkResource(colorProperty.leftColor)) { + props->hasCustomLeftBorderColor = true; + } + if (SystemProperties::ConfigChangePerform() && !CheckDarkResource(colorProperty.rightColor)) { + props->hasCustomRightBorderColor = true; + } + colorProperty.multiValued = true; + RegisterBorderColorRes(colorProperty, commonColor, isLocalizedEdgeColor); + return true; + } + return false; +} + bool JSViewAbstract::ParseBorderWidthProps(const JSRef& args, NG::BorderWidthProperty& borderWidthProperty) { RefPtr resourceObj; @@ -11802,6 +11873,64 @@ void JSViewAbstract::SetDragNumberBadge(const JSCallbackInfo& info, NG::DragPrev } } +void JSViewAbstract::ParseDialogJsColor( + RefPtr& colorResObj, const Color& color, Shadow& shadow, bool& hasCustomShadowColor) +{ + shadow.SetColor(color); + if (!SystemProperties::ConfigChangePerform() || CheckDarkResource(colorResObj)) { + return; + } + hasCustomShadowColor = true; + if (colorResObj) { + auto&& updateFunc = [](const RefPtr& colorResObj, Shadow& shadow) { + Color colorValue; + ResourceParseUtils::ParseResColor(colorResObj, colorValue); + shadow.SetColor(colorValue); + }; + shadow.AddResource("shadow.colorValue", colorResObj, std::move(updateFunc)); + } +} + +bool JSViewAbstract::ParseDialogShadowProps( + const JSRef& jsValue, Shadow& shadow, bool& hasCustomShadowColor, const bool configChangePerform) +{ + int32_t shadowStyle = 0; + if (ParseJsInteger(jsValue, shadowStyle)) { + auto style = static_cast(shadowStyle); + return GetShadowFromTheme(style, shadow, configChangePerform); + } + if (!jsValue->IsObject()) { + return false; + } + JSRef jsObj = JSRef::Cast(jsValue); + double radius = 0.0; + ParseShadowPropsUpdate(jsObj, radius, shadow); + if (LessNotEqual(radius, 0.0)) { + radius = 0.0; + } + shadow.SetBlurRadius(radius); + ParseShadowOffsetXY(jsObj, shadow); + Color color; + ShadowColorStrategy shadowColorStrategy; + auto jsColor = jsObj->GetProperty(static_cast(ArkUIIndex::COLOR)); + RefPtr colorResObj; + if (ParseJsShadowColorStrategy(jsColor, shadowColorStrategy)) { + shadow.SetShadowColorStrategy(shadowColorStrategy); + } else if (ParseJsColor(jsColor, color, colorResObj)) { + ParseDialogJsColor(colorResObj, color, shadow, hasCustomShadowColor); + } + + int32_t type = static_cast(ShadowType::COLOR); + JSViewAbstract::ParseJsInt32(jsObj->GetProperty(static_cast(ArkUIIndex::TYPE)), type); + if (type != static_cast(ShadowType::BLUR)) { + type = static_cast(ShadowType::COLOR); + } + shadow.SetShadowType(static_cast(type)); + bool isFilled = jsObj->GetPropertyValue(static_cast(ArkUIIndex::FILL), false); + shadow.SetIsFilled(isFilled); + return true; +} + void JSViewAbstract::SetDialogProperties(const JSRef& obj, DialogProperties& properties) { // Parse cornerRadius. @@ -11817,8 +11946,10 @@ void JSViewAbstract::SetDialogProperties(const JSRef& obj, DialogPrope properties.borderWidth = borderWidth; auto colorValue = obj->GetProperty("borderColor"); NG::BorderColorProperty borderColor; - if (ParseBorderColorProps(colorValue, borderColor)) { + CustomBorderColorProps customBorderColorProps; + if (ParseDialogBorderColorProps(colorValue, borderColor, customBorderColorProps)) { properties.borderColor = borderColor; + properties.customBorderColorProps = customBorderColorProps; } else { borderColor.SetColor(Color::BLACK); properties.borderColor = borderColor; @@ -11835,7 +11966,7 @@ void JSViewAbstract::SetDialogProperties(const JSRef& obj, DialogPrope } auto shadowValue = obj->GetProperty("shadow"); Shadow shadow; - if ((shadowValue->IsObject() || shadowValue->IsNumber()) && ParseShadowProps(shadowValue, shadow)) { + if ((shadowValue->IsObject() || shadowValue->IsNumber()) && ParseDialogShadowProps(shadowValue, shadow, properties.hasCustomShadowColor)) { properties.shadow = shadow; } auto widthValue = obj->GetProperty("width"); diff --git a/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.h b/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.h index 3313054f8ce47fc9d700773f9f3480d23ad53f18..930d1fef69e63e94b43e16079e14b70bc08d669a 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.h +++ b/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.h @@ -474,6 +474,9 @@ public: static bool GetJsMediaBundleInfo(const JSRef& jsValue, std::string& bundleName, std::string& moduleName); static void ParseShadowPropsUpdate(const JSRef& jsObj, double& radius, Shadow& shadow); static bool ParseShadowProps(const JSRef& jsValue, Shadow& shadow, const bool configChangePerform = false); + static bool ParseDialogShadowProps(const JSRef& jsValue, Shadow& shadow, bool& hasCustomShadowColor, + const bool configChangePerform = false); + static void ParseDialogJsColor(RefPtr& colorResObj, const Color& color, Shadow& shadow, bool& hasCustomShadowColor); static void ParseShadowOffsetXY(const JSRef& jsObj, Shadow& shadow); static bool GetShadowFromTheme(ShadowStyle shadowStyle, Shadow& shadow, const bool configChangePerform = false); static bool ParseJsResource(const JSRef& jsValue, CalcDimension& result); @@ -876,18 +879,21 @@ public: CHECK_NULL_VOID(pattern); pattern->RegisterResource(key, resObj, value); } + static bool CheckDarkResource(const RefPtr& resObj); + static bool CheckDarkResource(std::optional& color); + static bool ParseDialogBorderColorProps(const JSRef& args, NG::BorderColorProperty& colorProperty, + RefPtr& resourceObj, std::optional& props); static void UnRegisterResource(const std::string& key); static void ParseDragSpringLoadingConfiguration( const JSRef& paramObj, const RefPtr& config); static void SetBorderRadiusWithCheck(std::optional& result, NG::BorderRadiusProperty& dimension); - static bool CheckLengthMetrics(const JSRef& object); + static bool CheckLengthMetrics(const JSRef& object); static void CompleteResourceObjectFromColor(RefPtr& resObj, Color& color, bool state); static void JSAllowForceDark(const JSCallbackInfo& info); private: - static bool CheckDarkResource(const RefPtr& resObj); static bool ParseJsStrArrayInternal(const JSRef& jsArray, std::vector& result, std::vector>& resObjArray); static bool ParseJsIntegerArrayInternal(const JSRef& jsArray, std::vector& result, diff --git a/frameworks/bridge/declarative_frontend/ng/frontend_delegate_declarative_ng.cpp b/frameworks/bridge/declarative_frontend/ng/frontend_delegate_declarative_ng.cpp index f2f4f595983900c1d99ced5ab93f436d36999d80..3a907f08942eabf65305a7929697cbaebc733e43 100644 --- a/frameworks/bridge/declarative_frontend/ng/frontend_delegate_declarative_ng.cpp +++ b/frameworks/bridge/declarative_frontend/ng/frontend_delegate_declarative_ng.cpp @@ -885,6 +885,10 @@ DialogProperties FrontendDelegateDeclarativeNG::ParsePropertiesFromAttr(const Pr .borderWidth = dialogAttr.borderWidth, .borderColor = dialogAttr.borderColor, .borderStyle = dialogAttr.borderStyle, .shadow = dialogAttr.shadow, .width = dialogAttr.width, .height = dialogAttr.height, + .hasCustomMaskColor = dialogAttr.hasCustomMaskColor, + .hasCustomShadowColor = dialogAttr.hasCustomShadowColor, + .hasCustomBackgroundColor = dialogAttr.hasCustomBackgroundColor, + .customBorderColorProps = dialogAttr.customBorderColorProps, .isUserCreatedDialog = dialogAttr.isUserCreatedDialog, .maskRect = dialogAttr.maskRect, .transitionEffect = dialogAttr.transitionEffect, .contentNode = dialogAttr.contentNode, diff --git a/frameworks/core/components/dialog/dialog_properties.h b/frameworks/core/components/dialog/dialog_properties.h index 529ff1e6988a1e381ea1c431220339224d169a5c..b3a1b59136b7af36d04cf48e06cb139600bc0847 100644 --- a/frameworks/core/components/dialog/dialog_properties.h +++ b/frameworks/core/components/dialog/dialog_properties.h @@ -218,6 +218,16 @@ struct ButtonInfo { } }; +struct CustomBorderColorProps { + bool hasCustomBorderColor = false; + bool hasCustomLeftBorderColor = false; + bool hasCustomRightBorderColor = false; + bool hasCustomTopBorderColor = false; + bool hasCustomBottomBorderColor = false; + bool hasCustomStartBorderColor = false; + bool hasCustomEndBorderColor = false; +}; + struct DialogProperties { DialogType type = DialogType::COMMON; // type of dialog, current support common dialog and alert dialog. bool isAlertDialog = false; @@ -268,6 +278,7 @@ struct DialogProperties { bool hasCustomShadowColor = false; bool hasCustomBackgroundColor = false; bool hasCustomBorderColor = false; + std::optional customBorderColorProps; #ifndef NG_BUILD std::unordered_map callbacks; // @@ -338,6 +349,10 @@ struct PromptDialogAttr { std::optional width; std::optional height; std::optional hoverModeArea; + bool hasCustomMaskColor = false; + bool hasCustomShadowColor = false; + bool hasCustomBackgroundColor = false; + std::optional customBorderColorProps; WeakPtr contentNode; bool customStyle = false; diff --git a/frameworks/core/components_ng/pattern/dialog/dialog_view.cpp b/frameworks/core/components_ng/pattern/dialog/dialog_view.cpp index d90f0c94315765d30db76b1e191ff1646474f09b..56bd164d52c52c140d36c32b94971aeda8864042 100644 --- a/frameworks/core/components_ng/pattern/dialog/dialog_view.cpp +++ b/frameworks/core/components_ng/pattern/dialog/dialog_view.cpp @@ -382,16 +382,130 @@ void UpdateAndAddBorderRightColorCallback(RefPtr dialog, BorderColorP } } +void UpdateAndAddBorderStartColorCallback(RefPtr dialog, BorderColorProperty borderColor) +{ + if (borderColor.startColor.has_value()) { + Color startBorderColor = borderColor.startColor.value(); + RefPtr resObj; + ResourceParseUtils::CompleteResourceObjectFromColor(resObj, startBorderColor, dialog->GetTag()); + auto updateFunc = [dialogWeak = AceType::WeakClaim(AceType::RawPtr(dialog))]( + const RefPtr& resObj) { + auto dialog = dialogWeak.Upgrade(); + CHECK_NULL_VOID(dialog); + auto pattern = dialog->GetPattern(); + CHECK_NULL_VOID(pattern); + auto pipelineContext = dialog->GetContext(); + CHECK_NULL_VOID(pipelineContext); + auto dialogTheme = pipelineContext->GetTheme(); + CHECK_NULL_VOID(dialogTheme); + + Color startBorderColor; + auto state = ResourceParseUtils::ParseResColor(resObj, startBorderColor); + startBorderColor = state ? startBorderColor : dialogTheme->GetBackgroundBorderColor(); + + auto contentNode = AceType::DynamicCast(dialog->GetFirstChild()); + CHECK_NULL_VOID(contentNode); + auto contentRenderContext = contentNode->GetRenderContext(); + CHECK_NULL_VOID(contentRenderContext); + auto currentBorderColor = contentRenderContext->GetBorderColor(); + CHECK_NULL_VOID(currentBorderColor.has_value()); + currentBorderColor->startColor = startBorderColor; + contentRenderContext->UpdateBorderColor(currentBorderColor.value()); + contentNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE); + contentNode->MarkModifyDone(); + }; + auto pattern = dialog->GetPattern(); + CHECK_NULL_VOID(pattern); + pattern->AddResObj("dialog.borderColor.startColor", resObj, std::move(updateFunc)); + + auto contentNode = AceType::DynamicCast(dialog->GetFirstChild()); + CHECK_NULL_VOID(contentNode); + auto contentRenderContext = contentNode->GetRenderContext(); + CHECK_NULL_VOID(contentRenderContext); + auto currentBorderColor = contentRenderContext->GetBorderColor(); + CHECK_NULL_VOID(currentBorderColor.has_value()); + currentBorderColor->startColor = startBorderColor; + contentRenderContext->UpdateBorderColor(currentBorderColor.value()); + } +} + +void UpdateAndAddBorderEndColorCallback(RefPtr dialog, BorderColorProperty borderColor) +{ + if (borderColor.endColor.has_value()) { + Color endBorderColor = borderColor.endColor.value(); + RefPtr resObj; + ResourceParseUtils::CompleteResourceObjectFromColor(resObj, endBorderColor, dialog->GetTag()); + auto updateFunc = [dialogWeak = AceType::WeakClaim(AceType::RawPtr(dialog))]( + const RefPtr& resObj) { + auto dialog = dialogWeak.Upgrade(); + CHECK_NULL_VOID(dialog); + auto pattern = dialog->GetPattern(); + CHECK_NULL_VOID(pattern); + auto pipelineContext = dialog->GetContext(); + CHECK_NULL_VOID(pipelineContext); + auto dialogTheme = pipelineContext->GetTheme(); + CHECK_NULL_VOID(dialogTheme); + + Color endBorderColor; + auto state = ResourceParseUtils::ParseResColor(resObj, endBorderColor); + endBorderColor = state ? endBorderColor : dialogTheme->GetBackgroundBorderColor(); + + auto contentNode = AceType::DynamicCast(dialog->GetFirstChild()); + CHECK_NULL_VOID(contentNode); + auto contentRenderContext = contentNode->GetRenderContext(); + CHECK_NULL_VOID(contentRenderContext); + auto currentBorderColor = contentRenderContext->GetBorderColor(); + CHECK_NULL_VOID(currentBorderColor.has_value()); + currentBorderColor->endColor = endBorderColor; + contentRenderContext->UpdateBorderColor(currentBorderColor.value()); + contentNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE); + contentNode->MarkModifyDone(); + }; + auto pattern = dialog->GetPattern(); + CHECK_NULL_VOID(pattern); + pattern->AddResObj("dialog.borderColor.endColor", resObj, std::move(updateFunc)); + + auto contentNode = AceType::DynamicCast(dialog->GetFirstChild()); + CHECK_NULL_VOID(contentNode); + auto contentRenderContext = contentNode->GetRenderContext(); + CHECK_NULL_VOID(contentRenderContext); + auto currentBorderColor = contentRenderContext->GetBorderColor(); + CHECK_NULL_VOID(currentBorderColor.has_value()); + currentBorderColor->endColor =endBorderColor; + contentRenderContext->UpdateBorderColor(currentBorderColor.value()); + } +} + void UpdateAndAddBorderColorCallback(RefPtr dialog, const DialogProperties& dialogProps) { - CHECK_NULL_VOID(dialogProps.hasCustomBorderColor); - if (dialogProps.borderColor.has_value()) { + CHECK_NULL_VOID(dialogProps.borderColor.has_value()); + CHECK_NULL_VOID(dialogProps.customBorderColorProps.has_value()); + if (dialogProps.customBorderColorProps.value().hasCustomBorderColor) { BorderColorProperty borderColor = dialogProps.borderColor.value(); UpdateAndAddBorderTopColorCallback(dialog, borderColor); UpdateAndAddBorderBottomColorCallback(dialog, borderColor); UpdateAndAddBorderLeftColorCallback(dialog, borderColor); UpdateAndAddBorderRightColorCallback(dialog, borderColor); - } + } else { + if (dialogProps.customBorderColorProps.value().hasCustomLeftBorderColor) { + UpdateAndAddBorderLeftColorCallback(dialog, BorderColorProperty()); + } + if (dialogProps.customBorderColorProps.value().hasCustomRightBorderColor) { + UpdateAndAddBorderRightColorCallback(dialog, BorderColorProperty()); + } + if (dialogProps.customBorderColorProps.value().hasCustomTopBorderColor) { + UpdateAndAddBorderTopColorCallback(dialog, BorderColorProperty()); + } + if (dialogProps.customBorderColorProps.value().hasCustomBottomBorderColor) { + UpdateAndAddBorderBottomColorCallback(dialog, BorderColorProperty()); + } + if (dialogProps.customBorderColorProps.value().hasCustomStartBorderColor) { + UpdateAndAddBorderStartColorCallback(dialog, BorderColorProperty()); + } + if (dialogProps.customBorderColorProps.value().hasCustomEndBorderColor) { + UpdateAndAddBorderEndColorCallback(dialog, BorderColorProperty()); + } + } } void UpdateAndAddBlurStyleOptionCallback(RefPtr dialog, const DialogProperties& dialogProps) diff --git a/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp b/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp index 2eb39bc6bc59abb85200a5c65fa17cfdb86e58df..cdd5a91cddd85f016b7e5c4c7a884a40e1124788 100644 --- a/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp +++ b/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp @@ -3205,6 +3205,10 @@ RefPtr OverlayManager::SetDialogMask(const DialogProperties& dialogPr Maskarg.autoCancel = dialogProps.autoCancel; Maskarg.onWillDismiss = dialogProps.onWillDismiss; Maskarg.maskColor = dialogProps.maskColor; + Maskarg.hasCustomMaskColor = dialogProps.hasCustomMaskColor; + Maskarg.hasCustomShadowColor = dialogProps.hasCustomShadowColor; + Maskarg.hasCustomBackgroundColor = dialogProps.hasCustomBackgroundColor; + Maskarg.customBorderColorProps = dialogProps.customBorderColorProps; Maskarg.focusable = dialogProps.focusable; Maskarg.levelOrder = GetTopOrder(); return ShowDialog(Maskarg, nullptr, false); diff --git a/interfaces/napi/kits/promptaction/prompt_action.cpp b/interfaces/napi/kits/promptaction/prompt_action.cpp index 7de6930117541a9c0d8552db7e1934afdafce239..d24c2cb121db68d754e657faf632aebda2b4ed5b 100644 --- a/interfaces/napi/kits/promptaction/prompt_action.cpp +++ b/interfaces/napi/kits/promptaction/prompt_action.cpp @@ -702,6 +702,21 @@ struct PromptAsyncContext { napi_value focusableApi = nullptr; }; +bool CheckDarkResource(const Color& color) +{ + uint32_t resId = color.GetResourceId(); + if (resId != 0) { + auto colorMode = Container::CurrentColorMode(); + if (colorMode != ColorMode::DARK) { + return true; + } + auto resourceAdapter = ResourceManager::GetInstance().GetResourceAdapter(Container::CurrentIdSafely()); + CHECK_NULL_RETURN(resourceAdapter, false); + return resourceAdapter->ExistDarkResById(std::to_string(resId)); + } + return false; +} + void DeleteContextAndThrowError( napi_env env, std::shared_ptr& context, const std::string& errorMessage) { @@ -962,8 +977,9 @@ void CheckNapiDimension(CalcDimension value) } std::optional GetBorderColorProps( - napi_env env, const std::shared_ptr& asyncContext) + napi_env env, const std::shared_ptr& asyncContext, std::optional props) { + CHECK_NULL_RETURN(props, std::nullopt); napi_valuetype valueType = napi_undefined; NG::BorderColorProperty colorProperty; napi_typeof(env, asyncContext->borderColorApi, &valueType); @@ -973,6 +989,9 @@ std::optional GetBorderColorProps( Color borderColor; if (ParseNapiColor(env, asyncContext->borderColorApi, borderColor)) { colorProperty.SetColor(borderColor); + if (SystemProperties::ConfigChangePerform() && !CheckDarkResource(borderColor)) { + props->hasCustomBorderColor = true; + } return colorProperty; } else if (valueType == napi_object) { napi_value leftApi = nullptr; @@ -989,15 +1008,27 @@ std::optional GetBorderColorProps( Color bottomColor; if (ParseNapiColor(env, leftApi, leftColor)) { colorProperty.leftColor = leftColor; + if (SystemProperties::ConfigChangePerform() && !CheckDarkResource(leftColor)) { + props->hasCustomLeftBorderColor = true; + } } if (ParseNapiColor(env, rightApi, rightColor)) { colorProperty.rightColor = rightColor; + if (SystemProperties::ConfigChangePerform() && !CheckDarkResource(rightColor)) { + props->hasCustomRightBorderColor = true; + } } if (ParseNapiColor(env, topApi, topColor)) { colorProperty.topColor = topColor; + if (SystemProperties::ConfigChangePerform() && !CheckDarkResource(topColor)) { + props->hasCustomTopBorderColor = true; + } } if (ParseNapiColor(env, bottomApi, bottomColor)) { colorProperty.bottomColor = bottomColor; + if (SystemProperties::ConfigChangePerform() && !CheckDarkResource(bottomColor)) { + props->hasCustomBottomBorderColor = true; + } } colorProperty.multiValued = true; return colorProperty; @@ -1155,7 +1186,8 @@ std::optional GetBorderStyleProps( return std::nullopt; } -void GetNapiObjectShadow(napi_env env, const std::shared_ptr& asyncContext, Shadow& shadow) +void GetNapiObjectShadow( + napi_env env, const std::shared_ptr& asyncContext, Shadow& shadow, bool& hasCustomShadowColor) { napi_value radiusApi = nullptr; napi_value colorApi = nullptr; @@ -1176,6 +1208,9 @@ void GetNapiObjectShadow(napi_env env, const std::shared_ptr if (ParseShadowColorStrategy(env, colorApi, shadowColorStrategy)) { shadow.SetShadowColorStrategy(shadowColorStrategy); } else if (ParseNapiColor(env, colorApi, color)) { + if (SystemProperties::ConfigChangePerform() && !CheckDarkResource(color)) { + hasCustomShadowColor = true; + } shadow.SetColor(color); } napi_valuetype valueType = GetValueType(env, typeApi); @@ -1197,7 +1232,8 @@ void GetNapiObjectShadow(napi_env env, const std::shared_ptr shadow.SetIsFilled(isFilled); } -std::optional GetShadowProps(napi_env env, const std::shared_ptr& asyncContext) +std::optional GetShadowProps( + napi_env env, const std::shared_ptr& asyncContext, bool& hasCustomShadowColor) { Shadow shadow; napi_valuetype valueType = napi_undefined; @@ -1218,6 +1254,7 @@ std::optional GetShadowProps(napi_env env, const std::shared_ptrshadowApi, "offsetX", &offsetXApi); napi_get_named_property(env, asyncContext->shadowApi, "offsetY", &offsetYApi); ResourceInfo recv; + CalcDimension offsetX; bool isRtl = AceApplicationInfo::GetInstance().IsRightToLeft(); if (ParseResourceParam(env, offsetXApi, recv)) { auto resourceWrapper = CreateResourceWrapper(recv); @@ -1225,25 +1262,20 @@ std::optional GetShadowProps(napi_env env, const std::shared_ptrGetDimension(recv.resId); double xValue = isRtl ? offsetX.Value() * (-1) : offsetX.Value(); shadow.SetOffsetX(xValue); - } else { - CalcDimension offsetX; - if (ParseNapiDimension(env, offsetX, offsetXApi, DimensionUnit::VP)) { - double xValue = isRtl ? offsetX.Value() * (-1) : offsetX.Value(); - shadow.SetOffsetX(xValue); - } + } else if (ParseNapiDimension(env, offsetX, offsetXApi, DimensionUnit::VP)) { + double xValue = isRtl ? offsetX.Value() * (-1) : offsetX.Value(); + shadow.SetOffsetX(xValue); } + CalcDimension offsetY; if (ParseResourceParam(env, offsetYApi, recv)) { auto resourceWrapper = CreateResourceWrapper(recv); CHECK_NULL_RETURN(resourceWrapper, std::nullopt); auto offsetY = resourceWrapper->GetDimension(recv.resId); shadow.SetOffsetY(offsetY.Value()); - } else { - CalcDimension offsetY; - if (ParseNapiDimension(env, offsetY, offsetYApi, DimensionUnit::VP)) { - shadow.SetOffsetY(offsetY.Value()); - } + } else if (ParseNapiDimension(env, offsetY, offsetYApi, DimensionUnit::VP)) { + shadow.SetOffsetY(offsetY.Value()); } - GetNapiObjectShadow(env, asyncContext, shadow); + GetNapiObjectShadow(env, asyncContext, shadow, hasCustomShadowColor); return shadow; } return std::nullopt; @@ -1621,6 +1653,8 @@ napi_value JSPromptShowDialog(napi_env env, napi_callback_info info) LevelMode dialogLevelMode = LevelMode::OVERLAY; int32_t dialogLevelUniqueId = -1; ImmersiveMode dialogImmersiveMode = ImmersiveMode::DEFAULT; + bool hasCustomShadowColor = false; + bool hasCustomBackgroundColor = false; PromptDialogAttr lifeCycleAttr = {}; for (size_t i = 0; i < argc; i++) { napi_valuetype valueType = napi_undefined; @@ -1658,7 +1692,11 @@ napi_value JSPromptShowDialog(napi_env env, napi_callback_info info) GetNapiString(env, asyncContext->messageNApi, asyncContext->messageString, valueType); GetNapiDialogProps(env, asyncContext, alignment, offset, maskRect); backgroundColor = GetColorProps(env, asyncContext->backgroundColorApi); - shadowProps = GetShadowProps(env, asyncContext); + if (backgroundColor && SystemProperties::ConfigChangePerform() && + !CheckDarkResource(backgroundColor.value())) { + hasCustomBackgroundColor = true; + } + shadowProps = GetShadowProps(env, asyncContext, hasCustomShadowColor); GetNapiBlurStyleAndHoverModeProps(env, asyncContext, backgroundBlurStyle, hoverModeArea, enableHoverMode); GetBackgroundBlurStyleOption(env, asyncContext, blurStyleOption); GetBackgroundEffect(env, asyncContext, effectOption); @@ -1702,13 +1740,14 @@ napi_value JSPromptShowDialog(napi_env env, napi_callback_info info) return nullptr; } } - auto onLanguageChange = [shadowProps, alignment, offset, maskRect, + auto onLanguageChange = [shadowProps, alignment, offset, maskRect, hasCustomShadowColor, updateAlignment = UpdatePromptAlignment](DialogProperties& dialogProps) { bool isRtl = AceApplicationInfo::GetInstance().IsRightToLeft(); if (shadowProps.has_value()) { std::optional shadow = shadowProps.value(); double offsetX = isRtl ? shadow->GetOffset().GetX() * (-1) : shadow->GetOffset().GetX(); shadow->SetOffsetX(offsetX); + dialogProps.hasCustomShadowColor = hasCustomShadowColor; dialogProps.shadow = shadow.value(); } if (alignment.has_value()) { @@ -1829,12 +1868,14 @@ napi_value JSPromptShowDialog(napi_env env, napi_callback_info info) .effectOption = effectOption, .shadow = shadowProps, .hoverModeArea = hoverModeArea, - .onLanguageChange = onLanguageChange, - .levelOrder = GetLevelOrderParam(asyncContext->env, asyncContext), + .hasCustomShadowColor = hasCustomShadowColor, + .hasCustomBackgroundColor = hasCustomBackgroundColor, .onDidAppear = lifeCycleAttr.onDidAppear, .onDidDisappear = lifeCycleAttr.onDidDisappear, .onWillAppear = lifeCycleAttr.onWillAppear, + .onLanguageChange = onLanguageChange, .onWillDisappear = lifeCycleAttr.onWillDisappear, + .levelOrder = GetLevelOrderParam(asyncContext->env, asyncContext), .dialogLevelMode = dialogLevelMode, .dialogLevelUniqueId = dialogLevelUniqueId, .dialogImmersiveMode = dialogImmersiveMode, @@ -2284,11 +2325,12 @@ void ParseDialogCallback(std::shared_ptr& asyncContext, } void ParseBorderColorAndStyle(napi_env env, const std::shared_ptr& asyncContext, - std::optional& borderWidthProps, std::optional& borderColorProps, - std::optional& borderStyleProps) + std::optional& borderColorProps, std::optional& borderStyleProps, + std::optional props) { + auto borderWidthProps = GetBorderWidthProps(env, asyncContext); if (borderWidthProps.has_value()) { - borderColorProps = GetBorderColorProps(env, asyncContext); + borderColorProps = GetBorderColorProps(env, asyncContext, props); if (!borderColorProps.has_value()) { NG::BorderColorProperty borderColor; borderColor.SetColor(Color::BLACK); @@ -2400,18 +2442,29 @@ PromptDialogAttr GetPromptActionDialog(napi_env env, const std::shared_ptr blurStyleOption; std::optional effectOption; std::optional enableHoverMode; + bool hasCustomMaskColor = false; + bool hasCustomShadowColor = false; + bool hasCustomBackgroundColor = false; + CustomBorderColorProps customBorderColorProps; GetNapiDialogProps(env, asyncContext, alignment, offset, maskRect); GetNapiBlurStyleAndHoverModeProps(env, asyncContext, backgroundBlurStyle, hoverModeArea, enableHoverMode); GetBackgroundBlurStyleOption(env, asyncContext, blurStyleOption); GetBackgroundEffect(env, asyncContext, effectOption); - auto borderWidthProps = GetBorderWidthProps(env, asyncContext); std::optional borderColorProps; std::optional borderStyleProps; - ParseBorderColorAndStyle(env, asyncContext, borderWidthProps, borderColorProps, borderStyleProps); + ParseBorderColorAndStyle(env, asyncContext, borderColorProps, borderStyleProps, customBorderColorProps); auto backgroundColorProps = GetColorProps(env, asyncContext->backgroundColorApi); + if (backgroundColorProps && SystemProperties::ConfigChangePerform() && + !CheckDarkResource(backgroundColorProps.value())) { + hasCustomBackgroundColor = true; + } auto builder = GetCustomBuilder(env, asyncContext); auto* nodePtr = reinterpret_cast(asyncContext->nativePtr); auto maskColorProps = GetColorProps(env, asyncContext->maskColorApi); + if (maskColorProps && SystemProperties::ConfigChangePerform() && !CheckDarkResource(maskColorProps.value())) { + hasCustomMaskColor = true; + } + auto shadowProps = GetShadowProps(env, asyncContext, hasCustomShadowColor); auto transitionEffectProps = GetTransitionProps(env, asyncContext); auto dialogTransitionEffectProps = GetDialogTransitionProps(env, asyncContext); auto maskTransitionEffectProps = GetMaskTransitionProps(env, asyncContext); @@ -2434,16 +2487,20 @@ PromptDialogAttr GetPromptActionDialog(napi_env env, const std::shared_ptr