!40145 [bugfix]:[toast shadow offset支持解析资源]

Merge pull request !40145 from miaoyu/dev-0810
This commit is contained in:
openharmony_ci 2024-08-12 08:39:44 +00:00 committed by Gitee
commit e89745e229
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -294,6 +294,26 @@ void GetToastObjectShadow(napi_env env, napi_value shadowNApi, Shadow& shadowPro
shadowProps.SetIsFilled(isFilled); 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) void GetToastShadow(napi_env env, napi_value shadowNApi, std::optional<Shadow>& shadow)
{ {
Shadow shadowProps; Shadow shadowProps;
@ -313,10 +333,11 @@ void GetToastShadow(napi_env env, napi_value shadowNApi, std::optional<Shadow>&
ResourceInfo recv; ResourceInfo recv;
bool isRtl = AceApplicationInfo::GetInstance().IsRightToLeft(); bool isRtl = AceApplicationInfo::GetInstance().IsRightToLeft();
if (ParseResourceParam(env, offsetXApi, recv)) { if (ParseResourceParam(env, offsetXApi, recv)) {
auto resourceWrapper = CreateResourceWrapper(recv); CalcDimension offsetX;
auto offsetX = resourceWrapper->GetDimension(recv.resId); if (ParseResource(recv, offsetX)) {
double xValue = isRtl ? offsetX.Value() * (-1) : offsetX.Value(); double xValue = isRtl ? offsetX.Value() * (-1) : offsetX.Value();
shadowProps.SetOffsetX(xValue); shadowProps.SetOffsetX(xValue);
}
} else { } else {
CalcDimension offsetX; CalcDimension offsetX;
if (ParseNapiDimension(env, offsetX, offsetXApi, DimensionUnit::VP)) { if (ParseNapiDimension(env, offsetX, offsetXApi, DimensionUnit::VP)) {
@ -325,9 +346,10 @@ void GetToastShadow(napi_env env, napi_value shadowNApi, std::optional<Shadow>&
} }
} }
if (ParseResourceParam(env, offsetYApi, recv)) { if (ParseResourceParam(env, offsetYApi, recv)) {
auto resourceWrapper = CreateResourceWrapper(recv); CalcDimension offsetY;
auto offsetY = resourceWrapper->GetDimension(recv.resId); if (ParseResource(recv, offsetY)) {
shadowProps.SetOffsetY(offsetY.Value()); shadowProps.SetOffsetY(offsetY.Value());
}
} else { } else {
CalcDimension offsetY; CalcDimension offsetY;
if (ParseNapiDimension(env, offsetY, offsetYApi, DimensionUnit::VP)) { if (ParseNapiDimension(env, offsetY, offsetYApi, DimensionUnit::VP)) {