Skip to content

[DetectorType][MessageLabel] Add custom, mention and hashtag detector type 👻#913

Merged
nathantannar4 merged 9 commits into
MessageKit:3.0.0-betafrom
JulienKode:CustomDetectorType
Mar 25, 2019
Merged

[DetectorType][MessageLabel] Add custom, mention and hashtag detector type 👻#913
nathantannar4 merged 9 commits into
MessageKit:3.0.0-betafrom
JulienKode:CustomDetectorType

Conversation

@JulienKode

@JulienKode JulienKode commented Oct 16, 2018

Copy link
Copy Markdown
Contributor

Adding other DetectorTypes such as:

  • .mention
  • .hashtag
  • .custom(regex: NSRegularExpression)

Others elements of the enum are made with NSDataDetector which inherit from NSRegularExpression

Theses three new element use only NSRegularExpression

We can discuss of the API or changes to make here

@JulienKode JulienKode changed the title [DetectorType][MessageLabel] Add custom detector type [DetectorType][MessageLabel] Add custom, mention and hashtag detector type Oct 16, 2018

@nathantannar4 nathantannar4 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We need some ample test cases to ensure the regex matches all cases for hashtag and mention

Comment thread Sources/Models/DetectorType.swift Outdated
@nathantannar4 nathantannar4 changed the base branch from master to development October 16, 2018 21:35
@nathantannar4

Copy link
Copy Markdown
Member

Please make sure your branch, JulienKode:CustomDetectorType is up to date with the latest development branch

Comment thread Sources/Models/DetectorType.swift Outdated
@SD10

SD10 commented Oct 16, 2018

Copy link
Copy Markdown
Member

This looks promising ❤️ Thanks for working on this @JulienKode 🥇 💯

@JulienKode JulienKode changed the title [DetectorType][MessageLabel] Add custom, mention and hashtag detector type [DetectorType][MessageLabel] Add custom, mention and hashtag detector type 👻 Oct 17, 2018
@JulienKode

Copy link
Copy Markdown
Contributor Author

@nathantannar4 Thanks it's now sync with the development branch

@SD10 I've change it into a var

There now the testing to do I've see that there are already test for DetectorType in MessageLabelSpec but they're all commented. Anyone know the reason ?

If I uncomment theses tests they do not pass but they are right.
If any body know a limitation about that I'm interested
I'll try to fix that soon

Comment thread CHANGELOG.md

@talanov talanov left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Could you, please, squash commits into 1?

@JulienKode

Copy link
Copy Markdown
Contributor Author

@talanov for sure

Comment thread Sources/Models/DetectorType.swift Outdated
Comment thread CHANGELOG.md
Comment thread Sources/Models/DetectorType.swift Outdated
Comment thread Sources/Views/MessageLabel.swift Outdated
Comment thread Sources/Views/MessageLabel.swift
Comment thread Sources/Views/MessageLabel.swift
Comment thread Sources/Views/MessageLabel.swift Outdated
Comment thread Sources/Views/MessageLabel.swift Outdated
Comment thread Sources/Views/MessageLabel.swift Outdated
Comment thread Sources/Views/MessageLabel.swift Outdated
Comment thread Sources/Views/MessageLabel.swift Outdated
@nathantannar4

Copy link
Copy Markdown
Member

Very close! I'd like to see the Example updated so people can see these detectors in action 😊

…n pattern

[DetectorType] Put mention and hashtag as var

[CHANGELOG] Update

[DetectorType] Update to have at least 4 characters and more

[CHANGELOG] Update

[DetectorType]

[MessageLabel] run NSDataDetector once

[MessageLabel] Run NSDataDetector once

[Testing] Add testing and pass rangesOfDetectors as internal

[Refactoring]

[Filter] only .custom

[Examples]
@JulienKode

Copy link
Copy Markdown
Contributor Author

@nathantannar4 I’ve added examples

Sent with GitHawk

@sonnyio

sonnyio commented Oct 31, 2018

Copy link
Copy Markdown

Hey guys, in MessageLabel.swift, it's calling handleHashtag when it should be calling handleMention. Looking forward to this commit being pulled in!

handleHashtag(match)

@JulienKode

JulienKode commented Oct 31, 2018

Copy link
Copy Markdown
Contributor Author

@strujillojr Thanks, It's fixed now

@nathantannar4 nathantannar4 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@JulienKode can you please add the delegate methods in the Example so users know they exist?

func didSelectHashtag(_ hashtag: String) {
        print("Hashtag selected: \(hashtag)")
    }

    func didSelectMention(_ mention: String) {
        print("Mention selected: \(mention)")
    }

    func didSelectCustom(_ pattern: String, match: String?) {
        print("Custom data detector patter selected")
    }

@nathantannar4

Copy link
Copy Markdown
Member

After example changes it LGTM 💯 @SD10 Should we include this in 2.0.0?

@JulienKode

JulienKode commented Nov 1, 2018

Copy link
Copy Markdown
Contributor Author

@nathantannar4 I've update the branch to the latest development branch and updated the examples

@SD10 SD10 modified the milestones: 2.1, 3.0 Nov 2, 2018
@SD10

SD10 commented Nov 2, 2018

Copy link
Copy Markdown
Member

This can't be in 2.0 because we already did a beta. You can't have anything other than bugfixes in a beta or it defeats the purpose of the beta lol. This is an API breaking change so I changed it to be part of the 3.0 milestone.


case Hashtag = 8
case Mention = 9
case Custom = 10

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's make all these cases lowercased, it is not very Swifty 😆 If you could take care of all of them 💯

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That’s true, It’s not really swift, may I changes all of them in this PR or create another one ? To change others

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It can all be done in this PR 👍

Comment thread Sources/Views/MessageLabel.swift Outdated
let detector = try? NSDataDetector(types: checkingTypes)
let range = NSRange(location: 0, length: text.length)
let matches = detector?.matches(in: text.string, options: [], range: range) ?? []
var matches = [NSTextCheckingResult]()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: fix this double space please

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've did it, thanks

Comment thread Sources/Views/MessageLabel.swift
Comment thread Sources/Models/DetectorType.swift
Comment thread Sources/Models/DetectorType.swift Outdated
Comment thread Sources/Views/MessageLabel.swift
@JulienKode

Copy link
Copy Markdown
Contributor Author

@SD10 @nathantannar4

I've made some benchmarks here is the results

Here is the configuration of the first test:

img_6597
withoutpr

Here is the configuration of the second test
img_6598
withpr

What do you think ?

@nathantannar4

Copy link
Copy Markdown
Member

What are the graphs showing? FPS? CPU %?

Sent with GitHawk

@JulienKode

Copy link
Copy Markdown
Contributor Author

@nathantannar4 FPS in purple
and upper it's the CPU

@SD10

SD10 commented Nov 28, 2018

Copy link
Copy Markdown
Member

@JulienKode It does look like adding those code has some major spikes in the CPU 😞

@nathantannar4

Copy link
Copy Markdown
Member

It is optional, personally in my apps I wouldn't use this, I would use attributed strings. But this is a nice to have feature for ease of use

Sent with GitHawk

@JulienKode

JulienKode commented Nov 28, 2018

Copy link
Copy Markdown
Contributor Author

Ok, I understand, but It’s only in the worst case, if you just handle hashtag the perf is the same

I know it's a sensitive part of the library

If you have any idea of change to improve the performance. I want to know it

Sent with GitHawk

@nathantannar4 nathantannar4 changed the base branch from development to 3.0.0-beta March 1, 2019 03:19
@nathantannar4

Copy link
Copy Markdown
Member

Going to merge this into the 3.0.0-beta branch. While it does come at a performance hit I am going to leave it to the end user to decide if they want this since without using the new detectors there is no difference.

@JulienKode

JulienKode commented Mar 11, 2019

Copy link
Copy Markdown
Contributor Author

@nathantannar4 ok it makes sense, if someone have an idea to improve the speed, we also can improve it

@nathantannar4 nathantannar4 merged commit a465437 into MessageKit:3.0.0-beta Mar 25, 2019
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.

7 participants