@@ -58,6 +58,16 @@ public partial class SfEffectsView : SfContentView, ITouchListener, ITapGestureL
58
58
59
59
bool _canRepeat ;
60
60
61
+ #if WINDOWS
62
+ // Flag to track if touch is currently pressed
63
+ bool _isTouchDown ;
64
+
65
+ // Timer for custom long press detection
66
+ System . Timers . Timer ? _longPressTimer ;
67
+
68
+ // Default long press duration in milliseconds
69
+ const int _longPressDuration = 500 ;
70
+ #endif
61
71
double _tempScaleFactor ;
62
72
63
73
readonly string _rotationAnimation = "Rotation" ;
@@ -400,6 +410,9 @@ public SfEffectsView()
400
410
{
401
411
ThemeElement . InitializeThemeResources ( this , "SfEffectsViewTheme" ) ;
402
412
InitializeEffects ( ) ;
413
+ #if WINDOWS
414
+ InitializeLongPressTimer ( ) ;
415
+ #endif
403
416
this . AddGestureListener ( this ) ;
404
417
this . AddTouchListener ( this ) ;
405
418
}
@@ -1719,6 +1732,67 @@ void OnAnimationFinished(double value, bool completed)
1719
1732
}
1720
1733
}
1721
1734
1735
+ #if WINDOWS
1736
+ /// <summary>
1737
+ /// Initialize the long press timer.
1738
+ /// </summary>
1739
+ void InitializeLongPressTimer ( )
1740
+ {
1741
+ // Create and configure a timer with a simple timer implementation
1742
+ _longPressTimer = new System . Timers . Timer ( _longPressDuration ) ;
1743
+ _longPressTimer . AutoReset = false ;
1744
+ _longPressTimer . Elapsed += OnLongPressTimerElapsed ;
1745
+ }
1746
+
1747
+ /// <summary>
1748
+ /// Start the long press timer.
1749
+ /// </summary>
1750
+ /// <param name="touchPoint">The point where the touch started.</param>
1751
+ void StartLongPressTimer ( Point touchPoint )
1752
+ {
1753
+ // Store touch point and reset state
1754
+ _touchDownPoint = touchPoint ;
1755
+ LongPressHandled = false ;
1756
+
1757
+ // Start the timer - ensure it's stopped first
1758
+ if ( _longPressTimer != null )
1759
+ {
1760
+ _longPressTimer . Stop ( ) ;
1761
+ _longPressTimer . Start ( ) ;
1762
+ }
1763
+ }
1764
+
1765
+ /// <summary>
1766
+ /// Stop the long press timer.
1767
+ /// </summary>
1768
+ void StopLongPressTimer ( )
1769
+ {
1770
+ _longPressTimer ? . Stop ( ) ;
1771
+ }
1772
+
1773
+ /// <summary>
1774
+ /// Callback for the long press timer elapsed event.
1775
+ /// </summary>
1776
+ /// <param name="sender">The sender object.</param>
1777
+ /// <param name="e">The event args.</param>
1778
+ void OnLongPressTimerElapsed ( object ? sender , System . Timers . ElapsedEventArgs e )
1779
+ {
1780
+ // We need to dispatch back to the UI thread since timer callbacks occur on a background thread
1781
+ Application . Current ? . Dispatcher . Dispatch ( ( ) =>
1782
+ {
1783
+ // Check if touch is still active and not already handled
1784
+ if ( _isTouchDown && ! LongPressHandled )
1785
+ {
1786
+ var args = new LongPressEventArgs ( _touchDownPoint ) ;
1787
+ // Trigger the long press method
1788
+ OnLongPress ( args ) ;
1789
+ // Set handled flag to prevent multiple triggers
1790
+ LongPressHandled = true ;
1791
+ }
1792
+ } ) ;
1793
+ }
1794
+ #endif
1795
+
1722
1796
#endregion
1723
1797
1724
1798
#region Override methods
@@ -1893,6 +1967,9 @@ public void OnTouch(PointerEventArgs e)
1893
1967
{
1894
1968
_touchDownPoint = e . TouchPoint ;
1895
1969
LongPressHandled = false ;
1970
+ #if WINDOWS
1971
+ _isTouchDown = true ;
1972
+ #endif
1896
1973
1897
1974
if ( _rippleEffectLayer != null )
1898
1975
{
@@ -1909,10 +1986,19 @@ public void OnTouch(PointerEventArgs e)
1909
1986
{
1910
1987
AddEffects ( TouchDownEffects , e . TouchPoint ) ;
1911
1988
}
1989
+ #if WINDOWS
1990
+ // Start the long press timer
1991
+ StartLongPressTimer ( e . TouchPoint ) ;
1992
+ #endif
1912
1993
}
1913
1994
1914
1995
if ( e . Action == PointerActions . Released )
1915
1996
{
1997
+ #if WINDOWS
1998
+ // Stop the long press timer
1999
+ StopLongPressTimer ( ) ;
2000
+ _isTouchDown = false ;
2001
+ #endif
1916
2002
_elementBounds . X = 0 ;
1917
2003
_elementBounds . Y = 0 ;
1918
2004
_elementBounds . Height = ( float ) Height ;
@@ -1975,6 +2061,11 @@ public void OnTouch(PointerEventArgs e)
1975
2061
}
1976
2062
else if ( e . Action == PointerActions . Cancelled )
1977
2063
{
2064
+ #if WINDOWS
2065
+ // Stop the timer and reset state
2066
+ StopLongPressTimer ( ) ;
2067
+ _isTouchDown = false ;
2068
+ #endif
1978
2069
LongPressHandled = false ;
1979
2070
RemoveRippleEffect ( ) ;
1980
2071
RemoveHighlightEffect ( ) ;
@@ -1987,6 +2078,10 @@ public void OnTouch(PointerEventArgs e)
1987
2078
1988
2079
if ( diffX >= 20 || diffY >= 20 )
1989
2080
{
2081
+ #if WINDOWS
2082
+ // Cancel the long press timer since the finger has moved too much
2083
+ StopLongPressTimer ( ) ;
2084
+ #endif
1990
2085
RemoveRippleEffect ( ) ;
1991
2086
RemoveHighlightEffect ( ) ;
1992
2087
}
0 commit comments