Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[UWP] AccessKey support on VisualElement and TabbedPage #2061

Merged
merged 4 commits into from Apr 24, 2018

Conversation

henricm
Copy link
Contributor

@henricm henricm commented Mar 9, 2018

Description of Change

Fixes #1672 by adding AccessKey, AccessKeyPlacement and horizontal
and vertical offset properties to Windows specific VisualElement class.
Also handles AccessKeys for tabbed pages (ContentPage).

API Changes

Added:

  • New enum AccessKeyPlacement for specifying placement of the access key tooltip.
  • string WindowsSpecific.VisualElement.AccessKey { get; set; } //Bindable Property
  • AccessKeyPlacement WindowsSpecific.VisualElement.AccessKeyPlacement { get; set; } //Bindable Property
  • double WindowsSpecific.VisualElement.AccessKeyHorizontalOffset{ get; set; } //Bindable Property
  • double WindowsSpecific.VisualElement.AccessKeyVerticalOffset{ get; set; } //Bindable Property

Behavioral Changes

When you set AccessKey property button, tab etc will be able to execute its action when user presses the Alt-button. When the Alt-button is pushed once, access key tooltips will be displayed.

PR Checklist

  • Has tests (if omitted, state reason in description)
  • Rebased on top of master at time of PR
  • Changes adhere to coding standard
  • Consolidate commits as makes sense

@henricm henricm requested review from hartez and PureWeen March 9, 2018 10:11
case NotifyCollectionChangedAction.Replace:
if (e.NewItems != null)
foreach (var c in e.NewItems)
(c as Page).PropertyChanged += OnChildPagePropertyChanged;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if there is a way to not sub/unsub this event and still achieve this effect. Its expensive to sub PropertyChanged as it triggers a fair bit...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. However - is it that big difference compared to other property change handling.
One thought could be to try to handle this in xaml with converters or something? Haven't looked alot into that yet though.

@samhouts samhouts added this to Ready in v3.1.0 via automation Mar 9, 2018
@samhouts samhouts moved this from Ready to In Review in v3.1.0 Mar 9, 2018
Copy link
Contributor

@PureWeen PureWeen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks great. This will be super useful.

Did you look into implementing IsAccessKeyScope at the layout level at all?

Not sure if that will be translatable from a forms layout scope to UWP so was curious if you had looked into it much with this change?

Element.CurrentPage = page;
}

protected void UpdateAccessKey(TextBlock control) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize there are subtle differences but can the UpdateAccessKey that's in VisualElementRenderer and TabbedPageRenderer be generalized into a reusable internal static method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created AccessKeyHelper which should take care of this now.

case NotifyCollectionChangedAction.Remove:
case NotifyCollectionChangedAction.Replace:
if (e.NewItems != null)
foreach (var c in e.NewItems)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These might go away because of Jason's comments but if not can you change to for (int i

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Curious though - why is that preferred? :-)

Copy link
Contributor

@PureWeen PureWeen Mar 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are cases where foreach vs for doesn't matter and there are cases where it does matter as far as Memory and performance (especially on the Mono side). Generally the for will perform better or the same as foreach

