Not able to use inside NestedScrollView
Closed this issue · 12 comments
when used inside a nested scroll view, the scratching process does not work smoothly.
Hence i moved to simple scroll view. But, in future, there can a requirement to use it inside a nested scroll view
Just to update, this is not working in scroll view also.
Hi there, I'm sorry to hear you're having trouble, but without more information there's not much that can be done to help. Do you have a minimum working example to demonstrate the issues you're experiencing?
It's also worth noting that the system was never intended to run in any kind of scrollable content area. The way we simulate scratchable regions using the View's drawing caches would almost certainly not behave correctly inside a container that's also trying to manage the drawing.
Hi,
I am just using this scratchable layout inside a nested scroll View and i guess the touch listeners for both i.e scroll view and scratchable layout are conflicting.
Can you help in any way or suggest something?
In order for us to "scratch," we need the touch events passed to the ScratchoffController
. In order for it to receive all of those touch events, it must return true
on the initial ACTION_DOWN
event. Unfortunately, returning true there will prevent other Views behind it from receiving any of those events.
If you wanted to implement this inside of a scrolling container, you would have to handle all touch events and then manually delegate them to the correct systems (ScratchoffController / NestedScrollView) based on the gesture. This would also require a partial re-write of ScratchoffController.onTouch
and ScratchoffProcessor.onReceiveMotionEvent
in order to correctly handle the lack of an ACTION_DOWN event.
Is there a reason this has to be within a scrolling container, though? Can you post a minimum code sample of what you're trying to accomplish? Maybe I can recommend an alternative approach.
Sorry, i cannot put the code here.
But the basic idea is we want to show a scratch card to the user within a scrollable content because we have other data to be shown above and below scratch card.
Hi
I have finally found a solution to this. So basically I am using a custom Scroll view layout in which I can disable/enable scrolling whenever I get a ACTION_DOWN/ACTION_UP touch event on the Scratch layout. Please refer below code.
controller.getScratchImageLayout().setOnTouchListener(new View.OnTouchListener() {
@OverRide
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
mListener.toggleScroll(false);
break;
case MotionEvent.ACTION_UP:
mListener.toggleScroll(true);
break;
}
return controller.onTouch(v, event);
}
});
This is working perfectly fine for me. Please suggest if you find some fishy in this :)
That looks like it would work well; disabling the scrolling when an ACTION_DOWN occurs on the ScratchImageLayout. In fact, it might even be worth adding something similar to the library in the future, or at least exposing the touch events to allow this to work directly with the ScratchoffController.
Hi Matt,
Thanks for acknowledging the solution shared by me. I hope you add this to your library to make it more customizable :)
Having same issue. And your solution does not work for me.
When i scratch the card it automatically scratch to down.
Please help for this.
Having same issue. And your solution does not work for me.
Trying to use this within a NestedScrollView? This isn't intended use of the system, but there is a potential fix using shubii's idea that may allow additional touch observations. I'm still in the process of testing it, but you can try pulling in that branch locally if you'd like in the meantime.
When i scratch the card it automatically scratch to down.
I'm sorry, but could you rephrase that or provide a screenshot? I'm not understanding the behavior you're referring to.
Attached Screenshot. When i touch to top side of view it automatically scratch down.