I dont' get why it's always null.. presumably there's a flyweight impl piggy backing off iOS's tableview renderer here, or this parameter wouldn't exist - but it's always null and as such my cell always get's recreated.. I don't get what's wrong..
here's the codez:
using System;
using Xamarin.Forms;
using TwinEvents.Core.Media.View;
using TwinEvents.Ios.Media;
using Xamarin.Forms.Platform.iOS;
using UIKit;
using CoreGraphics;
using System.Threading.Tasks;
using TwinEvents.Core.Media.Model;
using SDWebImage;
using Foundation;
[assembly: ExportRenderer (typeof(MediaCell), typeof(MediaCellRenderer))]
namespace TwinEvents.Ios.Media
{
internal class NativeMediaCell : UITableViewCell
{
UIImageView _imageView;
UIImageView _thumbnailImageView;
UILabel _label;
UILabel _nameLabel;
public NativeMediaCell (NSString cellId) : base (UITableViewCellStyle.Default, cellId)
{
_imageView = new UIImageView (new CGRect (0, 0, 320, 260));
_thumbnailImageView = new UIImageView (new CGRect (5, 245, 40, 40));
_label = new UILabel (new CGRect (50, 245, 320, 20));
_nameLabel = new UILabel (new CGRect (0, 270, 320, 40));
_label.TextColor = UIColor.White;
_nameLabel.TextColor = UIColor.White;
ContentView.AddSubview (_imageView);
ContentView.AddSubview (_thumbnailImageView);
ContentView.AddSubview (_nameLabel);
ContentView.AddSubview (_label);
ContentView.BackgroundColor = UIColor.Black;
}
internal void UpdateValues (IMediaItem item)
{
if (item.ImagePath == null) {
_imageView.Image = UIImage.FromFile ("placeholder.png");
} else {
_imageView.SetImage (
url: new NSUrl (item.ImagePath.AbsoluteUri),
placeholder: UIImage.FromBundle ("placeholder.png")
);
}
if (item.UserThumbnailPath == null) {
_thumbnailImageView.Image = UIImage.FromFile ("placeholder.png");
} else {
_thumbnailImageView.SetImage (
url: new NSUrl (item.UserThumbnailPath.AbsoluteUri),
placeholder: UIImage.FromBundle ("placeholder.png")
);
}
_nameLabel.Text = item.Name;
}
public override void LayoutSubviews ()
{
base.LayoutSubviews ();
_imageView.Frame = new CGRect (0, 0, Frame.Width, 260);
_thumbnailImageView.Frame = new CGRect (5, 245, 40, 40);
_label.Frame = new CGRect (50, 245, Frame.Width - 50, 20);
_nameLabel.Frame = new CGRect (50, 270, Frame.Width - 50, 40);
}
}
public class MediaCellRenderer : ViewCellRenderer
{
public MediaCellRenderer ()
{
}
NSString cellId = new NSString ("Cell");
public override UITableViewCell GetCell (Cell item, UITableViewCell reusableCell, UITableView tv)
{
NativeMediaCell nativeCell = reusableCell as NativeMediaCell;
if (nativeCell == null) {
nativeCell = new NativeMediaCell (cellId);
}
var mediaCell = item as MediaCell;
nativeCell.UpdateValues (mediaCell.Item);
return nativeCell;
}
//
// protected override void OnElementPropertyChanged (object sender, System.ComponentModel.PropertyChangedEventArgs e)
// {
// base.OnElementPropertyChanged (sender, e);
// if (e.PropertyName == "Item") {
// UpdateValues (((MediaCell)sender).Item);
// }
// }
//
}
}