From 783caf2239718b2a6076fc3a53565edac3893b1d Mon Sep 17 00:00:00 2001 From: Michael Randolph Date: Thu, 21 Sep 2017 00:19:43 -0400 Subject: [PATCH] Added react-native-safari-view types --- types/react-native-safari-view/index.d.ts | 79 +++++++++++++++++++ .../react-native-safari-view-tests.tsx | 22 ++++++ types/react-native-safari-view/tsconfig.json | 24 ++++++ 3 files changed, 125 insertions(+) create mode 100644 types/react-native-safari-view/index.d.ts create mode 100644 types/react-native-safari-view/react-native-safari-view-tests.tsx create mode 100644 types/react-native-safari-view/tsconfig.json diff --git a/types/react-native-safari-view/index.d.ts b/types/react-native-safari-view/index.d.ts new file mode 100644 index 0000000000..7e1a2d66c5 --- /dev/null +++ b/types/react-native-safari-view/index.d.ts @@ -0,0 +1,79 @@ +// Type definitions for react-native-safari-view 2.0.0 +// Project: https://github.com/naoufal/react-native-safari-view +// Definitions by: Michael Randolph +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import { EmitterSubscription } from 'react-native'; + +export interface ISafariViewOptions { + /** + * A String containing the url you want to load in the Safari View + * + * @type {string} + * @memberof ISafariViewOptions + */ + url: string; + + /** + * A Boolean indicating to use Safari's Reader Mode if available + * + * @type {boolean} + * @memberof ISafariViewOptions + */ + readerMode?: boolean; + + /** + * A String containing a hex or rgba color to use for the browser controls + * + * @type {string} + * @memberof ISafariViewOptions + */ + tintColor?: string; + + /** + * A String containing a hex or rgba color to use for the background of the browser controls (only available on iOS 10 and higher) + * + * @type {string} + * @memberof ISafariViewOptions + */ + barTintColor?: string; + + /** + * A Boolean indicating to open the Safari View from the bottom + * + * @type {boolean} + * @memberof ISafariViewOptions + */ + fromBottom?: boolean; +} + +export default class SafariView { + /** + * Displays a Safari View with the provided URL + * + * @param {ISafariViewOptions} options + */ + public static show(options: ISafariViewOptions): Promise; + + /** + * Dismisses the currently active Safari View + */ + public static dismiss(): void; + + /** + * Checks if Safari View is available on the device + */ + public static isAvailable(): Promise; + + /** + * @param {string} event + * @param {function} listener + */ + public static addEventListener(event: string, listener: () => void): EmitterSubscription; + + /** + * @param {string} event + * @param {function} listener + */ + public static removeEventListener(event: string, listener: () => void): void; +} diff --git a/types/react-native-safari-view/react-native-safari-view-tests.tsx b/types/react-native-safari-view/react-native-safari-view-tests.tsx new file mode 100644 index 0000000000..2886f7b809 --- /dev/null +++ b/types/react-native-safari-view/react-native-safari-view-tests.tsx @@ -0,0 +1,22 @@ +import { EmitterSubscription } from 'react-native'; +import SafariView from 'react-native-safari-view'; + +const didShow: Promise = SafariView.show({ + barTintColor: '#FFFFFF', + fromBottom: true, + readerMode: true, + tintColor: '#000000', + url: 'http://test.url' +}); + +const listener = (): void => { + +} + +const subscription: EmitterSubscription = SafariView.addEventListener('onShow', listener); + +SafariView.removeEventListener('onShow', listener); + +SafariView.dismiss(); + +const available: Promise = SafariView.isAvailable(); diff --git a/types/react-native-safari-view/tsconfig.json b/types/react-native-safari-view/tsconfig.json new file mode 100644 index 0000000000..42b152437a --- /dev/null +++ b/types/react-native-safari-view/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "jsx": "react" + }, + "files": [ + "index.d.ts", + "react-native-safari-view-tests.tsx" + ] +}