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

chore: 🤖 feature flag uniffi related types #268

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dotlottie-ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ path = "uniffi-bindgen.rs"

[dependencies]
uniffi = { version = "0.28", features = ["cli"] }
dotlottie-rs = { path = "../dotlottie-rs", features = ["thorvg"] }
dotlottie-rs = { path = "../dotlottie-rs", features = ["thorvg", "uniffi"] }
cfg-if = "1.0"
bitflags = "2.6.0"

Expand Down
2 changes: 1 addition & 1 deletion dotlottie-ffi/Cargo.wasm.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ path = "uniffi-bindgen.rs"

[dependencies]
uniffi = { version = "0.25", features = ["cli"] }
dotlottie-rs = { path = "../dotlottie-rs", features = ["thorvg"] }
dotlottie-rs = { path = "../dotlottie-rs", features = ["thorvg", "uniffi"] }
cfg-if = "1.0"
bitflags = "2.6.0"

Expand Down
3 changes: 2 additions & 1 deletion dotlottie-ffi/src/ffi/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{ffi::c_char, slice};

use dotlottie_rs::{Config, DotLottiePlayer, LayerBoundingBox};
use dotlottie_rs::dotlottie_player::{Config, LayerBoundingBox};
use dotlottie_rs::uniffi::DotLottiePlayer;
use types::*;

pub mod types;
Expand Down
25 changes: 15 additions & 10 deletions dotlottie-ffi/src/ffi/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ use std::ffi::{c_char, CStr, CString};
use std::io;
use std::sync::Arc;

use dotlottie_rs::{
Config, Event, Fit, Layout, Manifest, ManifestAnimation, ManifestStateMachine, ManifestTheme,
Marker, Mode,
};
use dotlottie_rs::dotlottie_player::{Config, Mode};
use dotlottie_rs::fms::*;
use dotlottie_rs::layout::*;
use dotlottie_rs::markers::*;
use dotlottie_rs::state_machine::events::Event;

// Function return codes
pub const DOTLOTTIE_SUCCESS: i32 = 0;
Expand Down Expand Up @@ -514,7 +515,7 @@ pub struct Observer {
pub on_complete_op: OnOp,
}

impl dotlottie_rs::Observer for Observer {
impl dotlottie_rs::dotlottie_player::Observer for Observer {
fn on_load(&self) {
unsafe { (self.on_load_op)() }
}
Expand Down Expand Up @@ -545,8 +546,10 @@ impl dotlottie_rs::Observer for Observer {
}

impl Observer {
pub unsafe fn as_observer(&mut self) -> Arc<dyn dotlottie_rs::Observer> {
Arc::from(Box::from_raw(self as *mut dyn dotlottie_rs::Observer))
pub unsafe fn as_observer(&mut self) -> Arc<dyn dotlottie_rs::dotlottie_player::Observer> {
Arc::from(Box::from_raw(
self as *mut dyn dotlottie_rs::dotlottie_player::Observer,
))
}
}

Expand All @@ -562,7 +565,7 @@ pub struct StateMachineObserver {
pub on_state_exit_op: OnStateExitOp,
}

impl dotlottie_rs::StateMachineObserver for StateMachineObserver {
impl dotlottie_rs::state_machine::StateMachineObserver for StateMachineObserver {
fn on_transition(&self, previous_state: String, new_state: String) {
if let (Ok(previous_state), Ok(new_state)) =
(CString::new(previous_state), CString::new(new_state))
Expand Down Expand Up @@ -596,9 +599,11 @@ impl dotlottie_rs::StateMachineObserver for StateMachineObserver {
}

impl StateMachineObserver {
pub unsafe fn as_observer(&mut self) -> Arc<dyn dotlottie_rs::StateMachineObserver> {
pub unsafe fn as_observer(
&mut self,
) -> Arc<dyn dotlottie_rs::state_machine::StateMachineObserver> {
Arc::from(Box::from_raw(
self as *mut dyn dotlottie_rs::StateMachineObserver,
self as *mut dyn dotlottie_rs::state_machine::StateMachineObserver,
))
}
}
7 changes: 4 additions & 3 deletions dotlottie-ffi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub use dotlottie_rs::*;
pub use dotlottie_rs::uniffi::prelude::*;

mod ffi;

Expand All @@ -13,9 +13,10 @@ pub fn create_default_config() -> Config {
cfg_if::cfg_if! {
if #[cfg(target_arch = "wasm32")] {
pub fn transform_theme_to_lottie_slots(theme_data: &str, animation_id: &str) -> String {
dotlottie_rs::transform_theme_to_lottie_slots(theme_data, animation_id).unwrap_or_default()
theming::transform_theme_to_lottie_slots(theme_data, animation_id)
.unwrap_or_default()
}

uniffi::include_scaffolding!("dotlottie_player_cpp");
} else {
uniffi::include_scaffolding!("dotlottie_player");
Expand Down
1 change: 1 addition & 0 deletions dotlottie-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ links = "thorvg"
crate-type = ["staticlib", "cdylib", "rlib"]

[features]
uniffi = []
thorvg = []

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
Loading
Loading