2 * Copyright(c) 2020 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.ComponentModel;
19 using Tizen.NUI.BaseComponents;
21 namespace Tizen.NUI.Components.Extension
24 /// The SlidingSwitchExtension class makes attached Switch to animate thumb when selected/unselected.
26 /// This extension must be used within a class implementing SwitchStyle.
29 [EditorBrowsable(EditorBrowsableState.Never)]
30 internal class SlidingSwitchExtension : SwitchExtension
32 private Animation slidingAnimation;
34 public SlidingSwitchExtension() : base()
36 slidingAnimation = new Animation(100);
40 public override void OnSelectedChanged(Switch switchButton)
42 var track = switchButton.Track;
43 var thumb = switchButton.Thumb;
45 if (track == null || thumb == null || null == slidingAnimation)
50 if (slidingAnimation.State == Animation.States.Playing)
52 slidingAnimation.Stop();
55 slidingAnimation.Clear();
56 slidingAnimation.AnimateTo(thumb, "PositionX", track.Size.Width - thumb.Size.Width - thumb.Position.X);
57 slidingAnimation.Play();
60 public override void OnDispose(Button button)
62 if (slidingAnimation != null)
64 if (slidingAnimation.State == Animation.States.Playing)
66 slidingAnimation.Stop();
68 slidingAnimation.Dispose();
69 slidingAnimation = null;