Skip to content

Commit

Permalink
feat: Add a missing useAnimatedValue hook
Browse files Browse the repository at this point in the history
Issue: #2707
  • Loading branch information
retyui committed Nov 28, 2024
1 parent a5ba27c commit 39f37d7
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/react-native-web/src/exports/Animated/useAnimatedValue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Copyright (c) Davyd Narciso.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

'use client';

import useAnimatedValue from '../../vendor/react-native/Animated/useAnimatedValue';
export default useAnimatedValue;
1 change: 1 addition & 0 deletions packages/react-native-web/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,4 @@ export { default as DeviceEventEmitter } from './exports/DeviceEventEmitter';
export { default as useColorScheme } from './exports/useColorScheme';
export { default as useLocaleContext } from './exports/useLocaleContext';
export { default as useWindowDimensions } from './exports/useWindowDimensions';
export { default as useAnimatedValue } from './exports/Animated/useAnimatedValue';
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
*/

import type {AnimatedValueConfig} from './nodes/AnimatedValue';

import Animated from './Animated';
import {useRef} from 'react';

export default function useAnimatedValue(
initialValue: number,
config?: ?AnimatedValueConfig,
): Animated.Value {
const ref = useRef<null | Animated.Value>(null);
if (ref.current == null) {
ref.current = new Animated.Value(initialValue, config);
}
return ref.current;
}

0 comments on commit 39f37d7

Please sign in to comment.