diff --git a/types/react-native/globals.d.ts b/types/react-native/globals.d.ts new file mode 100644 index 0000000000..8ab096406f --- /dev/null +++ b/types/react-native/globals.d.ts @@ -0,0 +1,17 @@ +/* + * This file is necessary to declare global functions that might also be included by `--lib dom`. + * Due to a TypeScript bug, these cannot be placed inside a `declare global` block in index.d.ts. + */ + +// +// Timer Functions +// +declare function clearInterval(handle: number): void; +declare function clearTimeout(handle: number): void; +declare function setInterval(handler: (...args: any[]) => void, timeout: number): number; +declare function setTimeout(handler: (...args: any[]) => void, timeout: number): number; +declare function clearImmediate(handle: number): void; +declare function setImmediate(handler: (...args: any[]) => void): number; + +declare function cancelAnimationFrame(handle: number): void; +declare function requestAnimationFrame(callback: (time: number) => void): number; diff --git a/types/react-native/index.d.ts b/types/react-native/index.d.ts index d7648997f5..f07b6df158 100644 --- a/types/react-native/index.d.ts +++ b/types/react-native/index.d.ts @@ -11,7 +11,7 @@ /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // -// USING: these definitions are meant to be used with the TSC compiler target set to ES6 +// USING: these definitions are meant to be used with the TSC compiler target set to at least ES2015. // // USAGE EXAMPLES: check the RNTSExplorer project at https://github.com/bgrieder/RNTSExplorer // @@ -23,6 +23,8 @@ /// +/// + export type MeasureOnSuccessCallback = ( x: number, y: number, @@ -642,15 +644,23 @@ type GeolocationReturnType = { coords: { latitude: number longitude: number - altitude?: number - accuracy?: number - altitudeAccuracy?: number - heading?: number - speed?: number + altitude: number | null + accuracy: number + altitudeAccuracy: number | null + heading: number | null + speed: number | null } timestamp: number } +type GeolocationError = { + code: number; + message: string; + PERMISSION_DENIED: number; + POSITION_UNAVAILABLE: number; + TIMEOUT: number; +} + interface PerpectiveTransform { perspective: number; } @@ -8373,23 +8383,25 @@ export interface I18nManagerStatic { } export interface GeolocationStatic { - /* - * Invokes the success callback once with the latest location info. Supported - * options: timeout (ms), maximumAge (ms), enableHighAccuracy (bool) - * On Android, this can return almost immediately if the location is cached or - * request an update, which might take a while. - */ - getCurrentPosition(geo_success: (position: GeolocationReturnType) => void, geo_error?: (error: Error) => void, geo_options?: GetCurrentPositionOptions): void + /** + * Invokes the success callback once with the latest location info. Supported + * options: timeout (ms), maximumAge (ms), enableHighAccuracy (bool) + * On Android, this can return almost immediately if the location is cached or + * request an update, which might take a while. + */ + getCurrentPosition(geo_success: (position: GeolocationReturnType) => void, geo_error?: (error: GeolocationError) => void, geo_options?: GetCurrentPositionOptions): void - /* - * Invokes the success callback whenever the location changes. Supported - * options: timeout (ms), maximumAge (ms), enableHighAccuracy (bool), distanceFilter(m) - */ - watchPosition(success: (position: Geolocation) => void, error?: (error: Error) => void, options?: WatchPositionOptions): void + /** + * Invokes the success callback whenever the location changes. Supported + * options: timeout (ms), maximumAge (ms), enableHighAccuracy (bool), distanceFilter(m) + */ + watchPosition(success: (position: GeolocationReturnType) => void, error?: (error: GeolocationError) => void, options?: WatchPositionOptions): number clearWatch(watchID: number): void stopObserving(): void + + requestAuthorization(): void; } export interface OpenCameraDialogOptions { @@ -9230,6 +9242,33 @@ export var PointPropType: React.Requireable declare global { function require(name: string): any; + /** + * Console polyfill + * @see https://facebook.github.io/react-native/docs/javascript-environment.html#polyfills + */ + interface Console { + error(message?: any, ...optionalParams: any[]): void + info(message?: any, ...optionalParams: any[]): void + log(message?: any, ...optionalParams: any[]): void + warn(message?: any, ...optionalParams: any[]): void + trace(message?: any, ...optionalParams: any[]): void + debug(message?: any, ...optionalParams: any[]): void + table(...data: any[]): void; + } + + var console: Console + + /** + * Navigator object for accessing location API + * @see https://facebook.github.io/react-native/docs/javascript-environment.html#polyfills + */ + interface Navigator { + readonly product: string; + readonly geolocation: Geolocation; + } + + var navigator: Navigator; + /** * This contains the non-native `XMLHttpRequest` object, which you can use if you want to route network requests * through DevTools (to trace them):