Skip to content
Merged
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
9 changes: 7 additions & 2 deletions packages/dioxus/src/use_auto_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ use crate::{ShallowRc, types::WhileElementsMountedFn};
pub fn use_auto_update() -> Memo<ShallowRc<WhileElementsMountedFn>> {
use_memo(|| {
let rc: Rc<WhileElementsMountedFn> = Rc::new(|reference, floating, update| {
auto_update(reference, floating, update, AutoUpdateOptions::default())
auto_update(
reference,
Some(floating),
update,
AutoUpdateOptions::default(),
)
});

rc.into()
Expand All @@ -28,7 +33,7 @@ pub fn use_auto_update_with_options(
let options = options();

let rc: Rc<WhileElementsMountedFn> = Rc::new(move |reference, floating, update| {
auto_update(reference, floating, update, options.clone())
auto_update(reference, Some(floating), update, options.clone())
});

rc.into()
Expand Down
32 changes: 19 additions & 13 deletions packages/dom/src/auto_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ impl AutoUpdateOptions {
/// Should only be called when the floating element is mounted on the DOM or visible on the screen.
pub fn auto_update(
reference: ElementOrVirtual,
floating: &Element,
floating: Option<&Element>,
update: Rc<dyn Fn()>,
options: AutoUpdateOptions,
) -> Box<dyn Fn()> {
Expand All @@ -278,7 +278,9 @@ pub fn auto_update(
ancestors = get_overflow_ancestors(reference, ancestors, true);
}

ancestors.append(&mut get_overflow_ancestors(floating, vec![], true));
if let Some(floating) = floating {
ancestors.append(&mut get_overflow_ancestors(floating, vec![], true));
}

ancestors
} else {
Expand Down Expand Up @@ -327,16 +329,18 @@ pub fn auto_update(
let resize_observer: Rc<RefCell<Option<ResizeObserver>>> = Rc::new(RefCell::new(None));

if element_resize {
let reobserve_floating = floating.clone();
let reobserve_closure: Rc<Closure<dyn FnMut()>> = Rc::new(Closure::new({
let floating = floating.cloned();
let resize_observer = resize_observer.clone();

move || {
resize_observer
.borrow()
.as_ref()
.expect("Resize observer should exist.")
.observe(&reobserve_floating);
if let Some(floating) = floating.as_ref() {
resize_observer
.borrow()
.as_ref()
.expect("Resize observer should exist.")
.observe(floating);
}
}
}));

Expand Down Expand Up @@ -378,11 +382,13 @@ pub fn auto_update(
.observe(reference);
}

resize_observer
.borrow()
.as_ref()
.expect("Resize observer should exist.")
.observe(floating);
if let Some(floating) = floating {
resize_observer
.borrow()
.as_ref()
.expect("Resize observer should exist.")
.observe(floating);
}
}

let frame_id: Rc<RefCell<Option<i32>>> = Rc::new(RefCell::new(None));
Expand Down
34 changes: 17 additions & 17 deletions packages/dom/src/platform/get_clipping_rect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,25 +193,25 @@ pub fn get_clipping_rect(
.chain(vec![ElementOrRootBoundary::RootBoundary(root_boundary)])
.collect();

let init =
let first_rect =
get_client_rect_from_clipping_ancestor(element, clipping_ancestors[0].clone(), strategy);
let clipping_rect = clipping_ancestors
.into_iter()
.fold(init, |mut acc, clipping_ancestor| {
let rect = get_client_rect_from_clipping_ancestor(element, clipping_ancestor, strategy);

acc.top = acc.top.max(rect.top);
acc.right = acc.right.min(rect.right);
acc.bottom = acc.bottom.min(rect.bottom);
acc.left = acc.left.max(rect.left);

acc
});
let mut top = first_rect.top;
let mut right = first_rect.right;
let mut bottom = first_rect.bottom;
let mut left = first_rect.left;

for clipping_ancestor in clipping_ancestors.into_iter().skip(1) {
let rect = get_client_rect_from_clipping_ancestor(element, clipping_ancestor, strategy);
top = top.max(rect.top);
right = right.min(rect.right);
bottom = bottom.min(rect.bottom);
left = left.max(rect.left);
}

Rect {
x: clipping_rect.left,
y: clipping_rect.top,
width: clipping_rect.right - clipping_rect.left,
height: clipping_rect.bottom - clipping_rect.top,
x: left,
y: top,
width: right - left,
height: bottom - top,
}
}
18 changes: 14 additions & 4 deletions packages/leptos/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,12 @@ impl UseFloatingOptions {
pub fn while_elements_mounted_auto_update(self) -> Self {
let auto_update_rc: SendWrapper<Rc<WhileElementsMountedFn>> =
SendWrapper::new(Rc::new(|reference, floating, update| {
auto_update(reference, floating, update, AutoUpdateOptions::default())
auto_update(
reference,
Some(floating),
update,
AutoUpdateOptions::default(),
)
}));
self.while_elements_mounted(auto_update_rc)
}
Expand All @@ -102,7 +107,12 @@ impl UseFloatingOptions {
pub fn while_elements_mounted_auto_update_with_enabled(self, enabled: Signal<bool>) -> Self {
let auto_update_rc: SendWrapper<Rc<WhileElementsMountedFn>> =
SendWrapper::new(Rc::new(|reference, floating, update| {
auto_update(reference, floating, update, AutoUpdateOptions::default())
auto_update(
reference,
Some(floating),
update,
AutoUpdateOptions::default(),
)
}));
self.while_elements_mounted(MaybeProp::derive(move || {
if enabled.get() {
Expand All @@ -121,7 +131,7 @@ impl UseFloatingOptions {
let auto_update_rc =
move |options: AutoUpdateOptions| -> SendWrapper<Rc<WhileElementsMountedFn>> {
SendWrapper::new(Rc::new(move |reference, floating, update| {
auto_update(reference, floating, update, options.clone())
auto_update(reference, Some(floating), update, options.clone())
}))
};

Expand All @@ -139,7 +149,7 @@ impl UseFloatingOptions {
let auto_update_rc =
move |options: AutoUpdateOptions| -> SendWrapper<Rc<WhileElementsMountedFn>> {
SendWrapper::new(Rc::new(move |reference, floating, update| {
auto_update(reference, floating, update, options.clone())
auto_update(reference, Some(floating), update, options.clone())
}))
};

Expand Down
2 changes: 1 addition & 1 deletion packages/leptos/tests/visual/src/spec/auto_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pub fn AutoUpdate() -> impl IntoView {

cleanup.set_value(Some(SendWrapper::new(auto_update(
(&reference).into(),
&floating,
Some(&floating),
(*update).clone(),
options
.get()
Expand Down
10 changes: 8 additions & 2 deletions packages/yew/src/use_auto_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ use crate::types::WhileElementsMountedFn;
pub fn use_auto_update() -> Rc<Rc<WhileElementsMountedFn>> {
use_memo((), |_| {
let rc: Rc<WhileElementsMountedFn> = Rc::new(|reference, floating, update| {
auto_update(reference, floating, update, AutoUpdateOptions::default()).into()
auto_update(
reference,
Some(floating),
update,
AutoUpdateOptions::default(),
)
.into()
});

rc
Expand All @@ -28,7 +34,7 @@ pub fn use_auto_update_with_options(options: AutoUpdateOptions) -> Rc<Rc<WhileEl
let options = options.clone();

let rc: Rc<WhileElementsMountedFn> = Rc::new(move |reference, floating, update| {
auto_update(reference, floating, update, options.clone()).into()
auto_update(reference, Some(floating), update, options.clone()).into()
});

rc
Expand Down
2 changes: 1 addition & 1 deletion upstream.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[releases]
core = "1.7.5"
dom = "1.7.4"
dom = "1.7.6"
utils = "0.2.11"
vue = "1.1.9"
Loading