[NUI] Add fade transition
authorSeungho Baek <sbsh.baek@samsung.com>
Fri, 4 Jun 2021 08:53:35 +0000 (17:53 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Tue, 29 Jun 2021 06:46:52 +0000 (15:46 +0900)
Signed-off-by: Seungho Baek <sbsh.baek@samsung.com>
src/Tizen.NUI.Components/Controls/Navigation/Navigator.cs
src/Tizen.NUI.Components/Controls/Navigation/Page.cs
src/Tizen.NUI/src/internal/Interop/Interop.FadeItem.cs [new file with mode: 0755]
src/Tizen.NUI/src/internal/Interop/Interop.TransitionItemBase.cs
src/Tizen.NUI/src/internal/Transition/FadeItem.cs [new file with mode: 0755]
src/Tizen.NUI/src/internal/Transition/TransitionItemBase.cs
src/Tizen.NUI/src/public/Transition/Fade.cs [new file with mode: 0644]
src/Tizen.NUI/src/public/Transition/TransitionBase.cs

index 485b627..504418f 100755 (executable)
@@ -60,7 +60,7 @@ namespace Tizen.NUI.Components
     /// <since_tizen> 9 </since_tizen>
     public class Navigator : Control
     {
-        private static readonly int DefaultTransitionDuration = 500;
+        private const int DefaultTransitionDuration = 500;
 
         //This will be replaced with view transition class instance.
         private Animation curAnimation = null;
@@ -656,7 +656,6 @@ namespace Tizen.NUI.Components
                 }
                 newTransitionSet.AddTransition(pairTransition);
             }
-            newTransitionSet.Play();
 
             newTransitionSet.Finished += (object sender, EventArgs e) =>
             {
@@ -666,16 +665,18 @@ namespace Tizen.NUI.Components
                 currentTopPage.Opacity = 1.0f;
             };
 
-            // default entering/exit transition - fast fade (half duration compaired with that of view pair transition)
+            // default appearing/disappearing transition - fast fade (half duration compaired with that of view pair transition)
             int duration = (transition.TimePeriod.DurationMilliseconds + transition.TimePeriod.DelayMilliseconds);
             float durationSeconds = (float)duration / 1000.0f;
-            Animation fade = new Animation(0.8f * durationSeconds);
-            fade.AnimateTo(currentTopPage, "Opacity", 0.0f);
-            KeyFrames keyframes = new KeyFrames();
-            keyframes.Add(0.0f, 0.0f);
-            keyframes.Add(1.0f, 1.0f);
-            fade.AnimateBetween(newTopPage, "Opacity", keyframes);
-            fade.Play();
+
+            TransitionItemBase disappearingTransition = currentTopPage.DisappearingTransition.CreateTransition(currentTopPage, false);
+            TransitionItemBase appearingTransition = newTopPage.AppearingTransition.CreateTransition(newTopPage, true);
+            disappearingTransition.TransitionWithChild = true;
+            appearingTransition.TransitionWithChild = true;
+            newTransitionSet.AddTransition(disappearingTransition);
+            newTransitionSet.AddTransition(appearingTransition);
+
+            newTransitionSet.Play();
 
             return newTransitionSet;
         }
index 2faef39..9ee9440 100755 (executable)
@@ -57,8 +57,23 @@ namespace Tizen.NUI.Components
     /// <since_tizen> 9 </since_tizen>
     public abstract class Page : Control
     {
+        private const int DefaultTransitionDuration = 500;
+
         private Navigator navigator = null;
 
+        // Default transition is Fade.
+        private TransitionBase appearingTransition = new Fade()
+        {
+            TimePeriod = new TimePeriod(DefaultTransitionDuration),
+            AlphaFunction = new AlphaFunction(AlphaFunction.BuiltinFunctions.Default),
+        };
+
+        private TransitionBase disappearingTransition = new Fade()
+        {
+            TimePeriod = new TimePeriod(DefaultTransitionDuration),
+            AlphaFunction = new AlphaFunction(AlphaFunction.BuiltinFunctions.Default),
+        };
+
         /// <summary>
         /// Creates a new instance of a Page.
         /// </summary>
@@ -90,6 +105,38 @@ namespace Tizen.NUI.Components
         }
 
         /// <summary>
