4 namespace Tizen.Xamarin.Forms.Extension
7 /// The FloatingButton class
8 /// This is only supported for mobile profiles.
12 /// FloatingButton floatingButton = new FloatingButton
14 /// MovablePosition = FloatingButtonMovablePosition.All,
17 /// FloatingButtonItem item = new FloatingButtonItem();
18 /// item.Icon = new FileImageSource { File = "Icon.png" };
19 /// item.Clicked += (s,e) => { ... };
20 /// floatingButton.FirstButton = item;
22 /// this.Appearing += (s,e) =>
24 /// If (!floatingButton.IsShown)
25 /// floatingButton.Show();
27 /// this.Disappearing += (s,e) =>
29 /// If (floatingButton.IsShown)
30 /// floatingButton.Hide();
34 public class FloatingButton : BindableObject, IFloatingButton
36 public static readonly BindableProperty MovablePositionProperty = BindableProperty.Create(nameof(MovablePosition), typeof(FloatingButtonMovablePosition), typeof(FloatingButton), FloatingButtonMovablePosition.All);
38 public static readonly BindableProperty IsShownProperty = BindableProperty.Create(nameof(IsShown), typeof(bool), typeof(FloatingButton), true);
40 public static readonly BindableProperty FirstButtonProperty = BindableProperty.Create(nameof(FirstButton), typeof(FloatingButtonItem), typeof(FloatingButton), null);
42 public static readonly BindableProperty SecondButtonProperty = BindableProperty.Create(nameof(SecondButton), typeof(FloatingButtonItem), typeof(FloatingButton), null);
44 IFloatingButton _floatingButton = null;
47 /// Gets or sets the movability state of the FloatingButton. This is a bindable property.
49 public FloatingButtonMovablePosition MovablePosition
51 get { return (FloatingButtonMovablePosition)GetValue(MovablePositionProperty); }
52 set { SetValue(MovablePositionProperty, value); }
56 /// Gets the horizontal position of the FloatingButton. This is a bindable property
58 public FloatingButtonPosition Position
60 get { return _floatingButton.Position; }
64 /// Gets the visible state of the FloatingButton.
68 get { return (bool)GetValue(IsShownProperty); }
69 internal set { SetValue(IsShownProperty, value); }
73 /// Gets and sets the internal button of the FloatingButton
75 public FloatingButtonItem FirstButton
77 get { return (FloatingButtonItem)GetValue(FirstButtonProperty); }
78 set { SetValue(FirstButtonProperty, value); }
82 /// Gets and sets the internal button of the FloatingButton
84 public FloatingButtonItem SecondButton
86 get { return (FloatingButtonItem)GetValue(SecondButtonProperty); }
87 set { SetValue(SecondButtonProperty, value); }
91 /// Sets the horizontal position of the FloatingButton.
93 /// <param name="position"> FloatingButtonPosition value </param>
94 /// <param name="animated"> Bool value to set the animation when moving the position </param>
95 public void SetPosition(FloatingButtonPosition position, bool animated)
97 if (MovablePosition != FloatingButtonMovablePosition.None)
99 _floatingButton.SetPosition(position, animated);
104 /// A method to hide the FloatingButton
109 _floatingButton.Hide();
113 /// A method to show the FloatingButton
118 _floatingButton.Show();
121 public FloatingButton()
123 if (Device.Idiom != TargetIdiom.Phone)
124 throw new Exception("FloatingButton is support only mobile profile.");
126 _floatingButton = DependencyService.Get<IFloatingButton>(DependencyFetchTarget.GlobalInstance);
128 if (_floatingButton == null)
129 throw new Exception("Object reference not set to an instance of a FloatingButton.");
131 SetBinding(MovablePositionProperty, new Binding(nameof(MovablePosition), mode: BindingMode.TwoWay, source: _floatingButton));
132 SetBinding(FirstButtonProperty, new Binding(nameof(FirstButton), mode: BindingMode.TwoWay, source: _floatingButton));
133 SetBinding(SecondButtonProperty, new Binding(nameof(SecondButton), mode: BindingMode.TwoWay, source: _floatingButton));