Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to use inside NestedScrollView #12

Closed
shubii opened this issue Apr 5, 2019 · 12 comments
Closed

Not able to use inside NestedScrollView #12

shubii opened this issue Apr 5, 2019 · 12 comments

Comments

@shubii
Copy link

shubii commented Apr 5, 2019

No description provided.

@shubii
Copy link
Author

shubii commented Apr 5, 2019

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

@shubii
Copy link
Author

shubii commented Apr 5, 2019

Just to update, this is not working in scroll view also.

@mattsilber
Copy link
Collaborator

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.

@shubii
Copy link
Author

shubii commented Apr 5, 2019

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?

@mattsilber
Copy link
Collaborator

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.

@shubii
Copy link
Author

shubii commented Apr 5, 2019

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.

@shubii
Copy link
Author

shubii commented Apr 5, 2019

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 :)

@mattsilber
Copy link
Collaborator

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.

@shubii
Copy link
Author

shubii commented Apr 9, 2019

Hi Matt,

Thanks for acknowledging the solution shared by me. I hope you add this to your library to make it more customizable :)

@bytecodeworld
Copy link

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.

@mattsilber
Copy link
Collaborator

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.

@bytecodeworld
Copy link

Attached Screenshot. When i touch to top side of view it automatically scratch down.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants