divkit / divkit

DivKit is an open source Server-Driven UI (SDUI) framework. SDUI is a an emerging technique that leverage the server to build the user interfaces of their mobile app
https://divkit.tech
Other
2.22k stars 122 forks source link

Added support for SVG images. #41

Closed gkashin closed 5 months ago

gkashin commented 8 months ago

I hereby agree to the terms of the CLA available at: link

Notes

This pull request contains the changes that support loading images in SVG format.

  1. SVG Image Loading

    • To load SVG images, a separate image loader is created;
    • AndroidSVG library was used to decode SVG format;
    • A simple in-memory cache was implemented to store downloaded vector images locally;
    • Inside the app, vector images are represented in the format of PictureDrawable;
    • To render SVG, a new onSuccess(PictureDrawable) method was added in the DivImageDownloadCallback interface.
  2. Picasso and Glide backward compatibility

    • The interface of DivImageLoader has been extended to have doesSupportSvg() method indicating whether the image loader supports SVG;
    • To make Picasso and Glide work with SVG images, a special FlexibleImageLoader bean was created;
    • It represents a wrapper over the standard image loader which can replace it with the SvgImageLoader under the hood if SVG format is not supported by the chosen image loader;
  3. Rendering Vector Images

    • Vector images are being rendered inside of onSuccess(PictureDrawable) method in a similar way as bitmaps;
    • Images in vector format don't support tints and filters. To overcome this, DivImage shouldBeRasterized property was created which is being set to true if the tint or filters are overridden for the image;
    • If it should be rasterized, then that image is converted into bitmap of the size of the original SVG;
    • Background images don't support transparency and filters. When such properties are specified, then background image is converted to bitmap in a similar way.
  4. Previews

    • To decode SVG images from base64, DecodeBase64ImageTask was extended to work with both formats;
    • Instead of working only with Bitmaps, it now supports Bitmap and PictureDrawable which are aggregated under a newly created ImageRepresentation sealed template class.
  5. Samples and Testing Screens Updates

    • To demonstrate the features of vector images, Sample and Testing screens were updated accordingly.
flattened-duck commented 5 months ago

Thank you for your contribution! Changes was merged as 4657ced