Skip to content

Commit

Permalink
use cleanup to remove overlay for tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
dzhou121 committed May 10, 2024
1 parent 9a4c0fa commit ab28c54
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
5 changes: 4 additions & 1 deletion src/app_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,12 @@ impl AppState {
self.remove_view(child);
}
let view_state = id.state();
if let Some(action) = view_state.borrow().cleanup_listener.as_ref() {

let cleanup_listener = view_state.borrow().cleanup_listener.clone();
if let Some(action) = cleanup_listener {
action();
}

let node = view_state.borrow().node;
let taffy = id.taffy();
let mut taffy = taffy.borrow_mut();
Expand Down
11 changes: 3 additions & 8 deletions src/views/tooltip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ pub fn tooltip<V: IntoView + 'static, T: IntoView + 'static>(
style: Default::default(),
window_origin: None,
}
.on_cleanup(move || {
remove_overlay(id);
})
}

impl View for Tooltip {
Expand Down Expand Up @@ -107,11 +110,3 @@ impl View for Tooltip {
default_compute_layout(self.id, cx)
}
}

impl Drop for Tooltip {
fn drop(&mut self) {
if let Some(id) = self.overlay {
remove_overlay(id);
}
}
}

0 comments on commit ab28c54

Please sign in to comment.