-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adds touchable driver component * Adds touchable zoom in example * Wrap text in quotes for better display in diff tools * Extracts default animation out of class * Removes animation override via constructor
- Loading branch information
Showing
4 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { | ||
Animated, | ||
Easing, | ||
} from 'react-native'; | ||
|
||
/** | ||
* Returns the default animation callback to use. | ||
* | ||
* @param {Animated.Value} value | ||
* @param {double} toValue | ||
* @param {Object} animationOptions | ||
* @returns {CompositeAnimation} | ||
*/ | ||
function defaultAnimation(value, toValue, animationOptions) { | ||
return Animated.timing( | ||
value, | ||
{ | ||
toValue: toValue, | ||
...animationOptions | ||
} | ||
); | ||
} | ||
|
||
/** | ||
* Animation driver that creates an animated value changed on press events. | ||
* | ||
* Assign onPressIn and onPressOut props of React Native Touchable*, and | ||
* pass instance to any @shoutem/animation animation to run it | ||
* e.g.: | ||
* driver = new TouchableDriver(); | ||
* ... | ||
* <TouchableOpacity {...driver.touchableViewProps}> | ||
* ... | ||
* <ZoomIn driver={driver}> | ||
*/ | ||
export class TouchableDriver { | ||
|
||
/** | ||
* @param {Object} options Animation options. | ||
*/ | ||
constructor(options) { | ||
this.animationOptions = Object.assign({ | ||
easing: Easing.elastic(1), | ||
duration: 150, | ||
}, options); | ||
this.value = new Animated.Value(0); | ||
this.onPressIn = this.onPressIn.bind(this); | ||
this.onPressOut = this.onPressOut.bind(this); | ||
this.touchableViewProps = { | ||
onPressIn: this.onPressIn, | ||
onPressOut: this.onPressOut, | ||
}; | ||
} | ||
|
||
onPressIn() { | ||
defaultAnimation(this.value, 1, this.animationOptions).start(); | ||
} | ||
|
||
onPressOut() { | ||
defaultAnimation(this.value, 0, this.animationOptions).start(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React, { Component } from 'react'; | ||
import { ScrollView } from 'react-native'; | ||
|
||
import { | ||
ZoomIn, | ||
TouchableDriver, | ||
} from '@shoutem/animation'; | ||
|
||
|
||
import { | ||
Button, | ||
Row, | ||
Icon, | ||
Text, | ||
View, | ||
} from '@shoutem/ui'; | ||
|
||
export default class ZoomInTouchableExample extends Component { | ||
render() { | ||
const driver = new TouchableDriver(); | ||
|
||
return ( | ||
<View> | ||
<Row> | ||
<View styleName="horizontal h-center"> | ||
<ZoomIn driver={driver} maxFactor={1.3}> | ||
<Button {...driver.touchableViewProps}> | ||
<Icon name="add-to-favorites-full" /> | ||
<Text>{"TOUCH ME, I'M ZOOMING IN"}</Text> | ||
</Button> | ||
</ZoomIn> | ||
</View> | ||
</Row> | ||
</View> | ||
); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters