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

Any ETA for support of nested touch handlers with native driver? #71

Closed
jhalborg opened this issue Dec 12, 2017 · 5 comments
Closed

Any ETA for support of nested touch handlers with native driver? #71

jhalborg opened this issue Dec 12, 2017 · 5 comments

Comments

@jhalborg
Copy link

Hey,

Thanks for a great lib, it's got a lot of potential to be the de facto library for gesture handling, especially for Expo projects!

One question. I tried running one of the examples (rotate+pinch) with native driver set to true, but get the following error:

Nesting touch handlers with native animated driver is not supported yet
...

Any ETA on when this is supported? That would make this library near perfect :-) But until then, there's no big difference between just implementing it using the core handlers and using this.

@kmagiera
Copy link
Member

Hey @jhalborg thanks for reaching out about this issue.

So in general nesting touch handlers is supported from day 1. I think this warning may be a bit misleading. What is not supported ATM is having nested handlers as direct children. Supporting this will require upstream changes and is not currently on my roadmap.

But you can still nest handlers with native event as long as their direct child is a RN component (e.g. View). So instead of doing:

<PinchHandler ...>
   <RotationHandler ...>
      <Animated.View ... />
   </RotationHandler>
</PinchHandler>

you should do:

<PinchHandler ...>
  <Animated.View ... >
     <RotationHandler ...>
        <Animated.View ... />
     </RotationHandler>
   </Animated.View>
</PinchHandler>

If you're using native driver remember that the child should be an "Animated" component (e.g. Animated.View vs just View)

@jhalborg
Copy link
Author

@kmagiera - Thanks for getting back to me :)

I think you misunderstood, I wasn't clear enough. It wasn't nesting of handlers with native events, but nesting of handlers with nativeDriver:true .

I tried running the example "scaleAndRotate" from here, where the handlers are nested like

<PanGestureHandler ...>
   <RotationGestureHandler ...>
      <PinchGestureHandler ... />
          <View>
              <Animated.Image />
          </View>
      </PinchGestureHandler ... />
   </RotationGestureHandler>
</PanGestureHandler>

Then I commented out the import { USE_NATIVE_DRIVER } from '../config'; and instead made a const USE_NATIVE_DRIVER = true;, and I got the error above.

But maybe it was because of the plain non-animated View parent to the Animated.Image? Don't have time to test right now, though, maybe later this week if needed

@kmagiera
Copy link
Member

I did understand that correctly and I’m aware of this issue. As mentioned in my previous comment, you could put Animated.View in between each handler and that should do. Also whenever you use native driver it should have an Animated element as a direct child

@jhalborg
Copy link
Author

Thanks again.

I'm sorry, it seems I misunderstood, not you ;)

I tested it real quick, and it seems to build without the redbox if I insert an Animated.View between each handler, but it seems to have lost responsiveness on the panhandler for some reason from it. I'll have to investigate more when I find time.

On a sidenote, I realize now when reading it again how arrogant i sounds starting out with "I think you misunderstood", my apologies :-)

@JonnyBurger
Copy link

If for some reason you want multiple nested elements but don't want to put <Animated.View>'s inbetween them, you can create Animated ghost elements:

class Ghost extends React.Component {
	render() {
		return this.props.children;
	}
}

const AnimatedGhost = Animated.createAnimatedComponent(Ghost);
<PanGestureHandler>
   <AnimatedGhost>
       <TapGestureHandler>

This could be useful if putting elements inbetween complicates your layout.

YouKnowEno added a commit to YouKnowEno/react-native-draggable-flatlist that referenced this issue Mar 15, 2021
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