+        /// Transition properties for the transition of Views in this page during this page is pushed to Navigator.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public TransitionBase AppearingTransition
+        {
+            set
+            {
+                appearingTransition = value;
+            }
+            get
+            {
+                return appearingTransition;
+            }
+        }
+
+        /// <summary>
+        /// Transition properties for the transition of Views in this page during this page is popped from Navigator.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public TransitionBase DisappearingTransition
+        {
+            set
+            {
+                disappearingTransition = value;
+            }
+            get
+            {
+                return disappearingTransition;
+            }
+        }
+
+        /// <summary>
         /// An event for the page appearing signal which can be used to subscribe or unsubscribe the event handler provided by the user.
         /// </summary>
         [EditorBrowsable(EditorBrowsableState.Never)]
diff --git a/src/Tizen.NUI/src/internal/Interop/Interop.FadeItem.cs b/src/Tizen.NUI/src/internal/Interop/Interop.FadeItem.cs
new file mode 100755 (executable)
index 0000000..02856c6
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright(c) 2021 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+namespace Tizen.NUI
+{
+    using global::System;
+    using global::System.Runtime.InteropServices;
+
+    internal static partial class Interop
+    {
+        internal static partial class FadeItem
+        {
+            [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_new_Fade")]
+            public static extern IntPtr NewEmpty();
+
+            [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Fade_New")]
+            public static extern IntPtr New(HandleRef view, float opacity, HandleRef timePeriod);
+
+            [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_delete_Fade")]
+            public static extern void Delete(HandleRef fade);
+
+            [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_new_Fade_Set")]
+            public static extern IntPtr NewFadeItem(HandleRef fade);
+
+            [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Fade_Assign")]
+            public static extern IntPtr Assign(HandleRef destination, HandleRef source);
+        }
+    }
+}
index 587f2c0..a4da56d 100755 (executable)
@@ -53,6 +53,9 @@ namespace Tizen.NUI
 
             [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_TransitionBase_TransitionWithChild")]
             public static extern void TransitionWithChild(HandleRef transition, bool transitionWithChild);
+
+            [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_TransitionBase_SetAppearingTransition")]
+            public static extern void SetAppearingTransition(HandleRef transition, bool appearingTransition);
         }
     }
 }
diff --git a/src/Tizen.NUI/src/internal/Transition/FadeItem.cs b/src/Tizen.NUI/src/internal/Transition/FadeItem.cs
new file mode 100755 (executable)
index 0000000..2ce9ed4
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * Copyright(c) 2021 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+namespace Tizen.NUI
+{
+    using System;
+    using System.ComponentModel;
+
+    using Tizen.NUI.BaseComponents;
+
+    /// <summary>
+    /// FadeItem is an object to set Fade transition of a View that will appear or disappear.
+    /// FadeItem object is required to be added to the TransitionSet to play.
+    /// </summary>
+    internal class FadeItem : TransitionItemBase
+    {
+        /// <summary>
+        /// Creates an initialized fade.<br />
+        /// </summary>
+        /// <remarks>DurationmSeconds must be greater than zero.</remarks>
+        public FadeItem(View view, float opacity, bool isAppearing, TimePeriod timePeriod, AlphaFunction alphaFunction) : this(Interop.FadeItem.New(view.SwigCPtr, opacity, timePeriod.SwigCPtr), true)
+        {
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            AppearingTransition = isAppearing;
+            AlphaFunction = alphaFunction;
+        }
+
+        internal FadeItem(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
+        {
+        }
+
+        internal static global::System.Runtime.InteropServices.HandleRef getCPtr(FadeItem obj)
+        {
+            return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.SwigCPtr;
+        }
+
+        internal FadeItem(FadeItem handle) : this(Interop.FadeItem.NewFadeItem(FadeItem.getCPtr(handle)), true)
+        {
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
+        internal FadeItem Assign(FadeItem rhs)
+        {
+            FadeItem ret = new FadeItem(Interop.FadeItem.Assign(SwigCPtr, FadeItem.getCPtr(rhs)), false);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
+        }
+
+        /// <summary>
+        /// To make fade instance be disposed.
+        /// </summary>
+        protected override void Dispose(DisposeTypes type)
+        {
+            if (disposed)
+            {
+                return;
+            }
+            base.Dispose(type);
+        }
+
+        /// This will not be public opened.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
+        {
+            if (swigCPtr.Handle == IntPtr.Zero || this.HasBody() == false)
+            {
+                Tizen.Log.Fatal("NUI", $"[ERROR] FadeItem ReleaseSwigCPtr()! IntPtr=0x{swigCPtr.Handle:X} HasBody={this.HasBody()}");
+                return;
+            }
+            Interop.FadeItem.Delete(swigCPtr);
+        }
+    }
+}
index 67a4387..bcbcabf 100755 (executable)
@@ -26,9 +26,12 @@ namespace Tizen.NUI
         /// <summary>
         /// Creates an initialized TransitionItemBase.<br />
         /// </summary>
-        public TransitionItemBase(View target, bool isEntering, TimePeriod timePeriod, AlphaFunction alphaFunction) : this(Interop.TransitionItemBase.New(/*target.SwigCPtr, isEntering, timePeriod.SwigCPtr*/), true)
+        public TransitionItemBase(View target, bool isAppearing, TimePeriod timePeriod, AlphaFunction alphaFunction) : this(Interop.TransitionItemBase.New(), true)
         {
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            
+            AppearingTransition = isAppearing;
+            TimePeriod = timePeriod;
             AlphaFunction = alphaFunction;
         }
 
@@ -85,6 +88,18 @@ namespace Tizen.NUI
         }
 
         /// <summary>
+        /// Gets or sets whether this transition is appearing transition or not.
+        /// </summary>
+        public bool AppearingTransition
+        {
+            set
+            {
+                Interop.TransitionItemBase.SetAppearingTransition(SwigCPtr, value);
+                if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            }
+        }
+
+        /// <summary>
         /// Downcasts a handle to TransitionItemBase handle.<br />
         /// If handle points to an TransitionItemBase object, the downcast produces a valid handle.<br />
         /// If not, the returned handle is left uninitialized.<br />
diff --git a/src/Tizen.NUI/src/public/Transition/Fade.cs b/src/Tizen.NUI/src/public/Transition/Fade.cs
new file mode 100644 (file)
index 0000000..a1c8734
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Copyright(c) 2021 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+namespace Tizen.NUI
+{
+    using System;
+    using System.ComponentModel;
+    using Tizen.NUI.BaseComponents;
+
+    /// <summary>
+    /// Fade class is a cluster of properties for the fade transition of a View.
+    /// </summary>
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public class Fade : TransitionBase
+    {
+        private float opacity = 0.0f;
+
+        /// <summary>
+        /// Create a Fade for the View pair.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public Fade()
+        {
+        }
+
+        /// <summary>
+        /// Set Opacity for this fade transition.
+        /// If this transition is for appearing, the opacity of target View is animated from this property.
+        /// If this transition is for disappearing, the opacity of target View is animated to this property.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public float Opacity
+        {
+            get
+            {
+                return opacity;
+            }
+            set
+            {
+                opacity = value;
+            }
+        }
+
+        internal override TransitionItemBase CreateTransition(View view, bool isAppearing)
+        {
+            FadeItem fade = new FadeItem(view, Opacity, isAppearing, TimePeriod, AlphaFunction);
+            return fade;
+        }
+    }
+}
index 7d7f137..e5f41d4 100644 (file)
@@ -72,9 +72,9 @@ namespace Tizen.NUI
             }
         }
 
-        internal TransitionItemBase CreateTransition(View target, bool isEntering)
+        internal virtual TransitionItemBase CreateTransition(View view, bool isAppearing)
         {
-            return new TransitionItemBase(target, isEntering, timePeriod, alphaFunction);
+            return new TransitionItemBase(view, isAppearing, timePeriod, alphaFunction);
         }
 
         [EditorBrowsable(EditorBrowsableState.Never)]