Skip to content

Commit

Permalink
fix: 🐛 .lottie file load failure with float speed property (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
theashraf authored May 20, 2024
1 parent be8895e commit cf22e35
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 76 deletions.
2 changes: 1 addition & 1 deletion dotlottie-ffi/src/dotlottie_player.udl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ dictionary ManifestAnimation {
boolean? loop;
u32? loop_count;
string? playMode;
u32? speed;
f32? speed;
string? themeColor;
};

Expand Down
2 changes: 1 addition & 1 deletion dotlottie-ffi/src/dotlottie_player_cpp.udl
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ dictionary Config {
/// boolean? loop;
/// u32? loop_count;
/// string? playMode;
/// u32? speed;
/// f32? speed;
/// string? themeColor;
///};

Expand Down
8 changes: 4 additions & 4 deletions dotlottie-fms/src/manifest_animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct ManifestAnimation {
pub r#loop: Option<bool>,
pub loop_count: Option<u32>,
pub playMode: Option<String>,
pub speed: Option<u32>,
pub speed: Option<f32>,
pub themeColor: Option<String>,
}

Expand All @@ -30,7 +30,7 @@ impl ManifestAnimation {
r#loop: Option<bool>,
loop_count: Option<u32>,
playMode: Option<String>,
speed: Option<u32>,
speed: Option<f32>,
themeColor: Option<String>,
) -> Self {
Self {
Expand Down Expand Up @@ -71,7 +71,7 @@ impl ManifestAnimation {
} else {
playMode
},
speed: if speed.is_none() { Some(1) } else { speed },
speed: if speed.is_none() { Some(1.0) } else { speed },
themeColor: if themeColor.is_none() {
Some("".to_string())
} else {
Expand All @@ -91,7 +91,7 @@ impl ManifestAnimation {
r#loop: Some(false),
loop_count: Some(0),
playMode: Some("normal".to_string()),
speed: Some(1),
speed: Some(1.0),
themeColor: Some("".to_string()),
}
}
Expand Down
133 changes: 65 additions & 68 deletions dotlottie-fms/src/tests/manifest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,35 +35,33 @@ fn display() {
None,
);

let animation_02 =
ManifestAnimation::new(
Some(false),
Some("red_theme".to_string()),
Some(-1),
None,
"animation_02".to_string(),
None,
Some(false),
Some(12),
Some("bounce".to_string()),
Some(2),
None,
);

let animation_03 =
ManifestAnimation::new(
Some(true),
Some("orange_theme".to_string()),
Some(1),
None,
"animation_02".to_string(),
None,
Some(true),
Some(12),
None,
None,
None,
);
let animation_02 = ManifestAnimation::new(
Some(false),
Some("red_theme".to_string()),
Some(-1),
None,
"animation_02".to_string(),
None,
Some(false),
Some(12),
Some("bounce".to_string()),
Some(2.0),
None,
);

let animation_03 = ManifestAnimation::new(
Some(true),
Some("orange_theme".to_string()),
Some(1),
None,
"animation_02".to_string(),
None,
Some(true),
Some(12),
None,
None,
None,
);

animations.push(animation_01);

Expand Down Expand Up @@ -95,7 +93,7 @@ fn display() {
"loop": true,
"loopCount": 0,
"playMode": "normal",
"speed": 1,
"speed": 1.0,
"themeColor": ""
}
],
Expand Down Expand Up @@ -134,44 +132,43 @@ fn display() {

let dis_02 = manifest_with_two_animations.to_json();

let dis_02_expected =
object! {
"activeAnimationId": "default_animation_id",
"animations": [
{
"autoplay": false,
"defaultTheme": "red_theme",
"direction": -1,
"hover": false,
"id": "animation_02",
"intermission": 0,
"loop": false,
"loopCount": 12,
"playMode": "bounce",
"speed": 2,
"themeColor": ""
},
{
"autoplay": true,
"defaultTheme": "orange_theme",
"direction": 1,
"hover": false,
"id": "animation_02",
"intermission": 0,
"loop": true,
"loopCount": 12,
"playMode": "Normal",
"speed": 1,
"themeColor": ""
}
],
"author": "test_author",
"description": "Multi animation",
"generator": "dotLottie-fms",
"keywords": "dotLottie",
"revision": 2,
"version": "1.0.0"
};
let dis_02_expected = object! {
"activeAnimationId": "default_animation_id",
"animations": [
{
"autoplay": false,
"defaultTheme": "red_theme",
"direction": -1,
"hover": false,
"id": "animation_02",
"intermission": 0,
"loop": false,
"loopCount": 12,
"playMode": "bounce",
"speed": 2.0,
"themeColor": ""
},
{
"autoplay": true,
"defaultTheme": "orange_theme",
"direction": 1,
"hover": false,
"id": "animation_02",
"intermission": 0,
"loop": true,
"loopCount": 12,
"playMode": "Normal",
"speed": 1.0,
"themeColor": ""
}
],
"author": "test_author",
"description": "Multi animation",
"generator": "dotLottie-fms",
"keywords": "dotLottie",
"revision": 2,
"version": "1.0.0"
};

assert_eq!(dis_02.dump(), dis_02_expected.dump());
}
4 changes: 2 additions & 2 deletions dotlottie-rs/src/dotlottie_player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ impl DotLottieRuntime {

match playback_settings_result {
Ok(playback_settings) => {
let speed = playback_settings.speed.unwrap_or(1);
let speed = playback_settings.speed.unwrap_or(1.0);
let loop_animation = playback_settings.r#loop.unwrap_or(false);
let direction = playback_settings.direction.unwrap_or(1);
let autoplay = playback_settings.autoplay.unwrap_or(false);
Expand All @@ -726,7 +726,7 @@ impl DotLottieRuntime {
_ => Mode::Forward,
};

self.config.speed = speed as f32;
self.config.speed = speed;
self.config.autoplay = autoplay;
self.config.mode = if play_mode == "normal" {
if direction == 1 {
Expand Down

0 comments on commit cf22e35

Please sign in to comment.