2016-03-22 23:02:25 +03:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2016-04-17 22:33:52 +03:00
|
|
|
|
using CoreLocation;
|
2016-03-22 23:02:25 +03:00
|
|
|
|
using Foundation;
|
2016-09-15 00:56:17 +03:00
|
|
|
|
using MapKit;
|
|
|
|
|
using UIKit;
|
|
|
|
|
using Xamarin.Forms;
|
|
|
|
|
using Xamarin.Forms.ControlGallery.iOS;
|
|
|
|
|
using Xamarin.Forms.Controls;
|
2016-11-17 00:07:30 +03:00
|
|
|
|
using Xamarin.Forms.Controls.Issues;
|
2016-09-15 00:56:17 +03:00
|
|
|
|
using Xamarin.Forms.Platform.iOS;
|
2016-03-30 22:01:54 +03:00
|
|
|
|
using RectangleF = CoreGraphics.CGRect;
|
|
|
|
|
|
|
|
|
|
[assembly: ExportRenderer(typeof(Bugzilla21177.CollectionView), typeof(CollectionViewRenderer))]
|
|
|
|
|
[assembly: ExportRenderer(typeof(Bugzilla31395.CustomContentView), typeof(CustomContentRenderer))]
|
|
|
|
|
[assembly: ExportRenderer(typeof(NativeCell), typeof(NativeiOSCellRenderer))]
|
|
|
|
|
[assembly: ExportRenderer(typeof(NativeListView2), typeof(NativeiOSListViewRenderer))]
|
|
|
|
|
[assembly: ExportRenderer(typeof(NativeListView), typeof(NativeListViewRenderer))]
|
2016-04-17 22:33:52 +03:00
|
|
|
|
[assembly: ExportRenderer(typeof(CustomMapView), typeof(CustomIOSMapRenderer))]
|
2016-06-28 13:25:45 +03:00
|
|
|
|
[assembly: ExportRenderer(typeof(TabbedPage), typeof(TabbedPageWithCustomBarColorRenderer))]
|
2016-09-13 14:39:36 +03:00
|
|
|
|
[assembly: ExportRenderer(typeof(Bugzilla43161.AccessoryViewCell), typeof(AccessoryViewCellRenderer))]
|
2016-11-16 11:21:55 +03:00
|
|
|
|
[assembly: ExportRenderer(typeof(Bugzilla36802.AccessoryViewCell), typeof(AccessoryViewCellRenderer))]
|
2017-06-20 21:12:17 +03:00
|
|
|
|
[assembly: ExportRenderer(typeof(Bugzilla52700.NoSelectionViewCell), typeof(NoSelectionViewCellRenderer))]
|
2016-03-22 23:02:25 +03:00
|
|
|
|
namespace Xamarin.Forms.ControlGallery.iOS
|
|
|
|
|
{
|
2016-04-17 22:33:52 +03:00
|
|
|
|
public class CustomIOSMapRenderer : ViewRenderer<CustomMapView, MKMapView>
|
|
|
|
|
{
|
|
|
|
|
private MKMapView _mapView;
|
|
|
|
|
|
|
|
|
|
protected override void OnElementChanged(ElementChangedEventArgs<CustomMapView> e)
|
|
|
|
|
{
|
|
|
|
|
base.OnElementChanged(e);
|
|
|
|
|
|
|
|
|
|
if (e.NewElement != null)
|
|
|
|
|
{
|
|
|
|
|
if (Control == null)
|
|
|
|
|
{
|
|
|
|
|
_mapView = new MKMapView(UIScreen.MainScreen.Bounds);
|
|
|
|
|
_mapView.MapType = MKMapType.Standard;
|
|
|
|
|
_mapView.RotateEnabled = false;
|
|
|
|
|
SetNativeControl(_mapView);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CLLocationCoordinate2D coords = new CLLocationCoordinate2D(48.857, 2.351);
|
|
|
|
|
MKCoordinateSpan span = new MKCoordinateSpan(MilesToLatitudeDegrees(20), MilesToLongitudeDegrees(20, coords.Latitude));
|
|
|
|
|
_mapView.Region = new MKCoordinateRegion(coords, span);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public double MilesToLatitudeDegrees(double miles)
|
|
|
|
|
{
|
|
|
|
|
double earthRadius = 3960.0; // in miles
|
|
|
|
|
double radiansToDegrees = 180.0 / Math.PI;
|
|
|
|
|
return (miles / earthRadius) * radiansToDegrees;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public double MilesToLongitudeDegrees(double miles, double atLatitude)
|
|
|
|
|
{
|
|
|
|
|
double earthRadius = 3960.0; // in miles
|
|
|
|
|
double degreesToRadians = Math.PI / 180.0;
|
|
|
|
|
double radiansToDegrees = 180.0 / Math.PI;
|
|
|
|
|
// derive the earth's radius at that point in latitude
|
|
|
|
|
double radiusAtLatitude = earthRadius * Math.Cos(atLatitude * degreesToRadians);
|
|
|
|
|
return (miles / radiusAtLatitude) * radiansToDegrees;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-03-22 23:02:25 +03:00
|
|
|
|
public class NativeiOSCellRenderer : ViewCellRenderer
|
|
|
|
|
{
|
|
|
|
|
static NSString s_rid = new NSString("NativeCell");
|
|
|
|
|
|
2016-03-30 22:01:54 +03:00
|
|
|
|
public NativeiOSCellRenderer()
|
2016-03-22 23:02:25 +03:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-30 22:01:54 +03:00
|
|
|
|
public override UITableViewCell GetCell(Xamarin.Forms.Cell item, UITableViewCell reusableCell, UITableView tv)
|
2016-03-22 23:02:25 +03:00
|
|
|
|
{
|
|
|
|
|
var x = (NativeCell)item;
|
2016-03-30 22:01:54 +03:00
|
|
|
|
Console.WriteLine(x);
|
2016-03-22 23:02:25 +03:00
|
|
|
|
|
2016-03-30 22:01:54 +03:00
|
|
|
|
NativeiOSCell c = reusableCell as NativeiOSCell;
|
2016-03-22 23:02:25 +03:00
|
|
|
|
|
2016-03-30 22:01:54 +03:00
|
|
|
|
if (c == null)
|
|
|
|
|
{
|
|
|
|
|
c = new NativeiOSCell(s_rid);
|
2016-03-22 23:02:25 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UIImage i = null;
|
2016-03-30 22:01:54 +03:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(x.ImageFilename))
|
|
|
|
|
{
|
|
|
|
|
i = UIImage.FromFile("Images/" + x.ImageFilename + ".jpg");
|
2016-03-22 23:02:25 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-30 22:01:54 +03:00
|
|
|
|
base.WireUpForceUpdateSizeRequested(item, c, tv);
|
2016-03-22 23:02:25 +03:00
|
|
|
|
|
2016-03-30 22:01:54 +03:00
|
|
|
|
c.UpdateCell(x.Name, x.Category, i);
|
2016-03-22 23:02:25 +03:00
|
|
|
|
|
|
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sample of a custom cell layout, taken from the iOS docs at
|
|
|
|
|
/// http://developer.xamarin.com/guides/ios/user_interface/tables/part_3_-_customizing_a_table's_appearance/
|
|
|
|
|
/// </summary>
|
2016-03-30 22:01:54 +03:00
|
|
|
|
public class NativeiOSCell : UITableViewCell
|
|
|
|
|
{
|
2016-03-22 23:02:25 +03:00
|
|
|
|
UILabel _headingLabel;
|
|
|
|
|
UILabel _subheadingLabel;
|
|
|
|
|
UIImageView _imageView;
|
|
|
|
|
|
2016-03-30 22:01:54 +03:00
|
|
|
|
public NativeiOSCell(NSString cellId) : base(UITableViewCellStyle.Default, cellId)
|
2016-03-22 23:02:25 +03:00
|
|
|
|
{
|
|
|
|
|
SelectionStyle = UITableViewCellSelectionStyle.Gray;
|
|
|
|
|
|
2016-03-30 22:01:54 +03:00
|
|
|
|
ContentView.BackgroundColor = UIColor.FromRGB(255, 255, 224);
|
2016-03-22 23:02:25 +03:00
|
|
|
|
|
|
|
|
|
_imageView = new UIImageView();
|
|
|
|
|
|
2016-04-17 22:33:52 +03:00
|
|
|
|
_headingLabel = new UILabel()
|
|
|
|
|
{
|
2016-03-22 23:02:25 +03:00
|
|
|
|
Font = UIFont.FromName("Cochin-BoldItalic", 22f),
|
2016-03-30 22:01:54 +03:00
|
|
|
|
TextColor = UIColor.FromRGB(127, 51, 0),
|
2016-03-22 23:02:25 +03:00
|
|
|
|
BackgroundColor = UIColor.Clear
|
|
|
|
|
};
|
|
|
|
|
|
2016-04-17 22:33:52 +03:00
|
|
|
|
_subheadingLabel = new UILabel()
|
|
|
|
|
{
|
2016-03-22 23:02:25 +03:00
|
|
|
|
Font = UIFont.FromName("AmericanTypewriter", 12f),
|
2016-03-30 22:01:54 +03:00
|
|
|
|
TextColor = UIColor.FromRGB(38, 127, 0),
|
2016-03-22 23:02:25 +03:00
|
|
|
|
TextAlignment = UITextAlignment.Center,
|
|
|
|
|
BackgroundColor = UIColor.Clear
|
|
|
|
|
};
|
|
|
|
|
|
2016-03-30 22:01:54 +03:00
|
|
|
|
ContentView.Add(_headingLabel);
|
|
|
|
|
ContentView.Add(_subheadingLabel);
|
|
|
|
|
ContentView.Add(_imageView);
|
2016-03-22 23:02:25 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-30 22:01:54 +03:00
|
|
|
|
public void UpdateCell(string caption, string subtitle, UIImage image)
|
2016-03-22 23:02:25 +03:00
|
|
|
|
{
|
|
|
|
|
_imageView.Image = image;
|
|
|
|
|
_headingLabel.Text = caption;
|
|
|
|
|
_subheadingLabel.Text = subtitle;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-30 22:01:54 +03:00
|
|
|
|
public override void LayoutSubviews()
|
2016-03-22 23:02:25 +03:00
|
|
|
|
{
|
2016-03-30 22:01:54 +03:00
|
|
|
|
base.LayoutSubviews();
|
2016-03-22 23:02:25 +03:00
|
|
|
|
|
|
|
|
|
_imageView.Frame = new RectangleF(ContentView.Bounds.Width - 63, 5, 33, 33);
|
|
|
|
|
_headingLabel.Frame = new RectangleF(5, 4, ContentView.Bounds.Width - 63, 25);
|
|
|
|
|
_subheadingLabel.Frame = new RectangleF(100, 18, 100, 20);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sample of a custom cell layout, taken from the iOS docs at
|
|
|
|
|
/// http://developer.xamarin.com/guides/ios/user_interface/tables/part_3_-_customizing_a_table's_appearance/
|
|
|
|
|
/// </summary>
|
2016-03-30 22:01:54 +03:00
|
|
|
|
public class NativeiOSListViewCell : UITableViewCell
|
|
|
|
|
{
|
2016-03-22 23:02:25 +03:00
|
|
|
|
UILabel _headingLabel;
|
|
|
|
|
UILabel _subheadingLabel;
|
|
|
|
|
UIImageView _imageView;
|
|
|
|
|
|
2016-03-30 22:01:54 +03:00
|
|
|
|
public NativeiOSListViewCell(NSString cellId) : base(UITableViewCellStyle.Default, cellId)
|
2016-03-22 23:02:25 +03:00
|
|
|
|
{
|
|
|
|
|
SelectionStyle = UITableViewCellSelectionStyle.Gray;
|
|
|
|
|
|
2016-03-30 22:01:54 +03:00
|
|
|
|
ContentView.BackgroundColor = UIColor.FromRGB(218, 255, 127);
|
2016-03-22 23:02:25 +03:00
|
|
|
|
|
|
|
|
|
_imageView = new UIImageView();
|
|
|
|
|
|
2016-04-17 22:33:52 +03:00
|
|
|
|
_headingLabel = new UILabel()
|
|
|
|
|
{
|
2016-03-22 23:02:25 +03:00
|
|
|
|
Font = UIFont.FromName("Cochin-BoldItalic", 22f),
|
2016-03-30 22:01:54 +03:00
|
|
|
|
TextColor = UIColor.FromRGB(127, 51, 0),
|
2016-03-22 23:02:25 +03:00
|
|
|
|
BackgroundColor = UIColor.Clear
|
|
|
|
|
};
|
|
|
|
|
|
2016-04-17 22:33:52 +03:00
|
|
|
|
_subheadingLabel = new UILabel()
|
|
|
|
|
{
|
2016-03-22 23:02:25 +03:00
|
|
|
|
Font = UIFont.FromName("AmericanTypewriter", 12f),
|
2016-03-30 22:01:54 +03:00
|
|
|
|
TextColor = UIColor.FromRGB(38, 127, 0),
|
2016-03-22 23:02:25 +03:00
|
|
|
|
TextAlignment = UITextAlignment.Center,
|
|
|
|
|
BackgroundColor = UIColor.Clear
|
|
|
|
|
};
|
|
|
|
|
|
2016-03-30 22:01:54 +03:00
|
|
|
|
ContentView.Add(_headingLabel);
|
|
|
|
|
ContentView.Add(_subheadingLabel);
|
|
|
|
|
ContentView.Add(_imageView);
|
2016-03-22 23:02:25 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-30 22:01:54 +03:00
|
|
|
|
public void UpdateCell(string caption, string subtitle, UIImage image)
|
2016-03-22 23:02:25 +03:00
|
|
|
|
{
|
|
|
|
|
_imageView.Image = image;
|
|
|
|
|
_headingLabel.Text = caption;
|
|
|
|
|
_subheadingLabel.Text = subtitle;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-30 22:01:54 +03:00
|
|
|
|
public override void LayoutSubviews()
|
2016-03-22 23:02:25 +03:00
|
|
|
|
{
|
2016-03-30 22:01:54 +03:00
|
|
|
|
base.LayoutSubviews();
|
2016-03-22 23:02:25 +03:00
|
|
|
|
|
|
|
|
|
_imageView.Frame = new RectangleF(ContentView.Bounds.Width - 63, 5, 33, 33);
|
|
|
|
|
_headingLabel.Frame = new RectangleF(5, 4, ContentView.Bounds.Width - 63, 25);
|
|
|
|
|
_subheadingLabel.Frame = new RectangleF(100, 18, 100, 20);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class NativeiOSListViewRenderer : ViewRenderer<NativeListView2, UITableView>
|
|
|
|
|
{
|
2016-03-30 22:01:54 +03:00
|
|
|
|
public NativeiOSListViewRenderer()
|
2016-03-22 23:02:25 +03:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-30 22:01:54 +03:00
|
|
|
|
protected override void OnElementChanged(ElementChangedEventArgs<NativeListView2> e)
|
2016-03-22 23:02:25 +03:00
|
|
|
|
{
|
2016-03-30 22:01:54 +03:00
|
|
|
|
base.OnElementChanged(e);
|
2016-03-22 23:02:25 +03:00
|
|
|
|
|
2016-03-30 22:01:54 +03:00
|
|
|
|
if (Control == null)
|
|
|
|
|
{
|
|
|
|
|
SetNativeControl(new UITableView());
|
2016-03-22 23:02:25 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-30 22:01:54 +03:00
|
|
|
|
if (e.OldElement != null)
|
|
|
|
|
{
|
2016-03-22 23:02:25 +03:00
|
|
|
|
// unsubscribe
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-30 22:01:54 +03:00
|
|
|
|
if (e.NewElement != null)
|
|
|
|
|
{
|
2016-03-22 23:02:25 +03:00
|
|
|
|
// subscribe
|
|
|
|
|
|
2016-03-30 22:01:54 +03:00
|
|
|
|
var s = new NativeiOSListViewSource(e.NewElement);
|
2016-03-22 23:02:25 +03:00
|
|
|
|
Control.Source = s;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-03-30 22:01:54 +03:00
|
|
|
|
|
|
|
|
|
protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
2016-03-22 23:02:25 +03:00
|
|
|
|
{
|
2016-03-30 22:01:54 +03:00
|
|
|
|
base.OnElementPropertyChanged(sender, e);
|
2016-03-22 23:02:25 +03:00
|
|
|
|
|
2016-03-30 22:01:54 +03:00
|
|
|
|
if (e.PropertyName == NativeListView.ItemsProperty.PropertyName)
|
|
|
|
|
{
|
2016-03-22 23:02:25 +03:00
|
|
|
|
// update the Items list in the UITableViewSource
|
2016-03-30 22:01:54 +03:00
|
|
|
|
var s = new NativeiOSListViewSource(Element);
|
2016-03-22 23:02:25 +03:00
|
|
|
|
|
|
|
|
|
Control.Source = s;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-03-30 22:01:54 +03:00
|
|
|
|
|
|
|
|
|
public override SizeRequest GetDesiredSize(double widthConstraint, double heightConstraint)
|
2016-03-22 23:02:25 +03:00
|
|
|
|
{
|
2016-03-30 22:01:54 +03:00
|
|
|
|
return Control.GetSizeRequest(widthConstraint, heightConstraint, 44, 44);
|
2016-03-22 23:02:25 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class NativeListViewRenderer : ViewRenderer<NativeListView, UITableView>
|
|
|
|
|
{
|
2016-03-30 22:01:54 +03:00
|
|
|
|
public NativeListViewRenderer()
|
2016-03-22 23:02:25 +03:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-30 22:01:54 +03:00
|
|
|
|
protected override void OnElementChanged(ElementChangedEventArgs<NativeListView> e)
|
2016-03-22 23:02:25 +03:00
|
|
|
|
{
|
2016-03-30 22:01:54 +03:00
|
|
|
|
base.OnElementChanged(e);
|
2016-03-22 23:02:25 +03:00
|
|
|
|
|
2016-03-30 22:01:54 +03:00
|
|
|
|
if (Control == null)
|
|
|
|
|
{
|
|
|
|
|
SetNativeControl(new UITableView());
|
2016-03-22 23:02:25 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-30 22:01:54 +03:00
|
|
|
|
if (e.OldElement != null)
|
|
|
|
|
{
|
2016-03-22 23:02:25 +03:00
|
|
|
|
// unsubscribe
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-30 22:01:54 +03:00
|
|
|
|
if (e.NewElement != null)
|
|
|
|
|
{
|
2016-03-22 23:02:25 +03:00
|
|
|
|
// subscribe
|
|
|
|
|
|
2016-03-30 22:01:54 +03:00
|
|
|
|
var s = new NativeListViewSource(e.NewElement);
|
2016-03-22 23:02:25 +03:00
|
|
|
|
Control.Source = s;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-03-30 22:01:54 +03:00
|
|
|
|
|
|
|
|
|
protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
2016-03-22 23:02:25 +03:00
|
|
|
|
{
|
2016-03-30 22:01:54 +03:00
|
|
|
|
base.OnElementPropertyChanged(sender, e);
|
2016-03-22 23:02:25 +03:00
|
|
|
|
|
2016-03-30 22:01:54 +03:00
|
|
|
|
if (e.PropertyName == NativeListView.ItemsProperty.PropertyName)
|
|
|
|
|
{
|
2016-03-22 23:02:25 +03:00
|
|
|
|
// update the Items list in the UITableViewSource
|
2016-03-30 22:01:54 +03:00
|
|
|
|
var s = new NativeListViewSource(Element);
|
2016-03-22 23:02:25 +03:00
|
|
|
|
Control.Source = s;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-03-30 22:01:54 +03:00
|
|
|
|
|
|
|
|
|
public override SizeRequest GetDesiredSize(double widthConstraint, double heightConstraint)
|
2016-03-22 23:02:25 +03:00
|
|
|
|
{
|
2016-03-30 22:01:54 +03:00
|
|
|
|
return Control.GetSizeRequest(widthConstraint, heightConstraint, 44, 44);
|
2016-03-22 23:02:25 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class NativeiOSListViewSource : UITableViewSource
|
|
|
|
|
{
|
|
|
|
|
// declare vars
|
|
|
|
|
IList<DataSource> _tableItems;
|
|
|
|
|
NativeListView2 _listView;
|
|
|
|
|
readonly NSString _cellIdentifier = new NSString("TableCell");
|
|
|
|
|
|
2016-03-30 22:01:54 +03:00
|
|
|
|
public IEnumerable<DataSource> Items
|
|
|
|
|
{
|
2016-03-22 23:02:25 +03:00
|
|
|
|
//get{ }
|
2016-09-15 00:56:17 +03:00
|
|
|
|
set { _tableItems = new List<DataSource>(value); }
|
2016-03-22 23:02:25 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-30 22:01:54 +03:00
|
|
|
|
public NativeiOSListViewSource(NativeListView2 view)
|
2016-03-22 23:02:25 +03:00
|
|
|
|
{
|
2016-06-22 17:59:54 +03:00
|
|
|
|
_tableItems = new List<DataSource>(view.Items);
|
2016-03-22 23:02:25 +03:00
|
|
|
|
_listView = view;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Called by the TableView to determine how many cells to create for that particular section.
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
2016-03-30 22:01:54 +03:00
|
|
|
|
public override nint RowsInSection(UITableView tableview, nint section)
|
2016-03-22 23:02:25 +03:00
|
|
|
|
{
|
|
|
|
|
return _tableItems.Count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region user interaction methods
|
|
|
|
|
|
2016-03-30 22:01:54 +03:00
|
|
|
|
public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
|
2016-03-22 23:02:25 +03:00
|
|
|
|
{
|
2016-03-30 22:01:54 +03:00
|
|
|
|
_listView.NotifyItemSelected(_tableItems[indexPath.Row]);
|
|
|
|
|
Console.WriteLine("Row " + indexPath.Row.ToString() + " selected");
|
|
|
|
|
tableView.DeselectRow(indexPath, true);
|
2016-03-22 23:02:25 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-30 22:01:54 +03:00
|
|
|
|
public override void RowDeselected(UITableView tableView, NSIndexPath indexPath)
|
2016-03-22 23:02:25 +03:00
|
|
|
|
{
|
2016-03-30 22:01:54 +03:00
|
|
|
|
Console.WriteLine("Row " + indexPath.Row.ToString() + " deselected");
|
2016-03-22 23:02:25 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Called by the TableView to get the actual UITableViewCell to render for the particular section and row
|
|
|
|
|
/// </summary>
|
2016-03-30 22:01:54 +03:00
|
|
|
|
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
|
2016-03-22 23:02:25 +03:00
|
|
|
|
{
|
|
|
|
|
// request a recycled cell to save memory
|
2016-03-30 22:01:54 +03:00
|
|
|
|
NativeiOSListViewCell cell = tableView.DequeueReusableCell(_cellIdentifier) as NativeiOSListViewCell;
|
2016-03-22 23:02:25 +03:00
|
|
|
|
|
|
|
|
|
// if there are no cells to reuse, create a new one
|
2016-03-30 22:01:54 +03:00
|
|
|
|
if (cell == null)
|
|
|
|
|
{
|
|
|
|
|
cell = new NativeiOSListViewCell(_cellIdentifier);
|
2016-03-22 23:02:25 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-30 22:01:54 +03:00
|
|
|
|
if (string.IsNullOrWhiteSpace(_tableItems[indexPath.Row].ImageFilename))
|
|
|
|
|
{
|
|
|
|
|
cell.UpdateCell(_tableItems[indexPath.Row].Name
|
|
|
|
|
, _tableItems[indexPath.Row].Category
|
2016-03-22 23:02:25 +03:00
|
|
|
|
, null);
|
2016-03-30 22:01:54 +03:00
|
|
|
|
}
|
2016-04-17 22:33:52 +03:00
|
|
|
|
else
|
|
|
|
|
{
|
2016-03-30 22:01:54 +03:00
|
|
|
|
cell.UpdateCell(_tableItems[indexPath.Row].Name
|
2016-03-22 23:02:25 +03:00
|
|
|
|
, _tableItems[indexPath.Row].Category
|
2016-03-30 22:01:54 +03:00
|
|
|
|
, UIImage.FromFile("Images/" + _tableItems[indexPath.Row].ImageFilename + ".jpg"));
|
2016-03-22 23:02:25 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return cell;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class NativeListViewSource : UITableViewSource
|
|
|
|
|
{
|
|
|
|
|
// declare vars
|
|
|
|
|
IList<string> _tableItems;
|
|
|
|
|
string _cellIdentifier = "TableCell";
|
|
|
|
|
NativeListView _listView;
|
|
|
|
|
|
2016-03-30 22:01:54 +03:00
|
|
|
|
public IEnumerable<string> Items
|
|
|
|
|
{
|
2016-06-22 17:59:54 +03:00
|
|
|
|
set { _tableItems = new List<string>(value);
|
|
|
|
|
}
|
2016-03-22 23:02:25 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-30 22:01:54 +03:00
|
|
|
|
public NativeListViewSource(NativeListView view)
|
2016-03-22 23:02:25 +03:00
|
|
|
|
{
|
2016-06-22 17:59:54 +03:00
|
|
|
|
_tableItems = new List<string>(view.Items);
|
2016-03-22 23:02:25 +03:00
|
|
|
|
_listView = view;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-30 22:01:54 +03:00
|
|
|
|
public override nint RowsInSection(UITableView tableview, nint section)
|
2016-03-22 23:02:25 +03:00
|
|
|
|
{
|
|
|
|
|
return _tableItems.Count;
|
|
|
|
|
}
|
2016-03-30 22:01:54 +03:00
|
|
|
|
|
2016-03-22 23:02:25 +03:00
|
|
|
|
#region user interaction methods
|
|
|
|
|
|
2016-03-30 22:01:54 +03:00
|
|
|
|
public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
|
2016-03-22 23:02:25 +03:00
|
|
|
|
{
|
2016-03-30 22:01:54 +03:00
|
|
|
|
_listView.NotifyItemSelected(_tableItems[indexPath.Row]);
|
2016-03-22 23:02:25 +03:00
|
|
|
|
|
2016-03-30 22:01:54 +03:00
|
|
|
|
Console.WriteLine("Row " + indexPath.Row.ToString() + " selected");
|
2016-03-22 23:02:25 +03:00
|
|
|
|
|
2016-03-30 22:01:54 +03:00
|
|
|
|
tableView.DeselectRow(indexPath, true);
|
2016-03-22 23:02:25 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-30 22:01:54 +03:00
|
|
|
|
public override void RowDeselected(UITableView tableView, NSIndexPath indexPath)
|
2016-03-22 23:02:25 +03:00
|
|
|
|
{
|
2016-03-30 22:01:54 +03:00
|
|
|
|
Console.WriteLine("Row " + indexPath.Row.ToString() + " deselected");
|
2016-03-22 23:02:25 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Called by the TableView to get the actual UITableViewCell to render for the particular section and row
|
|
|
|
|
/// </summary>
|
2016-03-30 22:01:54 +03:00
|
|
|
|
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
|
2016-03-22 23:02:25 +03:00
|
|
|
|
{
|
|
|
|
|
// declare vars
|
2016-03-30 22:01:54 +03:00
|
|
|
|
UITableViewCell cell = tableView.DequeueReusableCell(_cellIdentifier);
|
2016-03-22 23:02:25 +03:00
|
|
|
|
//string item = tableItems [indexPath.Row]; //.Items[indexPath.Row];
|
|
|
|
|
|
|
|
|
|
// if there are no cells to reuse, create a new one
|
|
|
|
|
if (cell == null)
|
2016-03-30 22:01:54 +03:00
|
|
|
|
cell = new UITableViewCell(UITableViewCellStyle.Subtitle, _cellIdentifier);
|
2016-03-22 23:02:25 +03:00
|
|
|
|
|
|
|
|
|
// set the item text
|
2016-04-17 22:33:52 +03:00
|
|
|
|
cell.TextLabel.Text = _tableItems[indexPath.Row]; //.Items[indexPath.Row].Heading;
|
2016-03-22 23:02:25 +03:00
|
|
|
|
|
|
|
|
|
// if it's a cell style that supports a subheading, set it
|
|
|
|
|
// if(item.CellStyle == UITableViewCellStyle.Subtitle
|
|
|
|
|
// || item.CellStyle == UITableViewCellStyle.Value1
|
|
|
|
|
// || item.CellStyle == UITableViewCellStyle.Value2)
|
|
|
|
|
// { cell.DetailTextLabel.Text = item.SubHeading; }
|
|
|
|
|
|
|
|
|
|
// if the item has a valid image, and it's not the contact style (doesn't support images)
|
|
|
|
|
// if(!string.IsNullOrEmpty(item.ImageName) && item.CellStyle != UITableViewCellStyle.Value2)
|
|
|
|
|
// {
|
|
|
|
|
// if(File.Exists(item.ImageName))
|
|
|
|
|
// cell.ImageView.Image = UIImage.FromBundle(item.ImageName);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// set the accessory
|
|
|
|
|
cell.Accessory = UITableViewCellAccessory.DisclosureIndicator;
|
|
|
|
|
|
|
|
|
|
return cell;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class CustomContentRenderer : ViewRenderer
|
|
|
|
|
{
|
|
|
|
|
}
|
2016-03-30 22:01:54 +03:00
|
|
|
|
|
|
|
|
|
public class CollectionViewRenderer : ViewRenderer<Bugzilla21177.CollectionView, UICollectionView>
|
|
|
|
|
{
|
|
|
|
|
public void ItemSelected(UICollectionView collectionViewView, NSIndexPath indexPath)
|
|
|
|
|
{
|
|
|
|
|
Element.InvokeItemSelected(indexPath.Row);
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-06 20:23:22 +03:00
|
|
|
|
CollectionViewController _controller;
|
|
|
|
|
|
2016-03-30 22:01:54 +03:00
|
|
|
|
protected override void OnElementChanged(ElementChangedEventArgs<Bugzilla21177.CollectionView> e)
|
|
|
|
|
{
|
|
|
|
|
if (e.NewElement != null)
|
|
|
|
|
{
|
2016-04-17 22:33:52 +03:00
|
|
|
|
var flowLayout = new UICollectionViewFlowLayout
|
|
|
|
|
{
|
2016-03-30 22:01:54 +03:00
|
|
|
|
SectionInset = new UIEdgeInsets(20, 20, 20, 20),
|
|
|
|
|
ScrollDirection = UICollectionViewScrollDirection.Vertical,
|
|
|
|
|
MinimumInteritemSpacing = 5, // minimum spacing between cells
|
|
|
|
|
MinimumLineSpacing = 5 // minimum spacing between rows if ScrollDirection is Vertical or between columns if Horizontal
|
|
|
|
|
};
|
2016-12-06 20:23:22 +03:00
|
|
|
|
_controller = new CollectionViewController(flowLayout, ItemSelected);
|
|
|
|
|
SetNativeControl(_controller.CollectionView);
|
2016-03-30 22:01:54 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
base.OnElementChanged(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class CollectionViewController : UICollectionViewController
|
|
|
|
|
{
|
|
|
|
|
readonly OnItemSelected _onItemSelected;
|
|
|
|
|
static NSString cellId = new NSString("CollectionViewCell");
|
|
|
|
|
List<string> items;
|
|
|
|
|
|
|
|
|
|
public delegate void OnItemSelected(UICollectionView collectionView, NSIndexPath indexPath);
|
|
|
|
|
|
|
|
|
|
public CollectionViewController(UICollectionViewLayout layout, OnItemSelected onItemSelected) : base(layout)
|
|
|
|
|
{
|
2016-06-22 17:59:54 +03:00
|
|
|
|
items = new List<string>();
|
|
|
|
|
for (int i = 0; i < 20; i++) {
|
|
|
|
|
items.Add($"#{i}");
|
|
|
|
|
}
|
2016-03-30 22:01:54 +03:00
|
|
|
|
_onItemSelected = onItemSelected;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void ViewDidLoad()
|
|
|
|
|
{
|
|
|
|
|
base.ViewDidLoad();
|
2016-09-15 00:56:17 +03:00
|
|
|
|
CollectionView.RegisterClassForCell(typeof(CollectionViewCell), cellId);
|
2016-03-30 22:01:54 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override nint NumberOfSections(UICollectionView collectionView)
|
|
|
|
|
{
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override nint GetItemsCount(UICollectionView collectionView, nint section)
|
|
|
|
|
{
|
|
|
|
|
return items.Count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override UICollectionViewCell GetCell(UICollectionView collectionView, NSIndexPath indexPath)
|
|
|
|
|
{
|
|
|
|
|
var cell = (CollectionViewCell)collectionView.DequeueReusableCell(cellId, indexPath);
|
|
|
|
|
cell.Label.Text = items[indexPath.Row];
|
|
|
|
|
return cell;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void ItemSelected(UICollectionView collectionView, NSIndexPath indexPath)
|
|
|
|
|
{
|
|
|
|
|
_onItemSelected(collectionView, indexPath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class CollectionViewCell : UICollectionViewCell
|
|
|
|
|
{
|
2016-04-17 22:33:52 +03:00
|
|
|
|
public UILabel Label { get; private set; }
|
2016-03-30 22:01:54 +03:00
|
|
|
|
|
|
|
|
|
[Export("initWithFrame:")]
|
|
|
|
|
public CollectionViewCell(RectangleF frame) : base(frame)
|
|
|
|
|
{
|
|
|
|
|
var rand = new Random();
|
|
|
|
|
BackgroundView = new UIView { BackgroundColor = UIColor.FromRGB(rand.Next(0, 256), rand.Next(0, 256), rand.Next(0, 256)) };
|
|
|
|
|
SelectedBackgroundView = new UIView { BackgroundColor = UIColor.Green };
|
|
|
|
|
ContentView.Layer.BorderColor = UIColor.LightGray.CGColor;
|
|
|
|
|
ContentView.Layer.BorderWidth = 2.0f;
|
|
|
|
|
Label = new UILabel(frame);
|
|
|
|
|
Label.Center = ContentView.Center;
|
|
|
|
|
ContentView.AddSubview(Label);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-28 13:25:45 +03:00
|
|
|
|
public class TabbedPageWithCustomBarColorRenderer : TabbedRenderer
|
|
|
|
|
{
|
|
|
|
|
public TabbedPageWithCustomBarColorRenderer()
|
|
|
|
|
{
|
|
|
|
|
TabBar.TintColor = UIColor.White;
|
|
|
|
|
TabBar.BarTintColor = UIColor.Purple;
|
|
|
|
|
|
|
|
|
|
//UITabBar.Appearance.TintColor = UIColor.White;
|
|
|
|
|
//UITabBar.Appearance.BarTintColor = UIColor.Purple;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-09-13 14:39:36 +03:00
|
|
|
|
|
|
|
|
|
public class AccessoryViewCellRenderer : ViewCellRenderer
|
|
|
|
|
{
|
|
|
|
|
public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, UITableView tv)
|
|
|
|
|
{
|
|
|
|
|
var cell = base.GetCell(item, reusableCell, tv);
|
|
|
|
|
|
|
|
|
|
// remove highlight on selected cell
|
|
|
|
|
cell.SelectionStyle = UITableViewCellSelectionStyle.None;
|
|
|
|
|
|
|
|
|
|
// iOS right arrow
|
|
|
|
|
cell.Accessory = UITableViewCellAccessory.DisclosureIndicator;
|
|
|
|
|
|
|
|
|
|
return cell;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-06-20 21:12:17 +03:00
|
|
|
|
|
|
|
|
|
public class NoSelectionViewCellRenderer : ViewCellRenderer
|
|
|
|
|
{
|
|
|
|
|
public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, UITableView tv)
|
|
|
|
|
{
|
|
|
|
|
var cell = base.GetCell(item, reusableCell, tv);
|
|
|
|
|
|
|
|
|
|
// remove highlight on selected cell
|
|
|
|
|
cell.SelectionStyle = UITableViewCellSelectionStyle.None;
|
|
|
|
|
|
|
|
|
|
return cell;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-03-22 23:02:25 +03:00
|
|
|
|
}
|
|
|
|
|
|