Skip to content

Commit

Permalink
Animated: Update Abstract Component Flow Type
Browse files Browse the repository at this point in the history
Summary:
Updates the return type of `createAnimatedComponent` to reflect the new behavior (where we forward the ref to the internal component).

I also improved the type annotation for `Props` so that we can still enforce that only valid prop names are supplied. (We still do not check the prop values because we do not currently have a good strategy for typing the "animated versions" of those.)

Changelog:
[General] [Changed] - Flow types for Animated components now validates prop names and yields the new component instance.

Reviewed By: TheSavior

Differential Revision: D18290473

fbshipit-source-id: 8c629ab6aff009ebe6dabca1683c99a357869977
  • Loading branch information
yungsters authored and facebook-github-bot committed Nov 4, 2019
1 parent 66e72bb commit e22946c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
15 changes: 6 additions & 9 deletions Libraries/Animated/src/createAnimatedComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@ const React = require('react');
const invariant = require('invariant');
const setAndForwardRef = require('../../Utilities/setAndForwardRef');

export type AnimatedComponentType<Props, Instance> = React.AbstractComponent<
any,
$ReadOnly<{
setNativeProps: Object => void,
getNode: () => React.ElementRef<React.AbstractComponent<Props, Instance>>,
}>,
>;

function createAnimatedComponent<Props, Instance>(
export type AnimatedComponentType<
Props: {+[string]: mixed},
Instance,
> = React.AbstractComponent<$ObjMap<Props, () => any>, Instance>;

function createAnimatedComponent<Props: {+[string]: mixed}, Instance>(
Component: React.AbstractComponent<Props, Instance>,
): AnimatedComponentType<Props, Instance> {
invariant(
Expand Down
2 changes: 1 addition & 1 deletion RNTester/js/examples/FlatList/FlatListExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ class FlatListExample extends React.PureComponent<Props, State> {
this._listRef.getNode().recordInteraction();
pressItem(this, key);
};
_listRef: Animated.FlatList;
_listRef: React.ElementRef<typeof Animated.FlatList>;
}

const styles = StyleSheet.create({
Expand Down
2 changes: 1 addition & 1 deletion RNTester/js/examples/SectionList/SectionListExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class SectionListExample extends React.PureComponent<{}, $FlowFixMeState> {
{useNativeDriver: true},
);

_sectionListRef: Animated.SectionList;
_sectionListRef: React.ElementRef<typeof Animated.SectionList>;
_captureRef = ref => {
this._sectionListRef = ref;
};
Expand Down

0 comments on commit e22946c

Please sign in to comment.