diff --git a/AiForms.Effects.Droid/AddCommandPlatformEffect.cs b/AiForms.Effects.Droid/AddCommandPlatformEffect.cs index d37b2e7..013205e 100644 --- a/AiForms.Effects.Droid/AddCommandPlatformEffect.cs +++ b/AiForms.Effects.Droid/AddCommandPlatformEffect.cs @@ -79,7 +79,7 @@ protected override void OnAttached() _isTapTargetSoundEffect = TapSoundEffectElementType.Any(x => x == Element.GetType()); if (_audioManager == null) { - _audioManager = (AudioManager)Forms.Context.GetSystemService(Context.AudioService); + _audioManager = (AudioManager)_view.Context.GetSystemService(Context.AudioService); } _gestureDetector = new GestureDetector(_view.Context, new ViewGestureListener(this)); @@ -182,7 +182,7 @@ void _view_Touch(object sender, Android.Views.View.TouchEventArgs e) _gestureDetector.OnTouchEvent(e.Event); // for any reason depending type of element, Handled value must be changed. // I don't know the reason. - if (!_useRipple && !Element.IsClickable()) { + if (!_useRipple && !IsClickable) { e.Handled = true; return; } @@ -237,7 +237,7 @@ void CommandCanExecuteChanged(object sender, System.EventArgs e) if (_isDisableEffectTarget) { forms.FadeTo(DisabledAlpha); } - if (Element.IsFastRenderer()) { + if (IsFastRenderer) { _view.Enabled = false; } } @@ -246,7 +246,7 @@ void CommandCanExecuteChanged(object sender, System.EventArgs e) if (_isDisableEffectTarget) { forms.FadeTo(1f); } - if (Element.IsFastRenderer()) { + if (IsFastRenderer) { _view.Enabled = true; } } @@ -359,7 +359,7 @@ void AddRipple() _view.Touch -= _view_Touch; _rippleOverlay.Touch += _view_Touch; } - else if (Element.IsFastRenderer()) { + else if (IsFastRenderer) { if (_fastListener == null) { _fastListener = new FastRendererOnLayoutChangeListener(this); _view.AddOnLayoutChangeListener(_fastListener); @@ -395,9 +395,8 @@ void RemoveRipple() _rippleOverlay = null; } - else if (Element.IsFastRenderer()) { + else if (IsFastRenderer) { _view.Touch -= _view_Touch; - //Control.AddOnLayoutChangeListener(null); Control.RemoveOnLayoutChangeListener(_fastListener); _view = Control; _fastListener.CleanUp(); diff --git a/AiForms.Effects.Droid/AddTextPlatformEffect.cs b/AiForms.Effects.Droid/AddTextPlatformEffect.cs index 85a87c1..ab81dba 100644 --- a/AiForms.Effects.Droid/AddTextPlatformEffect.cs +++ b/AiForms.Effects.Droid/AddTextPlatformEffect.cs @@ -27,7 +27,7 @@ protected override void OnAttached() _textView.SetMinLines(1); _textView.Ellipsize = Android.Text.TextUtils.TruncateAt.End; - if (Element.IsFastRenderer()) { + if (IsFastRenderer) { _container = new FrameLayout(_context); _fastListener = new FastRendererOnLayoutChangeListener(Control, _container); @@ -55,7 +55,7 @@ protected override void OnDetached() _container.RemoveView(_textView); _container.RemoveOnLayoutChangeListener(_listener); - if (Element.IsFastRenderer()) { + if (IsFastRenderer) { Control.RemoveOnLayoutChangeListener(_fastListener); _fastListener.CleanUp(); } diff --git a/AiForms.Effects.Droid/AiEffectBase.cs b/AiForms.Effects.Droid/AiEffectBase.cs index 64a1326..e2e06e6 100644 --- a/AiForms.Effects.Droid/AiEffectBase.cs +++ b/AiForms.Effects.Droid/AiEffectBase.cs @@ -8,6 +8,8 @@ namespace AiForms.Effects.Droid { public abstract class AiEffectBase : PlatformEffect { + public static bool IsFastRenderers = global::Xamarin.Forms.Forms.Flags.Any(x => x == "FastRenderers_Experimental"); + IVisualElementRenderer _renderer; bool _isDisposed = false; protected bool IsDisposed { @@ -20,7 +22,7 @@ protected bool IsDisposed { _renderer = (Container ?? Control) as IVisualElementRenderer; } - if (Element.IsFastRendererButton()) { + if (IsFastRendererButton) { return CheckButtonIsDisposed(); } @@ -28,6 +30,29 @@ protected bool IsDisposed { } } + // whether Element is FastRenderer.(Exept Button) + protected bool IsFastRenderer{ + get{ + //If Container is null, it regards this as FastRenderer Element. + //But this judging may not become right in the future. + return IsFastRenderers && (Container == null && !(Element is Xamarin.Forms.Button)); + } + } + + // whether Element is a Button of FastRenderer. + protected bool IsFastRendererButton{ + get{ + return (IsFastRenderers && (Element is Xamarin.Forms.Button)); + } + } + + // whether Element can add ClickListener. + protected bool IsClickable{ + get{ + return !(IsFastRenderer || Element is Xamarin.Forms.Layout || Element is Xamarin.Forms.BoxView); + } + } + static Func GetDisposed; //cache // In case Button of FastRenderer, IVisualElementRenderer.Tracker don't become null. diff --git a/AiForms.Effects.Droid/AiForms.Effects.Droid.csproj b/AiForms.Effects.Droid/AiForms.Effects.Droid.csproj index 97c6c89..85455b1 100644 --- a/AiForms.Effects.Droid/AiForms.Effects.Droid.csproj +++ b/AiForms.Effects.Droid/AiForms.Effects.Droid.csproj @@ -1,6 +1,6 @@ - + Debug AnyCPU @@ -9,7 +9,7 @@ Library AiForms.Effects.Droid AiForms.Effects.Droid - v7.1 + v8.0 Resources\Resource.designer.cs Resource Resources @@ -44,44 +44,68 @@ + + ..\packages\Xamarin.Android.Support.Annotations.25.4.0.2\lib\MonoAndroid70\Xamarin.Android.Support.Annotations.dll + + + ..\packages\Xamarin.Android.Support.Compat.25.4.0.2\lib\MonoAndroid70\Xamarin.Android.Support.Compat.dll + + + ..\packages\Xamarin.Android.Support.Core.UI.25.4.0.2\lib\MonoAndroid70\Xamarin.Android.Support.Core.UI.dll + + + ..\packages\Xamarin.Android.Support.Core.Utils.25.4.0.2\lib\MonoAndroid70\Xamarin.Android.Support.Core.Utils.dll + + + ..\packages\Xamarin.Android.Support.Media.Compat.25.4.0.2\lib\MonoAndroid70\Xamarin.Android.Support.Media.Compat.dll + + + ..\packages\Xamarin.Android.Support.Fragment.25.4.0.2\lib\MonoAndroid70\Xamarin.Android.Support.Fragment.dll + + + ..\packages\Xamarin.Android.Support.Transition.25.4.0.2\lib\MonoAndroid70\Xamarin.Android.Support.Transition.dll + - ..\packages\Xamarin.Android.Support.v4.23.3.0\lib\MonoAndroid403\Xamarin.Android.Support.v4.dll + ..\packages\Xamarin.Android.Support.v4.25.4.0.2\lib\MonoAndroid70\Xamarin.Android.Support.v4.dll - ..\packages\Xamarin.Android.Support.v7.CardView.23.3.0\lib\MonoAndroid403\Xamarin.Android.Support.v7.CardView.dll + ..\packages\Xamarin.Android.Support.v7.CardView.25.4.0.2\lib\MonoAndroid70\Xamarin.Android.Support.v7.CardView.dll + + + ..\packages\Xamarin.Android.Support.v7.Palette.25.4.0.2\lib\MonoAndroid70\Xamarin.Android.Support.v7.Palette.dll - ..\packages\Xamarin.Android.Support.v7.RecyclerView.23.3.0\lib\MonoAndroid403\Xamarin.Android.Support.v7.RecyclerView.dll + ..\packages\Xamarin.Android.Support.v7.RecyclerView.25.4.0.2\lib\MonoAndroid70\Xamarin.Android.Support.v7.RecyclerView.dll - ..\packages\Xamarin.Android.Support.Vector.Drawable.23.3.0\lib\MonoAndroid403\Xamarin.Android.Support.Vector.Drawable.dll + ..\packages\Xamarin.Android.Support.Vector.Drawable.25.4.0.2\lib\MonoAndroid70\Xamarin.Android.Support.Vector.Drawable.dll - ..\packages\Xamarin.Android.Support.Animated.Vector.Drawable.23.3.0\lib\MonoAndroid403\Xamarin.Android.Support.Animated.Vector.Drawable.dll + ..\packages\Xamarin.Android.Support.Animated.Vector.Drawable.25.4.0.2\lib\MonoAndroid70\Xamarin.Android.Support.Animated.Vector.Drawable.dll - ..\packages\Xamarin.Android.Support.v7.AppCompat.23.3.0\lib\MonoAndroid403\Xamarin.Android.Support.v7.AppCompat.dll + ..\packages\Xamarin.Android.Support.v7.AppCompat.25.4.0.2\lib\MonoAndroid70\Xamarin.Android.Support.v7.AppCompat.dll - ..\packages\Xamarin.Android.Support.Design.23.3.0\lib\MonoAndroid43\Xamarin.Android.Support.Design.dll + ..\packages\Xamarin.Android.Support.Design.25.4.0.2\lib\MonoAndroid70\Xamarin.Android.Support.Design.dll - ..\packages\Xamarin.Android.Support.v7.MediaRouter.23.3.0\lib\MonoAndroid403\Xamarin.Android.Support.v7.MediaRouter.dll + ..\packages\Xamarin.Android.Support.v7.MediaRouter.25.4.0.2\lib\MonoAndroid70\Xamarin.Android.Support.v7.MediaRouter.dll - ..\packages\Xamarin.Forms.2.4.0.282\lib\MonoAndroid10\FormsViewGroup.dll + ..\packages\Xamarin.Forms.2.5.0.121934\lib\MonoAndroid10\FormsViewGroup.dll - ..\packages\Xamarin.Forms.2.4.0.282\lib\MonoAndroid10\Xamarin.Forms.Core.dll + ..\packages\Xamarin.Forms.2.5.0.121934\lib\MonoAndroid10\Xamarin.Forms.Core.dll - ..\packages\Xamarin.Forms.2.4.0.282\lib\MonoAndroid10\Xamarin.Forms.Platform.Android.dll + ..\packages\Xamarin.Forms.2.5.0.121934\lib\MonoAndroid10\Xamarin.Forms.Platform.Android.dll - ..\packages\Xamarin.Forms.2.4.0.282\lib\MonoAndroid10\Xamarin.Forms.Platform.dll + ..\packages\Xamarin.Forms.2.5.0.121934\lib\MonoAndroid10\Xamarin.Forms.Platform.dll - ..\packages\Xamarin.Forms.2.4.0.282\lib\MonoAndroid10\Xamarin.Forms.Xaml.dll + ..\packages\Xamarin.Forms.2.5.0.121934\lib\MonoAndroid10\Xamarin.Forms.Xaml.dll @@ -103,9 +127,9 @@ - + @@ -121,6 +145,20 @@ - - + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/AiForms.Effects.Droid/AlterColorPlatformEffect.cs b/AiForms.Effects.Droid/AlterColorPlatformEffect.cs index 0c048de..6ec567b 100644 --- a/AiForms.Effects.Droid/AlterColorPlatformEffect.cs +++ b/AiForms.Effects.Droid/AlterColorPlatformEffect.cs @@ -23,7 +23,7 @@ protected override void OnAttached() _effect = new AlterColorTextView(Control as TextView, Element); } else if (Element is Page) { - _effect = new AlterColorStatusbar(Element); + _effect = new AlterColorStatusbar(Element,(Control ?? Container).Context); } else { Device.BeginInvokeOnMainThread(() => AlterColor.SetOn(Element, false)); diff --git a/AiForms.Effects.Droid/AlterColorStatusbar.cs b/AiForms.Effects.Droid/AlterColorStatusbar.cs index 27ff3f3..70baa32 100644 --- a/AiForms.Effects.Droid/AlterColorStatusbar.cs +++ b/AiForms.Effects.Droid/AlterColorStatusbar.cs @@ -2,6 +2,7 @@ using Xamarin.Forms.Platform.Android; using Android.Views; using Xamarin.Forms; +using Android.Content; namespace AiForms.Effects.Droid { @@ -11,9 +12,9 @@ public class AlterColorStatusbar : IAiEffectDroid Element _element; int _orgColor; - public AlterColorStatusbar(Element element) + public AlterColorStatusbar(Element element,Context context) { - _window = (Xamarin.Forms.Forms.Context as FormsAppCompatActivity).Window; + _window = (context as FormsAppCompatActivity).Window; _element = element; _orgColor = _window.StatusBarColor; } diff --git a/AiForms.Effects.Droid/ElementExtensions.cs b/AiForms.Effects.Droid/ElementExtensions.cs deleted file mode 100644 index dc2e3f6..0000000 --- a/AiForms.Effects.Droid/ElementExtensions.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.Linq; -using Xamarin.Forms; - -namespace AiForms.Effects.Droid -{ - public static class ElementExtensions - { - public static bool IsFastRenderers = global::Xamarin.Forms.Forms.Flags.Any(x => x == "FastRenderers_Experimental"); - - // whether Element is FastRenderer.(Exept Button) - public static bool IsFastRenderer(this Element elm) - { - return (IsFastRenderers && (elm is Label || elm is Image)); - } - - // whether Element can add ClickListener. - public static bool IsClickable(this Element elm) - { - return !(elm.IsFastRenderer() || elm is Layout || elm is BoxView); - } - - // whether Element is a Button of FastRenderer. - public static bool IsFastRendererButton(this Element elm) - { - return (IsFastRenderers && (elm is Button)); - } - } -} diff --git a/AiForms.Effects.Droid/SizeToFitPlatformEffect.cs b/AiForms.Effects.Droid/SizeToFitPlatformEffect.cs new file mode 100644 index 0000000..1ad4234 --- /dev/null +++ b/AiForms.Effects.Droid/SizeToFitPlatformEffect.cs @@ -0,0 +1,116 @@ +using System; +using AiForms.Effects; +using AiForms.Effects.Droid; +using Android.Graphics; +using Android.Util; +using Android.Views; +using Android.Widget; +using Xamarin.Forms; +using Xamarin.Forms.Platform.Android; + +[assembly: ExportEffect(typeof(SizeToFitPlatformEffect), nameof(SizeToFit))] +namespace AiForms.Effects.Droid +{ + public class SizeToFitPlatformEffect : AiEffectBase + { + FormsTextView _view; + float _orgFontSize; + + protected override void OnAttached() + { + _view = Control as FormsTextView; + _orgFontSize = _view.TextSize; + + UpdateFitFont(); + } + + protected override void OnDetached() + { + if(!IsDisposed){ + _view.SetTextSize(ComplexUnitType.Px, _orgFontSize); + } + _view = null; + } + + protected override void OnElementPropertyChanged(System.ComponentModel.PropertyChangedEventArgs args) + { + base.OnElementPropertyChanged(args); + if (args.PropertyName == VisualElement.HeightProperty.PropertyName || + args.PropertyName == VisualElement.WidthProperty.PropertyName || + args.PropertyName == Label.TextProperty.PropertyName || + args.PropertyName == SizeToFit.CanExpandProperty.PropertyName) + { + UpdateFitFont(); + } + else if (args.PropertyName == Label.FontProperty.PropertyName) + { + _orgFontSize = _view.TextSize; + UpdateFitFont(); + } + //else if (args.PropertyName == Label.VerticalTextAlignmentProperty.PropertyName){ + // var label = Element as Label; + // _view.Gravity = label.HorizontalTextAlignment.ToHorizontalGravityFlags() | label.VerticalTextAlignment.ToVerticalGravityFlags(); + //} + } + + void UpdateFitFont() + { + var formsView = Element as Xamarin.Forms.View; + if (formsView.Width < 0 || formsView.Height < 0) + { + return; + } + + var nativeHeight = _view.Context.ToPixels(formsView.Height); + var nativeWidth = _view.Context.ToPixels(formsView.Width); + + var height = MeasureTextSize(_view.Text, nativeWidth, _orgFontSize, _view.Typeface); + + var fontSize = _orgFontSize; + + if (SizeToFit.GetCanExpand(Element) && height < nativeHeight) + { + while (height < nativeHeight) + { + fontSize += 1f; + height = MeasureTextSize(_view.Text, nativeWidth, fontSize, _view.Typeface); + } + } + + while (height > nativeHeight && fontSize > 0) + { + fontSize -= 1f; + height = MeasureTextSize(_view.Text, nativeWidth, fontSize, _view.Typeface); + } + + _view.SetTextSize(ComplexUnitType.Px, fontSize); + + if (!IsFastRenderer) + { + _view.SetHeight(Container.Height); + } + } + + + public double MeasureTextSize(string text, double width, double fontSize, Typeface typeface = null) + { + var textView = new TextView(_view.Context); + textView.Typeface = typeface ?? Typeface.Default; + textView.SetText(text, TextView.BufferType.Normal); + textView.SetTextSize(ComplexUnitType.Px, (float)fontSize); + + int widthMeasureSpec = Android.Views.View.MeasureSpec.MakeMeasureSpec( + (int)width, MeasureSpecMode.AtMost); + int heightMeasureSpec = Android.Views.View.MeasureSpec.MakeMeasureSpec( + 0, MeasureSpecMode.Unspecified); + + textView.Measure(widthMeasureSpec, heightMeasureSpec); + var height = (double)textView.MeasuredHeight; + + textView.Dispose(); + + return height; + } + + } +} \ No newline at end of file diff --git a/AiForms.Effects.Droid/packages.config b/AiForms.Effects.Droid/packages.config index 2cbc42b..48756ce 100644 --- a/AiForms.Effects.Droid/packages.config +++ b/AiForms.Effects.Droid/packages.config @@ -1,12 +1,20 @@  - - - - - - - - - + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/AiForms.Effects.iOS/AiForms.Effects.iOS.csproj b/AiForms.Effects.iOS/AiForms.Effects.iOS.csproj index e549075..256db19 100644 --- a/AiForms.Effects.iOS/AiForms.Effects.iOS.csproj +++ b/AiForms.Effects.iOS/AiForms.Effects.iOS.csproj @@ -1,6 +1,6 @@ - + Debug AnyCPU @@ -47,16 +47,16 @@ - ..\packages\Xamarin.Forms.2.4.0.282\lib\Xamarin.iOS10\Xamarin.Forms.Core.dll + ..\packages\Xamarin.Forms.2.5.0.121934\lib\Xamarin.iOS10\Xamarin.Forms.Core.dll - ..\packages\Xamarin.Forms.2.4.0.282\lib\Xamarin.iOS10\Xamarin.Forms.Platform.dll + ..\packages\Xamarin.Forms.2.5.0.121934\lib\Xamarin.iOS10\Xamarin.Forms.Platform.dll - ..\packages\Xamarin.Forms.2.4.0.282\lib\Xamarin.iOS10\Xamarin.Forms.Platform.iOS.dll + ..\packages\Xamarin.Forms.2.5.0.121934\lib\Xamarin.iOS10\Xamarin.Forms.Platform.iOS.dll - ..\packages\Xamarin.Forms.2.4.0.282\lib\Xamarin.iOS10\Xamarin.Forms.Xaml.dll + ..\packages\Xamarin.Forms.2.5.0.121934\lib\Xamarin.iOS10\Xamarin.Forms.Xaml.dll @@ -80,6 +80,7 @@ + @@ -91,5 +92,5 @@ - + \ No newline at end of file diff --git a/AiForms.Effects.iOS/SizeToFitPlatformEffect.cs b/AiForms.Effects.iOS/SizeToFitPlatformEffect.cs new file mode 100644 index 0000000..6acbf9f --- /dev/null +++ b/AiForms.Effects.iOS/SizeToFitPlatformEffect.cs @@ -0,0 +1,104 @@ +using System; +using System.Drawing; +using AiForms.Effects; +using AiForms.Effects.iOS; +using Foundation; +using UIKit; +using Xamarin.Forms; +using Xamarin.Forms.Platform.iOS; +using Metal; + +[assembly: ExportEffect(typeof(SizeToFitPlatformEffect), nameof(SizeToFit))] +namespace AiForms.Effects.iOS +{ + public class SizeToFitPlatformEffect : PlatformEffect + { + UILabel _view; + nfloat _orgFontSize; + + protected override void OnAttached() + { + _view = Control as UILabel; + _orgFontSize = _view.Font.PointSize; + + UpdateFitFont(); + } + + protected override void OnDetached() + { + _view.Font = UIFont.FromName(_view.Font.Name, _orgFontSize); + var render = Platform.GetRenderer(Element as Label) as LabelRenderer; + render.LayoutSubviews(); + _view = null; + } + + protected override void OnElementPropertyChanged(System.ComponentModel.PropertyChangedEventArgs args) + { + base.OnElementPropertyChanged(args); + if (args.PropertyName == VisualElement.HeightProperty.PropertyName || + args.PropertyName == VisualElement.WidthProperty.PropertyName || + args.PropertyName == Label.TextProperty.PropertyName || + args.PropertyName == SizeToFit.CanExpandProperty.PropertyName) + { + UpdateFitFont(); + } + else if(args.PropertyName == Label.FontProperty.PropertyName){ + _orgFontSize = _view.Font.PointSize; + UpdateFitFont(); + } + } + + void UpdateFitFont() + { + var formsView = Element as View; + if(formsView.Width < 0 || formsView.Height < 0){ + return; + } + + var height = MeasureTextSize(_view.Text, formsView.Width, _orgFontSize, _view.Font.Name); + + var fontSize = _orgFontSize; + + if (SizeToFit.GetCanExpand(Element) && height < formsView.Height) + { + while (height < formsView.Height) + { + fontSize += 0.5f; + height = MeasureTextSize(_view.Text, formsView.Width, fontSize, _view.Font.Name); + } + } + + while (height > formsView.Height && fontSize > 0) + { + fontSize -= 0.5f; + height = MeasureTextSize(_view.Text, formsView.Width, fontSize, _view.Font.Name); + } + + _view.Font = UIFont.FromName(_view.Font.Name, fontSize); + + var render = Platform.GetRenderer(formsView) as LabelRenderer; + render.LayoutSubviews(); + } + + public double MeasureTextSize(string text, double width, double fontSize, string fontName = null) + { + var nsText = new NSString(text); + var boundSize = new SizeF((float)width, float.MaxValue); + var options = NSStringDrawingOptions.UsesFontLeading | NSStringDrawingOptions.UsesLineFragmentOrigin; + + if (fontName == null) + { + fontName = "HelveticaNeue"; + } + + var attributes = new UIStringAttributes + { + Font = UIFont.FromName(fontName, (float)fontSize) + }; + + var sizeF = nsText.GetBoundingRect(boundSize, options, attributes, null).Size; + + return (double)sizeF.Height;// + 5; + } + } +} diff --git a/AiForms.Effects.iOS/packages.config b/AiForms.Effects.iOS/packages.config index bd990a3..5247602 100644 --- a/AiForms.Effects.iOS/packages.config +++ b/AiForms.Effects.iOS/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file diff --git a/AiForms.Effects/AiForms.Effects.csproj b/AiForms.Effects/AiForms.Effects.csproj index 5feb03f..b4c8d65 100644 --- a/AiForms.Effects/AiForms.Effects.csproj +++ b/AiForms.Effects/AiForms.Effects.csproj @@ -5,12 +5,10 @@ AnyCPU {14FCC004-FC52-4028-A5AE-228AFD6F6222} {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - true Library AiForms.Effects AiForms.Effects - v4.5 - Profile259 + v5.0 0.0.5-pre @@ -41,21 +39,10 @@ + - - ..\packages\Xamarin.Forms.2.4.0.282\lib\portable-win+net45+wp80+win81+wpa81\Xamarin.Forms.Core.dll - - - ..\packages\Xamarin.Forms.2.4.0.282\lib\portable-win+net45+wp80+win81+wpa81\Xamarin.Forms.Platform.dll - - - ..\packages\Xamarin.Forms.2.4.0.282\lib\portable-win+net45+wp80+win81+wpa81\Xamarin.Forms.Xaml.dll - - - - + - - \ No newline at end of file + diff --git a/AiForms.Effects/AiForms.Effects.nuget.props b/AiForms.Effects/AiForms.Effects.nuget.props new file mode 100644 index 0000000..3f45c91 --- /dev/null +++ b/AiForms.Effects/AiForms.Effects.nuget.props @@ -0,0 +1,18 @@ + + + + True + NuGet + /Users/kamu/Projects/AiForms.Effects/AiForms.Effects/project.lock.json + /Users/kamu/.nuget/packages/ + /Users/kamu/.nuget/packages/ + ProjectJson + 4.3.1 + + + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) + + + + + \ No newline at end of file diff --git a/AiForms.Effects/AiForms.Effects.nuget.targets b/AiForms.Effects/AiForms.Effects.nuget.targets new file mode 100644 index 0000000..f685a79 --- /dev/null +++ b/AiForms.Effects/AiForms.Effects.nuget.targets @@ -0,0 +1,9 @@ + + + + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) + + + + + \ No newline at end of file diff --git a/AiForms.Effects/SizeToFit.cs b/AiForms.Effects/SizeToFit.cs new file mode 100644 index 0000000..e4997a2 --- /dev/null +++ b/AiForms.Effects/SizeToFit.cs @@ -0,0 +1,71 @@ +using System; +using System.Linq; +using Xamarin.Forms; + +namespace AiForms.Effects +{ + public static class SizeToFit + { + public static readonly BindableProperty OnProperty = + BindableProperty.CreateAttached( + "On", + typeof(bool), + typeof(SizeToFit), + default(bool), + propertyChanged: OnOffChanged + ); + + public static void SetOn(BindableObject view, bool value) + { + view.SetValue(OnProperty, value); + } + + public static bool GetOn(BindableObject view) + { + return (bool)view.GetValue(OnProperty); + } + + private static void OnOffChanged(BindableObject bindable, object oldValue, object newValue) + { + var view = bindable as View; + if (view == null) + return; + if (!(view is Label)) + return; + + if ((bool)newValue) + { + view.Effects.Add(new SizeToFitRoutingEffect()); + } + else + { + var toRemove = view.Effects.FirstOrDefault(e => e is SizeToFitRoutingEffect); + if (toRemove != null) + view.Effects.Remove(toRemove); + } + } + + public static readonly BindableProperty CanExpandProperty = + BindableProperty.CreateAttached( + "CanExpand", + typeof(bool), + typeof(SizeToFit), + true + ); + + public static void SetCanExpand(BindableObject view, bool value) + { + view.SetValue(CanExpandProperty, value); + } + + public static bool GetCanExpand(BindableObject view) + { + return (bool)view.GetValue(CanExpandProperty); + } + + class SizeToFitRoutingEffect : RoutingEffect + { + public SizeToFitRoutingEffect() : base("AiForms." + nameof(SizeToFit)) { } + } + } +} diff --git a/AiForms.Effects/packages.config b/AiForms.Effects/packages.config deleted file mode 100644 index 221433a..0000000 --- a/AiForms.Effects/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/AiForms.Effects/project.json b/AiForms.Effects/project.json new file mode 100644 index 0000000..4d219d0 --- /dev/null +++ b/AiForms.Effects/project.json @@ -0,0 +1,10 @@ +{ + "dependencies": { + "Xamarin.Forms": "2.5.0.121934", + "NETStandard.Library": "1.6.0", + "Microsoft.NETCore.Portable.Compatibility": "1.0.1" + }, + "frameworks": { + "netstandard1.4": {} + } +} \ No newline at end of file diff --git a/README.md b/README.md index cfed281..ebb45cd 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,8 @@ Xamarin.Forms Effects for only Android / iOS. ## Features +* [SizeToFit](#sizetofit) + * make font size adjusted to fit the Label size. * [Border](#border) * add border to a view. * [Placeholder](#placeholder) @@ -54,6 +56,36 @@ public override bool FinishedLaunching(UIApplication app, NSDictionary options) } ``` +## SizeToFit + +This is the effect that make font size adjusted to fit the Label size. +This can be used only Label. + +### Parameters + +* On + * Effect On/Off (true is On) +* CanExpand + * Whether font size is expanded when making it fit. (Default true) + * If false, font size won't be expanded and only shrinked. + +### Demo + +https://youtu.be/yMjcFOp38XE + +### How to write with Xaml + +```xml + + +``` + ## Border This is the effect that add border to a view. diff --git a/Tests/AiEffects.TestApp/AiEffects.TestApp.Droid/AiEffects.TestApp.Droid.csproj b/Tests/AiEffects.TestApp/AiEffects.TestApp.Droid/AiEffects.TestApp.Droid.csproj index 44bd22c..45cc2c4 100644 --- a/Tests/AiEffects.TestApp/AiEffects.TestApp.Droid/AiEffects.TestApp.Droid.csproj +++ b/Tests/AiEffects.TestApp/AiEffects.TestApp.Droid/AiEffects.TestApp.Droid.csproj @@ -1,6 +1,6 @@ - + Debug AnyCPU @@ -9,7 +9,7 @@ Library AiEffects.TestApp.Droid AiEffects.TestApp.Droid - v7.1 + v8.0 True Resources\Resource.designer.cs Resource @@ -46,85 +46,111 @@ + + ..\packages\CommonServiceLocator.1.3\lib\portable-net4+sl5+netcore45+wpa81+wp8\Microsoft.Practices.ServiceLocation.dll + + + ..\packages\Unity.4.0.1\lib\portable-net45+wp80+win8+wpa81+MonoAndroid10+MonoTouch10\Microsoft.Practices.Unity.dll + + + + + ..\..\..\packages\Xamarin.Android.Support.Annotations.25.4.0.2\lib\MonoAndroid70\Xamarin.Android.Support.Annotations.dll + + + ..\..\..\packages\Xamarin.Android.Support.Compat.25.4.0.2\lib\MonoAndroid70\Xamarin.Android.Support.Compat.dll + + + ..\..\..\packages\Xamarin.Android.Support.Core.UI.25.4.0.2\lib\MonoAndroid70\Xamarin.Android.Support.Core.UI.dll + + + ..\..\..\packages\Xamarin.Android.Support.Core.Utils.25.4.0.2\lib\MonoAndroid70\Xamarin.Android.Support.Core.Utils.dll + + + ..\..\..\packages\Xamarin.Android.Support.Media.Compat.25.4.0.2\lib\MonoAndroid70\Xamarin.Android.Support.Media.Compat.dll + + + ..\..\..\packages\Xamarin.Android.Support.Fragment.25.4.0.2\lib\MonoAndroid70\Xamarin.Android.Support.Fragment.dll + + + ..\..\..\packages\Xamarin.Android.Support.Transition.25.4.0.2\lib\MonoAndroid70\Xamarin.Android.Support.Transition.dll + - ..\packages\Xamarin.Android.Support.v4.23.3.0\lib\MonoAndroid403\Xamarin.Android.Support.v4.dll + ..\..\..\packages\Xamarin.Android.Support.v4.25.4.0.2\lib\MonoAndroid70\Xamarin.Android.Support.v4.dll - ..\packages\Xamarin.Android.Support.v7.CardView.23.3.0\lib\MonoAndroid403\Xamarin.Android.Support.v7.CardView.dll + ..\..\..\packages\Xamarin.Android.Support.v7.CardView.25.4.0.2\lib\MonoAndroid70\Xamarin.Android.Support.v7.CardView.dll + + + ..\..\..\packages\Xamarin.Android.Support.v7.Palette.25.4.0.2\lib\MonoAndroid70\Xamarin.Android.Support.v7.Palette.dll - ..\packages\Xamarin.Android.Support.v7.RecyclerView.23.3.0\lib\MonoAndroid403\Xamarin.Android.Support.v7.RecyclerView.dll + ..\..\..\packages\Xamarin.Android.Support.v7.RecyclerView.25.4.0.2\lib\MonoAndroid70\Xamarin.Android.Support.v7.RecyclerView.dll - ..\packages\Xamarin.Android.Support.Vector.Drawable.23.3.0\lib\MonoAndroid403\Xamarin.Android.Support.Vector.Drawable.dll + ..\..\..\packages\Xamarin.Android.Support.Vector.Drawable.25.4.0.2\lib\MonoAndroid70\Xamarin.Android.Support.Vector.Drawable.dll - ..\packages\Xamarin.Android.Support.Animated.Vector.Drawable.23.3.0\lib\MonoAndroid403\Xamarin.Android.Support.Animated.Vector.Drawable.dll + ..\..\..\packages\Xamarin.Android.Support.Animated.Vector.Drawable.25.4.0.2\lib\MonoAndroid70\Xamarin.Android.Support.Animated.Vector.Drawable.dll - ..\packages\Xamarin.Android.Support.v7.AppCompat.23.3.0\lib\MonoAndroid403\Xamarin.Android.Support.v7.AppCompat.dll + ..\..\..\packages\Xamarin.Android.Support.v7.AppCompat.25.4.0.2\lib\MonoAndroid70\Xamarin.Android.Support.v7.AppCompat.dll - ..\packages\Xamarin.Android.Support.Design.23.3.0\lib\MonoAndroid43\Xamarin.Android.Support.Design.dll + ..\..\..\packages\Xamarin.Android.Support.Design.25.4.0.2\lib\MonoAndroid70\Xamarin.Android.Support.Design.dll - ..\packages\Xamarin.Android.Support.v7.MediaRouter.23.3.0\lib\MonoAndroid403\Xamarin.Android.Support.v7.MediaRouter.dll + ..\..\..\packages\Xamarin.Android.Support.v7.MediaRouter.25.4.0.2\lib\MonoAndroid70\Xamarin.Android.Support.v7.MediaRouter.dll - - ..\packages\CommonServiceLocator.1.3\lib\portable-net4+sl5+netcore45+wpa81+wp8\Microsoft.Practices.ServiceLocation.dll + + ..\..\..\packages\Xamarin.Forms.2.5.0.121934\lib\MonoAndroid10\FormsViewGroup.dll - - ..\packages\Unity.4.0.1\lib\portable-net45+wp80+win8+wpa81+MonoAndroid10+MonoTouch10\Microsoft.Practices.Unity.dll + + ..\..\..\packages\Xamarin.Forms.2.5.0.121934\lib\MonoAndroid10\Xamarin.Forms.Core.dll + + + ..\..\..\packages\Xamarin.Forms.2.5.0.121934\lib\MonoAndroid10\Xamarin.Forms.Platform.Android.dll + + + ..\..\..\packages\Xamarin.Forms.2.5.0.121934\lib\MonoAndroid10\Xamarin.Forms.Platform.dll + + + ..\..\..\packages\Xamarin.Forms.2.5.0.121934\lib\MonoAndroid10\Xamarin.Forms.Xaml.dll - - - ..\packages\Prism.Core.6.3.0-pre1\lib\MonoAndroid10\Prism.dll + ..\..\..\packages\Prism.Core.6.3.0\lib\MonoAndroid10\Prism.dll - ..\packages\Prism.Forms.6.3.0-pre1\lib\MonoAndroid1.0\Prism.Forms.dll + ..\..\..\packages\Prism.Forms.6.3.0\lib\MonoAndroid1.0\Prism.Forms.dll - ..\packages\Prism.Unity.Forms.6.3.0-pre1\lib\MonoAndroid1.0\Prism.Unity.Forms.dll + ..\..\..\packages\Prism.Unity.Forms.6.3.0\lib\MonoAndroid1.0\Prism.Unity.Forms.dll + + - ..\..\..\packages\System.Reactive.Interfaces.3.0.0\lib\netstandard1.0\System.Reactive.Interfaces.dll + ..\..\..\packages\System.Reactive.Interfaces.3.1.1\lib\netstandard1.0\System.Reactive.Interfaces.dll - ..\..\..\packages\System.Reactive.Core.3.0.0\lib\netstandard1.3\System.Reactive.Core.dll + ..\..\..\packages\System.Reactive.Core.3.1.1\lib\netstandard1.3\System.Reactive.Core.dll - ..\..\..\packages\System.Reactive.Linq.3.0.0\lib\netstandard1.3\System.Reactive.Linq.dll + ..\..\..\packages\System.Reactive.Linq.3.1.1\lib\netstandard1.3\System.Reactive.Linq.dll - ..\..\..\packages\System.Reactive.PlatformServices.3.0.0\lib\netstandard1.3\System.Reactive.PlatformServices.dll + ..\..\..\packages\System.Reactive.PlatformServices.3.1.1\lib\netstandard1.3\System.Reactive.PlatformServices.dll - ..\..\..\packages\ReactiveProperty.3.2.0\lib\MonoAndroid\ReactiveProperty.Android.dll + ..\..\..\packages\ReactiveProperty.3.6.0\lib\MonoAndroid\ReactiveProperty.Android.dll - ..\..\..\packages\ReactiveProperty.3.2.0\lib\MonoAndroid\ReactiveProperty.dll - - - ..\..\..\packages\Xamarin.Forms.2.4.0.282\lib\MonoAndroid10\FormsViewGroup.dll - - - ..\..\..\packages\Xamarin.Forms.2.4.0.282\lib\MonoAndroid10\Xamarin.Forms.Core.dll - - - ..\..\..\packages\Xamarin.Forms.2.4.0.282\lib\MonoAndroid10\Xamarin.Forms.Platform.Android.dll - - - ..\..\..\packages\Xamarin.Forms.2.4.0.282\lib\MonoAndroid10\Xamarin.Forms.Platform.dll - - - ..\..\..\packages\Xamarin.Forms.2.4.0.282\lib\MonoAndroid10\Xamarin.Forms.Xaml.dll + ..\..\..\packages\ReactiveProperty.3.6.0\lib\MonoAndroid\ReactiveProperty.dll - ..\..\..\packages\AiForms.Effects.1.1.0-pre1\lib\MonoAndroid\AiForms.Effects.dll + ..\..\..\packages\AiForms.Effects.1.1.1\lib\MonoAndroid\AiForms.Effects.dll - ..\..\..\packages\AiForms.Effects.1.1.0-pre1\lib\MonoAndroid\AiForms.Effects.Droid.dll + ..\..\..\packages\AiForms.Effects.1.1.1\lib\MonoAndroid\AiForms.Effects.Droid.dll @@ -166,5 +192,20 @@ - + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Tests/AiEffects.TestApp/AiEffects.TestApp.Droid/MainActivity.cs b/Tests/AiEffects.TestApp/AiEffects.TestApp.Droid/MainActivity.cs index 8384517..72f9ac7 100644 --- a/Tests/AiEffects.TestApp/AiEffects.TestApp.Droid/MainActivity.cs +++ b/Tests/AiEffects.TestApp/AiEffects.TestApp.Droid/MainActivity.cs @@ -9,6 +9,8 @@ using Android.OS; using Prism.Unity; using Microsoft.Practices.Unity; +using Xamarin.Forms.Internals; +using Android.Media; namespace AiEffects.TestApp.Droid { diff --git a/Tests/AiEffects.TestApp/AiEffects.TestApp.Droid/packages.config b/Tests/AiEffects.TestApp/AiEffects.TestApp.Droid/packages.config index 907d57b..5dab7e2 100644 --- a/Tests/AiEffects.TestApp/AiEffects.TestApp.Droid/packages.config +++ b/Tests/AiEffects.TestApp/AiEffects.TestApp.Droid/packages.config @@ -1,43 +1,86 @@  - + - - - - + + + + + + + + + + + + + + + + + + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Tests/AiEffects.TestApp/AiEffects.TestApp.iOS/AiEffects.TestApp.iOS.csproj b/Tests/AiEffects.TestApp/AiEffects.TestApp.iOS/AiEffects.TestApp.iOS.csproj index bfac557..74653f5 100644 --- a/Tests/AiEffects.TestApp/AiEffects.TestApp.iOS/AiEffects.TestApp.iOS.csproj +++ b/Tests/AiEffects.TestApp/AiEffects.TestApp.iOS/AiEffects.TestApp.iOS.csproj @@ -1,6 +1,6 @@  - + Debug iPhoneSimulator @@ -94,53 +94,55 @@ ..\packages\Unity.4.0.1\lib\portable-net45+wp80+win8+wpa81+MonoAndroid10+MonoTouch10\Microsoft.Practices.Unity.dll + + ..\..\..\packages\Xamarin.TestCloud.Agent.0.20.6\lib\Xamarin.iOS10\Calabash.dll + + + ..\..\..\packages\Xamarin.Forms.2.5.0.121934\lib\Xamarin.iOS10\Xamarin.Forms.Core.dll + + + ..\..\..\packages\Xamarin.Forms.2.5.0.121934\lib\Xamarin.iOS10\Xamarin.Forms.Platform.dll + + + ..\..\..\packages\Xamarin.Forms.2.5.0.121934\lib\Xamarin.iOS10\Xamarin.Forms.Platform.iOS.dll + + + ..\..\..\packages\Xamarin.Forms.2.5.0.121934\lib\Xamarin.iOS10\Xamarin.Forms.Xaml.dll + - ..\packages\Prism.Core.6.3.0-pre1\lib\Xamarin.iOS10\Prism.dll + ..\..\..\packages\Prism.Core.6.3.0\lib\Xamarin.iOS10\Prism.dll - ..\packages\Prism.Forms.6.3.0-pre1\lib\Xamarin.iOS1.0\Prism.Forms.dll + ..\..\..\packages\Prism.Forms.6.3.0\lib\Xamarin.iOS1.0\Prism.Forms.dll - ..\packages\Prism.Unity.Forms.6.3.0-pre1\lib\Xamarin.iOS1.0\Prism.Unity.Forms.dll + ..\..\..\packages\Prism.Unity.Forms.6.3.0\lib\Xamarin.iOS1.0\Prism.Unity.Forms.dll + + - ..\..\..\packages\System.Reactive.Interfaces.3.0.0\lib\netstandard1.0\System.Reactive.Interfaces.dll + ..\..\..\packages\System.Reactive.Interfaces.3.1.1\lib\netstandard1.0\System.Reactive.Interfaces.dll - ..\..\..\packages\System.Reactive.Core.3.0.0\lib\netstandard1.3\System.Reactive.Core.dll + ..\..\..\packages\System.Reactive.Core.3.1.1\lib\netstandard1.3\System.Reactive.Core.dll - ..\..\..\packages\System.Reactive.Linq.3.0.0\lib\netstandard1.3\System.Reactive.Linq.dll + ..\..\..\packages\System.Reactive.Linq.3.1.1\lib\netstandard1.3\System.Reactive.Linq.dll - ..\..\..\packages\System.Reactive.PlatformServices.3.0.0\lib\netstandard1.3\System.Reactive.PlatformServices.dll + ..\..\..\packages\System.Reactive.PlatformServices.3.1.1\lib\netstandard1.3\System.Reactive.PlatformServices.dll - ..\..\..\packages\ReactiveProperty.3.2.0\lib\Xamarin.iOS10\ReactiveProperty.dll + ..\..\..\packages\ReactiveProperty.3.6.0\lib\Xamarin.iOS10\ReactiveProperty.dll - ..\..\..\packages\ReactiveProperty.3.2.0\lib\Xamarin.iOS10\ReactiveProperty.iOS.dll - - - ..\..\..\packages\Xamarin.TestCloud.Agent.0.20.6\lib\Xamarin.iOS10\Calabash.dll - - - ..\..\..\packages\Xamarin.Forms.2.4.0.282\lib\Xamarin.iOS10\Xamarin.Forms.Core.dll - - - ..\..\..\packages\Xamarin.Forms.2.4.0.282\lib\Xamarin.iOS10\Xamarin.Forms.Platform.dll - - - ..\..\..\packages\Xamarin.Forms.2.4.0.282\lib\Xamarin.iOS10\Xamarin.Forms.Platform.iOS.dll - - - ..\..\..\packages\Xamarin.Forms.2.4.0.282\lib\Xamarin.iOS10\Xamarin.Forms.Xaml.dll + ..\..\..\packages\ReactiveProperty.3.6.0\lib\Xamarin.iOS10\ReactiveProperty.iOS.dll - ..\..\..\packages\AiForms.Effects.1.1.0-pre1\lib\Xamarin.iOS10\AiForms.Effects.dll + ..\..\..\packages\AiForms.Effects.1.1.1\lib\Xamarin.iOS10\AiForms.Effects.dll - ..\..\..\packages\AiForms.Effects.1.1.0-pre1\lib\Xamarin.iOS10\AiForms.Effects.iOS.dll + ..\..\..\packages\AiForms.Effects.1.1.1\lib\Xamarin.iOS10\AiForms.Effects.iOS.dll @@ -174,5 +176,5 @@ - + \ No newline at end of file diff --git a/Tests/AiEffects.TestApp/AiEffects.TestApp.iOS/packages.config b/Tests/AiEffects.TestApp/AiEffects.TestApp.iOS/packages.config index 6a8821f..21e22d3 100644 --- a/Tests/AiEffects.TestApp/AiEffects.TestApp.iOS/packages.config +++ b/Tests/AiEffects.TestApp/AiEffects.TestApp.iOS/packages.config @@ -1,42 +1,74 @@  - + - - - - + + + + + + + + + + + + + + + + + + + + + + - - - - - + + + + + + + + + + + + + + + + + + + - + \ No newline at end of file diff --git a/Tests/AiEffects.TestApp/AiEffects.TestApp/AiEffects.TestApp.csproj b/Tests/AiEffects.TestApp/AiEffects.TestApp/AiEffects.TestApp.csproj index 26ba982..34febd2 100644 --- a/Tests/AiEffects.TestApp/AiEffects.TestApp/AiEffects.TestApp.csproj +++ b/Tests/AiEffects.TestApp/AiEffects.TestApp/AiEffects.TestApp.csproj @@ -8,8 +8,7 @@ Library AiEffects.TestApp AiEffects.TestApp - v4.6 - Profile44 + v5.0 0.0.5-pre @@ -77,6 +76,10 @@ PlaceholderPage.xaml + + SizeToFitPage.xaml + + @@ -115,6 +118,10 @@ MSBuild:UpdateDesignTimeXaml + + Designer + MSBuild:UpdateDesignTimeXaml + @@ -123,47 +130,9 @@ ..\packages\Unity.4.0.1\lib\portable-net45+wp80+win8+wpa81+MonoAndroid10+MonoTouch10\Microsoft.Practices.Unity.dll - - ..\packages\Prism.Core.6.3.0-pre1\lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Prism.dll - - - ..\packages\Prism.Forms.6.3.0-pre1\lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Prism.Forms.dll - - - ..\packages\Prism.Unity.Forms.6.3.0-pre1\lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Prism.Unity.Forms.dll - - - ..\..\..\packages\System.Reactive.Interfaces.3.0.0\lib\netstandard1.0\System.Reactive.Interfaces.dll - - - ..\..\..\packages\System.Reactive.Core.3.0.0\lib\netstandard1.1\System.Reactive.Core.dll - - - ..\..\..\packages\System.Reactive.Linq.3.0.0\lib\netstandard1.1\System.Reactive.Linq.dll - - - ..\..\..\packages\System.Reactive.PlatformServices.3.0.0\lib\netstandard1.0\System.Reactive.PlatformServices.dll - - - ..\..\..\packages\ReactiveProperty.3.2.0\lib\portable-net45+win81+MonoTouch+MonoAndroid\ReactiveProperty.dll - - - ..\..\..\packages\Xamarin.Forms.2.4.0.282\lib\portable-win+net45+wp80+win81+wpa81\Xamarin.Forms.Core.dll - - - ..\..\..\packages\Xamarin.Forms.2.4.0.282\lib\portable-win+net45+wp80+win81+wpa81\Xamarin.Forms.Platform.dll - - - ..\..\..\packages\Xamarin.Forms.2.4.0.282\lib\portable-win+net45+wp80+win81+wpa81\Xamarin.Forms.Xaml.dll - - - ..\..\..\packages\AiForms.Effects.1.1.0-pre1\lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\AiForms.Effects.dll - - + - - - \ No newline at end of file + diff --git a/Tests/AiEffects.TestApp/AiEffects.TestApp/AiEffects.TestApp.nuget.props b/Tests/AiEffects.TestApp/AiEffects.TestApp/AiEffects.TestApp.nuget.props new file mode 100644 index 0000000..2e859dc --- /dev/null +++ b/Tests/AiEffects.TestApp/AiEffects.TestApp/AiEffects.TestApp.nuget.props @@ -0,0 +1,18 @@ + + + + True + NuGet + /Users/kamu/Projects/AiForms.Effects/Tests/AiEffects.TestApp/AiEffects.TestApp/project.lock.json + /Users/kamu/.nuget/packages/ + /Users/kamu/.nuget/packages/ + ProjectJson + 4.3.1 + + + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) + + + + + \ No newline at end of file diff --git a/Tests/AiEffects.TestApp/AiEffects.TestApp/AiEffects.TestApp.nuget.targets b/Tests/AiEffects.TestApp/AiEffects.TestApp/AiEffects.TestApp.nuget.targets new file mode 100644 index 0000000..f685a79 --- /dev/null +++ b/Tests/AiEffects.TestApp/AiEffects.TestApp/AiEffects.TestApp.nuget.targets @@ -0,0 +1,9 @@ + + + + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) + + + + + \ No newline at end of file diff --git a/Tests/AiEffects.TestApp/AiEffects.TestApp/ViewModels/SizeToFitPageViewModel.cs b/Tests/AiEffects.TestApp/AiEffects.TestApp/ViewModels/SizeToFitPageViewModel.cs new file mode 100644 index 0000000..a3cdadd --- /dev/null +++ b/Tests/AiEffects.TestApp/AiEffects.TestApp/ViewModels/SizeToFitPageViewModel.cs @@ -0,0 +1,103 @@ +using System; +using Reactive.Bindings; +using Xamarin.Forms; + +namespace AiEffects.TestApp.ViewModels +{ + public class SizeToFitPageViewModel + { + public ReactiveProperty EffectOn { get; } = new ReactiveProperty(); + public ReactiveProperty LabelText { get; } = new ReactiveProperty(); + public ReactiveProperty LabelHeight { get; } = new ReactiveProperty(); + public ReactiveProperty LabelWidth { get; } = new ReactiveProperty(); + public ReactiveProperty FontSize { get; } = new ReactiveProperty(); + public ReactiveProperty CanExpand { get; } = new ReactiveProperty(false); + public ReactiveProperty TextAlign { get; } = new ReactiveProperty(); + public ReactiveProperty VTextAlign { get; } = new ReactiveProperty(); + public ReactiveProperty TextToggle { get; } = new ReactiveProperty(); + public ReactiveProperty HeightToggle { get; } = new ReactiveProperty(); + public ReactiveProperty WidthToggle { get; } = new ReactiveProperty(); + public ReactiveProperty FontToggle { get; } = new ReactiveProperty(); + public ReactiveProperty ExpandToggle { get; } = new ReactiveProperty(); + + public ReactiveCommand HAlignCommand { get; } = new ReactiveCommand(); + public ReactiveCommand VAlignCommand { get; } = new ReactiveCommand(); + + public SizeToFitPageViewModel() + { + EffectOn.Value = false; + + LabelHeight.Value = 40f; + + TextToggle.Subscribe(x=>{ + if (!x) + { + LabelText.Value = "ShortTextEnd"; + } + else{ + LabelText.Value = "LongTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextEnd"; + } + }); + + HeightToggle.Subscribe(x=>{ + if(x){ + LabelHeight.Value = 400f; + } + else{ + LabelHeight.Value = 40f; + } + }); + + WidthToggle.Subscribe(x=>{ + if(x){ + LabelWidth.Value = 320f; + } + else{ + LabelWidth.Value = 150f; + } + }); + + FontToggle.Subscribe(x=>{ + if(x){ + FontSize.Value = 28f; + } + else{ + FontSize.Value = 14f; + } + }); + + + ExpandToggle.Subscribe(x=>{ + CanExpand.Value = x; + }); + ExpandToggle.Value = true; + + HAlignCommand.Subscribe(_=>{ + if(TextAlign.Value == TextAlignment.Start){ + TextAlign.Value = TextAlignment.Center; + } + else if(TextAlign.Value == TextAlignment.Center){ + TextAlign.Value = TextAlignment.End; + } + else if(TextAlign.Value == TextAlignment.End){ + TextAlign.Value = TextAlignment.Start; + } + }); + + VAlignCommand.Subscribe(_ => { + if (VTextAlign.Value == TextAlignment.Start) + { + VTextAlign.Value = TextAlignment.Center; + } + else if (VTextAlign.Value == TextAlignment.Center) + { + VTextAlign.Value = TextAlignment.End; + } + else if (VTextAlign.Value == TextAlignment.End) + { + VTextAlign.Value = TextAlignment.Start; + } + }); + } + } +} diff --git a/Tests/AiEffects.TestApp/AiEffects.TestApp/Views/MainPage.xaml b/Tests/AiEffects.TestApp/AiEffects.TestApp/Views/MainPage.xaml index 3f6626e..da9777a 100644 --- a/Tests/AiEffects.TestApp/AiEffects.TestApp/Views/MainPage.xaml +++ b/Tests/AiEffects.TestApp/AiEffects.TestApp/Views/MainPage.xaml @@ -64,6 +64,10 @@