示例#1
0
        private double ComputeHeight(ImageCell element, CellTableViewCell target)
        {
            double height = 0;
            var    labelPreferredWidth = Globals.LogicalScreenWidth
                                         - defaultImageViewLeftPadding
                                         - element.ImageWidth
                                         - leftPadding
                                         - rightPadding;

            // text
            var textSize = new NSString(target.TextLabel.Text).GetBoundingRect(
                new CGSize((nfloat)labelPreferredWidth, 0),
                NSStringDrawingOptions.UsesLineFragmentOrigin, new UIStringAttributes
            {
                Font = target.TextLabel.Font
            }, null);

            height += textSize.Height;

            // detail
            var detailSize = new NSString(target.DetailTextLabel.Text).GetBoundingRect(
                new CGSize((nfloat)labelPreferredWidth, 0),
                NSStringDrawingOptions.UsesLineFragmentOrigin, new UIStringAttributes
            {
                Font = target.DetailTextLabel.Font
            }, null);

            height += detailSize.Height;

            height = Math.Max(height, element.ImageHeight);

            height += topPadding + bottomPadding;

            return(height);
        }
        async void SetImage(CustomSwitchCell cell, CellTableViewCell target)
        {
            var source = cell.ImageSource;

            target.ImageView.Image = null;

            IImageSourceHandler handler = GetHandler(source);

            if (source != null && handler != null)
            {
                UIImage uiimage;
                try
                {
                    uiimage = await handler.LoadImageAsync(source).ConfigureAwait(false);
                }
                catch (TaskCanceledException)
                {
                    uiimage = null;
                }

                NSRunLoop.Main.BeginInvokeOnMainThread(() =>
                {
                    target.ImageView.Image = uiimage;
                    target.SetNeedsLayout();
                });
            }
            else
            {
                target.ImageView.Image = null;
            }
        }
        public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, UITableView tv)
        {
            var textCell = (TextCell)item;

            var fullName = item.GetType().FullName;
            var cell     = tv.DequeueReusableCell(fullName) as CellTableViewCell;

            if (cell == null)
            {
                cell = new CellTableViewCell(UITableViewCellStyle.Value1, fullName);
            }
            else
            {
                cell.Cell.PropertyChanged -= cell.HandlePropertyChanged;
            }

            cell.Cell = textCell;
            textCell.PropertyChanged += cell.HandlePropertyChanged;
            cell.PropertyChanged      = this.HandlePropertyChanged;

            cell.TextLabel.Text = textCell.Text;

            cell.DetailTextLabel.Text = textCell.Detail;


            UpdateBackground(cell, item);

            return(cell);
        }
示例#4
0
        public override UITableViewCell GetCell(Xamarin.Forms.Cell item, UITableView tv)
        {
            TextCell             textCell       = (TextCell)item;
            UITableViewCellStyle style          = UITableViewCellStyle.Value1;
            string            text              = "Xamarin.Forms.TextCell";
            CellTableViewCell cellTableViewCell = tv.DequeueReusableCell(text) as CellTableViewCell;

            if (cellTableViewCell == null)
            {
                cellTableViewCell = new CellTableViewCell(style, text);
            }
            else
            {
                cellTableViewCell.Cell.PropertyChanged -= new PropertyChangedEventHandler(cellTableViewCell.HandlePropertyChanged);
            }
            cellTableViewCell.Cell                 = textCell;
            textCell.PropertyChanged              += new PropertyChangedEventHandler(cellTableViewCell.HandlePropertyChanged);
            cellTableViewCell.PropertyChanged      = new Action <object, PropertyChangedEventArgs>(this.HandlePropertyChanged);
            cellTableViewCell.TextLabel.Text       = textCell.Text;
            cellTableViewCell.DetailTextLabel.Text = textCell.Detail;
            //cellTableViewCell.TextLabel.TextColor = textCell.TextColor.ToUIColor(TextCellRenderer.DefaultTextColor);
            //cellTableViewCell.DetailTextLabel.TextColor = textCell.DetailColor.ToUIColor(TextCellRenderer.DefaultDetailColor);
            base.UpdateBackground(cellTableViewCell, item);


            cellTableViewCell.Accessory = UITableViewCellAccessory.DisclosureIndicator;

            return(cellTableViewCell);
        }
        public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, UITableView tv)
        {
            var textCell = (TextCell)item;

            var tableViewCell = reusableCell as CellTableViewCell;

            if (tableViewCell == null)
            {
                tableViewCell = new CellTableViewCell(UITableViewCellStyle.Value1, item.GetType().FullName);
            }
            else
            {
                tableViewCell.Cell.PropertyChanged -= tableViewCell.HandlePropertyChanged;
            }

            tableViewCell.Cell            = textCell;
            textCell.PropertyChanged     += tableViewCell.HandlePropertyChanged;
            tableViewCell.PropertyChanged = HandlePropertyChanged;

            tableViewCell.TextLabel.Text       = textCell.Text;
            tableViewCell.DetailTextLabel.Text = textCell.Detail;

            WireUpForceUpdateSizeRequested(item, tableViewCell, tv);

            UpdateIsEnabled(tableViewCell, textCell);

            UpdateBackground(tableViewCell, item);
            tableViewCell.Accessory = UITableViewCellAccessory.DisclosureIndicator;

            return(tableViewCell);
        }
