summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordarkleem <cdark.lim@samsung.com>2017-07-25 08:00:19 (GMT)
committerKangho Hur <kangho.hur@samsung.com>2017-10-23 04:34:41 (GMT)
commit311fce98e30366a9059ae170bd686c0c0afe98db (patch)
treee7bf739c7bde0bb8542f23d75275f7878b46c80e
parent2f28640d2d1667922ac3ac4adc80cb51253358e1 (diff)
downloadxamarin-forms-311fce98e30366a9059ae170bd686c0c0afe98db.zip
xamarin-forms-311fce98e30366a9059ae170bd686c0c0afe98db.tar.gz
xamarin-forms-311fce98e30366a9059ae170bd686c0c0afe98db.tar.bz2
Fix GestureDetector crash issue
- TASK=TCAPI-2607 - This patch is required(https://review.tizen.org/gerrit/#/c/145081/) Change-Id: I5ff1f62475835c2c7b7fc528f7fc3383c729f3e8 Signed-off-by: darkleem <cdark.lim@samsung.com>
-rw-r--r--Xamarin.Forms.Platform.Tizen/GestureDetector.cs95
-rw-r--r--Xamarin.Forms.Platform.Tizen/Renderers/ViewRenderer.cs6
2 files changed, 25 insertions, 76 deletions
diff --git a/Xamarin.Forms.Platform.Tizen/GestureDetector.cs b/Xamarin.Forms.Platform.Tizen/GestureDetector.cs
index 501b8b4..720b23f 100644
--- a/Xamarin.Forms.Platform.Tizen/GestureDetector.cs
+++ b/Xamarin.Forms.Platform.Tizen/GestureDetector.cs
@@ -3,9 +3,8 @@ using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Linq;
-using Xamarin.Forms.Internals;
using ElmSharp;
-using EColor = ElmSharp.Color;
+using Xamarin.Forms.Internals;
using EGestureType = ElmSharp.GestureLayer.GestureType;
namespace Xamarin.Forms.Platform.Tizen
@@ -16,7 +15,6 @@ namespace Xamarin.Forms.Platform.Tizen
readonly IVisualElementRenderer _renderer;
GestureLayer _gestureLayer;
- Polygon _hitBox;
double _doubleTapTime = 0;
double _longTapTime = 0;
int _horizontalSwipeTime = 0;
@@ -40,7 +38,7 @@ namespace Xamarin.Forms.Platform.Tizen
public void Clear()
{
// this will clear all callbacks in ElmSharp GestureLayer
- _gestureLayer.Unrealize();
+ _gestureLayer?.Unrealize();
_gestureLayer = null;
foreach (var handlers in _handlerCache.Values)
{
@@ -50,54 +48,17 @@ namespace Xamarin.Forms.Platform.Tizen
}
}
_handlerCache.Clear();
-
- if (_hitBox != null)
- {
- _renderer.NativeView.Moved -= OnMoveToHitbox;
- _hitBox.Unrealize();
- _hitBox = null;
- }
- }
-
- void OnMoveToHitbox(object sender, EventArgs e)
- {
- UpdateHitBox();
- }
-
- public void UpdateHitBox()
- {
- if (_hitBox == null)
- return;
- // _hitBox has to be used because gestures do not work well with transformations (EvasMap)
- // so we create additional object which has the same shape as tranformed target, but does not have EvasMap on it
- EvasObject target = _renderer.NativeView;
- _hitBox.ClearPoints();
- if (target.IsMapEnabled)
- {
- var map = target.EvasMap;
- Point3D point;
- for (var i = 0; i < 4; i++)
- {
- point = map.GetPointCoordinate(i);
- _hitBox.AddPoint(point.X, point.Y);
- }
- }
- else
- {
- var geometry = target.Geometry;
- if (geometry.Width == 0 || geometry.Height == 0)
- return;
- _hitBox.AddPoint(geometry.Left, geometry.Top);
- _hitBox.AddPoint(geometry.Right, geometry.Top);
- _hitBox.AddPoint(geometry.Right, geometry.Bottom);
- _hitBox.AddPoint(geometry.Left, geometry.Bottom);
- }
}
void CreateGestureLayer()
{
_gestureLayer = new GestureLayer(_renderer.NativeView);
_gestureLayer.Attach(_renderer.NativeView);
+ _gestureLayer.Deleted += (s, e) =>
+ {
+ _gestureLayer = null;
+ Clear();
+ };
}
void AddGestures(IEnumerable<IGestureRecognizer> recognizers)
@@ -219,26 +180,8 @@ namespace Xamarin.Forms.Platform.Tizen
}
}
- void EnsureHitBoxExists()
- {
- if (_hitBox == null)
- {
- Box parent = (Platform.GetRenderer(_renderer.Element.RealParent) as LayoutRenderer).Control;
- _hitBox = new Polygon(parent)
- {
- Color = EColor.Transparent
- };
- _renderer.NativeView.Moved += OnMoveToHitbox;
- _hitBox.Show();
- UpdateHitBox();
- parent.PackAfter(_hitBox, _renderer.NativeView);
- _gestureLayer.Attach(_hitBox);
- }
- }
-
void AddLineGesture(EGestureType type)
{
- EnsureHitBoxExists();
_gestureLayer.SetLineCallback(GestureLayer.GestureState.Start, (data) => { OnGestureStarted(type, data); });
_gestureLayer.SetLineCallback(GestureLayer.GestureState.Move, (data) => { OnGestureMoved(type, data); });
_gestureLayer.SetLineCallback(GestureLayer.GestureState.End, (data) => { OnGestureCompleted(type, data); });
@@ -247,7 +190,6 @@ namespace Xamarin.Forms.Platform.Tizen
void AddPinchGesture(EGestureType type)
{
- EnsureHitBoxExists();
_gestureLayer.SetZoomCallback(GestureLayer.GestureState.Start, (data) => { OnGestureStarted(type, data); });
_gestureLayer.SetZoomCallback(GestureLayer.GestureState.Move, (data) => { OnGestureMoved(type, data); });
_gestureLayer.SetZoomCallback(GestureLayer.GestureState.End, (data) => { OnGestureCompleted(type, data); });
@@ -283,7 +225,6 @@ namespace Xamarin.Forms.Platform.Tizen
void AddFlickGesture(EGestureType type, double timeout)
{
- EnsureHitBoxExists();
if (timeout > 0)
_gestureLayer.FlickTimeLimit = (int)(timeout * 1000);
_gestureLayer.SetFlickCallback(GestureLayer.GestureState.Start, (data) => { OnGestureStarted(type, data); });
@@ -294,7 +235,6 @@ namespace Xamarin.Forms.Platform.Tizen
void AddRotateGesture(EGestureType type)
{
- EnsureHitBoxExists();
_gestureLayer.SetRotateCallback(GestureLayer.GestureState.Start, (data) => { OnGestureStarted(type, data); });
_gestureLayer.SetRotateCallback(GestureLayer.GestureState.Move, (data) => { OnGestureMoved(type, data); });
_gestureLayer.SetRotateCallback(GestureLayer.GestureState.End, (data) => { OnGestureCompleted(type, data); });
@@ -303,9 +243,24 @@ namespace Xamarin.Forms.Platform.Tizen
void AddMomentumGesture(EGestureType type)
{
- EnsureHitBoxExists();
- _gestureLayer.SetMomentumCallback(GestureLayer.GestureState.Start, (data) => { OnGestureStarted(type, data); });
- _gestureLayer.SetMomentumCallback(GestureLayer.GestureState.Move, (data) => { OnGestureMoved(type, data); });
+ // Task to correct wrong coordinates information when applying EvasMap(Xamarin ex: Translation, Scale, Rotate property)
+ // Always change to the absolute coordinates of the pointer.
+ int startX = 0;
+ int startY = 0;
+ _gestureLayer.SetMomentumCallback(GestureLayer.GestureState.Start, (data) =>
+ {
+ startX = _gestureLayer.EvasCanvas.Pointer.X;
+ startY = _gestureLayer.EvasCanvas.Pointer.Y;
+ OnGestureStarted(type, data);
+ });
+ _gestureLayer.SetMomentumCallback(GestureLayer.GestureState.Move, (data) =>
+ {
+ data.X1 = startX;
+ data.Y1 = startY;
+ data.X2 = _gestureLayer.EvasCanvas.Pointer.X;
+ data.Y2 = _gestureLayer.EvasCanvas.Pointer.Y;
+ OnGestureMoved(type, data);
+ });
_gestureLayer.SetMomentumCallback(GestureLayer.GestureState.End, (data) => { OnGestureCompleted(type, data); });
_gestureLayer.SetMomentumCallback(GestureLayer.GestureState.Abort, (data) => { OnGestureCanceled(type, data); });
}
diff --git a/Xamarin.Forms.Platform.Tizen/Renderers/ViewRenderer.cs b/Xamarin.Forms.Platform.Tizen/Renderers/ViewRenderer.cs
index f104ba4..c086f93 100644
--- a/Xamarin.Forms.Platform.Tizen/Renderers/ViewRenderer.cs
+++ b/Xamarin.Forms.Platform.Tizen/Renderers/ViewRenderer.cs
@@ -44,11 +44,5 @@ namespace Xamarin.Forms.Platform.Tizen
return (TNativeView)NativeView;
}
}
-
- protected override void ApplyTransformation()
- {
- base.ApplyTransformation();
- _gestureDetector?.UpdateHitBox();
- }
}
} \ No newline at end of file