In a case like this with so few items, where it happens very infrequently and it's UWP it's most likely irrelevant but it's more about a consistent pattern we use throughout the code base. So unless there's a compelling reason (other than just being easier) to use foreach we just use for (int i

@henricm
Copy link
Contributor Author

henricm commented Mar 13, 2018

@PureWeen thanks for the feedback!

I haven't looked into implementing access key scope in this PR. I read about how it works in UWP but I reasoned that as a first step we only wanted basic support for access keys.
However, I could dive more into that if desired? In that case we probably want to add support for AccessKeyInvoked event too.
There is also localization of access keys which natively is handled in XAML and I'm not sure how that would translate in the Xamarin.Forms world.

@PureWeen
Copy link
Contributor

@henricm Yea I looked at the Localization as well seeing what made sense. My thought here is that since this is all settable from forms as a string you can just use the Localization APIs through forms to set things to a Localized value.. If you use the bindings to set these properties then localization can just be achieved that way

As far as the native support for localization that feels like it would just be a different issue as that's just about setting the Uid of the elements right? Opening up a platform API that lets you set the Uid on the native control would just be generally useful it seems but outside the scope of this issue.

As far as IsAccessKeyScope. My thoughts would be that if it's easy enough to apply the property at the layout level and then translate this down into UWP go for it but if the devil in the details makes this too tricky then a separate issue would suffice.. Is it as easy as adding a property to Xamarin.Forms.Layout then having LayoutRenderer on UWP set the property? Or am I being short sighted?

@henricm
Copy link
Contributor Author

henricm commented Mar 14, 2018

@PureWeen sounds good regarding localization and I will definitely have a look at access key scope. Hopefully later this week.

@samhouts samhouts added this to In Progress in Enhancements Mar 22, 2018
Copy link
Contributor

@hartez hartez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, just need to reduce the duplicate code and I think it's ready.

@@ -429,5 +460,65 @@ void UpdateBarIcons()
Control.InvalidateMeasure();
}
}
void UpdateToolbarPlacement()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces -> Tabs

@henricm henricm force-pushed the AccessKeyWindows branch 2 times, most recently from 85a05b0 to 909f070 Compare March 27, 2018 14:09
@xamarin-release-manager xamarin-release-manager added the API-change Heads-up to reviewers that this PR may contain an API change label Mar 27, 2018
@henricm
Copy link
Contributor Author

henricm commented Mar 27, 2018

@PureWeen I wrestled a bit with adding IsAccessKeyScope on Layout and then setting the property on the UWP control. However I couldn't get it to work I'm afraid. I also tried enumerate the UWP specific controls (Panels etc) and try to figure out if the property could be set there instead. But I never managed to find a way to get it to work. I'm sure that someone with more UWP and/or Xamarin.Forms knowledge will be able to solve this.

@PureWeen
Copy link
Contributor

@henricm yea :-/ I hoped it'd be just be an easy win but I'm not surprised it wasn't. Changes look good

Fixes xamarin#1672 by adding AccessKey, AccessKeyPlacement and horizontal
and vertical offset properties to Windows specific VisualElement class.
Also handles AccessKeys for tabbed pages (ContentPage).
Refs xamarin#1672 and fixes issue with AccessKey not being updated
after tabbed page and its children had been created. The problem
was that the Reset event in OnPagesChange wasn't handled correctly.
We now add listeners to the child pages of the tabbed page which
makes sure AccessKey gets updated if user makes changes to tab object.
Updated foreach-loop and replaced spaces with tabs.
@xamarin-release-manager xamarin-release-manager added the API-change Heads-up to reviewers that this PR may contain an API change label Apr 9, 2018
@henricm
Copy link
Contributor Author

henricm commented Apr 9, 2018

@hartez the duplicate has been removed and everything is rebased as of today so please take another look when you have time. Thanks!

@xamarin-release-manager xamarin-release-manager added the API-change Heads-up to reviewers that this PR may contain an API change label Apr 23, 2018
@rmarinho rmarinho merged commit efbadcf into xamarin:master Apr 24, 2018
v3.1.0 automation moved this from In Review to Done Apr 24, 2018
Enhancements automation moved this from In Progress to Done Apr 24, 2018
@henricm henricm deleted the AccessKeyWindows branch April 24, 2018 12:34
@samhouts samhouts added this to the 3.1.0 milestone May 5, 2018
@samhouts samhouts modified the milestone: 3.1.0 Jun 1, 2018
@samhouts samhouts removed this from Done in Enhancements Jun 12, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
API-change Heads-up to reviewers that this PR may contain an API change community-sprint F100 p/UWP t/enhancement ➕
Projects
No open projects
v3.1.0
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

7 participants