We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Trackball - No feedback/event when disappearing

Hello 

When the property ActivationMode from ChartTrackballBehavior is set to "LongPress" I can't get any feedback when the trackball disappear. 
But when it's set to "TouchMove" the "TouchUp" event is fired and that's what I need because I want to display/hide some parts of the UI.

Is there any way to have this event fired or any feedback when using "LongPress"  ?

Thanks in advance



8 Replies

HM Hemalatha Marikumar Syncfusion Team February 10, 2020 04:06 AM

Hi Joan Caron, 
  
Greetings from Syncfusion. 
  
QueryIs there any way to have this event fired or any feedback when using "LongPress"? 
  
Yes. It is possible and your requirement has been achieved by using the OnLongPress and OnTouchUp override methods of ChartTrackballBehavior as in below code snippet.  
C#: 
public class TrackballBehaviorExt : ChartTrackballBehavior 
{ 
   private bool isLongPressActivated = false; 
  
   protected override void OnLongPress(float pointX, float pointY) 
   { 
       base.OnLongPress(pointX, pointY); 
       isLongPressActivated = true; 
   } 
  
   protected override void OnTouchUp(float pointX, float pointY) 
   { 
       base.OnTouchUp(pointX, pointY); 
       if (isLongPressActivated) 
       { 
          isLongPressActivated = false; 
          //Write your logic here 
       } 
   } 
} 
  
Please let us know if you need any further assistance on this. 
 
Regards,
Hemalatha M. 



JC Joan Caron February 12, 2020 01:46 AM

Thank you for your quick answer!
But it doesn't cover what I want..

The event OnTouchUp is not fired when ActivationMode is set to LongPress
I need to run my Logic when the user stops interacting with the trackball like when OnTouchUp event occurs


DD Devakumar Dhanapoosanam Syncfusion Team February 13, 2020 05:41 AM

Hi Joan Caron, 
 
Currently we are validating the reported issue at our end and will update you the details on February 17, 2020.  
 
Regards, 
Devakumar D 



JC Joan Caron February 13, 2020 05:43 AM

Thank you Devakumar Dhanapoosanam


JC Joan Caron February 18, 2020 10:36 PM

Hello 

Do you have any feedback regarding this issue ?

Regards


DD Devakumar Dhanapoosanam Syncfusion Team February 19, 2020 05:11 AM

Hi Joan Caron, 
 
Sorry for the delay. Already provided solution is worked fine in Android platform. For iOS only we have some limitation. We can overcome this in iOS by using CustomRenderer in it calling the TouchUp method to resolve the issue as per in below codesnippet. 
 
C#: 
public class ChartTrackballBehaviorExt : ChartTrackballBehavior 
{ 
     public ChartExt chart { get; set; } 
     public ChartTrackballBehaviorExt() 
     { 
 
     } 
 
     protected override void OnLongPress(float pointX, float pointY) 
     { 
          chart.TrackballVisible = true; 
          base.OnLongPress(pointX, pointY); 
     } 
     //For Android this override OnTouchUp will work fine after LongPress 
     protected override void OnTouchUp(float pointX, float pointY) 
     {  
          base.OnTouchUp(pointX, pointY); 
     } 
       
     //For iOS after long press TouchUp method called here 
     public void TouchUp(float pointX, float pointY) 
     { 
         if (chart != null) 
         { 
              chart.TrackballVisible = false; 
              //check your logic here for iOS 
         } 
     } 
} 
 
C#:  
class CustomChartRenderer : SfChartRenderer 
{ 
   protected override void OnElementChanged(ElementChangedEventArgs<SfChart> e) 
   { 
       base.OnElementChanged(e); 
 
       var formsChart = Element as Syncfusion.SfChart.XForms.SfChart; 
 
       for (int i = 0; i < formsChart.ChartBehaviors.Count; i++) 
       { 
             if (formsChart.ChartBehaviors[i] is  Syncfusion.SfChart.XForms.ChartTrackballBehavior) 
             { 
                  var formsTrackball = formsChart.ChartBehaviors[i] as     
                                        Syncfusion.SfChart.XForms.ChartTrackballBehavior;                                                        Control.Behaviors.Remove((SFChartBehavior)SfChartRenderer.GetNativeObject(typeof 
                                    (Syncfusion.SfChart.XForms.ChartTrackballBehavior), formsTrackball)); 
                  CustomTrackballBehavior customTrackball = new CustomTrackballBehavior(); 
                  customTrackball.FormsBehavior = formsTrackball; 
 
                  var properties =  
SfChartRenderer.GetPropertiesChanged(typeof(Syncfusion.SfChart.XForms.ChartTrackballBehavior),   
                                     formsTrackball); 
                  foreach (var name in properties) 
                  {                                                                 
                        ChartTrackballBehaviorMapping.OnChartTrackballBehaviorPropertiesChanged(name,    
                                 formsTrackball, customTrackball); 
                  } 
                                                             
               SfChartRenderer.SetNativeObject(typeof(Syncfusion.SfChart.XForms.ChartTrackballBehavior),  
                                 formsTrackball, customTrackball); 
                 Control.Behaviors.Insert(i, customTrackball); 
             } 
         } 
     } 
} 
 
public class CustomTrackballBehavior : ChartTrackballBehaviorHelper 
{ 
      public override void LongPressWithGestureRecognizer(UILongPressGestureRecognizer   
                                            longPressGestureRecognizer) 
      { 
               base.LongPressWithGestureRecognizer(longPressGestureRecognizer); 
              var locationInChart = longPressGestureRecognizer.LocationInView(Chart); 
              if (UIGestureRecognizerState.Ended == longPressGestureRecognizer.State) 
              { 
                     (FormsBehavior as ChartTrackballBehaviorExt).TouchUp((float)locationInChart.X,  
                                     (float)locationInChart.Y); 
               } 
     } 
} 
 
XAML: 
 
<local:ChartExt x:Name="chart" HorizontalOptions="FillAndExpand"   
          VerticalOptions="FillAndExpand"> 
      …. 
      <chart:SfChart.ChartBehaviors> 
        <local:ChartTrackballBehaviorExt chart="{x:Reference chart}"  
                 ActivationMode="LongPress"> 
        </local:ChartTrackballBehaviorExt> 
   </chart:SfChart.ChartBehaviors> 
</local:ChartExt> 
 
 
 
Please let us know if you need further assistance on this. 
 
Regards, 
Devakumar D 



JC Joan Caron February 19, 2020 10:35 AM

That's perfect
Thank you a lot Devakumar Dhanapoosanam !


SJ Suyamburaja Jayakumar Syncfusion Team February 19, 2020 11:06 PM

  
Hi Joan Caron, 
 
We glad to know the given solution works, 
 
Please let us know if you need any further assistance and please don't hesitate to contact us. 
 
Regards, 
Suyamburaja J. 


Loader.
Live Chat Icon For mobile
Up arrow icon