From d2b42a49bd670138344d88ae31ebda094f53781c Mon Sep 17 00:00:00 2001 From: Hiva Javaher Date: Tue, 7 May 2019 12:29:53 -0700 Subject: [PATCH] Multi Icon Support Modifications to allow the button or Label renderer to support multiple icons using a pipe as a delimiter. --- .../Android/Renderers/IconButtonRenderer.cs | 28 +++++++++++++------ .../Android/Renderers/IconLabelRenderer.cs | 28 +++++++++++++------ .../iOS/Renderers/IconButtonRenderer.cs | 20 +++++++++---- .../iOS/Renderers/IconLabelRenderer.cs | 19 ++++++++----- 4 files changed, 64 insertions(+), 31 deletions(-) diff --git a/src/Plugin.Iconize/Platform/Android/Renderers/IconButtonRenderer.cs b/src/Plugin.Iconize/Platform/Android/Renderers/IconButtonRenderer.cs index 98d8b58..0ebee7b 100644 --- a/src/Plugin.Iconize/Platform/Android/Renderers/IconButtonRenderer.cs +++ b/src/Plugin.Iconize/Platform/Android/Renderers/IconButtonRenderer.cs @@ -124,24 +124,34 @@ private void UpdateText() #if USE_FASTRENDERERS TextChanged -= OnTextChanged; - var icon = Iconize.FindIconForKey(Button.Text); - if (!(icon is null)) + var icons = Element.Text.Split("|"); + var controlText = string.Empty; + foreach (var iconText in icons) { - Text = $"{icon.Character}"; - Typeface = Iconize.FindModuleOf(icon).ToTypeface(Context); + var icon = Iconize.FindIconForKey(iconText); + if (!(icon is null)) + { + Text += $"{icon.Character}"; + Typeface = Iconize.FindModuleOf(icon).ToTypeface(Context); + } } - + TextChanged += OnTextChanged; #else if (!(Control is null)) { Control.TextChanged -= OnTextChanged; - var icon = Iconize.FindIconForKey(Button.Text); - if (!(icon is null)) + var icons = Element.Text.Split("|"); + var controlText = string.Empty; + foreach (var iconText in icons) { - Control.Text = $"{icon.Character}"; - Control.Typeface = Iconize.FindModuleOf(icon).ToTypeface(Context); + var icon = Iconize.FindIconForKey(iconText); + if (!(icon is null)) + { + Control.Text += $"{icon.Character}"; + Control.Typeface = Iconize.FindModuleOf(icon).ToTypeface(Context); + } } Control.TextChanged += OnTextChanged; diff --git a/src/Plugin.Iconize/Platform/Android/Renderers/IconLabelRenderer.cs b/src/Plugin.Iconize/Platform/Android/Renderers/IconLabelRenderer.cs index 3cc75e3..e378fb9 100644 --- a/src/Plugin.Iconize/Platform/Android/Renderers/IconLabelRenderer.cs +++ b/src/Plugin.Iconize/Platform/Android/Renderers/IconLabelRenderer.cs @@ -110,24 +110,34 @@ private void UpdateText() #if USE_FASTRENDERERS TextChanged -= OnTextChanged; - var icon = Iconize.FindIconForKey(Label.Text); - if (!(icon is null)) + var icons = Element.Text.Split("|"); + var controlText = string.Empty; + foreach (var iconText in icons) { - Text = $"{icon.Character}"; - Typeface = Iconize.FindModuleOf(icon).ToTypeface(Context); + var icon = Iconize.FindIconForKey(iconText); + if (!(icon is null)) + { + Text += $"{icon.Character}"; + Typeface = Iconize.FindModuleOf(icon).ToTypeface(Context); + } } - + TextChanged += OnTextChanged; #else if (!(Control is null)) { Control.TextChanged -= OnTextChanged; - var icon = Iconize.FindIconForKey(Label.Text); - if (!(icon is null)) + var icons = Element.Text.Split("|"); + var controlText = string.Empty; + foreach (var iconText in icons) { - Control.Text = $"{icon.Character}"; - Control.Typeface = Iconize.FindModuleOf(icon).ToTypeface(Context); + var icon = Iconize.FindIconForKey(iconText); + if (!(icon is null)) + { + Control.Text += $"{icon.Character}"; + Control.Typeface = Iconize.FindModuleOf(icon).ToTypeface(Context); + } } Control.TextChanged += OnTextChanged; diff --git a/src/Plugin.Iconize/Platform/iOS/Renderers/IconButtonRenderer.cs b/src/Plugin.Iconize/Platform/iOS/Renderers/IconButtonRenderer.cs index dc618f1..45b1135 100644 --- a/src/Plugin.Iconize/Platform/iOS/Renderers/IconButtonRenderer.cs +++ b/src/Plugin.Iconize/Platform/iOS/Renderers/IconButtonRenderer.cs @@ -60,16 +60,24 @@ protected override void OnElementPropertyChanged(Object sender, PropertyChangedE /// private void UpdateText() { - var icon = Iconize.FindIconForKey(Element.Text); - if (!(icon is null)) + var icons = Element.Text.Split("|"); + UIFont font = null; + var controlText = string.Empty; + foreach (var iconText in icons) { - var font = Iconize.FindModuleOf(icon)?.ToUIFont((nfloat)Element.FontSize); - if (!(font is null)) + var icon = Iconize.FindIconForKey(iconText); + if (!(icon is null)) { - Control.SetTitle($"{icon.Character}", UIControlState.Normal); - Control.Font = font; + font = Iconize.FindModuleOf(icon)?.ToUIFont((nfloat)Element.FontSize); + controlText += icon.Character; } } + + if (!(font is null)) + { + Control.SetTitle($"{controlText}", UIControlState.Normal); + Control.Font = font; + } } } } \ No newline at end of file diff --git a/src/Plugin.Iconize/Platform/iOS/Renderers/IconLabelRenderer.cs b/src/Plugin.Iconize/Platform/iOS/Renderers/IconLabelRenderer.cs index fe21f92..4ff18a5 100644 --- a/src/Plugin.Iconize/Platform/iOS/Renderers/IconLabelRenderer.cs +++ b/src/Plugin.Iconize/Platform/iOS/Renderers/IconLabelRenderer.cs @@ -59,16 +59,21 @@ protected override void OnElementPropertyChanged(Object sender, PropertyChangedE /// private void UpdateText() { - var icon = Iconize.FindIconForKey(Element.Text); - if (!(icon is null)) + var icons = Element.Text.Split("|"); + var controlText = string.Empty; + foreach (var iconText in icons) { - var font = Iconize.FindModuleOf(icon)?.ToUIFont((nfloat)Element.FontSize); - if (!(font is null)) + var icon = Iconize.FindIconForKey(iconText); + if (!(icon is null)) { - Control.Text = $"{icon.Character}"; - Control.Font = font; + var font = Iconize.FindModuleOf(icon)?.ToUIFont((nfloat)Element.FontSize); + if (!(font is null)) + { + Control.Text += $"{controlText}"; + Control.Font = font; + } } - } + } } } } \ No newline at end of file