Esempio n. 1
0
        public RichContentCell() : base(UITableViewCellStyle.Default, ListView.CellId.ToString())
        {
            AutoresizingMask = UIViewAutoresizing.FlexibleWidth;
            SelectionStyle   = UITableViewCellSelectionStyle.None;

            webView = new UIWebView(ContentView.Frame)
            {
                AutoresizingMask  = UIViewAutoresizing.FlexibleWidth,
                BackgroundColor   = null,
                DataDetectorTypes = UIDataDetectorType.Link,
                Opaque            = false
            };

            webView.ShouldStartLoad += (sender, request, type) =>
            {
                if (type == UIWebViewNavigationType.LinkClicked && request?.Url != null)
                {
                    iApp.Navigate(request.Url.ToString());
                    return(false);
                }

                return(true);
            };

            webView.LoadFinished += (sender, e) =>
            {
                webView.Frame = ContentView.Frame;

                if (webView.ScrollView != null)
                {
                    webView.ScrollView.ScrollEnabled = false;
                }

                webView.InvokeOnMainThread(() =>
                {
                    webView.Frame = new CGRect(webView.Frame.X, webView.Frame.Y, webView.Frame.Width, webView.GetDocumentHeight());

                    {
                        var tableView = this.GetSuperview <TableView>();
                        if (tableView != null)
                        {
                            NSIndexPath path = tableView.IndexPathForCell(this);
                            if (path != null)
                            {
                                var frame    = Frame;
                                frame.Height = (float)Math.Min(Math.Max(Math.Min(webView.Frame.Height, MaxHeight), MinHeight), float.MaxValue);
                                Frame        = frame;

                                tableView.ResizeRow(path);
                            }
                            return;
                        }
                    }

                    {
                        var tableView = this.GetSuperview <UITableView>();
                        if (tableView != null)
                        {
                            NSIndexPath path = tableView.IndexPathForCell(this);
                            if (path != null)
                            {
                                var frame     = tableView.RectForRowAtIndexPath(path);
                                nfloat height = frame.Height;
                                frame.Height  = (nfloat)Math.Min(Math.Max(Math.Min((float)webView.Frame.Height, MaxHeight), MinHeight), float.MaxValue);
                                if (height == frame.Height)
                                {
                                    return;
                                }

                                Frame = frame;

                                tableView.BeginUpdates();
                                tableView.ReloadRows(new[] { path }, UITableViewRowAnimation.None);
                                tableView.EndUpdates();
                            }
                        }
                    }
                });
            };

            ContentView.Add(webView);
        }