Skip to content

Conversation

@avknaidu
Copy link
Member

Issue: #1091

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[x] Feature
[ ] Code style update (formatting)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build or CI related changes
[ ] Documentation content changes
[ ] Sample app changes
[ ] Other... Please describe:

What is the current behavior?

Images cannot be clicked with current implementation

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tested code with current supported SDKs
  • Docs have been added/updated which fit documentation template. (for bug fixes / features)
  • Sample in sample app has been added / updated (for bug fixes / features)
  • Tests for the changes have been added (for bug fixes / features) (if applicable)

What is the new behavior?

Images can be tapped and will work as regular Hyperlink giving user option to Handle them in LinkClicked event

Does this PR introduce a breaking change?

[ ] Yes
[x] No

@avknaidu
Copy link
Member Author

@skendrot @nmetulev @WilliamABradley Although the Link Clicked on Images also work, I would like to add a Extra Property e.Type which will return if the clicked FrameworkElement is a Link or Image. That way dev can choose what they want to do with the clicked Links. Thoughts?

@skendrot
Copy link
Contributor

What's the use case for needing to know if an image was clicked?

@avknaidu
Copy link
Member Author

Devs can handle Links and Images in 2 different UI ways. Gives them benefit of building Different UI's for each Link Type if required.

For example, Links can be opened in a web view inside the app and Images can be opened in a Content Dialog with full scale width an height even though in MarkdownTextblock it it set to specific ImageStretch. If this type is not set, Devs need to figure out if the clicked link is a regular link or an image link. We can eliminate that and provide that info from Toolkit Itself. Make their life a little bit more easy.

@skendrot
Copy link
Contributor

Aren't images already links?

image

@avknaidu
Copy link
Member Author

They are. When you clicked on the Image, It opened a New Tab. It does the same when you click on a regular link too. With Toolkit returning what is that Link Pertaining to, it will give an extra option for Developer to actually do different things while handling links.

Maybe if we return e.Type as HyperLink and Image instead of Link and Image it might make more sense.

@WilliamABradley
Copy link
Contributor

@avknaidu #1650 has now been merged, you will need to ensure that your PR conforms to the new structure.

@nmetulev
Copy link
Contributor

I agree, Type seems like a good addition.

@avknaidu avknaidu closed this Feb 14, 2018
@avknaidu avknaidu reopened this Feb 14, 2018
@skendrot
Copy link
Contributor

sorry, I was misunderstanding the PR. I thought you could already tap an image. That was this PR is doing!

I'm not sure adding a type is all that beneficial. Easy enough to know it's an image based on the uri

@nmetulev
Copy link
Contributor

It's easy to know if an uri is an image, but not if that uri is coming from an image or a regular link

@avknaidu
Copy link
Member Author

@skendrot @nmetulev let me know if i need to make any more changes.

/// Holds a list of hyperlinks we are listening to.
/// </summary>
private readonly List<Hyperlink> _listeningHyperlinks = new List<Hyperlink>();
private readonly List<object> _listeningHyperlinks = new List<object>();
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice to wrap this into a new class, or tuple or something, for Type safety.

Copy link
Contributor

Choose a reason for hiding this comment

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

You could change it to UIElement (I think).

Copy link
Member Author

Choose a reason for hiding this comment

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

Image is derived from UIElement. Pretty sure Hyperlink is not.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, that's right. I'm ok with this being how it is right now unless @WilliamABradley has any concerns

/// <summary>
/// Gets the type of link that was tapped.(Image/Link)
/// </summary>
public string Type { get; }
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you change this to Enum instead of a string?

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.

Looks good to me. other than the change requested by @WilliamABradley

/// Holds a list of hyperlinks we are listening to.
/// </summary>
private readonly List<Hyperlink> _listeningHyperlinks = new List<Hyperlink>();
private readonly List<object> _listeningHyperlinks = new List<object>();
Copy link
Contributor

Choose a reason for hiding this comment

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

You could change it to UIElement (I think).

// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************


Copy link
Contributor

@nmetulev nmetulev Feb 19, 2018

Choose a reason for hiding this comment

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

I think there is an extra space here, that's why the build is failing.

@avknaidu
Copy link
Member Author

Do not merge this PR yet. I found an issue with my commit. Fixing it.