示例#6
0
 UIView CreateBackgroundView(CellTableViewCell cell, FullScheduleCellViewModel viewModel)
 {
     return(new UIView {
         AutoresizingMask = UIViewAutoresizing.FlexibleHeight,
         Frame = cell.Bounds,
         BackgroundColor = ((Xamarin.Forms.Color) new TrackBackgroundColorConverter()
                            .Convert(viewModel.Track, typeof(Xamarin.Forms.Color),
                                     null, CultureInfo.CurrentCulture))
                           .ToUIColor()
     });
 }
示例#7
0
        private void UpdateIsEnabled(CellTableViewCell cell, CheckBoxCell checkBoxCell)
        {
            cell.UserInteractionEnabled  = checkBoxCell.IsEnabled;
            cell.TextLabel.Enabled       = checkBoxCell.IsEnabled;
            cell.DetailTextLabel.Enabled = checkBoxCell.IsEnabled;
            var bemCheckBox = cell.AccessoryView as BEMCheckBox;

            if (bemCheckBox != null)
            {
                bemCheckBox.Enabled = checkBoxCell.IsEnabled;
            }
        }
        public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, UITableView tv)
        {
            var tvc = reusableCell as CellTableViewCell;

            if (tvc == null)
            {
                tvc = new CellTableViewCell(UITableViewCellStyle.Value1, item.GetType().FullName);
            }
            tvc.Cell = item;
            var cell = base.GetCell(item, tvc, tv);

            cell.SetDisclosure(item.StyleId);
            return(cell);
        }
示例#9
0
 private void RenderCircle(ImageCell element, CellTableViewCell target)
 {
     if (element.RenderCircle)
     {
         double num = Math.Min(element.ImageWidth, element.ImageHeight);
         target.ImageView.Layer.CornerRadius  = (nfloat)(num / 2);
         target.ImageView.Layer.MasksToBounds = false;
         target.ImageView.ClipsToBounds       = true;
     }
     else
     {
         target.ImageView.Layer.CornerRadius = 0;
     }
 }
 // Start of BugFix
 static Action SetImage(CellTableViewCell target, UIImage uiimage)
 {
     return(() =>
     {
         if (target.Cell != null)
         {
             target.ImageView.Image = uiimage;
             target.SetNeedsLayout();
         }
         else
         {
             uiimage?.Dispose();
         }
     });
 }
示例#11
0
        public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, UITableView tv)
        {
            if (!(reusableCell is CellTableViewCell tvc))
            {
                tvc = new CellTableViewCell(UITableViewCellStyle.Value1, CellName);
            }
            var pc = item as PickerCell;

            pc.SetValue(ReusableCellProperty, tvc);
            pc.Tapped               += ShowTap;
            pc.PropertyChanged      += HandlePropertyChanged;
            tvc.TextLabel.Text       = pc.Title;
            tvc.DetailTextLabel.Text = pc.Items[pc.SelectedIndex];
            tvc.Accessory            = UITableViewCellAccessory.DisclosureIndicator;
            return(tvc);
        }
