Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Proof-of-concept] Image render API #505

Merged
merged 6 commits into from
Feb 8, 2021

Conversation

erickok
Copy link
Collaborator

@erickok erickok commented Jan 18, 2021

A proposal for an all-encompassing image render API. See #497 for a discussion and #504 for an alternative.

Copy link
Collaborator

@ryan-berger ryan-berger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, nice job, one small nitpick, but I would be fine accepting this proposal.

We will need to document this extremely well though, so before we merge we may want to do that....

lib/image_render.dart Show resolved Hide resolved
lib/src/replaced_element.dart Show resolved Hide resolved
@erickok
Copy link
Collaborator Author

erickok commented Feb 4, 2021

I will complete my proposal with support for the other source/target combinations we currently supported.

Also swallow missing sources silently and add several examples
@erickok
Copy link
Collaborator Author

erickok commented Feb 5, 2021

Okay I am feature-complete now with regards to the existing implementation. As I bonus we support asset svgs. It's easy to extend support but the PR is big enough as it stands. @tneotia could you test-drive this for me?

@tneotia
Copy link
Collaborator

tneotia commented Feb 5, 2021

@erickok Test-drive has passed with flying colors. Just three things:

  1. If I use
assetUriMatcher(): (context, attributes, element) {
              return Image.asset(attributes['src'].replaceAll("asset:", ""));
            }

I get an error because the SVG element can't be rendered by Image.asset. I created a review above that talked about this, basically I think that you should split the asset rendering into an assetImage render and an assetSvg render, like how you've split the network renders.

  1. I created another review above related to the question I had on Use intrinsic with for <table> columns with otherwise undefined size #519 where you said that we no longer had to check for the size of the image before passing to a table, please check that.

  2. There seems to be a merge conflict, can you update your branch and push again to resolve it?

Great work, this is fantastic! Can't wait for the customRender to transition to this type of implementation too.

P.S. Go to sleep - you're working on this at like 2a.m. lol No need to be grinding that much :)

@ryan-berger
Copy link
Collaborator

@erickok Could we also add some unit tests for matchers before we merge? I think that this is a thing that ought to have tests just in case

@erickok
Copy link
Collaborator Author

erickok commented Feb 8, 2021

@ryan-berger I have added unit tests for the different image source matchers (asset, base64 data and network).

@tneotia good point, I have included the fix you did for #523 and made sure the size checking (for use in tables) is still needed and unfortunately it still is (so it is working as intended now).

@erickok
Copy link
Collaborator Author

erickok commented Feb 8, 2021

Screenshot 2021-02-08 at 13 19 19

@ryan-berger
Copy link
Collaborator

ryan-berger commented Feb 8, 2021

@erickok This is looking very good, I think I have one last question that I'm not sure if we addressed via proposals:

Who is handing the error if the render function for the image throws an exception? Do we want to throw in a placeholder?

Once we have that answered, I say we merge it

@erickok
Copy link
Collaborator Author

erickok commented Feb 8, 2021

Good point. For the moment I decided not to change this behaviour, so the error callback is still as-is, namely the onImageError. That's for 'expected' errors such as when an image could not be loaded. Programming errors are caught in any specific way (and we don't do that anywhere else either in our lib).

@ryan-berger
Copy link
Collaborator

Oh duh, forgot about that callback.

I think this looks good to me then! I'll approve the merge and let you do it!

Copy link
Collaborator

@ryan-berger ryan-berger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely done! I'm quite excited to see this go to production!

@erickok
Copy link
Collaborator Author

erickok commented Feb 8, 2021

Thanks for the help and support, @ryan-berger and @tneotia . I am going to merge. Much more coming soon!

@erickok erickok merged commit e8f50ed into Sub6Resources:master Feb 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants