question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

iOS native touch effect may keep the pressed state when touch input moves away

See original GitHub issue

Reporting against package version 4.1.28

I’m experiencing a problem that is very similar to #35 but on iOS. If I add the touch effect to a control inside a scrollable container, then it is possible to drag my finger off the control without reverting the control’s touch state to normal, leaving its appearance in a “pressed” state.

As noted above, this is similar to what was happening on Android in #35. I also experienced that problem, but the DisallowTouchThreshold property helpfully solved that. AFAIK there is no equivalent for iOS.

I have managed to come up with a workaround for iOS (see code below), but there are several problems that prevent me from using this in my project:

  1. I had to subclass ScrollView to create a new renderer
  2. It has to be included in the TouchEffect.iOS project
  3. PlatformTouchEff.HandleTouch has to be changed to internal

Of course, this workaround only works for ScrollView, so using the same logic I’d have to similarly subclass CollectionView, ListView, CarouselView etc.

Rather than the top-down approach of my solution where the antecedent scroll container handles the touch in all its children, I think it would be better to implement a solution where the child control hooks into the parent scrollcontainers’s gesture events. My limited knowledge of iOS prevents me from thinking of a solution for this. Do you have any suggestions?

[assembly: ExportRenderer(typeof(ScrollViewExtended), typeof(ScrollViewExtendedRenderer))]
namespace TouchEffectSample.iOS
{
    public class ScrollViewExtendedRenderer : ScrollViewRenderer
    {
        public ScrollViewExtendedRenderer() : base()
        {
        }

        public override bool GestureRecognizerShouldBegin(UIGestureRecognizer gestureRecognizer)
        {
            HandleSubViewTouches(gestureRecognizer.View);
            return base.GestureRecognizerShouldBegin(gestureRecognizer);
        }

        private void HandleSubViewTouches(UIView view)
        {
            if (view.GestureRecognizers != null && view.GestureRecognizers.Any())
            {
                foreach (var gestureRecognizer in view.GestureRecognizers)
                {
                    if (gestureRecognizer is TouchUITapGestureRecognizer touchGestureRecognizer)
                    {
                        touchGestureRecognizer.HandleTouch(TouchStatus.Canceled);
                    }
                }
            }

            if (view.Subviews != null && view.Subviews.Any())
            {
                foreach (var subView in view.Subviews)
                {
                    HandleSubViewTouches(subView);
                }
            }
        }
    }
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
rredohcommented, May 20, 2020

Hi Andrei, I’m so sorry, maybe there’s a cache bug or something. I tried to reinstall the package and it’s working as expected

0reactions
AndreiMisiukevichcommented, May 20, 2020

Hi Andrei, I’m so sorry, maybe there’s a cache bug or something. I tried to reinstall the package and it’s working as expected

I am glad to hear it 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android native touch effect may keep the pressed state ...
Example: I tap and hold an item. it goes darker as expected. I move the finger away from the item, but still touching...
Read more >
How to prevent sticky hover effects for buttons on touch ...
These buttons have a hover state, they turn blue. On touch devices, like iPad, the hover state is sticky, so the button stays...
Read more >
React Native touchable vs. pressable components
Learn the difference between touchable and pressable components in React Native, and how to implement different effects with each kind.
Read more >
Native Touch - Faster touch via callbacks from the OS, with ...
Native Touch achieve lowest latency input by bringing back callback-style input handling to you in Unity, by hacking into the earliest line possible...
Read more >
Touch events - Web APIs - MDN Web Docs - Mozilla
During this interaction, an application receives touch events during the start, move, and end phases. Touch events are similar to mouse events ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found