Skip to content

Commit e6479ee

Browse files
authored
fix style schedule (#965)
1 parent b7aa52c commit e6479ee

3 files changed

Lines changed: 38 additions & 11 deletions

File tree

src/context.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -669,14 +669,23 @@ impl<'a> StyleCx<'a> {
669669

670670
let view_interact_state = self.get_interact_state(&view_id);
671671
self.disabled = view_interact_state.is_disabled;
672-
let mut new_frame = view_id.state().borrow_mut().compute_combined(
672+
let (mut new_frame, classes_applied) = view_id.state().borrow_mut().compute_combined(
673673
view_style,
674674
view_interact_state,
675675
self.window_state.screen_size_bp,
676676
view_class,
677677
&self.current,
678678
self.hidden,
679679
);
680+
if classes_applied {
681+
let children = view_id.children();
682+
for child in children {
683+
let view_state = child.state();
684+
let mut state = view_state.borrow_mut();
685+
state.request_style_recursive = true;
686+
state.requested_changes.insert(ChangeFlags::STYLE);
687+
}
688+
}
680689

681690
self.direct = view_state.borrow().combined_style.clone();
682691
Style::apply_only_inherited(&mut self.current, &self.direct);
@@ -708,6 +717,10 @@ impl<'a> StyleCx<'a> {
708717
&self.now,
709718
&mut new_frame,
710719
);
720+
if new_frame {
721+
// if any transitioning layout props, shedule layout
722+
self.window_state.schedule_layout(view_id);
723+
}
711724

712725
view_state.view_style_props.read_explicit(
713726
&self.direct,
@@ -724,7 +737,7 @@ impl<'a> StyleCx<'a> {
724737
let taffy_style = self.direct.clone().apply(layout_style).to_taffy_style();
725738
if taffy_style != view_state.borrow().taffy_style {
726739
view_state.borrow_mut().taffy_style = taffy_style;
727-
view_id.request_layout();
740+
self.window_state.schedule_layout(view_id);
728741
}
729742

730743
view.borrow_mut().style_pass(self);
@@ -961,6 +974,9 @@ impl<'a> ComputeLayoutCx<'a> {
961974
layout_rect
962975
};
963976

977+
let transform = view_state.borrow().transform;
978+
let layout_rect = transform.transform_rect_bbox(layout_rect);
979+
964980
view_state.borrow_mut().layout_rect = layout_rect;
965981

966982
self.restore();

src/style.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2011,13 +2011,14 @@ pub(crate) fn screen_size_bp_to_key(breakpoint: ScreenSizeBp) -> StyleKey {
20112011
}
20122012
}
20132013

2014+
/// the bool in the return is a classes_applied flag. if a new class has been applied, we need to do a request_style_recursive
20142015
pub(crate) fn resolve_nested_maps(
20152016
style: Style,
20162017
interact_state: &InteractionState,
20172018
screen_size_bp: ScreenSizeBp,
20182019
classes: &[StyleClassRef],
20192020
context: &mut Style,
2020-
) -> Style {
2021+
) -> (Style, bool) {
20212022
// Start with depth 0 for the initial call
20222023
resolve_nested_maps_internal(style, interact_state, screen_size_bp, context, classes, 0)
20232024
}
@@ -2029,13 +2030,14 @@ fn resolve_nested_maps_internal(
20292030
context: &mut Style,
20302031
classes: &[StyleClassRef],
20312032
depth: u32,
2032-
) -> Style {
2033+
) -> (Style, bool) {
20332034
const MAX_DEPTH: u32 = 6;
20342035
if depth >= MAX_DEPTH {
2035-
return style;
2036+
return (style, false);
20362037
}
20372038

20382039
let mut changed = false;
2040+
let mut classes_applied = false;
20392041

20402042
let old_style = style.clone();
20412043
style = style.apply_classes_from_context(classes, context);
@@ -2044,6 +2046,7 @@ fn resolve_nested_maps_internal(
20442046
context.remove_nested_map(class.key);
20452047
}
20462048
changed = true;
2049+
classes_applied = true;
20472050
}
20482051

20492052
// Apply context mappings first
@@ -2153,17 +2156,19 @@ fn resolve_nested_maps_internal(
21532156

21542157
// Recurse once at the end if anything changed
21552158
if changed && depth + 1 < MAX_DEPTH {
2156-
style = resolve_nested_maps_internal(
2159+
let (new_style, recursive_classes_applied) = resolve_nested_maps_internal(
21572160
style,
21582161
interact_state,
21592162
screen_size_bp,
21602163
context,
21612164
classes,
21622165
depth + 1,
21632166
);
2167+
style = new_style;
2168+
classes_applied |= recursive_classes_applied;
21642169
}
21652170

2166-
style
2171+
(style, classes_applied)
21672172
}
21682173

21692174
#[derive(Default, Clone)]

src/view_state.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ impl ViewState {
236236
}
237237
}
238238

239+
/// the first returned bool is new_frame. the second is classes_applied
239240
/// Returns `true` if a new frame is requested.
240241
///
241242
// The context has the nested maps of classes and inherited properties
@@ -248,7 +249,7 @@ impl ViewState {
248249
view_class: Option<StyleClassRef>,
249250
context: &Style,
250251
cx_hidden: bool,
251-
) -> bool {
252+
) -> (bool, bool) {
252253
let mut new_frame = false;
253254

254255
// Build the initial combined style
@@ -266,14 +267,17 @@ impl ViewState {
266267
}
267268

268269
let mut new_context = context.clone();
270+
let mut new_classes = false;
269271

270-
combined_style = resolve_nested_maps(
272+
let (resolved_style, classes_applied) = resolve_nested_maps(
271273
combined_style,
272274
&interact_state,
273275
screen_size_bp,
274276
&classes,
275277
&mut new_context,
276278
);
279+
combined_style = resolved_style;
280+
new_classes |= classes_applied;
277281

278282
if let Some(view_style) = &view_style {
279283
combined_style.apply_mut(view_style.clone());
@@ -283,13 +287,15 @@ impl ViewState {
283287

284288
combined_style.apply_mut(self_style.clone());
285289

286-
combined_style = resolve_nested_maps(
290+
let (resolved_style, classes_applied) = resolve_nested_maps(
287291
combined_style,
288292
&interact_state,
289293
screen_size_bp,
290294
&classes,
291295
&mut new_context,
292296
);
297+
combined_style = resolved_style;
298+
new_classes |= classes_applied;
293299

294300
// Track if this style has selectors for optimization purposes
295301
self.has_style_selectors = combined_style.selectors();
@@ -317,7 +323,7 @@ impl ViewState {
317323
}
318324

319325
self.combined_style = combined_style;
320-
new_frame
326+
(new_frame, new_classes)
321327
}
322328

323329
pub(crate) fn has_active_animation(&self) -> bool {

0 commit comments

Comments
 (0)