Skip to content

Instantly share code, notes, and snippets.

@kiok46
Last active August 18, 2017 04:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kiok46/8e4748fc2d875feef39f72ccbde6e583 to your computer and use it in GitHub Desktop.
Save kiok46/8e4748fc2d875feef39f72ccbde6e583 to your computer and use it in GitHub Desktop.
Animations and PanResponders.

Animations

3 main questions that needed to be answered.

  • Where is the item right now? (Use Animated.ValueVY)
  • Where is it the element moving to? (Use Animated.Spring)
  • Which element are we moving? (Use Animated.View)

Animations run compeltely outside the state system.)

PanResponder

import {
   PanResponder
} from 'react-native';

		const panResponder = PanResponder.create({
   		onStartShouldSetPanResponder: () => {},
   		onPanResponderMove: () => {},
   		onPanResponderRelease: () => {},
   	});

For onStartShouldSetPanResponder: () => {},, anytime the user presses this component and drags around the screen, we want this pan responder to be responsible for handeling that gesture. onStartShouldSetPanResponder: () => true,

For onPanResponderMove: () => {},, first argument is event, it has some abount of information that, which object was pressed by the user. second argument is gesture, what the user is doing on the screen. (pixels).

now wireup the pan responder to Component.

<View {...this.state.panResponder.panHandlers}>
</View>

we are spreading all the callbackds in the panHandlers object to our existing component.

Rotating

we use transform.

transform: [{ rotate: '45deg' }]

to tie 1 property to another property we use something called interpolation.

@kiok46
Copy link
Author

kiok46 commented Jul 24, 2017

screen shot 2017-07-24 at 10 26 33 am

This image is taken from one of the courses of Stephen Grieder, I don't remember which one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment