Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect LifeCycleCtx with FocusChanged event #878

Merged
merged 1 commit into from
Apr 25, 2020
Merged
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
14 changes: 11 additions & 3 deletions druid/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,10 @@ impl<T: Data, W: Widget<T>> WidgetPod<T, W> {
}

pub fn lifecycle(&mut self, ctx: &mut LifeCycleCtx, event: &LifeCycle, data: &T, env: &Env) {
// in the case of an internal routing event, if we are at our target
// we may replace the routing event with the actual event
let mut substitute_event = None;

let recurse = match event {
LifeCycle::Internal(internal) => match internal {
InternalLifeCycle::RouteWidgetAdded => {
Expand Down Expand Up @@ -641,10 +645,11 @@ impl<T: Data, W: Widget<T>> WidgetPod<T, W> {
// Only send FocusChanged in case there's actual change
if old != new {
self.state.has_focus = change;
let event = LifeCycle::FocusChanged(change);
self.inner.lifecycle(ctx, &event, data, env);
substitute_event = Some(LifeCycle::FocusChanged(change));
true
} else {
false
}
false
} else {
self.state.has_focus = false;
// Recurse when the target widgets could be our descendants.
Expand Down Expand Up @@ -694,6 +699,9 @@ impl<T: Data, W: Widget<T>> WidgetPod<T, W> {
}
};

// use the substitute event, if one exists
let event = substitute_event.as_ref().unwrap_or(event);

if recurse {
let mut child_ctx = LifeCycleCtx {
command_queue: ctx.command_queue,
Expand Down