-
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.
- Loading branch information
Showing
17 changed files
with
246 additions
and
31 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
export { default as makeZoomable } from './ZoomableComponent'; | ||
export { ScrollDriver } from './ScrollDriver'; | ||
export { TimingDriver } from './TimingDriver'; | ||
export { Parallax } from './Parallax'; | ||
export { FadeIn } from './FadeIn'; | ||
export { FadeOut } from './FadeOut'; | ||
export { ZoomIn } from './ZoomIn'; | ||
export { ZoomOut } from './ZoomOut'; | ||
export { HeroHeader } from './HeroHeader'; | ||
export { DriverShape } from './DriverShape'; | ||
export { connectAnimation } from './connectAnimation'; | ||
export { default as makeZoomable } from './src/components/ZoomableComponent'; | ||
export { ScrollDriver } from './src/drivers/ScrollDriver'; | ||
export { TimingDriver } from './src/drivers/TimingDriver'; | ||
export { TouchableDriver } from './src/drivers/TouchableDriver'; | ||
export { Parallax } from './src/animations/Parallax'; | ||
export { FadeIn } from './src/animations/FadeIn'; | ||
export { FadeOut } from './src/animations/FadeOut'; | ||
export { ZoomIn } from './src/animations/ZoomIn'; | ||
export { ZoomOut } from './src/animations/ZoomOut'; | ||
export { HeroHeader } from './src/animations/HeroHeader'; | ||
export { DriverShape } from './src/drivers/DriverShape'; | ||
export { connectAnimation } from './src/components/connectAnimation'; | ||
export { | ||
isAnimatedStyleValue, | ||
getAnimatedStyleValue, | ||
addAnimatedValueListener, | ||
removeAnimatedValueListener, | ||
} from './src/utils/animated-style'; |
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
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
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
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
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { Animated } from 'react-native'; | ||
|
||
/** | ||
* Checks if a style value is animated. | ||
* | ||
* @param value The value to check. | ||
* @returns {boolean} `true` if a value is animated, `false` otherwise. | ||
*/ | ||
export const isAnimatedStyleValue = (value) => value && typeof value.interpolate === 'function'; | ||
|
||
/** | ||
* Gets the current value of an animated style value. If | ||
* a value isn't animated, the original value will be returned. | ||
* | ||
* @param value The style value. | ||
* @return {*} The current value of a provided animated value. | ||
*/ | ||
export const getAnimatedStyleValue = (value) => { | ||
if (isAnimatedStyleValue(value)) { | ||
// If this is an animated value, we want to convert it to | ||
// a plain object in order to get its current value. | ||
return value.toJSON(); | ||
} | ||
|
||
return value; | ||
}; | ||
|
||
/** | ||
* Finds the closest `AnimatedValue` instance from the given | ||
* animated style value (e.g., AnimatedInterpolation, etc.). | ||
* This function will crawl the animated style hierarchy until | ||
* it finds the first `AnimatedValue` instance. | ||
* | ||
* @param animatedStyleValue The starting animated style value. | ||
* @returns {*} The closest `AnimatedValue`. | ||
*/ | ||
const findAnimatedValue = (animatedStyleValue) => { | ||
if (animatedStyleValue instanceof Animated.Value) { | ||
return animatedStyleValue; | ||
} | ||
|
||
const parent = animatedStyleValue._parent; | ||
if (parent) { | ||
return findAnimatedValue(parent); | ||
} | ||
|
||
return undefined; | ||
}; | ||
|
||
/** | ||
* Adds a listener to the animated value, or the closest parent | ||
* that is an animated value. This function is useful in components | ||
* that receive animated interpolations but need to react to changes | ||
* of those values during animations. | ||
* | ||
* @param styleValue The style value to add the listener to. | ||
* @param listener The listener to add. | ||
* @returns {string} The listener id, or `undefined` if the | ||
* listener couldn't be registered. | ||
*/ | ||
export const addAnimatedValueListener = (styleValue, listener) => { | ||
const animatedValue = findAnimatedValue(styleValue); | ||
if (animatedValue) { | ||
return animatedValue.addListener(listener); | ||
} | ||
|
||
return undefined; | ||
}; | ||
|
||
/** | ||
* Remove the animated value listener with the given id. The | ||
* listener will be removed from the `styleValue` argument if | ||
* it is an `AnimatedValue` or the closest `AnimatedValue` parent | ||
* if it isn't. | ||
* | ||
* @param styleValue The style value to remove the listener from. | ||
* @param listenerId The id of the listener to remove. | ||
*/ | ||
export const removeAnimatedValueListener = (styleValue, listenerId) => { | ||
const animatedValue = findAnimatedValue(styleValue); | ||
if (animatedValue) { | ||
animatedValue.removeListener(listenerId); | ||
} | ||
}; |