LottieFiles / dotlottie-rs

A universal, high-performance Lottie and dotLottie player built with Rust. Offers smooth rendering across platforms, low resource consumption, and extensive compatibility. Features FFI bindings for C/C++, Kotlin, Swift, and WASM for seamless integration in Android, iOS, and Web projects.
https://developers.lottiefiles.com/docs/dotlottie-player/
MIT License
156 stars 9 forks source link

Add method to retrieve currently loaded theme by its ID in .lottie file #119

Closed theashraf closed 7 months ago

theashraf commented 7 months ago
let player = DotLottiePlayer::new(Config::default());

let loaded = player.load_dotlottie_animation(...);

assert!(loaded); // ✅ 

let target_theme_id = "dark_theme";
let theme_loaded = player.load_theme(target_theme_id);

assert!(theme_loaded); // ✅ 

let current_theme = player.current_theme(); // return Some(ThemeManifest) instance 

assert!(current_theme.unwrap().id == target_theme_id); // should pass 

player.load_theme(""); // unload a theme 

let current_theme = player.current_theme(); // return None

assert!(current_theme.is_none()); // shall pass 
jk-gan commented 7 months ago

I'm interested to contribute to the project, may I take this ticket?

theashraf commented 7 months ago

Thanks, @jk-gan, for your interest. Feel free to pick it up, and please let me know if you need any help or are facing any issues

jk-gan commented 7 months ago

@theashraf I'm now starting to look at this. May I get more details about this issue?

theashraf commented 7 months ago

@jk-gan

The dotlottie-rs crate includes a module named dotlottie_player.rs, which contains the DotLottieRuntime and DotLottiePlayer structs. We need to introduce a new method to both called active_theme_id that will return the ID of the currently loaded theme.

DotLottiePlayer is the thread-safe version of DotLottieRuntime.

How themes are loaded by their IDs in the player:

In the dotlottie-ffi crate, we need to update the .udl files to add an FFI (Foreign Function Interface) for the active_theme_id function that was added in the dotlottie_player.rs module. This will make the newly added function available to the Kotlin/Swift/C++ bindings.

You may refer to this document on UniFFI UDL syntax: https://mozilla.github.io/uniffi-rs/udl/interfaces.html.

Lastly, we need to update the emscripten_bindings.cpp module in the dotlottie-ffi crate to port it to WebAssembly (WASM).

You can use the demo-player crate for testing the newly added method, and also don't forget to update the tests.

This document will help you understand how our build system works: https://github.com/LottieFiles/dotlottie-rs/blob/main/BUILD_SYSTEM.md.

jk-gan commented 7 months ago

Thanks @theashraf. I tried to run the demo-player, but it panic because the CARGO_MANIFEST_DIR not present.

Screenshot 2024-04-08 at 9 42 11 PM

I've run make mac-setup and also make demo-player. Am trying to look at the cause of this.

theashraf commented 7 months ago

@jk-gan, we don't have a proper workspace setup yet, so you'll need to navigate to the demo-player directory by running cd demo-player before executing cargo run

jk-gan commented 7 months ago

May I know what should I expected when running the demo-player? because what I saw is just a blank window.

Screenshot 2024-04-09 at 9 38 17 PM
theashraf commented 7 months ago

@jk-gan, everything is functioning correctly now. If you press the p key, the animation will start playing 👍🏼

jk-gan commented 7 months ago

Ahhhh, I see. Ok, saw the animation now!