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;
24 /// Define a List of LayoutTransitions
26 /// <since_tizen> 6 </since_tizen>
27 public class TransitionList : List<LayoutTransition> {}
30 /// The conditions for transitions.
32 /// <since_tizen> 6 </since_tizen>
33 [FlagsAttribute] public enum TransitionCondition
36 /// Default when a condition has not been set.
38 /// <since_tizen> 6 </since_tizen>
41 /// Animate changing layout to another layout.
43 /// <since_tizen> 6 </since_tizen>
47 /// Animate adding item.
49 /// <since_tizen> 6 </since_tizen>
53 /// Animate removing item.
55 /// <since_tizen> 6 </since_tizen>
59 /// Animation when an item changes due to a being added.
61 /// <since_tizen> 6 </since_tizen>
65 /// Animation when an item changes due to a being removed.
67 /// <since_tizen> 6 </since_tizen>
73 /// The properties that can be animated.
75 /// <since_tizen> 6 </since_tizen>
76 public enum AnimatableProperties
79 /// Position property.
81 /// <since_tizen> 6 </since_tizen>
87 /// <since_tizen> 6 </since_tizen>
93 /// <since_tizen> 6 </since_tizen>
99 /// Parts of the transition that can be configured to provide a custom effect.
101 /// <since_tizen> 6 </since_tizen>
102 public class TransitionComponents
105 /// TransitionComponents default constructor.
107 /// <since_tizen> 6 </since_tizen>
108 public TransitionComponents()
112 AlphaFunction = new AlphaFunction(AlphaFunction.BuiltinFunctions.Linear);
116 /// TransitionComponents constructor. Stores delay, duration and AlphaFunction.
118 /// <param name="delay">The delay before the animator starts.</param>
119 /// <param name="duration">the duration of the animator.</param>
120 /// <param name="alphaFunction">alpha function to use .</param>
121 /// <since_tizen> 6 </since_tizen>
123 public TransitionComponents(int delay, int duration, AlphaFunction alphaFunction)
127 AlphaFunction = alphaFunction;
131 /// Get, Set the time transition should execute for . Milliseconds.
133 /// <since_tizen> 6 </since_tizen>
136 /// Get, Set the delay before the transition executes. Milliseconds.
138 /// <since_tizen> 6 </since_tizen>
141 /// Get, Set the function to alter the transition path over time.
143 /// <since_tizen> 6 </since_tizen>
144 public AlphaFunction AlphaFunction;
148 /// LayoutTransition stores the animation setting for a transition conidition.
150 public class LayoutTransition
153 /// LayoutTransition default constructor.
155 /// <since_tizen> 6 </since_tizen>
156 public LayoutTransition()
158 Condition = TransitionCondition.Unspecified;
159 AnimatableProperty = AnimatableProperties.Position;
164 /// LayoutTransition constructor.
166 /// <param name="condition">The animatable condition.</param>
167 /// <param name="animatableProperty">the property to animate.</param>
168 /// <param name="targetValue">target value of the property.</param>
169 /// <param name="animator">Components to define the animator.</param>
170 /// <since_tizen> 6 </since_tizen>
171 public LayoutTransition( TransitionCondition condition,
172 AnimatableProperties animatableProperty,
174 TransitionComponents animator)
176 Condition = condition;
177 AnimatableProperty = animatableProperty;
179 TargetValue = targetValue;
183 /// Condition for this Transition
185 /// <since_tizen> 6 </since_tizen>
187 public TransitionCondition Condition{get; set;}
189 /// Property to animate.
191 /// <since_tizen> 6 </since_tizen>
193 public AnimatableProperties AnimatableProperty{get; set;}
195 /// Components of the Animator.
197 /// <since_tizen> 6 </since_tizen>
199 public TransitionComponents Animator{get; set;}
201 /// Target value to animate to.
203 /// <since_tizen> 6 </since_tizen>
205 public object TargetValue{get; set;}
210 /// Class to help manage the adding and updating of transitions.
212 internal static class LayoutTransitionsHelper
215 /// Adds the given transition and condition to a transition list.
217 /// <param name="targetTransitionList">The list to add the transition to.</param>
218 /// <param name="condition">Condition for the transition.</param>
219 /// <param name="transition">The transition to add.</param>
220 /// <param name="explicitlySet">True is set explicitly, false if inherited.</param>
221 static public void AddTransitionForCondition(
222 Dictionary<TransitionCondition, TransitionList> targetTransitionList,
223 TransitionCondition condition,
224 LayoutTransition transition,
227 bool replaced = false;
228 bool conditionNotInDictionary = false;
229 TransitionList transitionListMatchingCondition;
230 if (targetTransitionList.TryGetValue(condition, out transitionListMatchingCondition))
232 if (transitionListMatchingCondition != null)
234 for (var index = 0; index < transitionListMatchingCondition.Count; index++ )
236 if (transitionListMatchingCondition[index].AnimatableProperty == transition.AnimatableProperty)
240 transitionListMatchingCondition[index] = transition;
250 conditionNotInDictionary = true;
253 if (replaced == false)
255 if (transitionListMatchingCondition == null)
257 transitionListMatchingCondition = new TransitionList();
259 transitionListMatchingCondition.Add(transition);
260 // Update dictionary with new or replaced entry.
261 if (conditionNotInDictionary)
263 targetTransitionList.Add(condition, transitionListMatchingCondition); // new entry
267 targetTransitionList[condition] = transitionListMatchingCondition; // replaced
273 /// Retreive the transition list for the given condition.
275 /// <param name="sourceTransitionCollection">The source collection of transition lists to retrieve.</param>
276 /// <param name="condition">Condition for the transition.</param>
277 /// <param name="transitionsForCondition">transition list to return as out parameter.</param>
278 /// <returns>True if a transition list found for the given condition></returns>
279 static public bool GetTransitionsListForCondition(
280 Dictionary<TransitionCondition, TransitionList> sourceTransitionCollection,
281 TransitionCondition condition,
282 TransitionList transitionsForCondition )
284 TransitionCondition resolvedCondition = condition;
285 bool matched = false;
286 // LayoutChanged transitions overrides ChangeOnAdd and ChangeOnRemove as siblings will
287 // reposition to the new layout not to the insertion/removal of a sibling.
288 if ((condition & TransitionCondition.LayoutChanged) == TransitionCondition.LayoutChanged)
290 resolvedCondition = TransitionCondition.LayoutChanged;
293 if (sourceTransitionCollection.TryGetValue(resolvedCondition, out transitionsForCondition))
302 /// Copy the transitions in the source list to the target list
304 /// <param name="sourceTransitionList">The source transition list.</param>
305 /// <param name="targetTransitionList">The target transition list to copy to.</param>
306 static public void CopyTransitions( TransitionList sourceTransitionList,
307 TransitionList targetTransitionList )
309 targetTransitionList.Clear();
310 foreach (LayoutTransition transitionToApply in sourceTransitionList)
312 // Overwite existing transitions
313 targetTransitionList.Add(transitionToApply);
319 } // namespace Tizen.NUI