void SegmentValueChanged(object sender, EventArgs e)
        {
            if (_viewSegment.SelectedSegment == 0)
            {
                if (_previewView != null)
                {
                    _previewView.RemoveFromSuperview();
                    _previewView.Dispose();
                    _previewView = null;
                }

                Add(TextView);
                TextView.BecomeFirstResponder();
            }
            else
            {
                if (_previewView == null)
                {
                    _previewView = new WKWebView(this.View.Bounds, new WKWebViewConfiguration());
                }

                TextView.RemoveFromSuperview();
                Add(_previewView);

                var markdownService = Mvx.Resolve <IMarkdownService>();
                var markdownText = markdownService.Convert(Text);
                var model = new DescriptionModel(markdownText, (int)UIFont.PreferredSubheadline.PointSize);
                var view = new MarkdownView {
                    Model = model
                }.GenerateString();
                _previewView.LoadHtmlString(view, NSBundle.MainBundle.BundleUrl);
            }
        }
Beispiel #2
0
 public override void RemoveFromSuperview()
 {
     IsLoaded = false;
     _webView?.RemoveFromSuperview();
     _webView = null;
     base.RemoveFromSuperview();
 }
        void SegmentValueChanged()
        {
            if (_viewSegment.SelectedSegment == 0)
            {
                if (_previewView != null)
                {
                    _previewView.RemoveFromSuperview();
                    _previewView.Dispose();
                    _previewView = null;
                }

                Add(TextView);
                TextView.BecomeFirstResponder();
            }
            else
            {
                if (_previewView == null)
                {
                    _previewView = new WKWebView(this.View.Bounds, new WKWebViewConfiguration());
                }

                TextView.RemoveFromSuperview();
                Add(_previewView);

                LoadPreview(_previewView).ToBackground();
            }
        }
Beispiel #4
0
        public void AddUrlOverride(string url, Func <string> action)
        {
            if (_webView == null)
            {
                throw new System.Exception("WebView and WebViewClient were not initialized");
            }

            _webViewClient.AddOverrideUrl(url, action);

            var schemeHandler = new TrestleSchemeHandler();

            schemeHandler.AddOverrideUrl(url, action);

            _configuration.SetUrlSchemeHandler(schemeHandler, "trestle");

            _webView.EvaluateJavaScript("document.documentElement.outerHTML.toString()", (NSObject result, NSError err) => {
                if (err != null)
                {
                    System.Console.WriteLine(err);
                }
                if (result != null)
                {
                    _html = result.ToString();
                }
            });

            _webView.RemoveFromSuperview();
            _webView = new WKWebView(_layout.Bounds, _configuration);
            _webView.TranslatesAutoresizingMaskIntoConstraints = false;

            _webView.NavigationDelegate = _webViewClient;

            _layout.AddSubview(_webView);
            NSLayoutConstraint.Create(_webView, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, _layout, NSLayoutAttribute.CenterX, 1f, 0f).Active = true;
            NSLayoutConstraint.Create(_webView, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, _layout, NSLayoutAttribute.CenterY, 1f, 0f).Active = true;
            _webView.SetNeedsDisplay();
            _webView.LoadHtmlString(_html, null);
        }