Skip to content

Commit e01ae73

Browse files
author
mayintao3
committed
feat: 把fill mode解析成string
1 parent a9f56f6 commit e01ae73

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

__test__/fixure/pesudo.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.styletest {
2-
width: 5px;
2+
33
animation: name 1s linear 2s infinite forwards;
44
}
55

src/style_propetries/animation.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use std::{cell::RefCell, collections::HashMap, rc::Rc};
44

5-
use lightningcss::{printer::PrinterOptions, properties::{animation, Property}, traits::ToCss, values::{easing::EasingFunction, time}};
5+
use lightningcss::{printer::PrinterOptions, properties::{animation::{self, AnimationFillMode}, Property}, traits::ToCss, values::{easing::EasingFunction, time}};
66

77
use crate::{generate_expr_lit_num, generate_expr_enum, generate_expr_lit_str, style_parser::KeyFrameItem, style_propetries::style_property_enum, visitor::parse_style_values};
88
use swc_core::{common::DUMMY_SP, ecma::ast::*};
@@ -22,7 +22,7 @@ pub struct Animation {
2222
pub animation_duration: Option<f32>,
2323
pub animation_delay: Option<f32>,
2424
pub animation_iteration: Option<f32>,
25-
pub animation_fill_mode: Option<style_property_enum::ArkUI_AnimationFillMode>,
25+
pub animation_fill_mode: Option<AnimationFillMode>,
2626
pub animation_timeing_function: Option<AnimationTimingFunction>
2727
}
2828

@@ -33,7 +33,7 @@ impl From<(String, &Property<'_>, Option<Rc<RefCell<HashMap<String, Vec<KeyFrame
3333
let mut animation_duration = None; // 0.0
3434
let mut animation_delay = None; // 0.0
3535
let mut animation_iteration = None; // 1.0
36-
let mut animation_fill_mode = None;
36+
let mut animation_fill_mode: Option<AnimationFillMode> = None;
3737
let mut animation_timeing_function: Option<AnimationTimingFunction> = None; // EasingFunction::Ease
3838

3939
match value.1 {
@@ -61,12 +61,13 @@ impl From<(String, &Property<'_>, Option<Rc<RefCell<HashMap<String, Vec<KeyFrame
6161
animation::AnimationIterationCount::Infinite => -1.0,
6262
});
6363

64-
animation_fill_mode = Some(match animation.fill_mode {
65-
animation::AnimationFillMode::Forwards => style_property_enum::ArkUI_AnimationFillMode::ARKUI_ANIMATION_FILL_MODE_FORWARDS,
66-
animation::AnimationFillMode::Backwards => style_property_enum::ArkUI_AnimationFillMode::ARKUI_ANIMATION_FILL_MODE_BACKWARDS,
67-
animation::AnimationFillMode::Both => style_property_enum::ArkUI_AnimationFillMode::ARKUI_ANIMATION_FILL_MODE_BOTH,
68-
animation::AnimationFillMode::None => style_property_enum::ArkUI_AnimationFillMode::ARKUI_ANIMATION_FILL_MODE_NONE,
69-
});
64+
// animation_fill_mode = Some(match animation.fill_mode {
65+
// animation::AnimationFillMode::Forwards => style_property_enum::ArkUI_AnimationFillMode::ARKUI_ANIMATION_FILL_MODE_FORWARDS,
66+
// animation::AnimationFillMode::Backwards => style_property_enum::ArkUI_AnimationFillMode::ARKUI_ANIMATION_FILL_MODE_BACKWARDS,
67+
// animation::AnimationFillMode::Both => style_property_enum::ArkUI_AnimationFillMode::ARKUI_ANIMATION_FILL_MODE_BOTH,
68+
// animation::AnimationFillMode::None => style_property_enum::ArkUI_AnimationFillMode::ARKUI_ANIMATION_FILL_MODE_NONE,
69+
// });
70+
animation_fill_mode = Some(animation.fill_mode.clone());
7071

7172
animation_timeing_function = Some(match animation.timing_function {
7273
// EasingFunction::Linear => AnimationTimingFunction::AnimationCurve(style_property_enum::ArkUI_AnimationCurve::ARKUI_CURVE_LINEAR),
@@ -143,7 +144,8 @@ impl ToExpr for Animation {
143144
exprs.push((CSSPropertyType::AnimationDuration, generate_expr_lit_num!((duration * 1000.0) as f64)))
144145
}
145146
if let Some(fill_mode) = &self.animation_fill_mode {
146-
exprs.push((CSSPropertyType::AnimationFillMode, generate_expr_enum!(*fill_mode)));
147+
// exprs.push((CSSPropertyType::AnimationFillMode, generate_expr_enum!(*fill_mode)));
148+
exprs.push((CSSPropertyType::AnimationFillMode, generate_expr_lit_str!(fill_mode.to_css_string(PrinterOptions::default()).unwrap())));
147149
}
148150
if let Some(timeing_function) = &self.animation_timeing_function {
149151
match timeing_function {

0 commit comments

Comments
 (0)