-
Couldn't load subscription status.
- Fork 1.4k
Implementing Tapped on Images in MarkdownTextBlock #1807
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
Implementing Tapped on Images in MarkdownTextBlock #1807
Conversation
|
@skendrot @nmetulev @WilliamABradley Although the Link Clicked on Images also work, I would like to add a Extra Property |
|
What's the use case for needing to know if an image was clicked? |
|
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 |
|
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 |
|
I agree, Type seems like a good addition. |
|
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 |
|
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 |
| /// 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>(); |
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.
It would be nice to wrap this into a new class, or tuple or something, for Type safety.
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.
You could change it to UIElement (I think).
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.
Image is derived from UIElement. Pretty sure Hyperlink is not.
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.
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; } |
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.
Could you change this to Enum instead of a string?
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.
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>(); |
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.
You could change it to UIElement (I think).
| // THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE. | ||
| // ****************************************************************** | ||
|
|
||
|
|
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 there is an extra space here, that's why the build is failing.
|
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) |
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.
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;
}
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.
done
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 haven't had a chance to test the new feature, but code looks good. @nmetulev have you had a chance to test this?
|
I tested it and works as expected. Keep in mind, this PR does not add support for images to be wrapped in a hyperlink I think this is something that should be added next (in a separate PR) ;) |
|
@WilliamABradley, up to you now |
|
@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 |
|
@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 |
|
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 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. |
|
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. |
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.
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.
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.
Done. Let me know if there is anything else that i need to update.
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.
Thanks. @WilliamABradley up to you
|
@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. |
|
As discussed with @nmetulev, we can add Hand cursor clicking in a future PR. |
|
This PR is linked to unclosed issues. Please check if one of these issues should be closed: #1091 |
|
@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 |
|
@nmetulev does this mean this PR will not be part of 2.2? |
|
If it's changed to have a new event ImageClicked (for example), similar to LinkClicked then it can go into 2.2 |
|
If you want, I can submit a PR to add the new event Let me know. |
|
Please do. Based on what @nmetulev stated above, we would need to back out the change as-is |
|
That would be great @avknaidu, please do. Do you think you would be able to do it today? |
|
Sure. Give me 2 hrs. Finishing up some work related stuff. Should i submit another PR? |
|
Thank you. Yes, please submit a new PR and target the rel/2.2.0 branch |

Issue: #1091
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Images cannot be clicked with current implementation
PR Checklist
Please check if your PR fulfills the following requirements:
What is the new behavior?
Images can be tapped and will work as regular Hyperlink giving user option to Handle them in
LinkClickedeventDoes this PR introduce a breaking change?