Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for AXrLottieDrawable possible ? #33

Closed
eemi2010 opened this issue Aug 17, 2022 · 7 comments
Closed

Support for AXrLottieDrawable possible ? #33

eemi2010 opened this issue Aug 17, 2022 · 7 comments

Comments

@eemi2010
Copy 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

@Aghajari
Copy link
Owner

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:

AXrLottieEmoji

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!

AXrLottieEmoji.zip

@Aghajari Aghajari pinned this issue Aug 17, 2022
@eemi2010
Copy link
Author

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.

@eemi2010
Copy link
Author

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.

@Aghajari
Copy link
Owner

Aghajari commented Aug 18, 2022

Hello @eemi2010,

You are right, i just checked it and after an hour finally i bypassed it!

This is the output:
AXrLottieEmojiEditText

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!

@eemi2010
Copy link
Author

Having a look. Will give you feedback in a few. Thanks man. You rock.

@eemi2010
Copy link
Author

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.

@Aghajari
Copy link
Owner

Aghajari commented Aug 18, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants