Closed raghunandankavi2010 closed 3 years ago
Set a custom MentionSpanFactory
on the MentionsEditText
. The factory allows you to completely control how the spans are created, so you can implement logic to instantiate your own type of clickable mention span to redirect your users as needed.
@nhibner thank you. Can you put some sample code here or point me to some code to refer to.
I already referred to code in my previous response -- set a custom MentionSpanFactory
on the MentionsEditText
(also can set it on the RichEditorView
if you're using that).
In code, here's a very rough example of what this could look like:
// somewhere in your code
editorView.setMentionSpanFactory(new MyMentionSpanFactory());
// factory to create our custom mention spans
public class MyMentionSpanFactory extends MentionsEditText.MentionSpanFactory {
@NonNull
@Override
public MentionSpan createMentionSpan(@NonNull Mentionable mention, @Nullable MentionSpanConfig config) {
return new NavigationMentionSpan(mention);
}
}
// custom mention span to navigate to a specific activity when clicked
public class NavigationMentionSpan extends MentionSpan {
public NavigationMentionSpan(@NonNull Mentionable mention) {
super(mention);
}
@Override
public void onClick(@NonNull View widget) {
super.onClick(widget);
// Navigate to some other screen
Intent navToActivityIntent = new Intent();
widget.getContext().startActivity(navToActivityIntent);
}
}
Thank you.
On Tue, Apr 13, 2021, 12:07 AM Nathan Hibner @.***> wrote:
I already referred to code in my previous response -- set a custom MentionSpanFactory on the MentionsEditText (also can set it on the RichEditorView if you're using that).
In code, here's a very rough example of what this could look like:
// somewhere in your code editorView.setMentionSpanFactory(new MyMentionSpanFactory()); // factory to create our custom mention spans public class MyMentionSpanFactory extends MentionsEditText.MentionSpanFactory { @NonNull @Override public MentionSpan createMentionSpan(@NonNull Mentionable mention, @Nullable MentionSpanConfig config) { return new NavigationMentionSpan(mention); } } // custom mention span to navigate to a specific activity when clicked public class NavigationMentionSpan extends MentionSpan { public NavigationMentionSpan(@NonNull Mentionable mention) { super(mention); } @Override public void onClick(@NonNull View widget) { super.onClick(widget); // Navigate to some other screen Intent navToActivityIntent = new Intent(); widget.getContext().startActivity(navToActivityIntent); } }
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/linkedin/Spyglass/issues/118#issuecomment-818038319, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABAFPKOE2YOTHP7A65H3V3DTIM4U5ANCNFSM42QEDDRQ .
Is there a callback when user clicks a particular span so that we can redirect user to particular screen?