Browse Source

fade optimizations

pull/8/head
Tim Glasgow 2 years ago
parent
commit
87403a8b79
  1. 7
      squarenotsquare/src/components/Fade.js
  2. 4
      squarenotsquare/src/screens/Game.js

7
squarenotsquare/src/components/Fade.js

@ -4,14 +4,13 @@ import { useEffect, useRef } from "react";
function Fade(props){ function Fade(props){
const faded = useRef(new Animated.Value(0.1)); const faded = useRef(new Animated.Value(0.1));
const opaque = useRef(new Animated.Value(1));
useEffect(() => { useEffect(() => {
if (props.faded) { if (props.faded) {
Animated.timing( Animated.timing(
opaque.current, faded.current,
{ {
toValue: 0.25, toValue: 0.1,
duration: props.duration, duration: props.duration,
useNativeDriver: true useNativeDriver: true
} }
@ -30,7 +29,7 @@ function Fade(props){
return ( return (
<Animated.View style={{ opacity: (props.faded ? opaque.current : faded.current)}}> <Animated.View style={{ opacity: faded.current}}>
{props.children} {props.children}
</Animated.View> </Animated.View>
) )

4
squarenotsquare/src/screens/Game.js

@ -139,7 +139,7 @@ function Game(props){
function generatePair(answer, shapeIndex, pairIndex) { function generatePair(answer, shapeIndex, pairIndex) {
if (answer === 0) { if (answer === 0) {
return ( return (
<Fade key={pairIndex} faded={challengeState.current !== pairIndex} duration={100}> <Fade key={pairIndex} faded={challengeState.current !== pairIndex} duration={500}>
<View style={[styles.flexRow, styles.spaceEvenly, styles.buttonMargin]}> <View style={[styles.flexRow, styles.spaceEvenly, styles.buttonMargin]}>
{generateSquare(pairIndex)} {generateSquare(pairIndex)}
{generateShape(shapeIndex, pairIndex)} {generateShape(shapeIndex, pairIndex)}
@ -148,7 +148,7 @@ function Game(props){
); );
} else { } else {
return ( return (
<Fade key={pairIndex} faded={challengeState.current !== pairIndex} duration={100}> <Fade key={pairIndex} faded={challengeState.current !== pairIndex} duration={500}>
<View style={[styles.flexRow, styles.spaceEvenly, styles.buttonMargin]}> <View style={[styles.flexRow, styles.spaceEvenly, styles.buttonMargin]}>
{generateShape(shapeIndex, pairIndex)} {generateShape(shapeIndex, pairIndex)}
{generateSquare(pairIndex)} {generateSquare(pairIndex)}

Loading…
Cancel
Save