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

Adds LinkPreview support to MessageKit #1310

Merged
merged 8 commits into from Jun 30, 2020

Conversation

bguidolim
Copy link
Contributor

What does this implement/fix? Explain your changes.

This PR implements a default cell for Link Preview. It inherits from TextMessage calculator and cell and adds a small view containing the title, teaser text, domain, and a thumbnail image.

Here is an example:

LinkPreview

Does this close any currently open issues?

No.

Any relevant logs, error output, etc?

No.

Any other comments?

I'm not sure about the implementation itself. This is the first time a calculator and cell inherits a subclass.

I had to set a default font for the LinkPreview view on its calculator. Is it a good place to have it?
I also set a default max-width of 75% of the available view, please check if it is alright.

Where has this been tested?

Devices/Simulators: Simulator - iPhone 11 Pro
iOS Version: 13.4
Swift Version: 5.2
MessageKit Version: 3.1.0

@bguidolim bguidolim changed the title Add LinkPreview support to MessageKit Adds LinkPreview support to MessageKit Apr 5, 2020
@@ -110,6 +110,7 @@ public enum MessageKind {
case emoji(String) // TextMessageCell
case audio(AudioItem) // AudioMessageCell
case contact(ContactItem) // ContactMessageCell
case linkPreview(LinkItem) // LinkPreviewMessageCell
Copy link
Member

Choose a reason for hiding this comment

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

Wondering if this should be released with a new major version (i.e 4.0.0) because it adds a new case to a public enum. Switches on enum types must be exhaustive so anyone doing a switch on a MessageKind without a default case (completely legal) will have their code break.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, next version should be 4.0.0 anyways as we dropped iOS 9 and iOS 10 which is another breaking change. :)

@xcodefriend
Copy link

@bguidolim, what about video links like youtube? It would be great to have the option to play video links inline as Apple does with the LPLinkView class.

@andrija-ostojic
Copy link

When can we expect this pull request to be merged ?

@bguidolim
Copy link
Contributor Author

@bguidolim, what about video links like youtube? It would be great to have the option to play video links inline as Apple does with the LPLinkView class.

tbh, I never planned this. It can be possible, yes, but this is an effort that I don't want to invest in now.

@andrija-ostojic
Copy link

As far as I can see, you don't actually implement any metadata fetching for a provided URL. This pull request only creates new kind of message cell with an imageView and a couple of labels. That is in my opinion worth really little, considering the fact that someone using this library would still have to do the heavy lifting, which is fetching the metadata.

@bguidolim
Copy link
Contributor Author

As far as I can see, you don't actually implement any metadata fetching for a provided URL. This pull request only creates new kind of message cell with an imageView and a couple of labels. That is in my opinion worth really little, considering the fact that someone using this library would still have to do the heavy lifting, which is fetching the metadata.

Well, this is actually the proposal of the library, we don't deal with any data fetching, only the UI. The source of the date coulbe be from anywhere, how can I know from which source should I fetch?

@kinoroy
Copy link
Member

kinoroy commented Apr 28, 2020

@andre-3-000 MessageKit as a library only aims to provide the outlets for you to do things like fetching data, etc (see the VISION.md). Otherwise we would be imposing/favouring specific implementations. It's not too difficult to fetch the meta data, in fact Apple provides an API for it on iOS 13+ and there are other libraries that exist on Github to do it on older iOS versions.

Copy link
Member

@Kaspik Kaspik 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, nice job! Few things:

  • I see you added sample data - perfect, can you post screenshot from example app how it looks in light + dark mode? (we should be testing both modes now)
  • Definitely needs some tests to be added - probably "ViewsTests"?
  • Please add info to the changelog as a breaking change (there should be one already, just add it to it)

@Kaspik Kaspik added this to the 4.0.0 milestone May 1, 2020
@bguidolim
Copy link
Contributor Author

@Kaspik Here is a screenshot in dark mode.

Simulator Screen Shot - iPhone 11 Pro - 2020-05-10 at 12 42 22

@bguidolim
Copy link
Contributor Author

@Kaspik Just updated the PR with the changes requested. Please check if it's ok and let me know if you need anything else.

Copy link
Member

@Kaspik Kaspik left a comment

Choose a reason for hiding this comment

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

I would like to see also a view test that tests how the cell looks like (something like MessageCollectionViewCellTests.swift or update of this), otherwise looks good, thanks for doing this!

@codecov
Copy link

codecov bot commented May 14, 2020

Codecov Report

Merging #1310 into development will increase coverage by 1.59%.
The diff coverage is 91.42%.

Impacted file tree graph

@@               Coverage Diff               @@
##           development    #1310      +/-   ##
===============================================
+ Coverage        64.75%   66.34%   +1.59%     
===============================================
  Files               68       72       +4     
  Lines             3305     3515     +210     
===============================================
+ Hits              2140     2332     +192     
- Misses            1165     1183      +18     
Impacted Files Coverage Δ
Sources/Views/Cells/LinkPreviewMessageCell.swift 73.07% <73.07%> (ø)
Sources/Protocols/LinkItem.swift 88.88% <88.88%> (ø)
Sources/Views/LinkPreviewView.swift 97.14% <97.14%> (ø)
...rces/Layout/LinkPreviewMessageSizeCalculator.swift 97.87% <97.87%> (ø)
Sources/Controllers/MessagesViewController.swift 54.67% <100.00%> (+0.91%) ⬆️
...rces/Layout/MessagesCollectionViewFlowLayout.swift 43.35% <100.00%> (+0.80%) ⬆️
...ayout/MessagesCollectionViewLayoutAttributes.swift 98.52% <100.00%> (+0.11%) ⬆️
Sources/Protocols/MessagesDisplayDelegate.swift 83.67% <100.00%> (+0.34%) ⬆️
Sources/Views/MessagesCollectionView.swift 42.39% <100.00%> (+0.63%) ⬆️
.../ControllersTest/MessagesViewControllerTests.swift 96.85% <100.00%> (+0.48%) ⬆️
... and 5 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 81395b6...02b03f3. Read the comment docs.

@kinoroy kinoroy linked an issue May 15, 2020 that may be closed by this pull request
@fukemy
Copy link

fukemy commented Jun 5, 2020

hello, that's all what i want to do, please guild me how to get this update. thanks

@kinoroy
Copy link
Member

kinoroy commented Jun 30, 2020

@Kaspik Can we merge this into dev now since we're targeting 4.0 as the next release?

@Kaspik
Copy link
Member

Kaspik commented Jun 30, 2020

I think so. :)

@Kaspik Kaspik merged commit bf97b5b into MessageKit:development Jun 30, 2020
@bguidolim bguidolim deleted the link-preview-support branch June 30, 2020 18:27
@fukemy
Copy link

fukemy commented Jul 1, 2020

nice, hope it's merged soon 👍

@Kaspik Kaspik mentioned this pull request Aug 26, 2020
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.

Add MessageCollectionView with link preview ability
6 participants