From 8680e1d5b2d60633a3442416d77e7ae43950d123 Mon Sep 17 00:00:00 2001 From: bgrieder Date: Sun, 15 Nov 2015 07:44:36 +0100 Subject: [PATCH] Added AppState + ASyncStorage --- react-native/react-native.d.ts | 132 ++++++++++++++++++++++++++------- 1 file changed, 104 insertions(+), 28 deletions(-) diff --git a/react-native/react-native.d.ts b/react-native/react-native.d.ts index 9ff7771d5..de7576998 100644 --- a/react-native/react-native.d.ts +++ b/react-native/react-native.d.ts @@ -849,7 +849,7 @@ declare namespace ReactNative { */ injectedJavaScript?: string - onNavigationStateChange?: (event: NavState) => void + onNavigationStateChange?: ( event: NavState ) => void /** * Allows custom handling of any webview requests by a JS handler. @@ -885,7 +885,6 @@ declare namespace ReactNative { } - /** * @see */ @@ -2413,19 +2412,6 @@ declare namespace ReactNative { scale: number; } - // @see https://facebook.github.io/react-native/docs/asyncstorage.html#content - export interface AsyncStorageStatic { - getItem( key: string, callback?: ( error?: Error, result?: string ) => void ): Promise; - setItem( key: string, value: string, callback?: ( error?: Error ) => void ): Promise; - removeItem( key: string, callback?: ( error?: Error ) => void ): Promise; - mergeItem( key: string, value: string, callback?: ( error?: Error ) => void ): Promise; - clear( callback?: ( error?: Error ) => void ): Promise; - getAllKeys( callback?: ( error?: Error, keys?: string[] ) => void ): Promise; - multiGet( keys: string[], callback?: ( errors?: Error[], result?: string[][] ) => void ): Promise; - multiSet( keyValuePairs: string[][], callback?: ( errors?: Error[] ) => void ): Promise; - multiRemove( keys: string[], callback?: ( errors?: Error[] ) => void ): Promise; - multiMerge( keyValuePairs: string[][], callback?: ( errors?: Error[] ) => void ): Promise; - } export interface InteractionManagerStatic { runAfterInteractions( fn: () => void ): void; @@ -2752,8 +2738,8 @@ declare namespace ReactNative { * //FIXME: no documentation - inferred from RCTACtionSheetManager.m */ export interface ActionSheetIOSStatic { - showActionSheetWithOptions: (options: ActionSheetIOSOptions, callback: (buttonIndex: number) => void ) => void - showShareActionSheetWithOptions: (options: ShareActionSheetIOSOptions, failureCallback: (error: Error) => void, successCallback: (success: boolean, method: string) => void ) => void + showActionSheetWithOptions: ( options: ActionSheetIOSOptions, callback: ( buttonIndex: number ) => void ) => void + showShareActionSheetWithOptions: ( options: ShareActionSheetIOSOptions, failureCallback: ( error: Error ) => void, successCallback: ( success: boolean, method: string ) => void ) => void } @@ -2761,8 +2747,8 @@ declare namespace ReactNative { * //FIXME: No documentation - inferred from RCTAdSupport.m */ export interface AdSupportIOSStatic { - getAdvertisingId: (onSuccess: (deviceId: string) => void, onFailure: (err: Error) => void) => void - getAdvertisingTrackingEnabled: (onSuccess: (hasTracking: boolean) => void, onFailure: (err: Error) => void) => void + getAdvertisingId: ( onSuccess: ( deviceId: string ) => void, onFailure: ( err: Error ) => void ) => void + getAdvertisingTrackingEnabled: ( onSuccess: ( hasTracking: boolean ) => void, onFailure: ( err: Error ) => void ) => void } interface AlertIOSButton { @@ -2782,17 +2768,100 @@ declare namespace ReactNative { * @see https://facebook.github.io/react-native/docs/alertios.html#content */ export interface AlertIOSStatic { - alert: (title: string, message?: string, buttons?: Array, type?: string) => void - prompt: (title: string, value?: string, buttons?: Array, callback?: (value?: string) => void) => void + alert: ( title: string, message?: string, buttons?: Array, type?: string ) => void + prompt: ( title: string, value?: string, buttons?: Array, callback?: ( value?: string ) => void ) => void } + /** + * AppStateIOS can tell you if the app is in the foreground or background, + * and notify you when the state changes. + * + * AppStateIOS is frequently used to determine the intent and proper behavior + * when handling push notifications. + * + * iOS App States + * active - The app is running in the foreground + * background - The app is running in the background. The user is either in another app or on the home screen + * inactive - This is a transition state that currently never happens for typical React Native apps. + * + * For more information, see Apple's documentation: https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/TheAppLifeCycle/TheAppLifeCycle.html + * + * @see https://facebook.github.io/react-native/docs/appstateios.html#content + */ export interface AppStateIOSStatic { - currentState: string; - addEventListener( type: string, listener: ( state: string ) => void ): void; - removeEventListener( type: string, listener: ( state: string ) => void ): void; + currentState: string + addEventListener( type: string, listener: ( state: string ) => void ): void + removeEventListener( type: string, listener: ( state: string ) => void ): void } + /** + * AsyncStorage is a simple, asynchronous, persistent, key-value storage system that is global to the app. + * It should be used instead of LocalStorage. + * + * It is recommended that you use an abstraction on top of AsyncStorage + * instead of AsyncStorage directly for anything more than light usage since it operates globally. + * + * @see https://facebook.github.io/react-native/docs/asyncstorage.html#content + */ + export interface AsyncStorageStatic { + + /** + * Fetches key and passes the result to callback, along with an Error if there is any. + */ + getItem( key: string, callback?: ( error?: Error, result?: string ) => void ): Promise + + /** + * Sets value for key and calls callback on completion, along with an Error if there is any + */ + setItem( key: string, value: string, callback?: ( error?: Error ) => void ): Promise + + removeItem( key: string, callback?: ( error?: Error ) => void ): Promise + + /** + * Merges existing value with input value, assuming they are stringified json. Returns a Promise object. + * Not supported by all native implementation + */ + mergeItem( key: string, value: string, callback?: ( error?: Error ) => void ): Promise + + /** + * Erases all AsyncStorage for all clients, libraries, etc. You probably don't want to call this. + * Use removeItem or multiRemove to clear only your own keys instead. + */ + clear( callback?: ( error?: Error ) => void ): Promise + + /** + * Gets all keys known to the app, for all callers, libraries, etc + */ + getAllKeys( callback?: ( error?: Error, keys?: string[] ) => void ): Promise + + /** + * multiGet invokes callback with an array of key-value pair arrays that matches the input format of multiSet + */ + multiGet( keys: string[], callback?: ( errors?: Error[], result?: string[][] ) => void ): Promise + + /** + * multiSet and multiMerge take arrays of key-value array pairs that match the output of multiGet, + * + * multiSet([['k1', 'val1'], ['k2', 'val2']], cb); + */ + multiSet( keyValuePairs: string[][], callback?: ( errors?: Error[] ) => void ): Promise + + /** + * Delete all the keys in the keys array. + */ + multiRemove( keys: string[], callback?: ( errors?: Error[] ) => void ): Promise + + /** + * Merges existing values with input values, assuming they are stringified json. + * Returns a Promise object. + * + * Not supported by all native implementations. + */ + multiMerge( keyValuePairs: string[][], callback?: ( errors?: Error[] ) => void ): Promise + } + + ////////////////////////////////////////////////////////////////////////// // // R E - E X P O R T S @@ -2805,9 +2874,6 @@ declare namespace ReactNative { export var ActivityIndicatorIOS: ActivityIndicatorIOSStatic; export type ActivityIndicatorIOS = ActivityIndicatorIOSStatic; - export var AsyncStorage: AsyncStorageStatic; - export type AsyncStorage = AsyncStorageStatic; - export var CameraRoll: CameraRollStatic; export type CameraRoll = CameraRollStatic; @@ -2885,6 +2951,10 @@ declare namespace ReactNative { export var AlertIOS: AlertIOSStatic export type AlertIOS = AlertIOSStatic + export var AsyncStorage: AsyncStorageStatic + export type AsyncStorage = AsyncStorageStatic + + export var SegmentedControlIOS: React.ComponentClass; export var PixelRatio: PixelRatioStatic; @@ -2896,7 +2966,13 @@ declare namespace ReactNative { export var AppStateIOS: AppStateIOSStatic; - //react re-exported + ////////////////////////////////////////////////////////////////////////// + // + // R E A C T - 0 . 1 4 + // + ////////////////////////////////////////////////////////////////////////// + + export type ReactType = React.ReactType; export interface ReactElement

extends React.ReactElement

{}