-
-
Notifications
You must be signed in to change notification settings - Fork 905
Upgrade customRender to imitate customImageRender & add support for customRender for SelectableHtml #632
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
Upgrade customRender to imitate customImageRender & add support for customRender for SelectableHtml #632
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you did you great job here and it is exactly how I imagined the evolution of the API to go. This also makes modularization easy.
Of course it requires some extensive regression testing. I am sorry I don't have so much time now...
No problem at all. I don't create these PRs looking for immediate feedback, everyone has their own obligations to attend to first, even I was a bit inactive for a few weeks :) In the meantime I'll see about adding customization parameters to the default ones and updating docs. |
…into feature/upgrade-custom-render � Conflicts: � lib/flutter_html.dart � lib/html_parser.dart
…into feature/upgrade-custom-render � Conflicts: � example/lib/main.dart
…into feature/upgrade-custom-render � Conflicts: � README.md � example/lib/main.dart � lib/html_parser.dart
…into feature/upgrade-custom-render � Conflicts: � lib/flutter_html.dart � lib/html_parser.dart
…into feature/upgrade-custom-render � Conflicts: � lib/flutter_html.dart � lib/html_parser.dart
@erickok I know you're busy but since we've been making so many changes to the parser and the API recently it's been a bit hard to keep fixing merge conflicts with this branch - I always feel like I've missed something when migrating the parser changes to the customRender API. If you have any time to review and potentially merge that would be super helpful, but no pressure. I totally understand! |
I very much understand. I also find this an important topic. That's why I try to close as many fix PRs and small features as possible. The reworking means a sizable api change and as such warrants another major version bump (even though the internals largely remain the same). This means we have to try to get 2.0 stable asap so this rework can come, which aids modularisation. I think we're close though and much appreciate your work. Almost there. Also, in one month time I will have much more time myself to get back on the library, so it won't all be on you any more. |
…ustom-render # Conflicts: # lib/html_parser.dart # test/html_parser_test.dart
This is great work @tneotia . I wanted to make some small suggestions but it seems I actually pushed directly to your repo. 🤦 For which I apparently have rights. Anyway check out tneotia@1c7b9e2 for that. |
No problem, thanks for fixing the conflicts! Otherwise your changes are fine with me :) |
What do you think @tneotia of - since we are breaking anyway - removing the |
@erickok I might be misunderstanding what you mean but I think in the new implementation we don't build the child tree eagerly - As for the convenience method to use the default rendering engine, it would be a little difficult imho because the default renders return |
…into feature/upgrade-custom-render � Conflicts: � README.md � lib/flutter_html.dart � lib/html_parser.dart
@erickok this has been updated to reflect latest changes on master as well. I'd say if we want to merge #922, #932, and #879, we may as well go all-in and finish the modularization process to avoid multiple breaking change releases in a row. The process would look like this:
This way, we update all breaking changes in (basically) one release, rather than making major version updates for each breaking change. That might be a lot of changes in one release but I think it should be fine, mostly the code is just refactored to different places and I don't expect any functionality to break. If this sounds good to you I can make a v3.0.0 migration guide as well. |
Title.
The API is extremely similar to that of custom image render. A brief summary:
Users provide a
Map<CustomRenderMatcher, CustomRender>
in their widget code.CustomRenderMatcher
passesRenderContext
to the user and requires abool
to be returned.CustomRender
has two constructors:CustomRender.fromInlineSpan
andCustomRender.fromWidget
. Users provide one or the other in the aboveMap
. Both constructors pass theRenderContext
and a function that returns the built children when called. This avoids unncecessary widget creation if the user doesn't need to display children.The package has a number of default renders (see
custom_render.dart
) and prioritizes the user renders.For
SelectableHtml
, users passMap<CustomRenderMatcher, SelectableCustomRender>
in their widget code.SelectableCustomRender
extendsCustomRender
and allows users to pass aTextSpan
. It has the same constructor format asCustomRender
.If you have any thoughts on the API let me know.
A couple of things to still tackle:
I disabled some tests due to some modifications I needed to make to theDone._lexDomTree
function. We have to figure out a way to get those working again.Update READMEDone.Possibly add some easy customization parameters to the default renders? At the moment there are none.Done - now you can do stuff like this: