Avalonia icon indicating copy to clipboard operation
Avalonia copied to clipboard

FocusManager initialization should be handled by Locator

Open jinek opened this issue 1 year ago • 5 comments

Is your feature request related to a problem? Please describe. Currently FocusManager is created and bound by Application.RegisterServices, thus ignoring anything already bound to locator at the level of IWindowingPlatform or upper. Thus we have to inherit Application and override RegisterServices to be able to set custom FocusManager.

Describe the solution you'd like I think FocusManager shoudl be registered at platform initialization level and only consumed by Application.

Describe alternatives you've considered As described upper we could create our inheritor of Application, but then we need to duplicate initialization parts of it

Additional context May be there are some restrictions based on dependency order, thus may be it makes sense to consider to extract additional entities/splitting FocusManager to several parts if necessary.

jinek avatar Jul 20 '22 16:07 jinek

  • same for KeyboardNavigationHandler

jinek avatar Jul 20 '22 16:07 jinek

I think you actually can replace IKeyboardNavigationHandler with a locator. Consolonia did it https://github.com/jinek/Consolonia/pull/79/files#diff-87edd463c680c3814584dca5b6b1069eea554e8f412169d00db01865270f0066R23

Not sure if there is a reason to replace FocusManager. Replacing keyboard handler should be enough for custom navigation.

maxkatz6 avatar Jul 23 '22 06:07 maxkatz6

I think you actually can replace IKeyboardNavigationHandler with a locator.

Whatever we set to locator it is then overridden by Avalonia's Application https://github.com/AvaloniaUI/Avalonia/blob/master/src/Avalonia.Controls/Application.cs#L234 As a hack we need to create our own application and re-register the value in the locator one more time.

jinek avatar Jul 23 '22 10:07 jinek

You can register it after Application did it?

maxkatz6 avatar Jul 23 '22 17:07 maxkatz6

You can register it after Application did it?

Yes, as I said we need to inherit our own Application class and re-register the instance. Which means we can not just use regular Application

jinek avatar Jul 25 '22 13:07 jinek