From 3bf4892fc01fff5541226aead13f3fd9e61edbf6 Mon Sep 17 00:00:00 2001 From: William Candillon Date: Fri, 19 Jul 2019 05:44:32 +0200 Subject: [PATCH] =?UTF-8?q?fix(=F0=9F=90=9B):=20Fix=20semantic=20of=20useT?= =?UTF-8?q?ranstion()=20(#80)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 7 ++++--- src/AnimationRunners.ts | 5 +++-- src/Animations.ts | 7 ++++--- src/Array.ts | 10 +++++++--- src/Colors.ts | 6 +++--- src/Interactable.tsx | 6 ++---- src/Math.ts | 8 ++++---- src/SVG.ts | 6 ++++-- src/String.tsx | 1 + yarn.lock | 10 +++++++--- 10 files changed, 39 insertions(+), 27 deletions(-) diff --git a/package.json b/package.json index 5a5c2412..28af494e 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Utility library for React Native Reanimated", "main": "lib/module/index.js", "scripts": { - "lint": "eslint src/**/*", + "lint": "eslint --ext .ts,.tsx src", "tsc": "tsc --noEmit", "test": "npm run lint && npm run", "prepare": "bob build", @@ -31,7 +31,7 @@ "@types/react": "^16.8.15", "@types/react-native": "^0.57.51", "eslint": "^5.16.0", - "eslint-config-react-native-wcandillon": "2.0.0", + "eslint-config-react-native-wcandillon": "2.0.4", "react": "^16.8.6", "react-native": "^0.59.5", "react-native-gesture-handler": "^1.2.1", @@ -57,6 +57,7 @@ "dependencies": { "abs-svg-path": "^0.1.1", "normalize-svg-path": "^1.0.1", - "parse-svg-path": "^0.1.2" + "parse-svg-path": "^0.1.2", + "use-memo-one": "^1.1.1" } } diff --git a/src/AnimationRunners.ts b/src/AnimationRunners.ts index 19a98ce7..112135b2 100644 --- a/src/AnimationRunners.ts +++ b/src/AnimationRunners.ts @@ -1,5 +1,5 @@ import Animated from "react-native-reanimated"; -import {Platform} from "react-native"; +import { Platform } from "react-native"; const { Value, @@ -77,6 +77,7 @@ export function runSpring( set(state.time, 0), set(state.position, value), set(state.velocity, 0), + // eslint-disable-next-line @typescript-eslint/no-explicit-any set(config.toValue as any, dest), startClock(clock) ]), @@ -88,7 +89,7 @@ export function runSpring( export function runTiming( clock: Animated.Clock, - value: Animated.Adaptable, + value: Animated.Adaptable, config: Animated.TimingConfig ) { const state = { diff --git a/src/Animations.ts b/src/Animations.ts index 98e1886b..6d5e6031 100644 --- a/src/Animations.ts +++ b/src/Animations.ts @@ -1,5 +1,6 @@ import * as React from "react"; import Animated, { Easing } from "react-native-reanimated"; +import { useMemoOne } from "use-memo-one"; import { TransformsStyle } from "react-native"; import { min } from "./Math"; @@ -68,8 +69,8 @@ export const transformOrigin = ( { translateY: multiply(y, -1) } ]; -export const useTransition = ( - state: any, +export const useTransition = ( + state: T, src: Animated.Adaptable, dest: Animated.Adaptable, duration: number = 400, @@ -85,7 +86,7 @@ export const useTransition = ( "useCode() is only available in Reanimated 1.0.0 or higher" ); } - const { transitionVal, clock } = React.useMemo( + const { transitionVal, clock } = useMemoOne( () => ({ transitionVal: new Value(0), clock: new Clock() diff --git a/src/Array.ts b/src/Array.ts index 1635dce1..e8e73aa1 100644 --- a/src/Array.ts +++ b/src/Array.ts @@ -5,8 +5,12 @@ const { Value, cond, eq, or } = Animated; export const get = ( array: Animated.Adaptable[], index: Animated.Adaptable, - notFound: Animated.Node = new Value() -) => array.reduce((acc, v, i) => cond(eq(i, index), v, acc), notFound); + notFound: Animated.Node = new Value() +): Animated.Node => + array.reduce( + (acc, v, i) => cond(eq(i, index), v, acc), + notFound + ) as Animated.Node; export const contains = ( values: Animated.Node[], @@ -20,5 +24,5 @@ export const contains = ( export const find = ( values: Animated.Node[], fn: (v: Animated.Node) => Animated.Node, - notFound: Animated.Node = new Value() + notFound: Animated.Node = new Value() ) => values.reduce((acc, v) => cond(fn(v), v, acc), notFound); diff --git a/src/Colors.ts b/src/Colors.ts index d4caebad..e914e9e2 100644 --- a/src/Colors.ts +++ b/src/Colors.ts @@ -22,9 +22,9 @@ interface RGBColor { } function match( - condsAndResPairs: Animated.Adaptable[], + condsAndResPairs: readonly Animated.Adaptable[], offset = 0 -): any { +): Animated.Adaptable | undefined | Animated.Node { if (condsAndResPairs.length - offset === 1) { return condsAndResPairs[offset]; } @@ -84,7 +84,7 @@ const rgbToHsv = (c: RGBColor) => { const ma = Math.max(r, g, b); const mi = Math.min(r, g, b); - let h: number = 0; + let h = 0; const v = ma; const d = ma - mi; diff --git a/src/Interactable.tsx b/src/Interactable.tsx index df88f640..3af5d8f5 100644 --- a/src/Interactable.tsx +++ b/src/Interactable.tsx @@ -1,4 +1,4 @@ -/* eslint-disable react/sort-comp */ +/* eslint-disable react/sort-comp, @typescript-eslint/no-explicit-any */ import React from "react"; import Animated from "react-native-reanimated"; import { PanGestureHandler, State } from "react-native-gesture-handler"; @@ -286,9 +286,7 @@ export interface InteractableProps { boundaries?: Boundaries; } -export class Interactable extends React.PureComponent< - InteractableProps -> { +export class Interactable extends React.PureComponent { static defaultProps = { dragToss: 0.1, dragEnabled: true, diff --git a/src/Math.ts b/src/Math.ts index f8d5fb5d..71ae582d 100644 --- a/src/Math.ts +++ b/src/Math.ts @@ -42,10 +42,6 @@ export const toRad = (deg: Animated.Adaptable): Animated.Node => export const toDeg = (rad: Animated.Adaptable): Animated.Node => multiply(rad, 180 / Math.PI); -// https://developer.download.nvidia.com/cg/atan.html -export const atan = (x: Animated.Adaptable): Animated.Node => - atan2(x, 1); - // https://developer.download.nvidia.com/cg/atan2.html export const atan2 = ( y: Animated.Adaptable, @@ -78,6 +74,10 @@ export const atan2 = ( ]); }; +// https://developer.download.nvidia.com/cg/atan.html +export const atan = (x: Animated.Adaptable): Animated.Node => + atan2(x, 1); + // https://developer.download.nvidia.com/cg/acos.html export const acos = (x1: Animated.Adaptable) => { const negate: Animated.Value = new Value(); diff --git a/src/SVG.ts b/src/SVG.ts index f99f8e8a..18fe6e1b 100644 --- a/src/SVG.ts +++ b/src/SVG.ts @@ -57,8 +57,8 @@ interface BezierCubicCurve { } export interface PathInterpolationConfig { - inputRange: ReadonlyArray>; - outputRange: ReadonlyArray; + inputRange: readonly Animated.Adaptable[]; + outputRange: readonly (ReanimatedPath | string)[]; extrapolate?: Animated.Extrapolate; extrapolateLeft?: Animated.Extrapolate; extrapolateRight?: Animated.Extrapolate; @@ -222,6 +222,7 @@ export const getLengthAtX = ( const p3 = get(path.p3x, index); const t = cubicBezierSolve(p0, p1, p2, p3); const length = get(path.length, index); + /* eslint-disable @typescript-eslint/no-explicit-any */ const start = add( ...(path.length.map((l, i) => cond(lessThan(i, index), l, 0)) as [ any, @@ -229,5 +230,6 @@ export const getLengthAtX = ( ...any[] ]) ); + /* eslint-enable @typescript-eslint/no-explicit-any */ return add(start, multiply(t, length)); }; diff --git a/src/String.tsx b/src/String.tsx index 3a8b75a4..474dd8eb 100644 --- a/src/String.tsx +++ b/src/String.tsx @@ -13,5 +13,6 @@ export const string = ( if (values.length > strings.length) { result.push(values[values.length - 1]); } + // eslint-disable-next-line @typescript-eslint/no-explicit-any return concat(...(result as [any, any, ...any[]])); }; diff --git a/yarn.lock b/yarn.lock index 121a2750..703d7144 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2679,9 +2679,9 @@ eslint-config-prettier@^4.3.0: dependencies: get-stdin "^6.0.0" -eslint-config-react-native-wcandillon@2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/eslint-config-react-native-wcandillon/-/eslint-config-react-native-wcandillon-2.0.0.tgz#a397e6813eb26270450f197543aeda5b2d9176be" +eslint-config-react-native-wcandillon@2.0.4: + version "2.0.4" + resolved "https://registry.yarnpkg.com/eslint-config-react-native-wcandillon/-/eslint-config-react-native-wcandillon-2.0.4.tgz#78736e4eb6b7dcc6372150fc68c5314c1b2f7df4" dependencies: "@typescript-eslint/eslint-plugin" "1.11.0" "@typescript-eslint/parser" "1.11.0" @@ -7725,6 +7725,10 @@ url-template@^2.0.8: version "2.0.8" resolved "https://registry.yarnpkg.com/url-template/-/url-template-2.0.8.tgz#fc565a3cccbff7730c775f5641f9555791439f21" +use-memo-one@^1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/use-memo-one/-/use-memo-one-1.1.1.tgz#39e6f08fe27e422a7d7b234b5f9056af313bd22c" + use@^3.1.0: version "3.1.1" resolved "https://registry.yarnpkg.com/use/-/use-3.1.1.tgz#d50c8cac79a19fbc20f2911f56eb973f4e10070f"