示例#12
0
        void AddSubviews(FullScheduleCellViewModel viewModel, CellTableViewCell cellTableViewCell)
        {
            var textColor = ((Xamarin.Forms.Color) new TrackTextColorConverter()
                             .Convert(viewModel.Track, typeof(Xamarin.Forms.Color),
                                      null, CultureInfo.CurrentCulture))
                            .ToUIColor();

            cellTableViewCell.AddSubview(CreateBackgroundView(cellTableViewCell, viewModel));
            cellTableViewCell.AddSubview(CreateTitleLabel(viewModel, textColor));
            cellTableViewCell.AddSubview(CreateLocationLabel(viewModel, textColor));
            cellTableViewCell.AddSubview(CreateTrackLabel(viewModel, textColor));

            if (viewModel.IsOptional)
            {
                cellTableViewCell.AddSubview(
                    CreateSelectButton(viewModel, textColor, cellTableViewCell));
            }
        }
示例#13
0
        private void OnCheckBoxValueChanged(object sender, EventArgs eventArgs)
        {
            var view = (UIView)sender;
            var cb   = (BEMCheckBox)view;

            CellTableViewCell realCell = null;

            while (view.Superview != null && realCell == null)
            {
                view     = view.Superview;
                realCell = view as CellTableViewCell;
            }

            if (realCell != null)
            {
                ((CheckBoxCell)realCell.Cell).On = cb.On;
            }
        }
示例#14
0
        private async void SetImage(ImageCell cell, CellTableViewCell target)
        {
            ImageSource imageSource = cell.ImageSource;

            if (imageSource != null)
            {
                UIImage uiimage;
                try
                {
                    uiimage = await cell.ImageSource.GetUIImage();
                }
                catch (TaskCanceledException)
                {
                    uiimage = null;
                }

                if (uiimage == null)
                {
                    if (cell.ImagePlaceholder != null)
                    {
                        uiimage = UIImage.FromBundle(cell.ImagePlaceholder.File);
                    }
                }

                NSRunLoop.Main.BeginInvokeOnMainThread(delegate
                {
                    if (uiimage != null && cell.ImageWidth > 0 && cell.ImageHeight > 0)
                    {
                        target.ImageView.Image = uiimage.Scale(new CGSize((nfloat)cell.ImageWidth, (nfloat)cell.ImageHeight), 0);
                    }
                    else
                    {
                        target.ImageView.Image = uiimage;
                    }

                    target.SetNeedsLayout();
                });
            }
            else
            {
                target.ImageView.Image = null;
            }
        }
示例#15
0
        public override UIKit.UITableViewCell GetCell(Xamarin.Forms.Cell item, UIKit.UITableViewCell reusableCell, UIKit.UITableView tv)
        {
            var         tvc         = reusableCell as CellTableViewCell;
            BEMCheckBox bemCheckBox = null;

            if (tvc == null)
            {
                tvc = new CellTableViewCell(UIKit.UITableViewCellStyle.Value1, CellName);
            }
            else
            {
                bemCheckBox = tvc.AccessoryView as BEMCheckBox;
                tvc.Cell.PropertyChanged -= OnCellPropertyChanged;
            }

            SetRealCell(item, tvc);

            if (bemCheckBox == null)
            {
                bemCheckBox = new BEMCheckBox(Constants.CheckBoxSize);
                bemCheckBox.ValueChanged += OnCheckBoxValueChanged;
                tvc.AccessoryView         = bemCheckBox;
            }

            var boolCell = (CheckBoxCell)item;

            tvc.Cell = item;
            tvc.Cell.PropertyChanged += OnCellPropertyChanged;
            tvc.AccessoryView         = bemCheckBox;
            tvc.TextLabel.Text        = boolCell.Text;

            bemCheckBox.On = boolCell.On;

            WireUpForceUpdateSizeRequested(item, tvc, tv);

            UpdateBackground(tvc, item);
            UpdateIsEnabled(tvc, boolCell);

            return(tvc);
        }
