Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flow types for react-native's Animated library

I am trying to use react-native's Animated library alongside Flow. Unfortunately, I get a bunch of Flow errors that I cannot resolve (see Screenshot).

In the example below I render a circle on the screen and want to make it move when it is being rendered using Animated.spring. Is there anything else I need to add to make react-native work with Flow?

Flow version: 0.54.0 / react-native version: 0.48.0

Currently, I am just ignoring Animated in .flowconfig :(

; Ignore Animated
.*/react-native/Libraries/Animated/**/.*

enter image description here

like image 715
soosap Avatar asked Sep 04 '17 15:09

soosap


People also ask

What is flow in react?

Flow. Flow is a static type checker for your JavaScript code. It is developed at Facebook and is often used with React. It lets you annotate the variables, functions, and React components with a special type syntax, and catch mistakes early. You can read an introduction to Flow to learn its basics.


1 Answers

I believe your specific problem is fixed in a more recent version of react-native. What might be useful to know is that you can annotate position with AnimatedValueXY importing one of the two

import type AnimatedValueXY from 'react-native/Libraries/Animated/src/nodes/AnimatedValueXY';
import type AnimatedValue from 'react-native/Libraries/Animated/src/nodes/AnimatedValue';

It's kinda ugly but I didn't find a better alternative

like image 151
Fabio Crisci Avatar answered Oct 03 '22 14:10

Fabio Crisci