Created
September 1, 2017 15:04
-
-
Save olexale/b4cfff068eef592049db4e504794a1b5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace BeatlesApp | |
| { | |
| public class TagEffect : RoutingEffect | |
| { | |
| public TagEffect() : base("BeatlesApp.TagEffect") {} | |
| public static readonly BindableProperty TagProperty = | |
| BindableProperty.CreateAttached("Tag", typeof(int), typeof(TagEffect), 0, propertyChanged: OnTagChanged); | |
| public static int GetTag(BindableObject view) | |
| { | |
| return (int)view.GetValue(TagProperty); | |
| } | |
| public static void SetTag(BindableObject view, int value) | |
| { | |
| view.SetValue(TagProperty, value); | |
| } | |
| static void OnTagChanged(BindableObject bindable, object oldValue, object newValue) | |
| { | |
| var view = bindable as View; | |
| if (view == null) { return ; } | |
| var tag = (int)newValue; | |
| if (tag > 0) | |
| { | |
| view.Effects.Add(new TagEffect()); | |
| } | |
| else | |
| { | |
| var toRemove = view.Effects.FirstOrDefault(e => e is TagEffect); | |
| if (toRemove != null) | |
| { | |
| view.Effects.Remove(toRemove); | |
| } | |
| } | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [assembly: ResolutionGroupName("BeatlesApp")] | |
| [assembly: ExportEffect(typeof(TagEffect), "TagEffect")] | |
| namespace BeatlesApp.iOS | |
| { | |
| public class TagEffect : PlatformEffect | |
| { | |
| private System.nint _tag; | |
| protected override void OnAttached() | |
| { | |
| _tag = Control.Tag; | |
| Control.Tag = BeatlesApp.TagEffect.GetTag(Element); | |
| } | |
| protected override void OnDetached() | |
| { | |
| Control.Tag = _tag; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment