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;
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 [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1717:Only FlagsAttribute enums should have plural names")]
79 public enum AnimatableProperties
82 /// Position property.
84 /// <since_tizen> 6 </since_tizen>
90 /// <since_tizen> 6 </since_tizen>
96 /// <since_tizen> 6 </since_tizen>
102 /// Parts of the transition that can be configured to provide a custom effect.
104 /// <since_tizen> 6 </since_tizen>
105 public class TransitionComponents : IDisposable
107 private bool disposed = false;
109 /// TransitionComponents default constructor.
111 /// <since_tizen> 6 </since_tizen>
112 public TransitionComponents()
116 AlphaFunction = new AlphaFunction(AlphaFunction.BuiltinFunctions.Linear);
120 /// TransitionComponents constructor. Stores delay, duration and AlphaFunction.
122 /// <param name="delay">The delay before the animator starts.</param>
123 /// <param name="duration">the duration of the animator.</param>
124 /// <param name="alphaFunction">alpha function to use .</param>
125 /// <since_tizen> 6 </since_tizen>
127 public TransitionComponents(int delay, int duration, AlphaFunction alphaFunction)
131 AlphaFunction = alphaFunction;
135 /// Get, Set the time transition should execute for . Milliseconds.
137 /// <since_tizen> 6 </since_tizen>
140 /// Get, Set the delay before the transition executes. Milliseconds.
142 /// <since_tizen> 6 </since_tizen>
145 /// Get, Set the function to alter the transition path over time.
147 /// <since_tizen> 6 </since_tizen>
148 public AlphaFunction AlphaFunction;
151 [EditorBrowsable(EditorBrowsableState.Never)]
152 protected virtual void Dispose(bool disposing)
160 AlphaFunction?.Dispose();
165 [EditorBrowsable(EditorBrowsableState.Never)]
166 public void Dispose()
169 global::System.GC.SuppressFinalize(this);
174 /// LayoutTransition stores the animation setting for a transition conidition.
176 public class LayoutTransition
179 /// LayoutTransition default constructor.
181 /// <since_tizen> 6 </since_tizen>
182 public LayoutTransition()
184 Condition = TransitionCondition.Unspecified;
185 AnimatableProperty = AnimatableProperties.Position;
190 /// LayoutTransition constructor.
192 /// <param name="condition">The animatable condition.</param>
193 /// <param name="animatableProperty">the property to animate.</param>
194 /// <param name="targetValue">target value of the property.</param>
195 /// <param name="animator">Components to define the animator.</param>
196 /// <since_tizen> 6 </since_tizen>
197 public LayoutTransition(TransitionCondition condition,
198 AnimatableProperties animatableProperty,
200 TransitionComponents animator)
202 Condition = condition;
203 AnimatableProperty = animatableProperty;
205 TargetValue = targetValue;
209 /// Condition for this Transition
211 /// <since_tizen> 6 </since_tizen>
213 public TransitionCondition Condition { get; set; }
215 /// Property to animate.
217 /// <since_tizen> 6 </since_tizen>
219 public AnimatableProperties AnimatableProperty { get; set; }
221 /// Components of the Animator.
223 /// <since_tizen> 6 </since_tizen>
225 public TransitionComponents Animator { get; set; }
227 /// Target value to animate to.
229 /// <since_tizen> 6 </since_tizen>
231 public object TargetValue { get; set; }
236 /// Class to help manage the adding and updating of transitions.
238 internal static class LayoutTransitionsHelper
241 /// Adds the given transition and condition to a transition list.
243 /// <param name="targetTransitionList">The list to add the transition to.</param>
244 /// <param name="condition">Condition for the transition.</param>
245 /// <param name="transition">The transition to add.</param>
246 /// <param name="explicitlySet">True is set explicitly, false if inherited.</param>
247 static public void AddTransitionForCondition(
248 Dictionary<TransitionCondition, TransitionList> targetTransitionList,
249 TransitionCondition condition,
250 LayoutTransition transition,
253 bool replaced = false;
254 bool conditionNotInDictionary = false;
255 TransitionList transitionListMatchingCondition;
256 if (targetTransitionList.TryGetValue(condition, out transitionListMatchingCondition))
258 if (transitionListMatchingCondition != null)
260 for (var index = 0; index < transitionListMatchingCondition.Count; index++)
262 if (transitionListMatchingCondition[index].AnimatableProperty == transition.AnimatableProperty)
266 transitionListMatchingCondition[index] = transition;
276 conditionNotInDictionary = true;
279 if (replaced == false)
281 if (transitionListMatchingCondition == null)
283 transitionListMatchingCondition = new TransitionList();
285 transitionListMatchingCondition.Add(transition);
286 // Update dictionary with new or replaced entry.
287 if (conditionNotInDictionary)
289 targetTransitionList.Add(condition, transitionListMatchingCondition); // new entry
293 targetTransitionList[condition] = transitionListMatchingCondition; // replaced
299 /// Retreive the transition list for the given condition.
301 /// <param name="sourceTransitionCollection">The source collection of transition lists to retrieve.</param>
302 /// <param name="condition">Condition for the transition.</param>
303 /// <param name="transitionsForCondition">transition list to return as out parameter.</param>
304 /// <returns>True if a transition list found for the given condition></returns>
305 static public bool GetTransitionsListForCondition(
306 Dictionary<TransitionCondition, TransitionList> sourceTransitionCollection,
307 TransitionCondition condition,
308 TransitionList transitionsForCondition)
310 TransitionCondition resolvedCondition = condition;
311 bool matched = false;
312 // LayoutChanged transitions overrides ChangeOnAdd and ChangeOnRemove as siblings will
313 // reposition to the new layout not to the insertion/removal of a sibling.
314 if ((condition & TransitionCondition.LayoutChanged) == TransitionCondition.LayoutChanged)
316 resolvedCondition = TransitionCondition.LayoutChanged;
319 if (sourceTransitionCollection.TryGetValue(resolvedCondition, out transitionsForCondition))
328 /// Copy the transitions in the source list to the target list
330 /// <param name="sourceTransitionList">The source transition list.</param>
331 /// <param name="targetTransitionList">The target transition list to copy to.</param>
332 static public void CopyTransitions(TransitionList sourceTransitionList,
333 TransitionList targetTransitionList)
335 targetTransitionList.Clear();
336 foreach (LayoutTransition transitionToApply in sourceTransitionList)
338 // Overwite existing transitions
339 targetTransitionList.Add(transitionToApply);
345 } // namespace Tizen.NUI