Closed eemi2010 closed 2 years ago
Hello @eemi2010, Nice question!
I just wrote a simple test project for this by creating a new TextView on top of AXEmojiTextView
called AXrLottieTextView
And another class called AXrLottieEmoji
(like AXPresetEmoji
, It will create AXrLottieDrawable
).
At the end AXrLottieEmojiManager
maps all of your AXrLottieEmoji
instances which AXEmojiTextView
can show.
This is the output:
Initializing (Application):
AXrLottie.init(this);
ArrayList<AXrLottieEmoji> emojis = new ArrayList<>();
emojis.add(new AXrLottieEmoji("\uD83D\uD83E\uD83F", "a.json"));
emojis.add(new AXrLottieEmoji("\uD83D\uD83E\uD84F", "b.json"));
AXrLottieEmojiManager.install(emojis);
AXEmojiManager.install(this, new AXAppleEmojiProvider(this));
And set the text (Activity)
AXrLottieTextView tv = findViewById(R.id.tv);
tv.setText("Hell😍 World \uD83D\uD83E\uD83F\uD83D\uD83E\uD84F");
The unicodes I set for LottieEmojis are just for testing and don't mean anything!
This is dope !!!!!. Let me try and come back to you. Hopefully this can actually make it to the library. Would be terrific. Thanks a lot for you quick answer.
This is working great on AXEmojiTextView. Please can you provide an example with AXEmojiEditText. I tried to to the same as with AXEmojiTextView but on the onTextChanged method. But the emojis and not appearing. Can you please point me in the right direction.
Thanks a lot.
Hello @eemi2010,
You are right, i just checked it and after an hour finally i bypassed it!
This is the output:
This is the source-code: AXrLottieEmoji-v2.zip
Explanation:
As you know, EditText extends TextView. But When you make a TextView Editable (instantiate android.widget.Editor
which is hide in SDK), The Editor draws and caches the text rendering. So calling invalidate()
doesn't redraw the text.
But there is another method in Editor
called invalidateTextDisplayList()
. Unfortunately you don't have access to that, Not even with reflection! (btw, reflection isn't a good choice here at all)
Some methods such as setTextColor(int)
, setEnabled(boolean)
and setShadowLayer(float, float, float, int)
will call invalidateTextDisplayList()
because of the changes in the editor.
But almost all methods have an internal if-condition to invalidate only if the state has changed!
As far as I checked, setShadowLayer() is the only one that calls invalidateTextDisplayList()
without checking any condition.
So here's the trick, instead of postInvalidate()
, I call setShadowLayer()
with the stored values and it does exactly what I want :)
Good Luck!
Having a look. Will give you feedback in a few. Thanks man. You rock.
This is working great for our needs. Thanks a million for your help. Like you can suspect we are trying to mimic the latest Telegram update and I think we got it to work.
Would be awesome if this could make it to the next version of the library.
I'm glad it helped. 🙂
This sample is more related to AXrLottie than AXEmojiView. It works like a bridge between these two libraries, so I don't have plan to add it to the library for now, but you can easily add and use these few simple classes to your project and customize it however you want. Like loading lottie files from a link.
Hello there,
Thanks for your great work. This lib rocks. Is it possible to extend the lib to support AXrLottieDrawable? Idea is to render animated stickers within the text. For what I could see AXPresetEmojiReplacer does the work by transforming emoji into their corresponding drawables. How could one extend the method to also generate a AXrLottieDrawable?
Thanks a lot