API 参考

@kkwaenggwari/animated 的所有导出,附带签名以及讲解它的指南。

57 个 API

值与计算图

Value

new Value(initial: number)

可变的数字,带有 setValue、setOffset、flattenOffset、extractOffset、stopAnimation 和 resetAnimation。

指南: 值与 style

ValueXY

new ValueXY({ x?, y? })

成对的 x 和 y 值,支持同样的操作,另有 getLayout 和 getTranslateTransform。

指南: 值与 style

createValue

createValue(initial: number | Record<string, number>)

在 React 之外创建一个数字或具名的数值记录。创建本身不会产生任何动作。

指南: 值与 style

AnimatedNode

node.getValue() · node.interpolate(config) · node.addListener(fn)

所有值和计算图的只读基类:getValue、interpolate 和监听器。

指南: 值与 style

AnimatedInterpolation

node.interpolate({ inputRange, outputRange, easing?, extrapolate? })

从输入范围到输出范围的动态映射,支持 easing 以及 extend、clamp 或 identity 外推。

指南: 值与 style

AnimatedComputed

new AnimatedComputed(inputs, (...values) => result);

基于一个或多个输入的纯只读计算。使用它的输出在 JavaScript 中运行。

指南: 值与 style

React Hook

useAnimated

useAnimated(initial, value => { … }, deps?, { autoStart?, onComplete?, scope? }?)

持有一个值,以及在其工厂函数中声明的所有控制器、输入和输出。负责启动、在依赖变化时重新开始,并完成清理。

指南: 值与 style

useAnimatedCSS

useAnimatedCSS(node, { scope?, id? }?): string

为不是 calc() 表达式的派生节点提供专属的 CSS 变量,生命周期与组件一致。

指南: 值与 style

驱动器、组合与时间轴

Easing

Easing.inOut(Easing.cubic) · Easing.bezier(x1, y1, x2, y2)

与 React Native 一致的曲线:linear、quad、cubic、sin、circle、exp、elastic、back、bounce、bezier 以及 in/out 辅助函数。

指南: 时序、弹簧与组合

组件与布局

Animated

<Animated.div seed pose tempo respond depart move />;

Animated.div 等 HTML 和 SVG 宿主元素的命名空间,以及以 React Native 名称提供的核心函数。

指南: Animated 组件

输入与连接

event

Animated.event([{ nativeEvent: { contentOffset: { y } } }]);

像在 React Native 中一样,把嵌套的事件数据映射到值上。

指南: 输入与手势

dragInput

dragInput({ x?, y?, axis?, bounds?, elastic?, momentum?, settle? })

指针和键盘拖拽,支持边界、弹性边缘、惯性和 settle。

指南: 输入与手势

输出与诊断

bind

bind(element, style) → { update, inspect, dispose }

在 React 之外把 Animated 样式绑定到元素;返回 update、inspect 和 dispose。

指南: 性能与播放

output

output(targetRef, { style?, attributes?, properties?, text? })

在 useAnimated 中负责 style、属性、文本或对象属性的输出。

指南: 性能与播放

搜索

输入关键词搜索文档。