[NUI] Change Feedback as working on TouchEvent
authordongsug.song <dongsug.song@samsung.com>
Mon, 18 Jan 2021 11:46:49 +0000 (20:46 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Mon, 1 Feb 2021 08:04:43 +0000 (17:04 +0900)
src/Tizen.NUI.Components/Controls/Control.cs

index 81e5ddf..833ca7f 100755 (executable)
@@ -46,8 +46,6 @@ namespace Tizen.NUI.Components
 
         private Feedback feedback = null;
 
-        private TapGestureDetector tapGestureDetector = null;
-
         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
         [EditorBrowsable(EditorBrowsableState.Never)]
         public ControlStyle Style => (ControlStyle)ViewStyle.Clone();
@@ -113,25 +111,27 @@ namespace Tizen.NUI.Components
 
                 if (value)
                 {
-                    Debug.Assert(feedback == null && tapGestureDetector == null);
-
-                    tapGestureDetector = new TapGestureDetector();
-                    tapGestureDetector.Attach(this);
-                    tapGestureDetector.Detected += OnTapGestureDetected;
                     feedback = new Feedback();
+                    this.TouchEvent += OnTouchPlayFeedback;
                 }
                 else
                 {
-                    Debug.Assert(feedback != null && tapGestureDetector != null);
-
-                    feedback.Stop();
+                    this.TouchEvent -= OnTouchPlayFeedback;
                     feedback = null;
+                }
+            }
+        }
 
-                    tapGestureDetector.Detected -= OnTapGestureDetected;
-                    tapGestureDetector.Detach(this);
-                    tapGestureDetector = null;
+        private bool OnTouchPlayFeedback(object source, TouchEventArgs e)
+        {
+            if (Feedback && e?.Touch.GetState(0) == PointStateType.Down)
+            {
+                if (feedback != null && feedback.IsSupportedPattern(FeedbackType.Sound, "Tap"))
+                {
+                    feedback.Play(FeedbackType.Sound, "Tap");
                 }
             }
+            return false;
         }
 
         /// Internal used.
@@ -188,9 +188,11 @@ namespace Tizen.NUI.Components
                 return;
             }
 
+            feedback = null;
+            this.TouchEvent -= OnTouchPlayFeedback;
+
             if (type == DisposeTypes.Explicit)
             {
-                Feedback = false; // Release feedback resources.
             }
 
             base.Dispose(type);
@@ -249,25 +251,6 @@ namespace Tizen.NUI.Components
         }
 
         /// <summary>
-        /// Tap gesture callback.
-        /// </summary>
-        /// <param name="source">The sender</param>
-        /// <param name="e">The tap gesture event data</param>
-        /// <since_tizen> 6 </since_tizen>
-        /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        protected virtual void OnTapGestureDetected(object source, TapGestureDetector.DetectedEventArgs e)
-        {
-            if (Feedback && e?.TapGesture?.State == Gesture.StateType.Started)
-            {
-                if (feedback != null && feedback.IsSupportedPattern(FeedbackType.Sound, "Tap"))
-                {
-                    feedback.Play(FeedbackType.Sound, "Tap");
-                }
-            }
-        }
-
-        /// <summary>
         /// Update by style.
         /// </summary>
         /// <since_tizen> 6 </since_tizen>
@@ -320,6 +303,8 @@ namespace Tizen.NUI.Components
             StateFocusableOnTouchMode = false;
 
             EnableControlState = true;
+
+            Feedback = true;
         }
     }
 }