mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
at responsive-updates 47 lines 1.3 kB view raw
1/** 2 * Copyright (c) JOB TODAY S.A. and its affiliates. 3 * 4 * This source code is licensed under the MIT license found in the 5 * LICENSE file in the root directory of this source tree. 6 * 7 */ 8 9import {Animated} from 'react-native' 10 11const INITIAL_POSITION = {x: 0, y: 0} 12const ANIMATION_CONFIG = { 13 duration: 200, 14 useNativeDriver: true, 15} 16 17const useAnimatedComponents = () => { 18 const headerTranslate = new Animated.ValueXY(INITIAL_POSITION) 19 const footerTranslate = new Animated.ValueXY(INITIAL_POSITION) 20 21 const toggleVisible = (isVisible: boolean) => { 22 if (isVisible) { 23 Animated.parallel([ 24 Animated.timing(headerTranslate.y, {...ANIMATION_CONFIG, toValue: 0}), 25 Animated.timing(footerTranslate.y, {...ANIMATION_CONFIG, toValue: 0}), 26 ]).start() 27 } else { 28 Animated.parallel([ 29 Animated.timing(headerTranslate.y, { 30 ...ANIMATION_CONFIG, 31 toValue: -300, 32 }), 33 Animated.timing(footerTranslate.y, { 34 ...ANIMATION_CONFIG, 35 toValue: 300, 36 }), 37 ]).start() 38 } 39 } 40 41 const headerTransform = headerTranslate.getTranslateTransform() 42 const footerTransform = footerTranslate.getTranslateTransform() 43 44 return [headerTransform, footerTransform, toggleVisible] as const 45} 46 47export default useAnimatedComponents