!40260 [bugfix]:[toast shadow radius支持解析资源]

Merge pull request !40260 from Zhang Jinyu/toast_0812
This commit is contained in:
openharmony_ci 2024-08-13 11:28:29 +00:00 committed by Gitee
commit ec7876392c
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -245,6 +245,26 @@ bool GetShadowFromTheme(ShadowStyle shadowStyle, Shadow& shadow)
return true;
}
bool ParseResource(const ResourceInfo resource, CalcDimension& result)
{
auto resourceWrapper = CreateResourceWrapper(resource);
CHECK_NULL_RETURN(resourceWrapper, false);
if (resource.type == static_cast<uint32_t>(ResourceType::STRING)) {
auto value = resourceWrapper->GetString(resource.resId);
return StringUtils::StringToCalcDimensionNG(value, result, false);
}
if (resource.type == static_cast<uint32_t>(ResourceType::INTEGER)) {
auto value = std::to_string(resourceWrapper->GetInt(resource.resId));
StringUtils::StringToDimensionWithUnitNG(value, result);
return true;
}
if (resource.type == static_cast<uint32_t>(ResourceType::FLOAT)) {
result = resourceWrapper->GetDimension(resource.resId);
return true;
}
return false;
}
void GetToastObjectShadow(napi_env env, napi_value shadowNApi, Shadow& shadowProps)
{
napi_value radiusApi = nullptr;
@ -255,12 +275,20 @@ void GetToastObjectShadow(napi_env env, napi_value shadowNApi, Shadow& shadowPro
napi_get_named_property(env, shadowNApi, "color", &colorApi);
napi_get_named_property(env, shadowNApi, "type", &typeApi);
napi_get_named_property(env, shadowNApi, "fill", &fillApi);
double radius = 0.0;
napi_get_value_double(env, radiusApi, &radius);
if (LessNotEqual(radius, 0.0)) {
radius = 0.0;
ResourceInfo recv;
double radiusValue = 0.0;
if (ParseResourceParam(env, radiusApi, recv)) {
CalcDimension radius;
if (ParseResource(recv, radius)) {
radiusValue = LessNotEqual(radius.Value(), 0.0) ? 0.0 : radius.Value();
}
} else {
napi_get_value_double(env, radiusApi, &radiusValue);
if (LessNotEqual(radiusValue, 0.0)) {
radiusValue = 0.0;
}
}
shadowProps.SetBlurRadius(radius);
shadowProps.SetBlurRadius(radiusValue);
Color color;
ShadowColorStrategy shadowColorStrategy;
if (ParseShadowColorStrategy(env, colorApi, shadowColorStrategy)) {
@ -287,26 +315,6 @@ void GetToastObjectShadow(napi_env env, napi_value shadowNApi, Shadow& shadowPro
shadowProps.SetIsFilled(isFilled);
}
bool ParseResource(const ResourceInfo resource, CalcDimension& result)
{
auto resourceWrapper = CreateResourceWrapper(resource);
CHECK_NULL_RETURN(resourceWrapper, false);
if (resource.type == static_cast<uint32_t>(ResourceType::STRING)) {
auto value = resourceWrapper->GetString(resource.resId);
return StringUtils::StringToCalcDimensionNG(value, result, false);
}
if (resource.type == static_cast<uint32_t>(ResourceType::INTEGER)) {
auto value = std::to_string(resourceWrapper->GetInt(resource.resId));
StringUtils::StringToDimensionWithUnitNG(value, result);
return true;
}
if (resource.type == static_cast<uint32_t>(ResourceType::FLOAT)) {
result = resourceWrapper->GetDimension(resource.resId);
return true;
}
return false;
}
void GetToastShadow(napi_env env, napi_value shadowNApi, std::optional<Shadow>& shadow)
{
Shadow shadowProps;