Skip to content

Commit

Permalink
feat(ohos): fix alt image setting
Browse files Browse the repository at this point in the history
  • Loading branch information
sohotz committed Aug 16, 2024
1 parent 0adabe7 commit f45e59d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class ImageView : public BaseView, public ImageNodeDelegate {
std::string GetSrc();

protected:
virtual void FetchAltImage(const std::string &imageUrl);
virtual void FetchImage(const std::string &imageUrl);

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class RichTextImageSpanView : public BaseView {
void UpdateRenderViewFrame(const HRRect &frame, const HRPadding &padding) override;

private:
void FetchAltImage(const std::string &imageUrl);
void fetchImage(const std::string &imageUrl);

ImageSpanNode imageSpanNode_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ bool ImageView::SetProp(const std::string &propKey, const HippyValue &propValue)
} else if (propKey == "defaultSource") {
auto value = HRValueUtils::GetString(propValue);
if (!value.empty()) {
auto sourceUrl = HRUrlUtils::convertAssetImageUrl(value);
GetLocalRootArkUINode().SetAlt(sourceUrl);
FetchAltImage(value);
return true;
}
return false;
Expand Down Expand Up @@ -114,6 +113,25 @@ void ImageView::UpdateRenderViewFrame(const HRRect &frame, const HRPadding &padd
BaseView::UpdateRenderViewFrame(frame, padding);
}

void ImageView::FetchAltImage(const std::string &imageUrl) {
if (imageUrl.size() > 0) {
if (imageUrl.find(BASE64_IMAGE_PREFIX) == 0) {
GetLocalRootArkUINode().SetAlt(imageUrl);
return;
} else if (imageUrl.find(RAW_IMAGE_PREFIX) == 0) {
std::string convertUrl = ConvertToLocalPathIfNeeded(imageUrl);
GetLocalRootArkUINode().SetAlt(convertUrl);
return;
} else if (HRUrlUtils::isWebUrl(imageUrl)) {
GetLocalRootArkUINode().SetAlt(imageUrl);
return;
} else if (imageUrl.find(ASSET_PREFIX) == 0) {
std::string resourceStr = HRUrlUtils::convertAssetImageUrl(imageUrl);
GetLocalRootArkUINode().SetAlt(resourceStr);
}
}
}

void ImageView::FetchImage(const std::string &imageUrl) {
if (imageUrl.size() > 0) {
if (imageUrl.find(BASE64_IMAGE_PREFIX) == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ bool RichTextImageSpanView::SetProp(const std::string &propKey, const HippyValue
} else if (propKey == "defaultSource") {
auto value = HRValueUtils::GetString(propValue);
if (!value.empty()) {
auto sourceUrl = HRUrlUtils::convertAssetImageUrl(value);
GetLocalRootArkUINode().SetAlt(sourceUrl);
FetchAltImage(value);
return true;
}
return false;
Expand All @@ -97,6 +96,25 @@ void RichTextImageSpanView::UpdateRenderViewFrame(const HRRect &frame, const HRP
}
}

void RichTextImageSpanView::FetchAltImage(const std::string &imageUrl) {
if (imageUrl.size() > 0) {
if (imageUrl.find(BASE64_IMAGE_PREFIX) == 0) {
GetLocalRootArkUINode().SetAlt(imageUrl);
return;
} else if (imageUrl.find(RAW_IMAGE_PREFIX) == 0) {
std::string convertUrl = ConvertToLocalPathIfNeeded(imageUrl);
GetLocalRootArkUINode().SetAlt(convertUrl);
return;
} else if (HRUrlUtils::isWebUrl(imageUrl)) {
GetLocalRootArkUINode().SetAlt(imageUrl);
return;
} else if (imageUrl.find(ASSET_PREFIX) == 0) {
std::string resourceStr = HRUrlUtils::convertAssetImageUrl(imageUrl);
GetLocalRootArkUINode().SetAlt(resourceStr);
}
}
}

void RichTextImageSpanView::fetchImage(const std::string &imageUrl) {
if (imageUrl.size() > 0) {
if (imageUrl.find(BASE64_IMAGE_PREFIX) == 0) {
Expand Down

0 comments on commit f45e59d

Please sign in to comment.