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

Support for wrapping images in links #1984

Merged
merged 21 commits into from
May 18, 2018
Merged

Support for wrapping images in links #1984

merged 21 commits into from
May 18, 2018

Conversation

avknaidu
Copy link
Member

@avknaidu avknaidu commented Apr 18, 2018

Issue: #1836

PR Type

What kind of change does this PR introduce?

Feature

What is the current behavior?

When using Wrapped ImageLinks like Below it will not render.

[![image](https://avatars0.githubusercontent.com/u/711864)](https://github.com/nmetulev)

What is the new behavior?

Will render in Markdown TextBlock

expected

PR Checklist

Please check if your PR fulfills the following requirements:

[x] Tested code with current supported SDKs
[x] Docs have been added/updated which fit documentation template. (for bug fixes / features)
[x] Sample in sample app has been added / updated (for bug fixes / features)
[ ] Icon has been created (if new sample) following the Thumbnail Style Guide and templates
[ ] Tests for the changes have been added (for bug fixes / features) (if applicable)
[ ] Header has been added to all new source files (run build/UpdateHeaders.bat)
[x] Contains NO breaking changes

Tasks

  • Render Image for Wrapped Links
  • Render Image when used with references
  • Set Tooltips when Links are wrapped with Image reference. ( second scenario )
  • Images wrapped links should fire LinkClicked

@avknaidu
Copy link
Member Author

I do not think Sample needs an update. But if you want me to update sample, let me know.

Copy link
Contributor

@nmetulev nmetulev left a comment

Choose a reason for hiding this comment

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

My expectation here clicking the image would invoke the LinkClicked event and not the ImageClicked event. For example [![image](http://imageurl)](http://linkurl) would render the image and when clicked, it would invoke LinkClicked passing the http://linkurl. Instead, the ImageClicked is invoked passing the http://imageurl.

@Vijay-Nirmal
Copy link
Contributor

@avknaidu Include an example in the default .md file in the sample app.

@avknaidu
Copy link
Member Author

I made changes to open assigned Link instead of opening Image.

My expectation here clicking the image would invoke the LinkClicked event and not the ImageClicked event

Even though this is a link, Since you are clicking on the image, It will still invoke ImageClicked. I think now is the time to merge these two together as a single Event with a Type the way we did this before and went back to two different events before 2.2 release. See the comments at the end of the PR #1807

Include an example in the default .md file in the sample app.

Done.

}

// Check the scheme is allowed.
bool schemeIsAllowed = false;

Choose a reason for hiding this comment

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

could probably do without this flag .. just return true immediately in the loop .. and return false after the loop

Copy link
Contributor

@nmetulev nmetulev left a comment

Choose a reason for hiding this comment

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

There are few new tests failing with these changes.


// Check the scheme is allowed.
bool schemeIsAllowed = false;
foreach (var scheme in HyperlinkInline.KnownSchemes)
Copy link
Contributor

Choose a reason for hiding this comment

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

you can get the scheme directly from the result uri above and just check if the KnownSchemes contains it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

/// If this is a reference-style link, attempts to converts it to a regular link.
/// </summary>
/// <param name="document"> The document containing the list of references. </param>
public void ResolveReference(MarkdownDocument document)
Copy link
Contributor

Choose a reason for hiding this comment

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

does this need to be public?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. Because this method is being called from a Protected Method and I get an accessibility error.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why not internal?

@@ -378,18 +378,45 @@ renders in

You can also specify image width like this:

>\!\[SVG logo](https://upload.wikimedia.org/wikipedia/commons/0/02/SVG_logo.svg =32) (width is set to 32)
>\!\[SVG logo](https\://upload.wikimedia.org/wikipedia/commons/0/02/SVG_logo.svg =32) (width is set to 32)
Copy link
Contributor

Choose a reason for hiding this comment

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

why does the : need escaping now and not before - is it a breaking change?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is just a UI Choice. Before It used to render in example. Just for consistency, i added the escape character. or else even that URL will be rendered.

@nmetulev
Copy link
Contributor

On the ImageClicked vs LinkClicked, I think there is still benefit in having both to handle different cases. However, I would expect the LinkClicked to be fired instead of the ImageClicked event when an image is wrapped with a link.

@avknaidu
Copy link
Member Author

@nmetulev I will make remaining change (LinkClicked when tapped on Image) tomorrow. In the mean time, if you find any other issues, let me know.

@WilliamABradley could you please review the PR?

@avknaidu
Copy link
Member Author

On the ImageClicked vs LinkClicked, I think there is still benefit in having both to handle different cases. However, I would expect the LinkClicked to be fired instead of the ImageClicked event when an image is wrapped with a link.

@nmetulev When Images are wrapped as Links, it will now fire LinkClicked instead of ImageClicked with latest commit.

Copy link
Contributor

@nmetulev nmetulev left a comment

Choose a reason for hiding this comment

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

Works great.

I am still worried about the extra failing tests, can you make sure there are no additional failing tests with your changes?

Ex: Here is master:
image

Here is this PR:
image

/// If this is a reference-style link, attempts to converts it to a regular link.
/// </summary>
/// <param name="document"> The document containing the list of references. </param>
public void ResolveReference(MarkdownDocument document)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not internal?

@avknaidu
Copy link
Member Author

4 of the 6 tests

ImageInline_ParseEncodedUrl
ImageInline_WithHeight
ImageInline_WithWidth
ImageInline_WithWidthAndHeight

are failing because I added 2 new properties RenderURL and ReferenceID. Once these fields are added to the Tests, they do not fail anymore.

2 of the 6 tests

Hyperlink_Negative_SchemeOnly
Hyperlink_Negative_AngleBracketsPrefixOnly

are failing because we are taking the scheme from URI instead of the list. This changes the tests that are looking for : where in URI Scheme does not return :.

Let me know if you want me commit with changes. Below is the output after changes.

image

@avknaidu
Copy link
Member Author

ping @nmetulev

@nmetulev
Copy link
Contributor

Yes, please make sure the tests are updated to make sure we have the appropriate coverage

@avknaidu
Copy link
Member Author

@nmetulev ping

@avknaidu
Copy link
Member Author

@WilliamABradley ping

@avknaidu
Copy link
Member Author

@WilliamABradley do you think you verify this PR today?

I have PR's for #2069 , #1849 and #1383 lined up but cannot create a PR because of the commits on this PR. I merged changes into Master by mistake.

@WilliamABradley
Copy link
Contributor

WilliamABradley commented May 16, 2018 via email

@azchohfi azchohfi self-requested a review May 17, 2018 23:50
Copy link
Contributor

@azchohfi azchohfi left a comment

Choose a reason for hiding this comment

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

Should the images with links change the cursor to the hand one? If not, approved.

@avknaidu
Copy link
Member Author

I left a comment on the issue itself that we can wrap the image in hyperlink button. That way we can get the hand cursor. I already made that change in another PR. Will push for review.

@nmetulev nmetulev merged commit 6cdef20 into CommunityToolkit:master May 18, 2018
@avknaidu avknaidu deleted the TextToolBar branch May 18, 2018 20:36
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.

6 participants