linkedin / Hakawai

A powerful, extensible UITextView.
Apache License 2.0
782 stars 104 forks source link

Editing Mention after setting text to textview programmatically #86

Open AnkitGabani opened 5 years ago

AnkitGabani commented 5 years ago

Hello Dear, Mentions works nice in the Create mode.

Now on Edit screen. I am preloading textView with text that contains mentions. But Hakawai textView does not highlight those mentions which are set programatically as textView.text = "Hi XYZMention".

If I add new mention it highlights the new mention, when I call plugin.mentions() method it only returns the mentions that are newly created (typed by user) not the one that were already present in the text when textview is initialized.

I have also tried creating HKWMentionsAttribute for mentions that previously there in text and added it to plugin but still not working.

Here is my code

if let mentions = objPost?.mentions { for mention in mentions { let mentionAttrib = HKWMentionsAttribute() mentionAttrib.entityIdentifier = String(mention.id!)

      let str = messageString

      let range = (mention.start! - 1)..<(mention.start! + mention.length! - 1)

      let mySubstring = str[range]
      mentionAttrib.mentionText = mySubstring
      mentionAttrib.entityIdentifier = String(mention.id!)
      mentionAttrib.metadata = ["id": mention.id!, "type": 1, "length": mention.length!]
      mentionAttrib.range = NSMakeRange(mention.start! - 1, mention.length!)

      plugin!.addMention(mentionAttrib)
    }
  }

   plugin?.textViewDidProgrammaticallyUpdate(txtPost)

Please provide solution

dgattey commented 5 years ago

There may be other information on the attribute that you're not setting, I'm not entirely familiar. We'll look into this.

abbasnaqvi200 commented 5 years ago

I am facing the same issue. Can anyone help me out to fix it. // hashtags is array of dictionary having details of mentions @time of creation for item in hashtags{ let tempDic = item as? NSDictionary ?? [:] let location = Int(tempDic["Tag_Position"] as? String ?? "0") ?? 0 let length = Int(tempDic["Tag_Length"] as? String ?? "") ?? 0 let tagName = tempDic["Keyword_Tags"] as? String ?? "" let tagID = tempDic["Tag_ID"] as? String ?? "" let mentionAttrib = HKWMentionsAttribute() mentionAttrib.mentionText = tagName mentionAttrib.entityIdentifier = tagID mentionAttrib.metadata = ["id": tagID, "type": 1, "length": length] mentionAttrib.range = NSMakeRange(location, length) plugin?.addMention(mentionAttrib) }

haihoang88 commented 4 years ago

Does anyone have update on this?

perrygarg commented 2 years ago

Hi @cyuan1124 Any update on this? This is crucial.

cyuan1124 commented 2 years ago

Hi @cyuan1124 Any update on this? This is crucial.

Hi @perrygarg , I am not an owner of Hakawaii. The last commit I submitted was for a feature required by my team. You can reach out to @bkoatz for help.