Skip to content

Commit 9cc8ffd

Browse files
committed
Add TypeScript typings
1 parent b2d00d8 commit 9cc8ffd

File tree

2 files changed

+222
-0
lines changed

2 files changed

+222
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "cordova-plugin-safariviewcontroller",
33
"version": "1.6.0",
44
"description": "Forget InAppBrowser for iOS - this is way better for displaying read-only web content in your PhoneGap app.",
5+
"types": "./types/index.d.ts",
56
"cordova": {
67
"id": "cordova-plugin-safariviewcontroller",
78
"platforms": [

types/index.d.ts

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
/**
2+
* Options that may be passed to `SafariViewController.show()`.
3+
*/
4+
interface SafariViewControllerShowOptions {
5+
/**
6+
* The url to open in `SafariViewController`/custom tab view.
7+
*/
8+
url: string;
9+
10+
/**
11+
* Loads the `url` without showing the `SafariViewController`/custom tab view in foreground.
12+
* You can use this to load cookies etc in the background
13+
* (see https://github.com/EddyVerbruggen/cordova-plugin-safariviewcontroller/issues/1 for details).
14+
*
15+
* @default false
16+
*/
17+
hidden?: boolean;
18+
19+
/**
20+
* Whether opening/hiding the `SafariViewController`/custom tab should use a transition animation.
21+
* Note that `hide()` will reuse this preference (the 'Done' button will always animate though).
22+
*
23+
* @default true
24+
*/
25+
animated?: boolean;
26+
27+
/**
28+
* Unless animated is `false` you can choose a transition animation. This only works in iOS 9.1/9.2 and lower and on Android.
29+
* Only `'slide'` option is available on Android.
30+
*
31+
* @default 'slide'
32+
*/
33+
transition?: "curl" | "flip" | "fade" | "slide";
34+
35+
/**
36+
* Whether reader mode should be used for `SafariViewController`.
37+
*
38+
* @default false
39+
*/
40+
enterReaderModeIfAvailable?: boolean;
41+
42+
/**
43+
* The tint color to use.
44+
*
45+
* @default ios blue
46+
* @example '#ffffff'
47+
*/
48+
tintColor?: string;
49+
50+
/**
51+
* The color to tint the background of the navigation bar and the toolbar (iOS 10+ only).
52+
* See https://developer.apple.com/documentation/safariservices/sfsafariviewcontroller/2274394-preferredbartintcolor
53+
* for more details.
54+
*
55+
* @example '#0000ff'
56+
*/
57+
barColor?: string;
58+
59+
/**
60+
* The color to tint the control buttons on the navigation bar and the toolbar (iOS 10+ only).
61+
* See https://developer.apple.com/documentation/safariservices/sfsafariviewcontroller/2274393-preferredcontroltintcolor
62+
* for more details.
63+
*
64+
* @example '#ffffff'
65+
*/
66+
controlTintColor?: string;
67+
68+
/**
69+
* Sets the toolbar color (Android only). On Android L and above, this color is also applied to the status bar.
70+
*
71+
* @example '#ffffff'
72+
*/
73+
toolbarColor?: string;
74+
75+
/**
76+
* If set to `true`, will add a menu entry to share the current URL (Android only).
77+
*
78+
* @default false
79+
*/
80+
showDefaultShareMenuItem?: boolean;
81+
}
82+
83+
/**
84+
* The result of a `SafariViewController.show()` call.
85+
*/
86+
interface SafariViewControllerShowResult {
87+
/**
88+
* The event that describes what happened in the `SafariViewController`/custom tab view.
89+
* Only `'loaded'` and `'closed'` events will be dispatched on Android.
90+
*/
91+
event: "opened" | "loaded" | "closed";
92+
}
93+
94+
/**
95+
* The result of `SafariViewController.getViewHandlerPackages()` call.
96+
*/
97+
interface SafariViewControllerHandlerPackagesResult {
98+
/**
99+
* The default custom tab handler implementation (if available).
100+
*/
101+
defaultHandler: string | null;
102+
103+
/**
104+
* Contains the list of all available custom tab handler implementations.
105+
*/
106+
customTabsImplementations: string[];
107+
}
108+
109+
interface SafariViewController {
110+
/**
111+
* Check whether an implementation of `SafariViewController` on iOS/custom tab implementation
112+
* selected by `useCustomTabsImplementation()` on Android is actually available to be used.
113+
*
114+
* @param callback The callback function to pass the result of the check.
115+
*/
116+
isAvailable(callback: (isAvailable: boolean) => void): void;
117+
118+
/**
119+
* Show the `SafariViewController` on iOS/custom tab on Android.
120+
*
121+
* @param options The options for the `SafariViewController`/custom tab.
122+
* @param onSuccess The callback function to call with the different view events.
123+
* @param onError The callback function to call in case of an error.
124+
*/
125+
show(
126+
options: SafariViewControllerShowOptions,
127+
onSuccess?: (result: SafariViewControllerShowResult) => void,
128+
onError?: (error: unknown) => void
129+
): void;
130+
131+
/**
132+
* Hide a previously opened `SafariViewController`.
133+
*
134+
* **This method is iOS-specific. It will always error out on other platforms.**
135+
*
136+
* @param onSuccess The callback function to call when `SafariViewController` could be hidden successfully.
137+
* @param onError The callback function to call in case of an error or if method is unsupported on current platform.
138+
*/
139+
hide(onSuccess?: () => void, onError?: (error: unknown) => void): void;
140+
141+
/**
142+
* Get the list of available custom tab implementations. You can use the
143+
* values retrieved from this method in `useCustomTabsImplementation()`.
144+
*
145+
* **This method Android-specific. It will always error out on other platforms.**
146+
*
147+
* @param onSuccess The callback function to call after successfully retrieving the handler packages result.
148+
* @param onError The callback function to call in case of an error or if method is unsupported on current platform.
149+
*/
150+
getViewHandlerPackages(
151+
onSuccess: (
152+
handlerPackages: SafariViewControllerHandlerPackagesResult
153+
) => void,
154+
onError?: (error: unknown) => void
155+
): void;
156+
157+
/**
158+
* Set the custom tab implementation to use.
159+
*
160+
* **This method Android-specific. It will always error out on other platforms.**
161+
*
162+
* @param packageName The custom tab implementation to use previously retrieved via `getViewHandlerPackages()`.
163+
* @param onSuccess The callback function to call after successfully setting the custom tab implementation.
164+
* @param onError The callback function to call in case of an error or if method is unsupported on current platform.
165+
*/
166+
useCustomTabsImplementation(
167+
packageName: string,
168+
onSuccess?: (result: true) => void,
169+
onError?: (error: unknown) => void
170+
): void;
171+
172+
/**
173+
* Try to connect to the Chrome's custom tabs service. You must call this method before calling
174+
* `warmUp()` or `mayLaunchUrl()` methods.
175+
*
176+
* **This method Android-specific. It will always error out on other platforms.**
177+
*
178+
* @param onSuccess The callback function to call after successfully connecting to the custom tabs service.
179+
* @param onError The callback function to call in case of an error or if method is unsupported on current platform.
180+
*/
181+
connectToService(
182+
onSuccess?: (result: true) => void,
183+
onError?: (error: unknown) => void
184+
): void;
185+
186+
/**
187+
* Warm up the browser process. Call this method whenever there's a chance the user will open an external url. See
188+
* [Custom Tabs implementation guide](https://developers.google.com/web/android/custom-tabs/implementation-guide#warm_up_the_browser_process)
189+
* for more details.
190+
*
191+
* **This method Android-specific. It will always error out on other platforms.**
192+
*
193+
* @param onSuccess The callback function to call after successfully warming up the browser process.
194+
* @param onError The callback function to call in case of an error or if method is unsupported on current platform.
195+
*/
196+
warmUp(
197+
onSuccess?: (result: true) => void,
198+
onError?: (error: unknown) => void
199+
): void;
200+
201+
/**
202+
* Prepare the selected custom tab implementation to navigate to passed URL. For even better performance optimization,
203+
* call this methods if there's more than a 50% chance the user will open a certain URL. See
204+
* [CustomTabsSession docs](https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsSession#mayLaunchUrl(android.net.Uri,%20android.os.Bundle,%20java.util.List%3Candroid.os.Bundle%3E))
205+
* for more details.
206+
*
207+
* **This method Android-specific. It will always error out on other platforms.**
208+
*
209+
* @param url The URL that should be loaded next by the custom tab.
210+
* @param onSuccess The callback function to call after custom tab has accepted the URL to launch.
211+
* @param onError The callback function to call in case custom tab hasn't accepted the URL to launch,
212+
* if an error has occurred, or if method is unsupported on current platform.
213+
*/
214+
mayLaunchUrl(
215+
url: string,
216+
onSuccess?: (result: true) => void,
217+
onError?: (error: unknown) => void
218+
): void;
219+
}
220+
221+
declare var SafariViewController: SafariViewController;

0 commit comments

Comments
 (0)