Skip to content

Flow type definitions are not being found #784

Closed
@JameelMukadam

Description

@JameelMukadam

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch react-native-fast-image@8.3.4 for the project I'm working on.

Seems like the Flow type definitions are not being found because the file which is being imported is called index.cjs.js and the definition file is called index.js.flow. If I copy the index.js.flow and rename it to index.cjs.js.flow then it works.

Here is the diff that solved my problem:

diff --git a/node_modules/react-native-fast-image/dist/index.cjs.js.flow b/node_modules/react-native-fast-image/dist/index.cjs.js.flow
new file mode 100644
index 0000000..71fac3a
--- /dev/null
+++ b/node_modules/react-native-fast-image/dist/index.cjs.js.flow
@@ -0,0 +1,71 @@
+// @flow
+
+import type { ViewProps } from 'react-native/Libraries/Components/View/ViewPropTypes'
+import type { SyntheticEvent } from 'react-native/Libraries/Types/CoreEventTypes'
+
+export type OnLoadEvent = SyntheticEvent<
+    $ReadOnly<{
+        width: number,
+        height: number,
+    }>,
+>
+
+export type OnProgressEvent = SyntheticEvent<
+    $ReadOnly<{|
+        loaded: number,
+        total: number,
+    |}>,
+>
+
+export type ResizeMode = $ReadOnly<{|
+    contain: 'contain',
+    cover: 'cover',
+    stretch: 'stretch',
+    center: 'center',
+|}>
+
+export type Priority = $ReadOnly<{|
+    low: 'low',
+    normal: 'normal',
+    high: 'high',
+|}>
+
+export type CacheControl = $ReadOnly<{|
+    immutable: 'immutable',
+    web: 'web',
+    cacheOnly: 'cacheOnly',
+|}>
+
+export type ResizeModes = $Values<ResizeMode>
+export type Priorities = $Values<Priority>
+export type CacheControls = $Values<CacheControl>
+
+export type PreloadFn = (sources: Array<FastImageSource>) => void
+export type FastImageSource = {
+    uri?: string,
+    headers?: Object,
+    priority?: Priorities,
+    cache?: CacheControls,
+}
+
+export type FastImageProps = $ReadOnly<{|
+    ...ViewProps,
+    onError?: ?() => void,
+    onLoad?: ?(event: OnLoadEvent) => void,
+    onLoadEnd?: ?() => void,
+    onLoadStart?: ?() => void,
+    onProgress?: ?(event: OnProgressEvent) => void,
+
+    source: FastImageSource | number,
+
+    resizeMode?: ?ResizeModes,
+    fallback?: ?boolean,
+    testID?: ?string,
+|}>
+
+declare export default class FastImage extends React$Component<FastImageProps> {
+    static resizeMode: ResizeMode;
+    static priority: Priority;
+    static cacheControl: CacheControl;
+    static preload: PreloadFn;
+}

This issue body was partially generated by patch-package.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions