Skip to content
This repository has been archived by the owner on Aug 18, 2023. It is now read-only.

FEATURE - Highlight Hashtags #82

Closed
mikaelacaron opened this issue Oct 15, 2021 · 8 comments
Closed

FEATURE - Highlight Hashtags #82

mikaelacaron opened this issue Oct 15, 2021 · 8 comments
Assignees
Labels
feature New feature or request hacktoberfest Issues valid for Hacktoberfest participation

Comments

@mikaelacaron
Copy link
Owner

mikaelacaron commented Oct 15, 2021

Describe the solution you'd like

  • Highlight the hashtag like Twitter

Additional context
No need to have a hyperlink to the hashtag on Twitter, this is only to help highlight hashtags vs all the other words in a tweet
Screen Shot 2021-10-15 at 4 43 16 PM
.

@mikaelacaron mikaelacaron added feature New feature or request hacktoberfest Issues valid for Hacktoberfest participation labels Oct 15, 2021
@IgorChernyshov
Copy link

Hi Mikaela, could you please assign this one to me? I'd like work on it.

@Mcrich23
Copy link

Can I work on this?

@Mcrich23
Copy link

So I got it working with this code:

struct TweetBodyView: View {
    @State var tweetBody: String
    var body: some View {
        hilightedText(str: tweetBody, searched: "#")
            .multilineTextAlignment(.leading)
            .font(.body)
            .lineSpacing(8.0)
            .padding(EdgeInsets(top: 0, leading: 18, bottom: 18, trailing: 18))
            .fixedSize(horizontal: false, vertical: true)
    }
    
    func hilightedText(str: String, searched: String) -> Text {
        guard !str.isEmpty && !searched.isEmpty else { return Text(str) }
        
        var result: Text!
        let parts = str.components(separatedBy: searched)
        for i in parts.indices {
            result = (result == nil ? Text(parts[i]) : result + Text(parts[i]))
            if i != parts.count - 1 {
                let range = str.replacingOccurrences(of: "\n", with: " ").components(separatedBy: " ").filter({ stri in
                    stri.contains(searched)
                })
                print("preresult = \(result), range = \(range)")
                print("tex = \(range[i])")
                result = result + Text(range[i])
                    .bold()
                    .foregroundColor(.blue)
            }
        }
        return result ?? Text(str)
    }
}

However, then all the hashtags are duplicated. Any ideas?

@mikaelacaron
Copy link
Owner Author

Have you pushed this to your current branch? I can take a look.
Also be sure to use useful names, not stri, str, or tex

Mcrich23 added a commit to Mcrich23/brain-marks that referenced this issue Apr 2, 2022
@mikaelacaron mikaelacaron changed the title Highlight Hashtags FEATURE - Highlight Hashtags Oct 1, 2022
@MarshallARoss
Copy link
Contributor

I'd like to take a crack at this one please 😄

@MarshallARoss
Copy link
Contributor

Submitted the pull request for this ✅

@MarshallARoss
Copy link
Contributor

@mikaelacaron Please help. I've been trying to squash for 3 hours and it's not working. I've read your linked guide, YouTubed, stack overflowed, Googled. I'm literally at my wits end and I don't want to mess anything up.

@mikaelacaron
Copy link
Owner Author

DM me on Insta or Twitter, links here, and we can coordinate a time to pair

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature New feature or request hacktoberfest Issues valid for Hacktoberfest participation
Projects
None yet
Development

No branches or pull requests

4 participants