SKylander
Posts: 2
Joined: 20 Jun 2019, 14:49

Re: ScrollViewer Custom Manipulation issues

31 Jan 2023, 09:36

Hello, I am a colleague of CornNieu and am picking up where they left off.
For context, we are using Noesis 3.0.12.

We aren't receiving any calls to neither OnManipulationInertiaStarting nor OnManipulationDelta and I'm wondering if we've set up the OnManipulationStarted function incorrectly.
By "override OnManipulationStarted to capture the touch while dragging" I can only assume that you mean to call the CaptureTouch() function. The problem is that it's not doing anything. I can't seem to find any resources on how to receive the touch device ID for the manipulation event, but since we're testing on Windows right now I guess I can just pass 0 for now.
I've looked at the sample code in the Touch tutorial but it feels like the use case is very different from ours since we are overriding the behavior of a scroll viewer and not trying to implement manipulation on something that didn't already have it.
It's also unclear if I should call the super ParentClass::OnManipulationXXX() functions or not, but doing either has no effect on the app. Even overriding all of the manipulation functions and emptying them of any logic still leaves the scroll viewer fully functional, which is very suspicious to me.

This is the code we have so far:
CustomScrollViewer::CustomScrollViewer()
{
	SetIsManipulationEnabled(true);
}

void CustomScrollViewer::OnManipulationStarting(const Noesis::ManipulationStartingEventArgs& e)
{
	e.handled               = true;
	e.manipulationContainer = this;
	e.mode                  = Noesis::ManipulationModes_TranslateX;

	ParentClass::OnManipulationStarting(e);
}

void CustomScrollViewer::OnManipulationStarted(const Noesis::ManipulationStartedEventArgs& e)
{
	e.handled = true;
	CaptureTouch(0);

	ParentClass::OnManipulationStarted(e);
}

void CustomScrollViewer::OnManipulationInertiaStarting(const Noesis::ManipulationInertiaStartingEventArgs& e)
{
	e.handled = true;
	ReleaseTouchCapture(0);

	ParentClass::OnManipulationInertiaStarting(e);
}

void CustomScrollViewer::OnManipulationDelta(const Noesis::ManipulationDeltaEventArgs& e)
{
	e.handled = true;

	// ...

	ParentClass::OnManipulationDelta(e);
}

void CustomScrollViewer::OnManipulationCompleted(const Noesis::ManipulationCompletedEventArgs& e)
{
	e.handled = true;

	ParentClass::OnManipulationCompleted(e);
}
 
User avatar
sfernandez
Site Admin
Posts: 2997
Joined: 22 Dec 2011, 19:20

Re: ScrollViewer Custom Manipulation issues

02 Feb 2023, 19:05

There are a few differences between 3.0.12 and 3.1 regarding touch manipulations. Since 3.1 we only call the OnManipulationStarted when touch starts moving a bit, but in 3.0.12 it was called inmediately after OnManipulationStarting and capture was internally done, so there was no need to override OnManipulationStarted.

If you are overriding the default ScrollViewer behavior you don't need to call the ParentClass::OnManipulationXXX functions.

Are you at least being called to OnManipulationStarting? You should be as soon as you touch the screen and if no element in the event route handled the TouchDown event.

Please try the following code and let me know if all the manipulation overrides are being called:
CustomScrollViewer::CustomScrollViewer()
{
	SetIsManipulationEnabled(true);
}

void CustomScrollViewer::OnManipulationStarting(const Noesis::ManipulationStartingEventArgs& e)
{
	e.handled               = true;
	e.manipulationContainer = this;
	e.mode                  = Noesis::ManipulationModes_TranslateX;
}

void CustomScrollViewer::OnManipulationDelta(const Noesis::ManipulationDeltaEventArgs& e)
{
	e.handled = true;

	// ...somthing like this
	float hOffset = GetHorizontalOffset();
	float ratio = GetPanningRatio();
	float dx = e.deltaManipulation.translation.x;
	ScrollToHorizontalOffset(hOffset - ratio * dx);
}

void CustomScrollViewer::OnManipulationInertiaStarting(const Noesis::ManipulationInertiaStartingEventArgs& e)
{
	e.handled = true;
	e.translationBehavior.desiredDeceleration = GetPanningDeceleration();
}

void CustomScrollViewer::OnManipulationCompleted(const Noesis::ManipulationCompletedEventArgs& e)
{
	e.handled = true;
}
 
SKylander
Posts: 2
Joined: 20 Jun 2019, 14:49

Re: ScrollViewer Custom Manipulation issues

07 Feb 2023, 08:28

I figured out what the problem was. Fortunately, albeit painstakingly, we had set a style on the instance of CustomScrollViewer that internally was creating its own ScrollViewer which took precedence and therefor blocking manipulation events to our custom class. Resolving the style by setting it to {StaticResource {x:Type ScrollViewer}} made everything work again!
Thank you for your wonderful support.
 
User avatar
sfernandez
Site Admin
Posts: 2997
Joined: 22 Dec 2011, 19:20

Re: ScrollViewer Custom Manipulation issues

07 Feb 2023, 11:41

Glad to know is working fine now! Marking this as solved.

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 5 guests