From 12ba223dc455bb4d1748a3a35ebd59f1b111b297 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Wed, 12 Oct 2016 03:52:18 +0200 Subject: [PATCH] makes the height adjustment more clean (no more sleep(100)) --- BookAStar/BookAStar.Droid/MarkdownEditor.cs | 36 +++++++++---------- .../BookAStar.Droid/MarkdownEditor.cshtml | 34 +++++++++--------- .../BookAStar.Droid/MarkdownViewRenderer.cs | 9 ++--- 3 files changed, 40 insertions(+), 39 deletions(-) diff --git a/BookAStar/BookAStar.Droid/MarkdownEditor.cs b/BookAStar/BookAStar.Droid/MarkdownEditor.cs index cc3d106b..5f79ee21 100644 --- a/BookAStar/BookAStar.Droid/MarkdownEditor.cs +++ b/BookAStar/BookAStar.Droid/MarkdownEditor.cs @@ -126,24 +126,24 @@ WriteLiteral(@"> ['clean'] // remove formatting button ]; - var quill = new Quill('#bubble-container', { - modules: { - toolbar: toolbarOptions - }, - placeholder: 'Composez votre texte ...', - theme: 'snow' - }); - - function getMD() { - return markdownize($('#bubble-container div.ql-editor').html()) - } - quill.on('text-change', function (delta, oldDelta, source) - { - if (source === ""user"") { - invokeCSharpAction(getMD()); - } - }); - $(document).ready(function () { + + $(document).ready(function () { + var quill = new Quill('#bubble-container', { + modules: { + toolbar: toolbarOptions + }, + placeholder: 'Composez votre texte ...', + theme: 'snow' + }); + + function getMD() { + return markdownize($('#bubble-container div.ql-editor').html()) + } + quill.on('text-change', function (delta, oldDelta, source) { + if (source === ""user"") { + invokeCSharpAction(getMD()); + } + }); // TODO implement a dedicated injection invokeCSharpAction(getMD()); }); diff --git a/BookAStar/BookAStar.Droid/MarkdownEditor.cshtml b/BookAStar/BookAStar.Droid/MarkdownEditor.cshtml index f384e392..5001aa25 100644 --- a/BookAStar/BookAStar.Droid/MarkdownEditor.cshtml +++ b/BookAStar/BookAStar.Droid/MarkdownEditor.cshtml @@ -46,24 +46,24 @@ ['clean'] // remove formatting button ]; - var quill = new Quill('#bubble-container', { - modules: { - toolbar: toolbarOptions - }, - placeholder: 'Composez votre texte ...', - theme: 'snow' - }); + + $(document).ready(function () { + var quill = new Quill('#bubble-container', { + modules: { + toolbar: toolbarOptions + }, + placeholder: 'Composez votre texte ...', + theme: 'snow' + }); - function getMD() { - return markdownize($('#bubble-container div.ql-editor').html()) - } - quill.on('text-change', function (delta, oldDelta, source) - { - if (source === "user") { - invokeCSharpAction(getMD()); - } - }); - $(document).ready(function () { + function getMD() { + return markdownize($('#bubble-container div.ql-editor').html()) + } + quill.on('text-change', function (delta, oldDelta, source) { + if (source === "user") { + invokeCSharpAction(getMD()); + } + }); // TODO implement a dedicated injection invokeCSharpAction(getMD()); }); diff --git a/BookAStar/BookAStar.Droid/MarkdownViewRenderer.cs b/BookAStar/BookAStar.Droid/MarkdownViewRenderer.cs index 389f4e2a..f4514e7b 100644 --- a/BookAStar/BookAStar.Droid/MarkdownViewRenderer.cs +++ b/BookAStar/BookAStar.Droid/MarkdownViewRenderer.cs @@ -29,7 +29,7 @@ namespace BookAStar.Droid if (hybridWebViewRenderer != null && hybridWebViewRenderer.TryGetTarget(out hybridRenderer)) { hybridRenderer.Element.Markdown = data; - MarkdownViewRenderer.ProperOnPageFinished(hybridRenderer.Element, + MarkdownViewRenderer.AdjustHeightRequest(hybridRenderer.Element, hybridRenderer.EditorView); } } @@ -58,8 +58,10 @@ namespace BookAStar.Droid /// public static async void AdjustHeightRequest(MarkdownView xview, WebView view) { + xview.BatchBegin(); - xview.HeightRequest = view.ContentHeight; + var vch = view.ContentHeight; // FIXME why not 3? + xview.HeightRequest = vch > xview.MinimumHeightRequest ? vch : xview.MinimumHeightRequest; xview.BatchCommit(); } @@ -69,7 +71,6 @@ namespace BookAStar.Droid var html = editorTemplate.GenerateString(); EditorView.LoadDataWithBaseURL("file:///android_asset/", html, "text/html", "utf-8", null); - OnPageFinished(Element, editorView); } protected override void OnElementChanged(ElementChangedEventArgs e) @@ -78,6 +79,7 @@ namespace BookAStar.Droid if (Control == null) { SetNativeControl(CreateNativeControl()); + InjectJS(JavaScriptFunction); } if (e.OldElement != null) { @@ -91,7 +93,6 @@ namespace BookAStar.Droid EditorView.SetWebViewClient(viewclient); Control.AddJavascriptInterface(new JsBridgeMarkdown(this), "jsBridge"); SetMDEditorText(e.NewElement.Markdown); - InjectJS(JavaScriptFunction); } }