From 972f126ed06628fb061fb2dc173812556c6d12fe Mon Sep 17 00:00:00 2001 From: Tim Wang Date: Sat, 4 Nov 2017 21:40:01 +0800 Subject: [PATCH 1/4] Fix NetInfo module type --- types/react-native/index.d.ts | 90 +++++++++++++++++++++++------------ 1 file changed, 59 insertions(+), 31 deletions(-) diff --git a/types/react-native/index.d.ts b/types/react-native/index.d.ts index 7058f6169f..9e9c76b764 100644 --- a/types/react-native/index.d.ts +++ b/types/react-native/index.d.ts @@ -6712,22 +6712,6 @@ export interface DatePickerAndroidStatic { dismissedAction: string } -export interface FetchableListenable { - fetch: () => Promise - - /** - * eventName is expected to be `change` - * //FIXME: No doc - inferred from NetInfo.js - */ - addEventListener: (eventName: string, listener: (result: T) => void) => void - - /** - * eventName is expected to be `change` - * //FIXME: No doc - inferred from NetInfo.js - */ - removeEventListener: (eventName: string, listener: (result: T) => void) => void -} - export interface IntentAndroidStatic { /** * Starts a corresponding external activity for the given URL. @@ -6838,34 +6822,78 @@ export interface LinkingIOSStatic { /** * NetInfo exposes info about online/offline status - * - * Asynchronously determine if the device is online and on a cellular network. - * - * - `none` - device is offline - * - `wifi` - device is online and connected via wifi, or is the iOS simulator - * - `cell` - device is connected via Edge, 3G, WiMax, or LTE - * - `unknown` - error case and the network status is unknown * @see https://facebook.github.io/react-native/docs/netinfo.html#content */ -// This is from code, a few items more than documentation@0.25 -export type NetInfoReturnType = "none" | "wifi" | "cell" | "unknown" | +export type DeprecatedConnectionType = "none" | "wifi" | "cell" | "unknown" | "NONE" | "MOBILE" | "WIFI" | "MOBILE_MMS" | "MOBILE_SUPL" | "MOBILE_DUN" | "MOBILE_HIPRI" | "WIMAX" | "BLUETOOTH" | "DUMMY" | "ETHERNET" | "MOBILE_FOTA" | "MOBILE_IMS" | "MOBILE_CBS" | "WIFI_P2P" | "MOBILE_IA" | "MOBILE_EMERGENCY" | "PROXY" | "VPN" | "UNKNOWN" -export interface NetInfoStatic extends FetchableListenable { +export type EffectiveConnectionType = "2g" | "3g" | "4g" | "unknown" + +export interface ConnectionInfo { + type: DeprecatedConnectionType + effectiveType: EffectiveConnectionType +} + +export interface NetInfoStatic { /** - * - * Available on all platforms. - * Asynchronously fetch a boolean to determine internet connectivity. + * This function is deprecated. Use `getConnectionInfo` instead. Returns a promise that + * resolves with one of the deprecated connectivity types listed above. */ - isConnected: FetchableListenable + fetch: () => Promise /** - * Available on Android. Detect if the current active connection is + * Adds an event handler. Supported events: + * + * - `connectionChange`: Fires when the network status changes. The argument to the event + * handler is an object with keys: + * - `type`: A `DeprecatedConnectionType` (listed above) + * - `effectiveType`: An `EffectiveConnectionType` (listed above) + * - `change`: This event is deprecated. Listen to `connectionChange` instead. Fires when + * the network status changes. The argument to the event handler is one of the deprecated + * connectivity types listed above. + */ + addEventListener: (eventName: string, listener: (result: ConnectionInfo | DeprecatedConnectionType) => void) => void + + /** + * Removes the listener for network status changes. + */ + removeEventListener: (eventName: string, listener: (result: ConnectionInfo | DeprecatedConnectionType) => void) => void + + /** + * Returns a promise that resolves to an object with `type` and `effectiveType` keys + * whose values are a `ConnectionType` and an `EffectiveConnectionType`, (described above), + * respectively. + */ + getConnectionInfo: () => Promise + + /** + * An object with the same methods as above but the listener receives a + * boolean which represents the internet connectivity. + * Use this if you are only interested with whether the device has internet + * connectivity. + */ + isConnected: { + + fetch: () => Promise + + /** + * eventName is expected to be `change`(deprecated) or `connectionChange` + */ + addEventListener: (eventName: string, listener: (result: boolean) => void) => void + + /** + * eventName is expected to be `change`(deprecated) or `connectionChange` + */ + removeEventListener: (eventName: string, listener: (result: boolean) => void) => void + } + + /** + * Detect if the current active connection is * metered or not. A network is classified as metered when the user is * sensitive to heavy data usage on that connection due to monetary * costs, data limitations or battery/performance issues. From e6a22d9c00c7d1beabd95d6bb3c79e3db8e040eb Mon Sep 17 00:00:00 2001 From: Tim Wang Date: Sat, 4 Nov 2017 22:01:22 +0800 Subject: [PATCH 2/4] Fix linter issue --- types/react-native/index.d.ts | 99 ++++++++++++++++++----------------- 1 file changed, 51 insertions(+), 48 deletions(-) diff --git a/types/react-native/index.d.ts b/types/react-native/index.d.ts index 9e9c76b764..2c7f5be826 100644 --- a/types/react-native/index.d.ts +++ b/types/react-native/index.d.ts @@ -6879,13 +6879,13 @@ export interface NetInfoStatic { */ isConnected: { - fetch: () => Promise + fetch: () => Promise /** * eventName is expected to be `change`(deprecated) or `connectionChange` */ addEventListener: (eventName: string, listener: (result: boolean) => void) => void - + /** * eventName is expected to be `change`(deprecated) or `connectionChange` */ @@ -8113,52 +8113,55 @@ export interface ImagePickerIOSStatic { } export interface ImageStoreStatic { - /** - * Check if the ImageStore contains image data for the specified URI. - * @platform ios - */ - hasImageForTag(uri: string, callback: (hasImage: boolean) => void): void - /** - * Delete an image from the ImageStore. Images are stored in memory and - * must be manually removed when you are finished with them, otherwise they - * will continue to use up RAM until the app is terminated. It is safe to - * call `removeImageForTag()` without first calling `hasImageForTag()`, it - * will simply fail silently. - * @platform ios - */ - removeImageForTag(uri: string): void - /** - * Stores a base64-encoded image in the ImageStore, and returns a URI that - * can be used to access or display the image later. Images are stored in - * memory only, and must be manually deleted when you are finished with - * them by calling `removeImageForTag()`. - * - * Note that it is very inefficient to transfer large quantities of binary - * data between JS and native code, so you should avoid calling this more - * than necessary. - * @platform ios - */ - addImageFromBase64( - base64ImageData: string, - success: (uri: string) => void, - failure: (error: any) => void - ): void - /** - * Retrieves the base64-encoded data for an image in the ImageStore. If the - * specified URI does not match an image in the store, the failure callback - * will be called. - * - * Note that it is very inefficient to transfer large quantities of binary - * data between JS and native code, so you should avoid calling this more - * than necessary. To display an image in the ImageStore, you can just pass - * the URI to an `` component; there is no need to retrieve the - * base64 data. - */ - getBase64ForTag( - uri: string, - success: (base64ImageData: string) => void, - failure: (error: any) => void - ): void + /** + * Check if the ImageStore contains image data for the specified URI. + * @platform ios + */ + hasImageForTag(uri: string, callback: (hasImage: boolean) => void): void + + /** + * Delete an image from the ImageStore. Images are stored in memory and + * must be manually removed when you are finished with them, otherwise they + * will continue to use up RAM until the app is terminated. It is safe to + * call `removeImageForTag()` without first calling `hasImageForTag()`, it + * will simply fail silently. + * @platform ios + */ + removeImageForTag(uri: string): void + + /** + * Stores a base64-encoded image in the ImageStore, and returns a URI that + * can be used to access or display the image later. Images are stored in + * memory only, and must be manually deleted when you are finished with + * them by calling `removeImageForTag()`. + * + * Note that it is very inefficient to transfer large quantities of binary + * data between JS and native code, so you should avoid calling this more + * than necessary. + * @platform ios + */ + addImageFromBase64( + base64ImageData: string, + success: (uri: string) => void, + failure: (error: any) => void + ): void + + /** + * Retrieves the base64-encoded data for an image in the ImageStore. If the + * specified URI does not match an image in the store, the failure callback + * will be called. + * + * Note that it is very inefficient to transfer large quantities of binary + * data between JS and native code, so you should avoid calling this more + * than necessary. To display an image in the ImageStore, you can just pass + * the URI to an `` component; there is no need to retrieve the + * base64 data. + */ + getBase64ForTag( + uri: string, + success: (base64ImageData: string) => void, + failure: (error: any) => void + ): void } // From 0ff602e5b84a5c36440bb19194bab4559974281d Mon Sep 17 00:00:00 2001 From: Tim Wang Date: Sun, 5 Nov 2017 21:03:14 -0600 Subject: [PATCH 3/4] Remove deprecated warning from interface name. --- types/react-native/index.d.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/types/react-native/index.d.ts b/types/react-native/index.d.ts index 2c7f5be826..918145af77 100644 --- a/types/react-native/index.d.ts +++ b/types/react-native/index.d.ts @@ -6821,11 +6821,12 @@ export interface LinkingIOSStatic { /** + * @Deprecated * NetInfo exposes info about online/offline status * @see https://facebook.github.io/react-native/docs/netinfo.html#content */ -export type DeprecatedConnectionType = "none" | "wifi" | "cell" | "unknown" | +export type ConnectionType = "none" | "wifi" | "cell" | "unknown" | "NONE" | "MOBILE" | "WIFI" | "MOBILE_MMS" | "MOBILE_SUPL" | "MOBILE_DUN" | "MOBILE_HIPRI" | "WIMAX" | "BLUETOOTH" | "DUMMY" | "ETHERNET" | "MOBILE_FOTA" | "MOBILE_IMS" | "MOBILE_CBS" | "WIFI_P2P" | "MOBILE_IA" | "MOBILE_EMERGENCY" | @@ -6834,7 +6835,7 @@ export type DeprecatedConnectionType = "none" | "wifi" | "cell" | "unknown" | export type EffectiveConnectionType = "2g" | "3g" | "4g" | "unknown" export interface ConnectionInfo { - type: DeprecatedConnectionType + type: ConnectionType effectiveType: EffectiveConnectionType } @@ -6844,7 +6845,7 @@ export interface NetInfoStatic { * This function is deprecated. Use `getConnectionInfo` instead. Returns a promise that * resolves with one of the deprecated connectivity types listed above. */ - fetch: () => Promise + fetch: () => Promise /** * Adds an event handler. Supported events: @@ -6857,12 +6858,12 @@ export interface NetInfoStatic { * the network status changes. The argument to the event handler is one of the deprecated * connectivity types listed above. */ - addEventListener: (eventName: string, listener: (result: ConnectionInfo | DeprecatedConnectionType) => void) => void + addEventListener: (eventName: string, listener: (result: ConnectionInfo | ConnectionType) => void) => void /** * Removes the listener for network status changes. */ - removeEventListener: (eventName: string, listener: (result: ConnectionInfo | DeprecatedConnectionType) => void) => void + removeEventListener: (eventName: string, listener: (result: ConnectionInfo | ConnectionType) => void) => void /** * Returns a promise that resolves to an object with `type` and `effectiveType` keys From 0903b17fb075017cbe3b38e94df7e7e16c2f7132 Mon Sep 17 00:00:00 2001 From: Tim Wang Date: Sun, 5 Nov 2017 21:04:24 -0600 Subject: [PATCH 4/4] Fix docs comments --- types/react-native/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/react-native/index.d.ts b/types/react-native/index.d.ts index 918145af77..2b82a43ee1 100644 --- a/types/react-native/index.d.ts +++ b/types/react-native/index.d.ts @@ -6821,11 +6821,11 @@ export interface LinkingIOSStatic { /** - * @Deprecated * NetInfo exposes info about online/offline status * @see https://facebook.github.io/react-native/docs/netinfo.html#content */ +// @Deprecated ConnectionType export type ConnectionType = "none" | "wifi" | "cell" | "unknown" | "NONE" | "MOBILE" | "WIFI" | "MOBILE_MMS" | "MOBILE_SUPL" | "MOBILE_DUN" | "MOBILE_HIPRI" | "WIMAX" | "BLUETOOTH" | "DUMMY" | "ETHERNET" | "MOBILE_FOTA" |