Skip to content
Open
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
7 changes: 6 additions & 1 deletion styled-components/src/Card/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React,{useEffect} from 'react';
import { Animated } from 'react-native';

import { ACTION_OFFSET } from '../../utils/constants';
Expand All @@ -11,8 +11,13 @@ export default function Card({
isFirst,
swipe,
tiltSign,
setCurrentPet,
...rest
}) {
useEffect(() => {
setCurrentPet(name);
}, [name])

const rotate = Animated.multiply(swipe.x, tiltSign).interpolate({
inputRange: [-ACTION_OFFSET, 0, ACTION_OFFSET],
outputRange: ['8deg', '0deg', '-8deg'],
Expand Down
10 changes: 10 additions & 0 deletions styled-components/src/Main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { pets as petsObj } from './data';
import { Container } from './styles';

export default function Main() {
const [currentPet, setCurrentPet] = useState("");
const swipe = useRef(new Animated.ValueXY()).current;
const tiltSign = useRef(new Animated.Value(1)).current;
const [pets, setPets] = useState(petsObj);
Expand All @@ -18,6 +19,13 @@ export default function Main() {
}
}, [pets]);

const swipeLeft = (petName) => {
console.warn("swipe left",petName);
}
const swipeRight = (petName) => {
console.warn("swipe right",petName);
}

const panResponder = useRef(
PanResponder.create({
onMoveShouldSetPanResponder: () => true,
Expand All @@ -31,6 +39,7 @@ export default function Main() {
const userAction = Math.abs(dx) > ACTION_OFFSET;

if (userAction) {
dx > 0 ? swipeRight(currentPet) : swipeLeft(currentPet);
Animated.timing(swipe, {
duration: 200,
toValue: {
Expand Down Expand Up @@ -84,6 +93,7 @@ export default function Main() {
isFirst={isFirst}
swipe={swipe}
tiltSign={tiltSign}
setCurrentPet={setCurrentPet}
{...panHandlers}
/>
);
Expand Down