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.Collections.Generic;
20 using System.ComponentModel;
25 /// Define a List of LayoutTransitions
27 /// <since_tizen> 6 </since_tizen>
28 public class TransitionList : List<LayoutTransition> { }
31 /// The conditions for transitions.
33 /// <since_tizen> 6 </since_tizen>
35 public enum TransitionCondition
38 /// Default when a condition has not been set.
40 /// <since_tizen> 6 </since_tizen>
43 /// Animate changing layout to another layout.
45 /// <since_tizen> 6 </since_tizen>
49 /// Animate adding item.
51 /// <since_tizen> 6 </since_tizen>
55 /// Animate removing item.
57 /// <since_tizen> 6 </since_tizen>
61 /// Animation when an item changes due to a being added.
63 /// <since_tizen> 6 </since_tizen>
67 /// Animation when an item changes due to a being removed.
69 /// <since_tizen> 6 </since_tizen>
75 /// The properties that can be animated.
77 /// <since_tizen> 6 </since_tizen>
78 public enum AnimatableProperties
81 /// Position property.
83 /// <since_tizen> 6 </since_tizen>
89 /// <since_tizen> 6 </since_tizen>
95 /// <since_tizen> 6 </since_tizen>
101 /// Parts of the transition that can be configured to provide a custom effect.
103 /// <since_tizen> 6 </since_tizen>
104 public class TransitionComponents : Disposable
107 /// TransitionComponents default constructor.
109 /// <since_tizen> 6 </since_tizen>
110 public TransitionComponents()
114 AlphaFunction = new AlphaFunction(AlphaFunction.BuiltinFunctions.Linear);
118 /// destructor. This is HiddenAPI. recommended not to use in public.
120 [EditorBrowsable(EditorBrowsableState.Never)]
121 ~TransitionComponents()
127 /// TransitionComponents constructor. Stores delay, duration and AlphaFunction.
129 /// <param name="delay">The delay before the animator starts.</param>
130 /// <param name="duration">the duration of the animator.</param>
131 /// <param name="alphaFunction">alpha function to use .</param>
132 /// <since_tizen> 6 </since_tizen>
134 public TransitionComponents(int delay, int duration, AlphaFunction alphaFunction)
138 AlphaFunction = alphaFunction;
142 /// Get, Set the time transition should execute for . Milliseconds.
144 /// <since_tizen> 6 </since_tizen>
147 /// Get, Set the delay before the transition executes. Milliseconds.
149 /// <since_tizen> 6 </since_tizen>
152 /// Get, Set the function to alter the transition path over time.
154 /// <since_tizen> 6 </since_tizen>
155 public AlphaFunction AlphaFunction;
158 /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
160 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
161 [EditorBrowsable(EditorBrowsableState.Never)]
162 protected override void Dispose(DisposeTypes type)
169 AlphaFunction.Dispose();
175 /// LayoutTransition stores the animation setting for a transition conidition.
177 public class LayoutTransition
180 /// LayoutTransition default constructor.
182 /// <since_tizen> 6 </since_tizen>
183 public LayoutTransition()
185 Condition = TransitionCondition.Unspecified;
186 AnimatableProperty = AnimatableProperties.Position;
191 /// LayoutTransition constructor.
193 /// <param name="condition">The animatable condition.</param>
194 /// <param name="animatableProperty">the property to animate.</param>
195 /// <param name="targetValue">target value of the property.</param>
196 /// <param name="animator">Components to define the animator.</param>
197 /// <since_tizen> 6 </since_tizen>
198 public LayoutTransition(TransitionCondition condition,
199 AnimatableProperties animatableProperty,
201 TransitionComponents animator)
203 Condition = condition;
204 AnimatableProperty = animatableProperty;
206 TargetValue = targetValue;
210 /// Condition for this Transition
212 /// <since_tizen> 6 </since_tizen>
214 public TransitionCondition Condition { get; set; }
216 /// Property to animate.
218 /// <since_tizen> 6 </since_tizen>
220 public AnimatableProperties AnimatableProperty { get; set; }
222 /// Components of the Animator.
224 /// <since_tizen> 6 </since_tizen>
226 public TransitionComponents Animator { get; set; }
228 /// Target value to animate to.
230 /// <since_tizen> 6 </since_tizen>
232 public object TargetValue { get; set; }
237 /// Class to help manage the adding and updating of transitions.
239 internal static class LayoutTransitionsHelper
242 /// Adds the given transition and condition to a transition list.
244 /// <param name="targetTransitionList">The list to add the transition to.</param>
245 /// <param name="condition">Condition for the transition.</param>
246 /// <param name="transition">The transition to add.</param>
247 /// <param name="explicitlySet">True is set explicitly, false if inherited.</param>
248 static public void AddTransitionForCondition(
249 Dictionary<TransitionCondition, TransitionList> targetTransitionList,
250 TransitionCondition condition,
251 LayoutTransition transition,
254 bool replaced = false;
255 bool conditionNotInDictionary = false;
256 TransitionList transitionListMatchingCondition;
257 if (targetTransitionList.TryGetValue(condition, out transitionListMatchingCondition))
259 if (transitionListMatchingCondition != null)
261 for (var index = 0; index < transitionListMatchingCondition.Count; index++)
263 if (transitionListMatchingCondition[index].AnimatableProperty == transition.AnimatableProperty)
267 transitionListMatchingCondition[index] = transition;
277 conditionNotInDictionary = true;
280 if (replaced == false)
282 if (transitionListMatchingCondition == null)
284 transitionListMatchingCondition = new TransitionList();
286 transitionListMatchingCondition.Add(transition);
287 // Update dictionary with new or replaced entry.
288 if (conditionNotInDictionary)
290 targetTransitionList.Add(condition, transitionListMatchingCondition); // new entry
294 targetTransitionList[condition] = transitionListMatchingCondition; // replaced
300 /// Retreive the transition list for the given condition.
302 /// <param name="sourceTransitionCollection">The source collection of transition lists to retrieve.</param>
303 /// <param name="condition">Condition for the transition.</param>
304 /// <param name="transitionsForCondition">transition list to return as out parameter.</param>
305 /// <returns>True if a transition list found for the given condition></returns>
306 static public bool GetTransitionsListForCondition(
307 Dictionary<TransitionCondition, TransitionList> sourceTransitionCollection,
308 TransitionCondition condition,
309 TransitionList transitionsForCondition)
311 TransitionCondition resolvedCondition = condition;
312 bool matched = false;
313 // LayoutChanged transitions overrides ChangeOnAdd and ChangeOnRemove as siblings will
314 // reposition to the new layout not to the insertion/removal of a sibling.
315 if ((condition & TransitionCondition.LayoutChanged) == TransitionCondition.LayoutChanged)
317 resolvedCondition = TransitionCondition.LayoutChanged;
320 if (sourceTransitionCollection.TryGetValue(resolvedCondition, out transitionsForCondition))
329 /// Copy the transitions in the source list to the target list
331 /// <param name="sourceTransitionList">The source transition list.</param>
332 /// <param name="targetTransitionList">The target transition list to copy to.</param>
333 static public void CopyTransitions(TransitionList sourceTransitionList,
334 TransitionList targetTransitionList)
336 targetTransitionList.Clear();
337 foreach (LayoutTransition transitionToApply in sourceTransitionList)
339 // Overwite existing transitions
340 targetTransitionList.Add(transitionToApply);
346 } // namespace Tizen.NUI