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 /// LottieButtonExtension is a ButtonExtension class that uses Lottie image for a Button icon.
26 /// This extension must be used within a class implementing LottieButtonStyle.
29 [EditorBrowsable(EditorBrowsableState.Never)]
30 public class LottieButtonExtension : ButtonExtension
33 /// A constructor that creates LottieButtonExtension with a specified Lottie resource URL
35 [EditorBrowsable(EditorBrowsableState.Never)]
36 public LottieButtonExtension() : base()
38 LottieView = new LottieAnimationView();
42 /// The Lottie view that will be used as an icon part in a Button.
44 [EditorBrowsable(EditorBrowsableState.Never)]
45 protected LottieAnimationView LottieView { get; set; }
48 [EditorBrowsable(EditorBrowsableState.Never)]
49 public override ImageView OnCreateIcon(Button button, ImageView icon)
51 InitializeLottieView(button, LottieView);
57 [EditorBrowsable(EditorBrowsableState.Never)]
58 public override void OnControlStateChanged(Button button, ControlStates previousState, Touch touchInfo)
60 UpdateLottieView(button, previousState, touchInfo, LottieView);
63 internal static void InitializeLottieView(Button button, LottieAnimationView lottieView)
65 if (button.Style as ILottieButtonStyle == null)
67 throw new Exception("LottieButtonExtension must be used within a ILottieButtonStyle or derived class.");
70 var lottieStyle = (ILottieButtonStyle)button.Style;
71 lottieView.URL = lottieStyle.LottieUrl;
72 lottieView.StopBehavior = LottieAnimationView.StopBehaviorType.MaximumFrame;
73 lottieStyle.PlayRange?.GetValue(ControlStates.Normal)?.Show(lottieView, true);
76 internal static void UpdateLottieView(Button button, ControlStates previousState, Touch touchInfo, LottieAnimationView lottieView)
78 ((ILottieButtonStyle)button.Style).PlayRange?.GetValue(button.ControlState)?.Show(lottieView, ((int)previousState & (int)ControlStates.Pressed) == 0);