Exemplo n.º 1
0
        public void RecycleCell(object data, DataTemplate dataTemplate, VisualElement parent)
        {
            if (_viewCell == null)
            {
                _viewCell = (dataTemplate.CreateContent() as FastGridCell);

                //reflection method of setting isplatformenabled property
                // We are going to re - set the Platform here because in some cases (headers mostly) its possible this is unset and
                //   when the binding context gets updated the measure passes will all fail.By applying this here the Update call
                // further down will result in correct layouts.
                //var p = PlatformProperty.GetValue(parent);
                //PlatformProperty.SetValue(_viewCell, p);

                _viewCell.BindingContext = data;
                _viewCell.Parent         = parent;
                _viewCell.PrepareCell(new Size(Bounds.Width, Bounds.Height));
                _originalBindingContext = _viewCell.BindingContext;
                var renderer = Platform.CreateRenderer(_viewCell.View); //RendererFactory.GetRenderer (_viewCell.View);
                _view = renderer.NativeView;

                _view.AutoresizingMask = UIViewAutoresizing.All;
                _view.ContentMode      = UIViewContentMode.ScaleToFill;

                ContentView.AddSubview(_view);
                return;
            }
            else if (data == _originalBindingContext)
            {
                _viewCell.BindingContext = _originalBindingContext;
            }
            else
            {
                _viewCell.BindingContext = data;
            }
        }
        public void RecycleCell(object data, FastGridTemplateSelector dataTemplate, VisualElement parent)
        {
            if (ViewCell == null)
            {
                var cellSize = new Size(Bounds.Width, Bounds.Height);

                if (!(dataTemplate is FastGridTemplateSelector templateSelector))
                {
                    throw new NotSupportedException(@"DataTemplate should be FastGridTemplateSelector");
                }

                var template = templateSelector.SelectTemplate(data) as FastGridDataTemplate;
                ViewCell = template?.CreateContent() as FastGridCell;
                cellSize = template?.CellSize ?? cellSize;

                if (ViewCell != null)
                {
                    ViewCell.BindingContext = data;
                    ViewCell.PrepareCell(cellSize);
                    ViewCell.Parent = parent;

                    _originalBindingContext = data;
                    _view = ConvertFormsToNative(ViewCell.View, new Rectangle(new Point(0, 0), cellSize));
                }

                if (_view == null)
                {
                    return;
                }

                _view.AutoresizingMask = UIViewAutoresizing.All;
                _view.ContentMode      = UIViewContentMode.ScaleAspectFit;
                _view.ClipsToBounds    = true;

                ContentView.AddSubview(_view);
            }
            else if (data == _originalBindingContext)
            {
                ViewCell.BindingContext = _originalBindingContext;
            }
            else
            {
                ViewCell.BindingContext = data;
            }

            var gr = GestureRecognizers;

            if (gr != null && gr.Length > 0)
            {
                gr.ForEach(RemoveGestureRecognizer);
            }

            _tapGestureRecognizer = new UITapGestureRecognizer(Tapped);
            AddGestureRecognizer(_tapGestureRecognizer);
        }
Exemplo n.º 3
0
 public object GetBindingContextForReusedCell(FastGridCell cell)
 {
     if (OriginalBindingContextsForReusedItems.ContainsKey(cell))
     {
         return(OriginalBindingContextsForReusedItems [cell]);
     }
     else
     {
         return(null);
     }
 }
Exemplo n.º 4
0
 public void RecycleCell(Android.Views.View view, FastGridCell newCell)
 {
     if (CellItemsByCoreCells.ContainsKey(view))
     {
         var reusedItem = CellItemsByCoreCells [view];
         if (OriginalBindingContextsForReusedItems.ContainsKey(newCell))
         {
             reusedItem.BindingContext = OriginalBindingContextsForReusedItems [newCell];
         }
         else
         {
             reusedItem.BindingContext = newCell.BindingContext;
         }
     }
 }
        protected override void Dispose(bool disposing)
        {
            if (_tapGestureRecognizer != null)
            {
                Device.BeginInvokeOnMainThread(() => {
                    RemoveGestureRecognizer(_tapGestureRecognizer);
                    _tapGestureRecognizer = null;
                });
            }
            ;
            _view = null;
            _originalBindingContext = null;
            if (ViewCell != null)
            {
                ViewCell.BindingContext = null;
                ViewCell.Parent         = null;
                ViewCell = null;
            }

            base.Dispose(disposing);
        }
Exemplo n.º 6
0
 void CacheBindingContextForReusedCell(FastGridCell cell)
 {
     OriginalBindingContextsForReusedItems [cell] = cell.BindingContext;
 }
Exemplo n.º 7
0
 public void CacheCell(FastGridCell cell, Android.Views.View view)
 {
     CellItemsByCoreCells [view] = cell;
     OriginalBindingContextsForReusedItems [cell] = cell.BindingContext;
 }