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。

指南: 輸入與手勢

scrollInput

scrollInput({ x?, y?, progressX?, progressY?, target?, through? })

元素、頁面或穿過可視範圍之元素的捲動位置與進度。

指南: 輸入與手勢

輸出與診斷

bind

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

在 React 之外把 Animated 樣式綁定到元素;回傳 update、inspect 與 dispose。

指南: 效能與播放

output

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

在 useAnimated 中負責 style、屬性、文字或物件屬性的輸出。

指南: 效能與播放

搜尋

輸入關鍵字搜尋文件。