Last active
April 3, 2020 14:33
-
-
Save aliemir/d1d92bca1cd2bb7da8a98d2ab1abc2fc to your computer and use it in GitHub Desktop.
React Native Animated Interpolation Ornegi
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
const SearchView = ({navigation}) => { | |
const heroAnim = useRef(new Animated.Value(1)).current | |
const [isSearchFocus, setSearchFocus] = useState(false) | |
useEffect(() => { | |
if(isSearchFocus) { | |
Animated.timing(heroAnim, { | |
toValue: 1, | |
duration: 230, | |
useNativeDriver: false, | |
}).start() | |
} else { | |
Animated.timing(heroAnim, { | |
toValue: 0, | |
duration: 230, | |
useNativeDriver: false, | |
}).start() | |
} | |
}, [heroAnim, isSearchFocus]); | |
return ( | |
{/*...*/} | |
<Box | |
as={Animated.View} | |
height={heroAnim.interpolate({ | |
inputRange: [0,1], | |
outputRange: [0,230] | |
})} | |
{/*...*/} | |
> | |
<Box | |
as={Animated.View} | |
//Burada gerek yok ama göstermek için kullanmak istedim. | |
opacity={heroAnim.interpolate({ | |
inputRange: [0,1], | |
outputRange: [0,1] | |
})} | |
> | |
<Bg>{/*...*/}</Bg> | |
</Box> | |
</Box> | |
{/*...*/} | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment