2 * Copyright (c) 2019 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;
21 using System.Diagnostics.CodeAnalysis;
26 /// Define a List of LayoutTransitions
28 /// <since_tizen> 6 </since_tizen>
29 public class TransitionList : List<LayoutTransition> { }
32 /// The conditions for transitions.
34 /// <since_tizen> 6 </since_tizen>
36 public enum TransitionCondition
39 /// Default when a condition has not been set.
41 /// <since_tizen> 6 </since_tizen>
44 /// Animate changing layout to another layout.
46 /// <since_tizen> 6 </since_tizen>
50 /// Animate adding item.
52 /// <since_tizen> 6 </since_tizen>
56 /// Animate removing item.
58 /// <since_tizen> 6 </since_tizen>
62 /// Animation when an item changes due to a being added.
64 /// <since_tizen> 6 </since_tizen>
68 /// Animation when an item changes due to a being removed.
70 /// <since_tizen> 6 </since_tizen>
76 /// The properties that can be animated.
78 /// <since_tizen> 6 </since_tizen>
79 [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1717:Only FlagsAttribute enums should have plural names")]
80 public enum AnimatableProperties
83 /// Position property.
85 /// <since_tizen> 6 </since_tizen>
91 /// <since_tizen> 6 </since_tizen>
97 /// <since_tizen> 6 </since_tizen>
103 /// Parts of the transition that can be configured to provide a custom effect.
105 /// <since_tizen> 6 </since_tizen>
106 public class TransitionComponents : IDisposable
108 private bool disposed = false;
110 /// TransitionComponents default constructor.
112 /// <since_tizen> 6 </since_tizen>
113 public TransitionComponents()
117 AlphaFunction = new AlphaFunction(AlphaFunction.BuiltinFunctions.Linear);
121 /// TransitionComponents constructor. Stores delay, duration and AlphaFunction.
123 /// <param name="delay">The delay before the animator starts.</param>
124 /// <param name="duration">the duration of the animator.</param>
125 /// <param name="alphaFunction">alpha function to use .</param>
126 /// <since_tizen> 6 </since_tizen>
128 public TransitionComponents(int delay, int duration, AlphaFunction alphaFunction)
132 AlphaFunction = alphaFunction;
136 /// Get, Set the time transition should execute for . Milliseconds.
138 /// <since_tizen> 6 </since_tizen>
139 /// When deleting the field, change it to property.
140 [Obsolete("Deprecated in API9, will be removed in API11. Use GetDuration, SetDuration instead.")]
141 [SuppressMessage("Microsoft.Design", "CA1051:Do not declare visible instance fields")]
145 /// Get, Set the delay before the transition executes. Milliseconds.
147 /// <since_tizen> 6 </since_tizen>
148 /// When deleting the field, change it to property.
149 [Obsolete("Deprecated in API9, will be removed in API11. Use GetDelay, SetDelay instead.")]
150 [SuppressMessage("Microsoft.Design", "CA1051:Do not declare visible instance fields")]
154 /// Get, Set the function to alter the transition path over time.
156 /// <since_tizen> 6 </since_tizen>
157 [Obsolete("Deprecated in API9, will be removed in API11. Use GetAlphaFunction, SetAlphaFunction instead.")]
158 [SuppressMessage("Microsoft.Design", "CA1051:Do not declare visible instance fields")]
159 public AlphaFunction AlphaFunction;
162 /// Set the time transition should execute for . Milliseconds.
164 [EditorBrowsable(EditorBrowsableState.Never)]
165 public void SetDuration(int duration)
171 /// Get the time transition should execute for . Milliseconds.
173 [EditorBrowsable(EditorBrowsableState.Never)]
174 public int GetDuration()
180 /// Set the delay before the transition executes. Milliseconds.
182 [EditorBrowsable(EditorBrowsableState.Never)]
183 public void SetDelay(int delay)
189 /// Get the delay before the transition executes. Milliseconds.
191 [EditorBrowsable(EditorBrowsableState.Never)]
192 public int GetDelay()
198 /// Set the function to alter the transition path over time.
200 [EditorBrowsable(EditorBrowsableState.Never)]
201 public void SetAlphaFunction(AlphaFunction alphaFunction)
203 AlphaFunction = alphaFunction;
207 /// Get the function to alter the transition path over time.
209 [EditorBrowsable(EditorBrowsableState.Never)]
210 public AlphaFunction GetAlphaFunction()
212 return AlphaFunction;
215 [EditorBrowsable(EditorBrowsableState.Never)]
216 protected virtual void Dispose(bool disposing)
224 AlphaFunction?.Dispose();
229 [EditorBrowsable(EditorBrowsableState.Never)]
230 public void Dispose()
233 global::System.GC.SuppressFinalize(this);
238 /// LayoutTransition stores the animation setting for a transition condition.
240 public class LayoutTransition
243 /// LayoutTransition default constructor.
245 /// <since_tizen> 6 </since_tizen>
246 public LayoutTransition()
248 Condition = TransitionCondition.Unspecified;
249 AnimatableProperty = AnimatableProperties.Position;
254 /// LayoutTransition constructor.
256 /// <param name="condition">The animatable condition.</param>
257 /// <param name="animatableProperty">the property to animate.</param>
258 /// <param name="targetValue">target value of the property.</param>
259 /// <param name="animator">Components to define the animator.</param>
260 /// <since_tizen> 6 </since_tizen>
261 public LayoutTransition(TransitionCondition condition,
262 AnimatableProperties animatableProperty,
264 TransitionComponents animator)
266 Condition = condition;
267 AnimatableProperty = animatableProperty;
269 TargetValue = targetValue;
273 /// Condition for this Transition
275 /// <since_tizen> 6 </since_tizen>
277 public TransitionCondition Condition { get; set; }
279 /// Property to animate.
281 /// <since_tizen> 6 </since_tizen>
283 public AnimatableProperties AnimatableProperty { get; set; }
285 /// Components of the Animator.
287 /// <since_tizen> 6 </since_tizen>
289 public TransitionComponents Animator { get; set; }
291 /// Target value to animate to.
293 /// <since_tizen> 6 </since_tizen>
294 public object TargetValue { get; set; }
299 /// Class to help manage the adding and updating of transitions.
301 internal static class LayoutTransitionsHelper
304 /// Adds the given transition and condition to a transition list.
306 /// <param name="targetTransitionList">The list to add the transition to.</param>
307 /// <param name="condition">Condition for the transition.</param>
308 /// <param name="transition">The transition to add.</param>
309 /// <param name="explicitlySet">True is set explicitly, false if inherited.</param>
310 static public void AddTransitionForCondition(
311 Dictionary<TransitionCondition, TransitionList> targetTransitionList,
312 TransitionCondition condition,
313 LayoutTransition transition,
316 bool replaced = false;
317 bool conditionNotInDictionary = false;
318 TransitionList transitionListMatchingCondition;
319 if (targetTransitionList.TryGetValue(condition, out transitionListMatchingCondition))
321 if (transitionListMatchingCondition != null)
323 for (var index = 0; index < transitionListMatchingCondition.Count; index++)
325 if (transitionListMatchingCondition[index].AnimatableProperty == transition.AnimatableProperty)
329 transitionListMatchingCondition[index] = transition;
339 conditionNotInDictionary = true;
342 if (replaced == false)
344 if (transitionListMatchingCondition == null)
346 transitionListMatchingCondition = new TransitionList();
348 transitionListMatchingCondition.Add(transition);
349 // Update dictionary with new or replaced entry.
350 if (conditionNotInDictionary)
352 targetTransitionList.Add(condition, transitionListMatchingCondition); // new entry
356 targetTransitionList[condition] = transitionListMatchingCondition; // replaced
362 /// Retrieve the transition list for the given condition.
364 /// <param name="sourceTransitionCollection">The source collection of transition lists to retrieve.</param>
365 /// <param name="condition">Condition for the transition.</param>
366 /// <param name="transitionsForCondition">transition list to return as out parameter.</param>
367 /// <returns>True if a transition list found for the given condition></returns>
368 static public bool GetTransitionsListForCondition(
369 Dictionary<TransitionCondition, TransitionList> sourceTransitionCollection,
370 TransitionCondition condition,
371 TransitionList transitionsForCondition)
373 TransitionCondition resolvedCondition = condition;
374 bool matched = false;
375 // LayoutChanged transitions overrides ChangeOnAdd and ChangeOnRemove as siblings will
376 // reposition to the new layout not to the insertion/removal of a sibling.
377 if ((condition & TransitionCondition.LayoutChanged) == TransitionCondition.LayoutChanged)
379 resolvedCondition = TransitionCondition.LayoutChanged;
382 if (sourceTransitionCollection.TryGetValue(resolvedCondition, out transitionsForCondition))
391 /// Copy the transitions in the source list to the target list
393 /// <param name="sourceTransitionList">The source transition list.</param>
394 /// <param name="targetTransitionList">The target transition list to copy to.</param>
395 static public void CopyTransitions(TransitionList sourceTransitionList, TransitionList targetTransitionList)
397 targetTransitionList.Clear();
398 foreach (LayoutTransition transitionToApply in sourceTransitionList)
400 // Overwrite existing transitions
401 targetTransitionList.Add(transitionToApply);
405 } // namespace Tizen.NUI