diff options
author | Rui Marinho <me@ruimarinho.net> | 2017-01-30 12:29:27 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-30 12:29:27 +0000 |
commit | 0b7623b5e6dea1a4ab0257b94b6ce6c67864f34b (patch) | |
tree | e85e8fd0c2e3d2f346ac03d2367d98e77f76728b /Xamarin.Forms.Platform.MacOS | |
parent | 11331bc10e854c06c45cb9a6f860fcde2b71667f (diff) | |
download | xamarin-forms-0b7623b5e6dea1a4ab0257b94b6ce6c67864f34b.tar.gz xamarin-forms-0b7623b5e6dea1a4ab0257b94b6ce6c67864f34b.tar.bz2 xamarin-forms-0b7623b5e6dea1a4ab0257b94b6ce6c67864f34b.zip |
[MacOS] Fixes to ToolbarItems (#728)
* [MacOS] Support toolbar item property changes
* [UITest,MacOS] Support query by button hardcoded
* [UITests] Add and fix more toolbar tests
Diffstat (limited to 'Xamarin.Forms.Platform.MacOS')
-rw-r--r-- | Xamarin.Forms.Platform.MacOS/NativeToolbarTracker.cs | 41 |
1 files changed, 36 insertions, 5 deletions
diff --git a/Xamarin.Forms.Platform.MacOS/NativeToolbarTracker.cs b/Xamarin.Forms.Platform.MacOS/NativeToolbarTracker.cs index fc8bec04..fc24b770 100644 --- a/Xamarin.Forms.Platform.MacOS/NativeToolbarTracker.cs +++ b/Xamarin.Forms.Platform.MacOS/NativeToolbarTracker.cs @@ -15,6 +15,7 @@ namespace Xamarin.Forms.Platform.MacOS { public NSToolbarItem ToolbarItem; public NSButton Button; + public ToolbarItem Element; } public NativeToolbarGroup(NSToolbarItemGroup itemGroup) @@ -370,8 +371,8 @@ namespace Xamarin.Forms.Platform.MacOS UpdateGroup(_tabbedGroup, items, ToolbarItemWidth, ToolbarItemSpacing); } - static void UpdateGroup(NativeToolbarGroup group, IList<ToolbarItem> toolbarItems, double itemWidth, - double itemSpacing) + void UpdateGroup(NativeToolbarGroup group, IList<ToolbarItem> toolbarItems, double itemWidth, + double itemSpacing) { int count = toolbarItems.Count; group.Items.Clear(); @@ -390,6 +391,7 @@ namespace Xamarin.Forms.Platform.MacOS var button = new NSButton(); button.Title = element.Text ?? ""; + button.SizeToFit(); var buttonWidth = itemWidth; if (button.FittingSize.Width > itemWidth) @@ -406,13 +408,17 @@ namespace Xamarin.Forms.Platform.MacOS button.Image = new NSImage(element.Icon); button.SizeToFit(); - view.AddSubview(button); - item.Label = item.PaletteLabel = item.ToolTip = button.ToolTip = element.Text ?? ""; + button.Enabled = item.Enabled = element.IsEnabled; + element.PropertyChanged -= ToolBarItemPropertyChanged; + element.PropertyChanged += ToolBarItemPropertyChanged; + + view.AddSubview(button); + //item.Label = item.PaletteLabel = item.ToolTip = element.Text ?? ""; subItems[i] = item; - group.Items.Add(new NativeToolbarGroup.Item { ToolbarItem = item, Button = button }); + group.Items.Add(new NativeToolbarGroup.Item { ToolbarItem = item, Button = button, Element = element }); } view.Frame = new CGRect(0, 0, totalWidth + (itemSpacing * (count - 1)), ToolbarItemHeight); @@ -425,5 +431,30 @@ namespace Xamarin.Forms.Platform.MacOS group.Group.View = new NSView(); } } + + void ToolBarItemPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) + { + var nativeToolbarItem = _toolbarGroup.Items.FirstOrDefault((NativeToolbarGroup.Item arg1) => arg1.Element == sender); + if (nativeToolbarItem != null) + { + if (e.PropertyName.Equals(VisualElement.IsEnabledProperty.PropertyName)) + { + nativeToolbarItem.Button.Enabled = nativeToolbarItem.ToolbarItem.Enabled = nativeToolbarItem.Element.IsEnabled; + } + + if (e.PropertyName.Equals(ToolbarItem.TextProperty.PropertyName)) + { + nativeToolbarItem.Button.Title = nativeToolbarItem.ToolbarItem.Label = nativeToolbarItem.Element.Text; + } + } + } + + class ToolBarItemNSButton : NSView + { + public ToolBarItemNSButton(string automationID) + { + AccessibilityIdentifier = automationID; + } + } } }
\ No newline at end of file |