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

perf(use-native-driver): useNativeDriver for fade animation #33

Merged
merged 1 commit into from
Dec 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"expo": "^21.0.0",
"react": "16.0.0-alpha.12",
"react-native": "^0.48.4",
"react-native-scripts": "^1.8.1",
"rn-placeholder": "file:../rn-placeholder"
},
"devDependencies": {
Expand Down
14 changes: 10 additions & 4 deletions src/animation/fade.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,28 @@ import React from 'react';
import { Animated } from 'react-native';
import PropTypes from 'prop-types';

const START_VALUE = 0.5;
const END_VALUE = 1;
const DURATION = 500;
const useNativeDriver = true;

/**
* Create a repetitive fadein / fadeout animation
*/
const Fade = ({ children }) => {
const START_VALUE = 0.5;
const animation = new Animated.Value(START_VALUE);

function start() {
Animated.sequence([
Animated.timing(animation, {
toValue: 1,
duration: 500,
toValue: END_VALUE,
duration: DURATION,
useNativeDriver,
}),
Animated.timing(animation, {
toValue: START_VALUE,
duration: 500,
duration: DURATION,
useNativeDriver,
}),
]).start((e) => {
if (e.finished) {
Expand Down
12 changes: 8 additions & 4 deletions src/animation/shine.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import React from 'react';
import { Animated, View, StyleSheet } from 'react-native';
import PropTypes from 'prop-types';

const START_VALUE = 0;
const END_VALUE = 100;
const DURATION = 750;

const styles = StyleSheet.create({
shine: {
width: 30,
Expand All @@ -18,11 +22,11 @@ const Shine = ({ children }) => {
const animation = new Animated.Value(0);

function start() {
animation.setValue(0);
animation.setValue(START_VALUE);
Animated.sequence([
Animated.timing(animation, {
toValue: 100,
duration: 750,
toValue: END_VALUE,
duration: DURATION,
}),
]).start(() => {
start();
Expand All @@ -32,7 +36,7 @@ const Shine = ({ children }) => {
start();

const marginLeft = animation.interpolate({
inputRange: [0, 100],
inputRange: [START_VALUE, END_VALUE],
outputRange: ['0%', '100%'],
});

Expand Down
Loading