示例#16
0
        // Method partially copied from TextCellRenderer.
        // Can't base() since we need to create the UITableViewCell in our version of the method.
        public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, UITableView tv)
        {
            var textCell = (TabiTextCell)item;

            var tvc = reusableCell as CellTableViewCell;

            if (tvc == null)
            {
                // Change 1: use our selected cellstyle
                UITableViewCellStyle cellStyle = StringToStyle(textCell.UITableViewStyle);
                tvc = new CellTableViewCell(cellStyle, item.GetType().FullName);
            }
            else
            {
                tvc.Cell.PropertyChanged -= tvc.HandlePropertyChanged;
            }

            tvc.Cell = textCell;
            textCell.PropertyChanged += tvc.HandlePropertyChanged;
            tvc.PropertyChanged       = HandlePropertyChanged;

            tvc.TextLabel.Text            = textCell.Text;
            tvc.DetailTextLabel.Text      = textCell.Detail;
            tvc.TextLabel.TextColor       = textCell.TextColor.ToUIColor(DefaultTextColor);
            tvc.DetailTextLabel.TextColor = textCell.DetailColor.ToUIColor(DefaultDetailColor);

            // Change 2: add accessory
            tvc.Accessory = StringToAccessoryType(textCell.UITableViewCellAccessory);

            WireUpForceUpdateSizeRequested(item, tvc, tv);

            UpdateIsEnabled(tvc, textCell);

            UpdateBackground(tvc, item);

            return(tvc);
        }
        async void SetImage(ImageCell cell, CellTableViewCell target)
        {
            var source = cell.ImageSource;

            target.ImageView.Image = null;

            IImageSourceHandler handler;

            if (source != null && (handler = Xamarin.Forms.Internals.Registrar.Registered.GetHandlerForObject <IImageSourceHandler>(source)) != null)
            {
                UIImage uiimage;
                try
                {
                    uiimage = await handler.LoadImageAsync(source).ConfigureAwait(false);
                }
                catch (TaskCanceledException)
                {
                    uiimage = null;
                }

                // Start of BugFix
                if (NSThread.Current.IsMainThread)
                {
                    SetImage(target, uiimage).Invoke();
                }
                else
                {
                    NSRunLoop.Main.BeginInvokeOnMainThread(SetImage(target, uiimage));
                }
                // end of bugfix
            }
            else
            {
                target.ImageView.Image = null;
            }
        }
        public override UITableViewCell GetCell(Cell item, UITableView tv)
        {
            var extendedCell = (ExtendedTextCell)item;

            TextCell             textCell = (TextCell)item;
            UITableViewCellStyle style    = UITableViewCellStyle.Subtitle;

            if (extendedCell.DetailLocation == Xamarin.Forms.Labs.Enums.TextCellDetailLocation.Right)
            {
                style = UITableViewCellStyle.Value1;
            }

            string            fullName = item.GetType().FullName;
            CellTableViewCell cell     = tv.DequeueReusableCell(fullName) as CellTableViewCell;

            if (cell == null)
            {
                cell = new CellTableViewCell(style, fullName);
            }
            else
            {
                cell.Cell.PropertyChanged -= new PropertyChangedEventHandler(cell.HandlePropertyChanged);
            }
            cell.Cell = textCell;
            textCell.PropertyChanged      += new PropertyChangedEventHandler(cell.HandlePropertyChanged);
            cell.PropertyChanged           = new Action <object, PropertyChangedEventArgs> (this.HandlePropertyChanged);
            cell.TextLabel.Text            = textCell.Text;
            cell.DetailTextLabel.Text      = textCell.Detail;
            cell.TextLabel.TextColor       = textCell.TextColor.ToUIColor(ExtendedTextCellRenderer.DefaultTextColor);
            cell.DetailTextLabel.TextColor = textCell.DetailColor.ToUIColor(ExtendedTextCellRenderer.DefaultDetailColor);

            base.UpdateBackground(cell, item);

            if (cell != null)
            {
                cell.BackgroundColor = extendedCell.BackgroundColor.ToUIColor();
                cell.SeparatorInset  = new UIEdgeInsets((float)extendedCell.SeparatorPadding.Top, (float)extendedCell.SeparatorPadding.Left,
                                                        (float)extendedCell.SeparatorPadding.Bottom, (float)extendedCell.SeparatorPadding.Right);

                if (extendedCell.ShowDisclousure)
                {
                    cell.Accessory = MonoTouch.UIKit.UITableViewCellAccessory.DisclosureIndicator;
                    if (!string.IsNullOrEmpty(extendedCell.DisclousureImage))
                    {
                        var detailDisclosureButton = UIButton.FromType(UIButtonType.Custom);
                        detailDisclosureButton.SetImage(UIImage.FromBundle(extendedCell.DisclousureImage), UIControlState.Normal);
                        detailDisclosureButton.SetImage(UIImage.FromBundle(extendedCell.DisclousureImage), UIControlState.Selected);

                        detailDisclosureButton.Frame          = new RectangleF(0f, 0f, 30f, 30f);
                        detailDisclosureButton.TouchUpInside += (object sender, EventArgs e) => {
                            var index = tv.IndexPathForCell(cell);
                            tv.SelectRow(index, true, UITableViewScrollPosition.None);
                            tv.Source.AccessoryButtonTapped(tv, index);
                        };
                        cell.AccessoryView = detailDisclosureButton;
                    }
                }
            }

            if (!extendedCell.ShowSeparator)
            {
                tv.SeparatorStyle = UITableViewCellSeparatorStyle.None;
            }

            tv.SeparatorColor = extendedCell.SeparatorColor.ToUIColor();

            return(cell);
        }
示例#19
0
 // Method copied from TextCellRenderer. Can't override since it's private.
 static void UpdateIsEnabled(CellTableViewCell cell, TextCell entryCell)
 {
     cell.UserInteractionEnabled  = entryCell.IsEnabled;
     cell.TextLabel.Enabled       = entryCell.IsEnabled;
     cell.DetailTextLabel.Enabled = entryCell.IsEnabled;
 }
示例#20
0
        /// <summary>
        /// Gets the cell.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="reusableCell">The reusable TableView cell.</param>
        /// <param name="tv">The TableView.</param>
        /// <returns>UITableViewCell.</returns>
        public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, UITableView tv)
        {
            var extendedCell = (ExtendedTextCell)item;

            var textCell = (TextCell)item;
            var style    = extendedCell.DetailLocation == TextCellDetailLocation.Right ?
                           UITableViewCellStyle.Value1 :
                           UITableViewCellStyle.Subtitle;

            var fullName = item.GetType().FullName;
            var cell     = tv.DequeueReusableCell(fullName) as CellTableViewCell;

            if (cell == null)
            {
                cell = new CellTableViewCell(style, fullName);
            }
            else
            {
                cell.Cell.PropertyChanged -= cell.HandlePropertyChanged;
            }

            cell.Cell = textCell;
            textCell.PropertyChanged      += cell.HandlePropertyChanged;
            cell.PropertyChanged           = this.HandlePropertyChanged;
            cell.TextLabel.Text            = textCell.Text;
            cell.DetailTextLabel.Text      = textCell.Detail;
            cell.TextLabel.TextColor       = textCell.TextColor.ToUIColor(DefaultTextColor);
            cell.DetailTextLabel.TextColor = textCell.DetailColor.ToUIColor(DefaultDetailColor);

            UpdateBackground(cell, item);

            cell.BackgroundColor = extendedCell.BackgroundColor.ToUIColor();
            cell.SeparatorInset  = new UIEdgeInsets(
                (nfloat)extendedCell.SeparatorPadding.Top,
                (nfloat)extendedCell.SeparatorPadding.Left,
                (nfloat)extendedCell.SeparatorPadding.Bottom,
                (nfloat)extendedCell.SeparatorPadding.Right);

            if (extendedCell.ShowDisclousure)
            {
                cell.Accessory = UITableViewCellAccessory.DisclosureIndicator;
                if (!string.IsNullOrEmpty(extendedCell.DisclousureImage))
                {
                    var detailDisclosureButton = UIButton.FromType(UIButtonType.Custom);
                    detailDisclosureButton.SetImage(UIImage.FromBundle(extendedCell.DisclousureImage), UIControlState.Normal);
                    detailDisclosureButton.SetImage(UIImage.FromBundle(extendedCell.DisclousureImage), UIControlState.Selected);

                    detailDisclosureButton.Frame          = new CGRect(0f, 0f, 30f, 30f);
                    detailDisclosureButton.TouchUpInside += (sender, e) =>
                    {
                        var index = tv.IndexPathForCell(cell);
                        tv.SelectRow(index, true, UITableViewScrollPosition.None);
                        tv.Source.AccessoryButtonTapped(tv, index);
                    };
                    cell.AccessoryView = detailDisclosureButton;
                }
            }

            if (!extendedCell.ShowSeparator)
            {
                tv.SeparatorStyle = UITableViewCellSeparatorStyle.None;
            }

            tv.SeparatorColor = extendedCell.SeparatorColor.ToUIColor();

            return(cell);
        }
示例#21
0
 private void SetDetailFont(ImageCell element, CellTableViewCell target)
 {
     target.DetailTextLabel.Font = UIFont.FromName(element.DetailFontFamily, (nfloat)element.DetailFontSize);
 }