Skip to content

Commit 07eebd7

Browse files
chrisbobbegnprice
authored andcommitted
dep types: Use TsFlower for react-native-image-picker
1 parent 7688692 commit 07eebd7

File tree

6 files changed

+147
-64
lines changed

6 files changed

+147
-64
lines changed

flow-typed/react-native-image-picker_vx.x.x.js

-64
This file was deleted.

tools/tsflower

+4
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ run_only()
151151
run_on_package "${package}"
152152
format_dir "${rootdir}"/types/"${package}"
153153

154+
package=react-native-image-picker
155+
run_on_package "${package}"
156+
format_dir "${rootdir}"/types/"${package}"
157+
154158
package=expo-modules-core
155159
run_on_package "${package}"
156160
format_dir "${rootdir}"/types/"${package}"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Chris Bobbe <[email protected]>
3+
Date: Thu, 15 Dec 2022 16:03:05 -0800
4+
Subject: [upstream] image-picker: Use an interface for the argument of
5+
`extends`
6+
7+
The Flow error this fixes is a bit odd:
8+
9+
Cannot resolve name $Diff. [cannot-resolve-name]
10+
11+
But as Greg points out at
12+
https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/Flow.3A.20.22Cannot.20resolve.20name.20.60.24Diff.60.2E.20.5Bcannot-resolve-name.5D.22/near/1480926 :
13+
14+
> Confusing message. But I think the intent is that there's a
15+
> syntactic restriction there which is a reasonable one: the
16+
> argument of `extends` isn't an arbitrary type-expression, but
17+
> rather
18+
> * a name referring to an interface; or
19+
> * a name referring to a generic interface, followed by type
20+
> arguments.
21+
22+
So, factor out a common interface that both `CameraOptions` and
23+
`ImageLibraryOptions`. I've sent this upstream as a change to the
24+
TypeScript:
25+
https://github.com/react-native-image-picker/react-native-image-picker/pull/2062
26+
so we can remove this patch once that lands and we update.
27+
---
28+
.../lib/typescript/types.js.flow | 9 ++++++---
29+
1 file changed, 6 insertions(+), 3 deletions(-)
30+
31+
diff --git types/react-native-image-picker/lib/typescript/types.js.flow types/react-native-image-picker/lib/typescript/types.js.flow
32+
index fec604315..5104ae5ab 100644
33+
--- types/react-native-image-picker/lib/typescript/types.js.flow
34+
+++ types/react-native-image-picker/lib/typescript/types.js.flow
35+
@@ -3,8 +3,7 @@
36+
*/
37+
export type Callback = (response: ImagePickerResponse) => any;
38+
39+
-export interface ImageLibraryOptions {
40+
- selectionLimit?: number;
41+
+interface OptionsCommon {
42+
mediaType: MediaType;
43+
maxWidth?: number;
44+
maxHeight?: number;
45+
@@ -22,7 +21,11 @@ export interface ImageLibraryOptions {
46+
| 'overCurrentContext';
47+
}
48+
49+
-export interface CameraOptions extends $Diff<ImageLibraryOptions, {| selectionLimit: mixed |}> {
50+
+export interface ImageLibraryOptions extends OptionsCommon {
51+
+ selectionLimit?: number;
52+
+}
53+
+
54+
+export interface CameraOptions extends OptionsCommon {
55+
durationLimit?: number;
56+
saveToPhotos?: boolean;
57+
cameraType?: CameraType;
58+
--
59+
2.32.0
60+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/* @flow
2+
* @generated
3+
*/
4+
export * from './lib/typescript/index.js.flow';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* @flow
2+
* @generated by TsFlower
3+
*/
4+
import {
5+
type CameraOptions,
6+
type ImageLibraryOptions,
7+
type Callback,
8+
type ImagePickerResponse,
9+
} from './types';
10+
11+
export * from './types';
12+
declare export function launchCamera(
13+
options: CameraOptions,
14+
callback?: Callback,
15+
): Promise<ImagePickerResponse>;
16+
declare export function launchImageLibrary(
17+
options: ImageLibraryOptions,
18+
callback?: Callback,
19+
): Promise<ImagePickerResponse>;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/* @flow
2+
* @generated by TsFlower
3+
*/
4+
export type Callback = (response: ImagePickerResponse) => any;
5+
6+
interface OptionsCommon {
7+
mediaType: MediaType;
8+
maxWidth?: number;
9+
maxHeight?: number;
10+
quality?: PhotoQuality;
11+
videoQuality?: AndroidVideoOptions | iOSVideoOptions;
12+
includeBase64?: boolean;
13+
includeExtra?: boolean;
14+
presentationStyle?:
15+
| 'currentContext'
16+
| 'fullScreen'
17+
| 'pageSheet'
18+
| 'formSheet'
19+
| 'popover'
20+
| 'overFullScreen'
21+
| 'overCurrentContext';
22+
}
23+
24+
export interface ImageLibraryOptions extends OptionsCommon {
25+
selectionLimit?: number;
26+
}
27+
28+
export interface CameraOptions extends OptionsCommon {
29+
durationLimit?: number;
30+
saveToPhotos?: boolean;
31+
cameraType?: CameraType;
32+
}
33+
34+
export interface Asset {
35+
base64?: string;
36+
uri?: string;
37+
width?: number;
38+
height?: number;
39+
fileSize?: number;
40+
type?: string;
41+
fileName?: string;
42+
duration?: number;
43+
bitrate?: number;
44+
timestamp?: string;
45+
id?: string;
46+
}
47+
48+
export interface ImagePickerResponse {
49+
didCancel?: boolean;
50+
errorCode?: ErrorCode;
51+
errorMessage?: string;
52+
assets?: Asset[];
53+
}
54+
55+
export type PhotoQuality = 0 | 0.1 | 0.2 | 0.3 | 0.4 | 0.5 | 0.6 | 0.7 | 0.8 | 0.9 | 1;
56+
export type CameraType = 'back' | 'front';
57+
export type MediaType = 'photo' | 'video' | 'mixed';
58+
export type AndroidVideoOptions = 'low' | 'high';
59+
export type iOSVideoOptions = 'low' | 'medium' | 'high';
60+
export type ErrorCode = 'camera_unavailable' | 'permission' | 'others';

0 commit comments

Comments
 (0)