foreach (object link in _listeningHyperlinks)
{
link.Click -= Hyperlink_Click;
if (link is Hyperlink)
Copy link
Contributor

Choose a reason for hiding this comment

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

change the if statements to reduce casting

if(list is Hyperlink hyperlink)
{
    hyperlink.Click -= Hyperlink_Click;
}
else if(link in Image image)
{
    image.Tapped -= NewImagelink_Tapped;
}

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

Copy link
Contributor

@skendrot skendrot left a comment

Choose a reason for hiding this comment

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

I haven't had a chance to test the new feature, but code looks good. @nmetulev have you had a chance to test this?

@nmetulev
Copy link
Contributor

nmetulev commented Feb 20, 2018

I tested it and works as expected.

Keep in mind, this PR does not add support for images to be wrapped in a hyperlink
so this won't work: [![image](http://imagelink)](http://link.com)

I think this is something that should be added next (in a separate PR) ;)

@nmetulev
Copy link
Contributor

@WilliamABradley, up to you now

@avknaidu
Copy link
Member Author

@nmetulev I already did some research on the option above because it is the most commonly used scenario on Stackoverflow. I made changes to fit that scenario but they do not meet the standard of this toolkit. However when i work on updating my app, I will revisit this scenario and will implement that in a proper way. Probably before 3.0

@WilliamABradley
Copy link
Contributor

WilliamABradley commented Feb 21, 2018

@avknaidu This throws an exception on Local images in the sample app, you should catch all exceptions for link clicks, since other people could have implemented unsafe link launching like we have in the sample app, and it would be a breaking change.

The issue is on line 523 in Shell.xaml.cs.

@avknaidu
Copy link
Member Author

Clicking on Relative Links is an issue even with 2.1.1 release. If anything, this PR will fix that issue in sample app. I am not sure if a bug fix + improvement is considered a breaking change.

If you install the app from the store, enter [Link 1](/Link.html) and click on the Link in MarkdownTextBlock in sample below, It will close the app completely. So if any devs who use Relative Links option on MarkdownTextBlock from 2.1.1 notice this issue, They will already be handling the scenario because there is no way the app works without handling the scenario.

Although the Exception in the sample app for docs you mentioned above is handled with my last Push. If you want me to update the docs, I will be happy to do that.

@nmetulev
Copy link
Contributor

I think it's worth updating the docs to add the notice. Relative images didn't work before so don't think it's going to be a big issue.

### LinkClicked

Use this event to handle clicking on links for Markdown, by default the MarkdownTextBlock does not handle Clicking on Links.
Use this event to handle clicking on links or images for Markdown, by default the MarkdownTextBlock does not handle Clicking on Links or Images.
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you also add a note here that taping any image will raise the LinkClicked event and with the uri of the image?Developers should use the LinkType property to decide how to handle 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. Let me know if there is anything else that i need to update.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks. @WilliamABradley up to you

@WilliamABradley
Copy link
Contributor

WilliamABradley commented Feb 22, 2018

@avknaidu Can you make the mouse cursor if you hover over the Image into a Hand cursor if the link is clickable? Otherwise it doesn't look clickable, and it follows Hyperlink styling.

@WilliamABradley
Copy link
Contributor

As discussed with @nmetulev, we can add Hand cursor clicking in a future PR.

@WilliamABradley WilliamABradley merged commit 52f562f into CommunityToolkit:master Feb 22, 2018
@windowstoolkitbot
Copy link

This PR is linked to unclosed issues. Please check if one of these issues should be closed: #1091

@avknaidu avknaidu deleted the MarkdownImageTapped branch February 22, 2018 10:46
@nmetulev
Copy link
Contributor

@avknaidu, just wanted to give you a quick heads up - after discussing with few folks, there was a conclusion that the current implementation could be a breaking change since developers might already be handling the LinkClicked and they wouldn't expect image click to raise that event. I'm going to submit a quick update to add a new event ImageClicked to handle those cases

@avknaidu
Copy link
Member Author

@nmetulev does this mean this PR will not be part of 2.2?

@skendrot
Copy link
Contributor

skendrot commented Feb 22, 2018

If it's changed to have a new event ImageClicked (for example), similar to LinkClicked then it can go into 2.2

@avknaidu
Copy link
Member Author

If you want, I can submit a PR to

add the new event
remove the e.LinkType
update docs.

Let me know.

@skendrot
Copy link
Contributor

Please do. Based on what @nmetulev stated above, we would need to back out the change as-is

@nmetulev
Copy link
Contributor

That would be great @avknaidu, please do. Do you think you would be able to do it today?

@avknaidu
Copy link
Member Author

Sure. Give me 2 hrs. Finishing up some work related stuff. Should i submit another PR?

@nmetulev
Copy link
Contributor

Thank you. Yes, please submit a new PR and target the rel/2.2.0 branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants