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

Commit

Permalink
Add MacOS gallery and UITest (#721)
Browse files Browse the repository at this point in the history
* [MacOS] Cleanup

* [Controls] Add Header support to ListView

* [MacOS] NSView reuse on NSTableView

* [MacOS] Some fix on layour order

* [MacOS] Add CarouselPageRenderer

* [MacOS] Implement EventTracker on PageRenderer

* [MacOS] Cleanup CarouselPageRenderer

* [MacOS] Add MasterDetailPage renderer

* [MacOS] MDP renderer don't allow drag of splitter

* [MacOS] Add TabbedPage renderer

* [MacOS] Initial sketch of NavigationPageRenderer

* [MacOS] Send disappearing of CurrentPage on Dispose on NavigationPageRenderer

* [MacOS] Add Gallery page for Mac

* [MacOS] Add MacOSExpressionSearch

* [MacOS] Fix ColorExtension

* [MacOS] Fix MDP renderer layout

* [MacOS] Implement native selection on ListViewRenderer

* [MacOS] Deselect a item on NSTableView

* [MacOS] Remove previous SplitViewItems

* [MacOS] Fix navigationpage height

* [MacOS] Add toolbar for NavigationPageRenderer

* [MacOS] Don't remove selection for now (crashing)

* [MacOS] Refactor page and back button title on NavigationPageRenderer

* [MacOS] Fix bug when native navigate back

* [MacOS] Hide layer when transition

* [MacOS] ListviewRenderer fix BbackgroundColor

* [MacOS] Fix background on ScrollViewRenderer

* [MacOS] Fix header measure on ListViewRenderer

* [MacOS] Add Mac twitter demo

* [Controls] Spaces for easy reading

* [MacOS] More xaml cleanup

* [Core] Add Mac as aTargetPlatform

* [MacOS] Add alerts and actionsheets

* [MacOS] Add GestureRecognizers

* [MacOS] Fix Layout issues when adding children, enable transformations

* [MacOS] Fix title on tab item, move to tabbed navigation based on segmented control

* [MacOS] Hide toolbar when not needed, this allows to work with tabbed page, cleanup

* [MacOS] Add NativeBindings and NativeViewWrapper

* [MacOS] Fix AssemblyInfo

* [MacOS] FIX NRE on SetBackgroundColor BoxView

* [MacOS] Fix NavigationPageRenderer

* [MacOS] Fix build

* [MacOS] Also update page when it resizes

* [MacOS] Add LayoutRenderer for handle items position when the bounds change.

* [MacOS] Refactor/Cleanup

* [MacOS] Add toolbar items support to NavigationPage

* [MacOS] Resize images for TabViewITems

* [MacOS] Fix TabbedPage resize issues , allow users to override some features when creating TVI

* [MacOS] Fix hide/show Navigation toolbar

* [MacOS] Redo CarouselPageRenderer with NSPageController

* [MacOS] Add support for Modal pages

* [MacOS] Refactor navigation from platform

* [Nuget] Add nuget for MacOS

* [Nuget]Fix nuspec

* [Nuget] Add variables for CI

* [Controls] Remove MainMenu from MacOS

* [MacOS] Add TableView renderer (no headers yet)

* [MacOS] Refactoring, marking extensions as internal

* [MacOS] Add group headers for TableViewRenderer

* [MacOS] Workaround for updates on listview collection

* [MacOS] Handle updates of rows in the ListViewRenderer properly

* [MacOS] Fix navigation animation

* Fix navigation header issues with modal pages

* [MacOS] Fix MDP issues with resizing

* [MacOS] Fix general dispose

* [MacOS] Add a ViewControllerWrapper for NSSplitView

* [MacOS] MDP renderer fix animation

* [MacOS] Fix ListView selection bug

* [MacOS] Fix rendering MDP Layout inside wrappers

* [MacOS] Re write the MainToolbar handler

* [MacOS] Don't use Sierra new extensions so we can run in stable channel

* [MacOS] Another way to hide the toolbar (smarter i think)

* [MacOS] Fix MDP bug and remove debug color

* [Controls] Add HanselForms sample

* [MacOS] Fix NRE WebviewRenderer

* [MacOS] Fix uneven rows on ListView renderer

* [MacOS] Fix NRE on load (can+t find the reason this happens)

* [MacOS] Fix uneven rows

* [MacOS] Fix header sizing on ListViewRenderer

* [Controls] More stuff on HanselForms

* [MacOS] Remove warning from ListViewRenderer

* [MacOS] Fix PageRenderer bug double init

* [MacOS] Don't calculate height if RowHeight is provided

* [Controls] More Hanselforms stuff

* [MacOS] Once again a new implementation for the NavigationBar, this time using a custom view to support BackgroundColor

* [MacOS] Fix build

* [MacOS] Refactoring AwesomeBar related controls

* Fix build

* [MacOS] NavigationBar update background and t test colors

* [MacOS] Fix when we remove navigation so it works when the NavigationRenderer wasn't removed from the parent controller like in a TabbedPage

* [MacOS] Add support for ListView  grouping

* [MacOS] Fix image extension method.

* [MacOS] Add base Maps project

* [MacOS] Export MapRenderer

* [MacOS] Add pin click and geocoderbacked for Maps

* [MacOS] Add extra binding project for API not in stable.

* [MacOS] Add MacOS Maps lib

* [MacOS]Fix build on alpha

* [MacOS] Remove MacOS Maps extra binding

* [UITest] Basic macOS setup

* [UITest] Add MacOSApp wrapper implementation

* [MacOS] Set AutomationID

* [UITests] Add ActionSheetUITests to MacOS UITest

* [MacOS] Fix bug on Picker

* [UITests] Link basic uitest basefixture and related files

* [MacOS] Fix pickers reuse

* [UItests] Fix MacOS app path

* [UITest] Ignore UItest for appearing on macOS for now

* [UITest] Update macOS for 2.0.3

* [UITest] Refactor EnterText MacOS app

* [UITest]Fix ViewQuery on MacOS

* [UITest]Fix IsEnabled UItest on macOS

* [UITest] Implement Enter, mark some tests inconclusive fix others

* [MacOS] Implement Entry Completed event

* [UITests] Fix UITest for IsVisible, ignore ToolbarItem test for now

* [UITests] Fix ISVisible again add extra category

* [Controls] Cleanup macOS gallery

* [MacOS] Fix Assembly info

* [Docs] Fix docs

* Fix build

* [Nuget] Fix nuspec

* [Controls] Link files on MacOS

* [Core] Update Forms stack before firing a event saying page was removed, possible breaking change

* [MacOS] Implement RemovePage on NavigationPAgeRenderer

* [UItest] Ignore some , implement back on MacOS UITest app

* [MacOS] Add default back button name (needs to be translated)

* [MacOS] Fix dispose

* [UITest] Make 29257 work on MacOS

* [MacOS] Rename stuff

* [MacOS] More renaming and cleanup

* [MacOS] Share implementations for iOS

* [MacOS] Reuse more IOS extensions

* [MacOS] Reuse FontExtensions

* [MacOS] Share NativeViewWrapper related stuff

* [MAcOS] Share event args and ExportRenderer

* [MacOS] Share platform effect

* [MacOS] Fix build

* [Docs]Fixing docs

* [MacOS] Fix ViewCell reuse

* [Core] Support ListView CachingStrategy on MacOS

* [MacOS] Fix issues with TextCell and ImageCell (we can’t set null to a NSControl value)

* [MacOS] Fix MDP child sizing bug
[UITest] Query marked by id and text

* [MacOS] Comment test related with context actions

* [MacOS] Implement missing stuff on ticker

* [MacOS] Make sure VisualElemenTracker calls the ticker update

* [UITests]Ignore context actions and not possible to test

* [MacOS] Fix Grouping bug on Listview

* [MacOS] Fix selection on Listview when using grouping

* [MacOS] Update navbar when page is popped

* [MacOS] Cleanup NavigationBar

* [Controls] More info on exceptions

* [MacOS] Fix bug animation pop modal

* [MacOS] Bring back BackgroundColor of NavigationBar

* [MacOS] Fix UITest animation delay

* [MacOS] Treat warnings as errors

* [MacOS] Center title on toolbar

* [Core] Add Platform configuration specific for MacOS

* [MacOS] Implement TabbedPage platform specific to handle TabItems on NavigationPage bar

* [MacOS] Fix warning

* [MacOS] Fix bug on SearchBar color

* [MacOS]Fix build

* [MacOS] remove extra dll from maps

* [Docs] Update docs

* [MacOS]Cleanup and refactoring

* Revert "[MacOS] remove extra dll from maps"

This reverts commit 73b9489.

* [MacOS] Fix wrong refactoring

* [MacOS] dix formatting

* [MacOS] Fix build

* [MacOS] Fix bug on TabbedPageRenderer no title

* [MacOS,UITest] Update packages

* [MacOS ,UITest] Add delay when tapping something, and focus with double click

* [MacOS,UITest] Ignore UITest, not possible to test with current version

* [MacOS,UITest] Ignore test that uses Frame, UITest doesn’t return it

* [MacOS] Fix bug when no title on toolbar items

* [MacOS] Remove FormsNSView

* [MacOS] Cleanup on dispose on MDP renderer

* [MacOS] Different way to test leak of MDP, need to look at this again after

* [MacOS] Update current page when source changes

* [MacOS] More cleanup

* [MacOS,UITest] Implement ClearText

* [MacOS,UITest] ClearText doesn’t work for now on MacOS uitest

* [MacOS] Make sure we show the previous page when popping a Modal

* [MacOS] Fix issue with sizing the Header and visibility, remove for now header renderer reuse

* [MacOS] Clean CustomNSTableView

* [MacOS] Share LabelRenderer with iOS

* [MacOS,UITest] Don’t try to scroll for the element

* [MacOS] Share ResourcesProvider with iOS

* [MAcoS] Share VisualElementPackager with iOS

* [MacOS] Share ViewRenderer with iOS

* [MacOS] Merge with VisualElementTracker from iOS

* [MacOS] Merge with EventTracker from iOS

* [MacOS] Merge with VisualElementRenderer of iOS

* [MacOS] Make sure we always have a layer

* [MacOS] Fix Tracker merge with iOS version

* [MacOS] Fix bug with tabbed page on modal without navigation

* [Core] Rever change on core

* [Controls] Add missing image

* [MacOS] Clear renderers before setting them MDP

* [MacOS] Update tabbedPage ContainerArea

* [Controls] Add Custom renderers tests

* [MacOS] Fix ListViewRenderer

* [MacOS,UITest] Refactoring, implement index

* [MacOS] Make sure we don’t pass null to TextField string value

* [MacOS] Support for multiple clicks in same selected item on NSTableView

* [MacOS, UITest] Fix bug on Back because of refactoring

* [MacOS,UITest] Ignore UITest because we’d-not have ScrollDownTo yet

* [MacOS] Support Focus on EntryRenderer

* [MacOS,UITest] Ignore more a couple of tests that we can’t test on UITest Desktop

* [MacOS,UITest] MacOSApp looks for StaticText fields too

* [MacOS, UITest] Fix EnterText for marked Entry

* [MacOS] Fix index bug on TablevIewDataSource

* [MacOS] Fix SelectedItem TableViewDataSource

* [Nuget] Add Mac to Maps nuspec

* [Nuget]Fix path

* [Controls] Add basic FormsGallery sample

* [macOS] Fixed Tab NSImage crash in TabbedPageRenderer (#705)

* [macOS] Fixed Tab NSImage crash in TabbedPageRenderer

* Coding Style

* Coding Style

* [MacOS] Fix previous merge with master

* [MacOS] Possible simple fix for click on views overlapping

* [UItest] Ignore this part of the test we can’t click on NSViews yet

* [MacOS] Rename to IsOnViewCell

* fix docs

* [MacOS] Cleanup, Address feedback from Samantha’s review

* [MacOS] Add ContextActions

* [Controls] Remove FormsGalery for now

* [Docs] Update docs

* [MacOS] Implement ContextActions

* [MacOS,UITests] Enable and support UITests of ContextActions
  • Loading branch information
rmarinho committed Jan 27, 2017
1 parent de96051 commit 0041973
Show file tree
Hide file tree
Showing 59 changed files with 2,607 additions and 194 deletions.
246 changes: 246 additions & 0 deletions Xamarin.Forms.ControlGallery.MacOS/AppDelegate.cs
@@ -0,0 +1,246 @@
using System;
using System.Globalization;
using AppKit;
using CoreGraphics;
using Foundation;
using Xamarin.Forms.Controls;
using Xamarin.Forms.Controls.Issues;
using Xamarin.Forms.Platform.MacOS;

namespace Xamarin.Forms.ControlGallery.MacOS
{
[Register("AppDelegate")]
public class AppDelegate : FormsApplicationDelegate
{

NSWindow _window;
public AppDelegate()
{
ObjCRuntime.Runtime.MarshalManagedException += (sender, args) =>
{
Console.WriteLine(args.Exception.ToString());
};

var style = NSWindowStyle.Closable | NSWindowStyle.Resizable | NSWindowStyle.Titled;

var rect = new CoreGraphics.CGRect(200, 1000, 1024, 768);
//var rect = NSWindow.FrameRectFor(NSScreen.MainScreen.Frame, style);
_window = new NSWindow(rect, style, NSBackingStore.Buffered, false);
_window.Title = "Twitter XF Mac";
_window.TitleVisibility = NSWindowTitleVisibility.Hidden;
}

public override NSWindow MainWindow
{
get { return _window; }
}

public override void DidFinishLaunching(NSNotification notification)
{
Forms.Init();
FormsMaps.Init();

var app = new App();
// When the native control gallery loads up, it'll let us know so we can add the nested native controls
MessagingCenter.Subscribe<NestedNativeControlGalleryPage>(this, NestedNativeControlGalleryPage.ReadyForNativeControlsMessage, AddNativeControls);
MessagingCenter.Subscribe<Bugzilla40911>(this, Bugzilla40911.ReadyToSetUp40911Test, SetUp40911Test);

// When the native binding gallery loads up, it'll let us know so we can set up the native bindings
MessagingCenter.Subscribe<NativeBindingGalleryPage>(this, NativeBindingGalleryPage.ReadyForNativeBindingsMessage, AddNativeBindings);

LoadApplication(app);
base.DidFinishLaunching(notification);
}

void AddNativeControls(NestedNativeControlGalleryPage page)
{
if (page.NativeControlsAdded)
{
return;
}

StackLayout sl = page.Layout;

// Create and add a native UILabel
var originalText = "I am a native UILabel";
var longerText =
"I am a native UILabel with considerably more text. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";

var uilabel = new NSTextField
{
StringValue = originalText,
MaximumNumberOfLines = 0,
LineBreakMode = NSLineBreakMode.ByWordWrapping,
Font = NSFont.FromFontName("Helvetica", 24f)
};

sl?.Children.Add(uilabel);

// Create and add a native Button
var uibutton = NSButtonExtensions.CreateButton("Toggle Text Amount", () =>
{
uilabel.StringValue = uilabel.StringValue == originalText ? longerText : originalText;
uilabel.SizeToFit();
});
uibutton.Font = NSFont.FromFontName("Helvetica", 14f);


sl?.Children.Add(uibutton.ToView());

// Create some control which we know don't behave correctly with regard to measurement
var difficultControl0 = new BrokenNativeControl
{
Font = NSFont.FromFontName("Helvetica", 14f),
MaximumNumberOfLines = 0,
LineBreakMode = NSLineBreakMode.ByWordWrapping,
StringValue = "Doesn't play nice with sizing. That's why there's a big gap around it."
};

var difficultControl1 = new BrokenNativeControl
{
Font = NSFont.FromFontName("Helvetica", 14f),
MaximumNumberOfLines = 0,
LineBreakMode = NSLineBreakMode.ByWordWrapping,
StringValue = "Custom size fix specified. No gaps."
};

var explanation0 = new NSTextField
{
StringValue = "The next control is a customized label with a bad SizeThatFits implementation.",
MaximumNumberOfLines = 0,
LineBreakMode = NSLineBreakMode.ByWordWrapping,
Font = NSFont.FromFontName("Helvetica", 14f),
};

var explanation1 = new NSTextField
{
StringValue = "The next control is the same broken class as above, but we pass in an override to the GetDesiredSize method.",
MaximumNumberOfLines = 0,
LineBreakMode = NSLineBreakMode.ByWordWrapping,
Font = NSFont.FromFontName("Helvetica", 14f),
};

// Add a misbehaving control
sl?.Children.Add(explanation0);
sl?.Children.Add(difficultControl0);

// Add the misbehaving control with a custom delegate for FixSize
sl?.Children.Add(explanation1);
sl?.Children.Add(difficultControl1, FixSize);

page.NativeControlsAdded = true;
}

SizeRequest? FixSize(NativeViewWrapperRenderer renderer, double width, double height)
{
var uiView = renderer.Control;
var view = renderer.Element;

if (uiView == null || view == null)
{
return null;
}

var constraint = new CGSize(width, height);

// Let the BrokenNativeControl determine its size (which we know will be wrong)
var badRect = uiView.FittingSize;

// And we'll use the width (which is fine) and substitute our own height
return new SizeRequest(new Size(badRect.Width, 20));
}

void AddNativeBindings(NativeBindingGalleryPage page)
{
if (page.NativeControlsAdded)
return;

StackLayout sl = page.Layout;

int width = 200;
int heightCustomLabelView = 100;

var uilabel = new NSTextField(new CGRect(0, 0, width, heightCustomLabelView))
{
BackgroundColor = NSColor.Clear,
Editable = false,
Bezeled = false,
DrawsBackground = false,
MaximumNumberOfLines = 0,
LineBreakMode = NSLineBreakMode.ByWordWrapping,
Font = NSFont.FromFontName("Helvetica", 24f),
StringValue = "DefaultText"
};

var uibuttonColor = NSButtonExtensions.CreateButton("Toggle Text Color Binding", () => uilabel.TextColor = NSColor.Blue);
uibuttonColor.Font = NSFont.FromFontName("Helvetica", 14f);

uilabel.SetBinding("StringValue", new Binding("NativeLabel"));
uilabel.SetBinding(nameof(uilabel.TextColor), new Binding("NativeLabelColor", converter: new ColorConverter()));

sl?.Children.Add(uilabel);
sl?.Children.Add(uibuttonColor.ToView());
//var colorPicker = new NSColorWell();
//colorPicker.SetBinding("SelectedColor", new Binding("NativeLabelColor", BindingMode.TwoWay, new ColorConverter()), "ColorPicked");
//sl?.Children.Add(colorPicker);
page.NativeControlsAdded = true;
}

#region Stuff for repro of Bugzilla case 40911

void SetUp40911Test(Bugzilla40911 page)
{
var button = new Button { Text = "Start" };

button.Clicked += (s, e) =>
{
StartPressed40911();
};

page.Layout.Children.Add(button);
}

public void StartPressed40911()
{
var loginViewController = new NSViewController { View = { } };
var button = NSButtonExtensions.CreateButton("Login", () =>
{
Xamarin.Forms.Application.Current.MainPage = new ContentPage { Content = new Label { Text = "40911 Success" } };
//loginViewController.DismissViewController()true, null);
});

button.Frame = new CGRect(20, 100, 200, 44);
loginViewController.View.AddSubview(button);

var window = NSApplication.SharedApplication.KeyWindow;
var vc = window.ContentViewController;
while (vc.PresentedViewControllers.Length > 0)
{
vc = vc.PresentedViewControllers[0];
}

//vc.PresentViewController(loginViewController, new NSViewControllerPresentationAnimator();
}

#endregion

public class ColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is Color)
return ((Color)value).ToNSColor();
return value;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is NSColor)
return ((NSColor)value).ToColor();
return value;
}
}
}
}

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,68 @@
{
"images": [
{
"filename": "AppIcon-16.png",
"size": "16x16",
"scale": "1x",
"idiom": "mac"
},
{
"filename": "AppIcon-16@2x.png",
"size": "16x16",
"scale": "2x",
"idiom": "mac"
},
{
"filename": "AppIcon-32.png",
"size": "32x32",
"scale": "1x",
"idiom": "mac"
},
{
"filename": "AppIcon-32@2x.png",
"size": "32x32",
"scale": "2x",
"idiom": "mac"
},
{
"filename": "AppIcon-128.png",
"size": "128x128",
"scale": "1x",
"idiom": "mac"
},
{
"filename": "AppIcon-128@2x.png",
"size": "128x128",
"scale": "2x",
"idiom": "mac"
},
{
"filename": "AppIcon-256.png",
"size": "256x256",
"scale": "1x",
"idiom": "mac"
},
{
"filename": "AppIcon-256@2x.png",
"size": "256x256",
"scale": "2x",
"idiom": "mac"
},
{
"filename": "AppIcon-512.png",
"size": "512x512",
"scale": "1x",
"idiom": "mac"
},
{
"filename": "AppIcon-512@2x.png",
"size": "512x512",
"scale": "2x",
"idiom": "mac"
}
],
"info": {
"version": 1,
"author": "xcode"
}
}
@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
23 changes: 23 additions & 0 deletions Xamarin.Forms.ControlGallery.MacOS/BrokenNativeControl.cs
@@ -0,0 +1,23 @@
using System;
using AppKit;
using CoreGraphics;

namespace Xamarin.Forms.ControlGallery.MacOS
{
/// <summary>
/// This is a custom Android control which deliberately does some incorrect measuring/layout
/// </summary>
public class BrokenNativeControl : NSTextField
{
public override string StringValue
{
get { return base.StringValue; }
set { base.StringValue = value.ToUpper(); }
}

public override CGSize SizeThatFits(CGSize size)
{
return new CGSize(size.Width, 150);
}
}
}

0 comments on commit 0041973

Please sign in to comment.