From 45d7dc72d32f14dc1b21ae7c82c27cfc2910ae27 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Wed, 12 Oct 2016 02:08:16 +0200 Subject: [PATCH] fixes heiht request from MD --- BookAStar/BookAStar.Droid/MarkdownEditor.cs | 6 +++++- .../BookAStar.Droid/MarkdownEditor.cshtml | 4 ++++ .../BookAStar.Droid/MarkdownViewRenderer.cs | 20 ++++++++++--------- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/BookAStar/BookAStar.Droid/MarkdownEditor.cs b/BookAStar/BookAStar.Droid/MarkdownEditor.cs index 2dbf1da5..cc3d106b 100644 --- a/BookAStar/BookAStar.Droid/MarkdownEditor.cs +++ b/BookAStar/BookAStar.Droid/MarkdownEditor.cs @@ -17,7 +17,7 @@ using System.Linq; using System.Text; -[System.CodeDom.Compiler.GeneratedCodeAttribute("RazorTemplatePreprocessor", "4.2.0.680")] +[System.CodeDom.Compiler.GeneratedCodeAttribute("RazorTemplatePreprocessor", "4.2.0.703")] public partial class MarkdownEditor : MarkdownEditorBase { @@ -143,6 +143,10 @@ WriteLiteral(@"> invokeCSharpAction(getMD()); } }); + $(document).ready(function () { + // TODO implement a dedicated injection + invokeCSharpAction(getMD()); + }); diff --git a/BookAStar/BookAStar.Droid/MarkdownEditor.cshtml b/BookAStar/BookAStar.Droid/MarkdownEditor.cshtml index 86e90cf4..f384e392 100644 --- a/BookAStar/BookAStar.Droid/MarkdownEditor.cshtml +++ b/BookAStar/BookAStar.Droid/MarkdownEditor.cshtml @@ -63,6 +63,10 @@ invokeCSharpAction(getMD()); } }); + $(document).ready(function () { + // TODO implement a dedicated injection + invokeCSharpAction(getMD()); + }); diff --git a/BookAStar/BookAStar.Droid/MarkdownViewRenderer.cs b/BookAStar/BookAStar.Droid/MarkdownViewRenderer.cs index f811ac02..389f4e2a 100644 --- a/BookAStar/BookAStar.Droid/MarkdownViewRenderer.cs +++ b/BookAStar/BookAStar.Droid/MarkdownViewRenderer.cs @@ -11,11 +11,11 @@ using Android.Views; [assembly: Xamarin.Forms.ExportRenderer(typeof(MarkdownView), typeof(MarkdownViewRenderer))] namespace BookAStar.Droid { - public class JSBridge : Java.Lang.Object + public class JsBridgeMarkdown : Java.Lang.Object { readonly WeakReference hybridWebViewRenderer; - public JSBridge(MarkdownViewRenderer hybridRenderer) + public JsBridgeMarkdown(MarkdownViewRenderer hybridRenderer) { hybridWebViewRenderer = new WeakReference(hybridRenderer); } @@ -29,7 +29,7 @@ namespace BookAStar.Droid if (hybridWebViewRenderer != null && hybridWebViewRenderer.TryGetTarget(out hybridRenderer)) { hybridRenderer.Element.Markdown = data; - MarkdownViewRenderer.OnPageFinished(hybridRenderer.Element, + MarkdownViewRenderer.ProperOnPageFinished(hybridRenderer.Element, hybridRenderer.EditorView); } } @@ -51,16 +51,18 @@ namespace BookAStar.Droid return editorView; } } - - public static async void OnPageFinished(MarkdownView xview, WebView view) + /// + /// To be called once document finished loading + /// + /// + /// + public static async void AdjustHeightRequest(MarkdownView xview, WebView view) { - int i = 10; - while (view.ContentHeight == 0 && i-- > 0) // wait here till content is rendered - await System.Threading.Tasks.Task.Delay(100); xview.BatchBegin(); xview.HeightRequest = view.ContentHeight; xview.BatchCommit(); } + private void SetMDEditorText(string text) { editorTemplate.Model = (text == null) ? null : markdown.Transform(text); @@ -87,7 +89,7 @@ namespace BookAStar.Droid var viewclient = new MarkdownWebViewClient( md => { e.NewElement.Markdown = md; }); EditorView.SetWebViewClient(viewclient); - Control.AddJavascriptInterface(new JSBridge(this), "jsBridge"); + Control.AddJavascriptInterface(new JsBridgeMarkdown(this), "jsBridge"); SetMDEditorText(e.NewElement.Markdown); InjectJS(JavaScriptFunction); }