@capgo/inappbrowser 7.6.4 → 7.6.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -19
- package/android/src/main/AndroidManifest.xml +12 -1
- package/android/src/main/java/ee/forgr/capacitor_inappbrowser/InAppBrowserPlugin.java +113 -78
- package/android/src/main/java/ee/forgr/capacitor_inappbrowser/WebViewDialog.java +527 -38
- package/android/src/main/res/xml/file_paths.xml +14 -0
- package/dist/docs.json +32 -60
- package/dist/esm/definitions.d.ts +1 -11
- package/dist/esm/definitions.js.map +1 -1
- package/ios/Plugin/InAppBrowserPlugin.swift +38 -22
- package/ios/Plugin/WKWebViewController.swift +4 -107
- package/package.json +1 -1
package/dist/docs.json
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"text": "0.1.0"
|
|
23
23
|
}
|
|
24
24
|
],
|
|
25
|
-
"docs": "Open url in a new window fullscreen",
|
|
25
|
+
"docs": "Open url in a new window fullscreen, on android it use chrome custom tabs, on ios it use SFSafariViewController",
|
|
26
26
|
"complexTypes": [
|
|
27
27
|
"OpenOptions"
|
|
28
28
|
],
|
|
@@ -426,34 +426,6 @@
|
|
|
426
426
|
"complexTypes": [],
|
|
427
427
|
"type": "string"
|
|
428
428
|
},
|
|
429
|
-
{
|
|
430
|
-
"name": "headers",
|
|
431
|
-
"tags": [
|
|
432
|
-
{
|
|
433
|
-
"text": "0.1.0",
|
|
434
|
-
"name": "since"
|
|
435
|
-
}
|
|
436
|
-
],
|
|
437
|
-
"docs": "Headers to send with the request.",
|
|
438
|
-
"complexTypes": [
|
|
439
|
-
"Headers"
|
|
440
|
-
],
|
|
441
|
-
"type": "Headers"
|
|
442
|
-
},
|
|
443
|
-
{
|
|
444
|
-
"name": "credentials",
|
|
445
|
-
"tags": [
|
|
446
|
-
{
|
|
447
|
-
"text": "6.1.0",
|
|
448
|
-
"name": "since"
|
|
449
|
-
}
|
|
450
|
-
],
|
|
451
|
-
"docs": "Credentials to send with the request and all subsequent requests for the same host.",
|
|
452
|
-
"complexTypes": [
|
|
453
|
-
"Credentials"
|
|
454
|
-
],
|
|
455
|
-
"type": "Credentials"
|
|
456
|
-
},
|
|
457
429
|
{
|
|
458
430
|
"name": "isPresentAfterPageLoad",
|
|
459
431
|
"tags": [
|
|
@@ -480,37 +452,6 @@
|
|
|
480
452
|
}
|
|
481
453
|
]
|
|
482
454
|
},
|
|
483
|
-
{
|
|
484
|
-
"name": "Headers",
|
|
485
|
-
"slug": "headers",
|
|
486
|
-
"docs": "",
|
|
487
|
-
"tags": [],
|
|
488
|
-
"methods": [],
|
|
489
|
-
"properties": []
|
|
490
|
-
},
|
|
491
|
-
{
|
|
492
|
-
"name": "Credentials",
|
|
493
|
-
"slug": "credentials",
|
|
494
|
-
"docs": "",
|
|
495
|
-
"tags": [],
|
|
496
|
-
"methods": [],
|
|
497
|
-
"properties": [
|
|
498
|
-
{
|
|
499
|
-
"name": "username",
|
|
500
|
-
"tags": [],
|
|
501
|
-
"docs": "",
|
|
502
|
-
"complexTypes": [],
|
|
503
|
-
"type": "string"
|
|
504
|
-
},
|
|
505
|
-
{
|
|
506
|
-
"name": "password",
|
|
507
|
-
"tags": [],
|
|
508
|
-
"docs": "",
|
|
509
|
-
"complexTypes": [],
|
|
510
|
-
"type": "string"
|
|
511
|
-
}
|
|
512
|
-
]
|
|
513
|
-
},
|
|
514
455
|
{
|
|
515
456
|
"name": "ClearCookieOptions",
|
|
516
457
|
"slug": "clearcookieoptions",
|
|
@@ -1107,6 +1048,37 @@
|
|
|
1107
1048
|
}
|
|
1108
1049
|
]
|
|
1109
1050
|
},
|
|
1051
|
+
{
|
|
1052
|
+
"name": "Headers",
|
|
1053
|
+
"slug": "headers",
|
|
1054
|
+
"docs": "",
|
|
1055
|
+
"tags": [],
|
|
1056
|
+
"methods": [],
|
|
1057
|
+
"properties": []
|
|
1058
|
+
},
|
|
1059
|
+
{
|
|
1060
|
+
"name": "Credentials",
|
|
1061
|
+
"slug": "credentials",
|
|
1062
|
+
"docs": "",
|
|
1063
|
+
"tags": [],
|
|
1064
|
+
"methods": [],
|
|
1065
|
+
"properties": [
|
|
1066
|
+
{
|
|
1067
|
+
"name": "username",
|
|
1068
|
+
"tags": [],
|
|
1069
|
+
"docs": "",
|
|
1070
|
+
"complexTypes": [],
|
|
1071
|
+
"type": "string"
|
|
1072
|
+
},
|
|
1073
|
+
{
|
|
1074
|
+
"name": "password",
|
|
1075
|
+
"tags": [],
|
|
1076
|
+
"docs": "",
|
|
1077
|
+
"complexTypes": [],
|
|
1078
|
+
"type": "string"
|
|
1079
|
+
}
|
|
1080
|
+
]
|
|
1081
|
+
},
|
|
1110
1082
|
{
|
|
1111
1083
|
"name": "DisclaimerOptions",
|
|
1112
1084
|
"slug": "disclaimeroptions",
|
|
@@ -59,16 +59,6 @@ export interface OpenOptions {
|
|
|
59
59
|
* @since 0.1.0
|
|
60
60
|
*/
|
|
61
61
|
url: string;
|
|
62
|
-
/**
|
|
63
|
-
* Headers to send with the request.
|
|
64
|
-
* @since 0.1.0
|
|
65
|
-
*/
|
|
66
|
-
headers?: Headers;
|
|
67
|
-
/**
|
|
68
|
-
* Credentials to send with the request and all subsequent requests for the same host.
|
|
69
|
-
* @since 6.1.0
|
|
70
|
-
*/
|
|
71
|
-
credentials?: Credentials;
|
|
72
62
|
/**
|
|
73
63
|
* if true, the browser will be presented after the page is loaded, if false, the browser will be presented immediately.
|
|
74
64
|
* @since 0.1.0
|
|
@@ -407,7 +397,7 @@ export interface OpenWebViewOptions {
|
|
|
407
397
|
}
|
|
408
398
|
export interface InAppBrowserPlugin {
|
|
409
399
|
/**
|
|
410
|
-
* Open url in a new window fullscreen
|
|
400
|
+
* Open url in a new window fullscreen, on android it use chrome custom tabs, on ios it use SFSafariViewController
|
|
411
401
|
*
|
|
412
402
|
* @since 0.1.0
|
|
413
403
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAuBA,MAAM,CAAN,IAAY,eAGX;AAHD,WAAY,eAAe;IACzB,kCAAe,CAAA;IACf,kCAAe,CAAA;AACjB,CAAC,EAHW,eAAe,KAAf,eAAe,QAG1B;AACD,MAAM,CAAN,IAAY,WAgBX;AAhBD,WAAY,WAAW;IACrB;;;OAGG;IACH,oCAAqB,CAAA;IACrB;;;OAGG;IACH,wCAAyB,CAAA;IACzB;;;OAGG;IACH,8BAAe,CAAA;AACjB,CAAC,EAhBW,WAAW,KAAX,WAAW,QAgBtB","sourcesContent":["import type { PluginListenerHandle } from \"@capacitor/core\";\n\nexport interface UrlEvent {\n /**\n * Emit when the url changes\n *\n * @since 0.0.1\n */\n url: string;\n}\nexport interface BtnEvent {\n /**\n * Emit when a button is clicked.\n *\n * @since 0.0.1\n */\n url: string;\n}\n\nexport type UrlChangeListener = (state: UrlEvent) => void;\nexport type ConfirmBtnListener = (state: BtnEvent) => void;\nexport type ButtonNearListener = (state: object) => void;\n\nexport enum BackgroundColor {\n WHITE = \"white\",\n BLACK = \"black\",\n}\nexport enum ToolBarType {\n /**\n * Shows a simple toolbar with just a close button and share button\n * @since 0.1.0\n */\n ACTIVITY = \"activity\",\n /**\n * Shows a full navigation toolbar with back/forward buttons\n * @since 0.1.0\n */\n NAVIGATION = \"navigation\",\n /**\n * Shows no toolbar\n * @since 0.1.0\n */\n BLANK = \"blank\",\n}\n\nexport interface Headers {\n [key: string]: string;\n}\n\nexport interface GetCookieOptions {\n url: string;\n includeHttpOnly?: boolean;\n}\n\nexport interface ClearCookieOptions {\n url: string;\n}\n\nexport interface Credentials {\n username: string;\n password: string;\n}\n\nexport interface OpenOptions {\n /**\n * Target URL to load.\n * @since 0.1.0\n */\n url: string;\n /**\n * Headers to send with the request.\n * @since 0.1.0\n */\n headers?: Headers;\n /**\n * Credentials to send with the request and all subsequent requests for the same host.\n * @since 6.1.0\n */\n credentials?: Credentials;\n /**\n * if true, the browser will be presented after the page is loaded, if false, the browser will be presented immediately.\n * @since 0.1.0\n */\n isPresentAfterPageLoad?: boolean;\n /**\n * if true the deeplink will not be opened, if false the deeplink will be opened when clicked on the link\n * @since 0.1.0\n */\n preventDeeplink?: boolean;\n}\n\nexport interface DisclaimerOptions {\n /**\n * Title of the disclaimer dialog\n * @default \"Title\"\n */\n title: string;\n /**\n * Message shown in the disclaimer dialog\n * @default \"Message\"\n */\n message: string;\n /**\n * Text for the confirm button\n * @default \"Confirm\"\n */\n confirmBtn: string;\n /**\n * Text for the cancel button\n * @default \"Cancel\"\n */\n cancelBtn: string;\n}\n\nexport interface OpenWebViewOptions {\n /**\n * Target URL to load.\n * @since 0.1.0\n * @example \"https://capgo.app\"\n */\n url: string;\n /**\n * Headers to send with the request.\n * @since 0.1.0\n * @example\n * headers: {\n * 'Custom-Header': 'test-value',\n * 'Authorization': 'Bearer test-token'\n * }\n * Test URL: https://www.whatismybrowser.com/detect/what-http-headers-is-my-browser-sending/\n */\n headers?: Headers;\n /**\n * Credentials to send with the request and all subsequent requests for the same host.\n * @since 6.1.0\n * @example\n * credentials: {\n * username: 'test-user',\n * password: 'test-pass'\n * }\n * Test URL: https://www.whatismybrowser.com/detect/what-http-headers-is-my-browser-sending/\n */\n credentials?: Credentials;\n /**\n * materialPicker: if true, uses Material Design theme for date and time pickers on Android.\n * This improves the appearance of HTML date inputs to use modern Material Design UI instead of the old style pickers.\n * @since 7.4.1\n * @default false\n * @example\n * materialPicker: true\n * Test URL: https://show-picker.glitch.me/demo.html\n */\n materialPicker?: boolean;\n /**\n * JavaScript Interface:\n * The webview automatically injects a JavaScript interface providing:\n * - `window.mobileApp.close()`: Closes the webview from JavaScript\n * - `window.mobileApp.postMessage(obj)`: Sends a message to the app (listen via \"messageFromWebview\" event)\n *\n * @example\n * // In your webpage loaded in the webview:\n * document.getElementById('closeBtn').addEventListener('click', () => {\n * window.mobileApp.close();\n * });\n *\n * // Send data to the app\n * window.mobileApp.postMessage({ action: 'login', data: { user: 'test' }});\n *\n * @since 6.10.0\n */\n jsInterface?: never; // This property doesn't exist, it's just for documentation\n /**\n * Share options for the webview. When provided, shows a disclaimer dialog before sharing content.\n * This is useful for:\n * - Warning users about sharing sensitive information\n * - Getting user consent before sharing\n * - Explaining what will be shared\n * - Complying with privacy regulations\n *\n * Note: shareSubject is required when using shareDisclaimer\n * @since 0.1.0\n * @example\n * shareDisclaimer: {\n * title: 'Disclaimer',\n * message: 'This is a test disclaimer',\n * confirmBtn: 'Accept',\n * cancelBtn: 'Decline'\n * }\n * Test URL: https://capgo.app\n */\n shareDisclaimer?: DisclaimerOptions;\n /**\n * Toolbar type determines the appearance and behavior of the browser's toolbar\n * - \"activity\": Shows a simple toolbar with just a close button and share button\n * - \"navigation\": Shows a full navigation toolbar with back/forward buttons\n * - \"blank\": Shows no toolbar\n * - \"\": Default toolbar with close button\n * @since 0.1.0\n * @default ToolBarType.DEFAULT\n * @example\n * toolbarType: ToolBarType.ACTIVITY,\n * title: 'Activity Toolbar Test'\n * Test URL: https://capgo.app\n */\n toolbarType?: ToolBarType;\n /**\n * Subject text for sharing. Required when using shareDisclaimer.\n * This text will be used as the subject line when sharing content.\n * @since 0.1.0\n * @example \"Share this page\"\n */\n shareSubject?: string;\n /**\n * Title of the browser\n * @since 0.1.0\n * @default 'New Window'\n * @example \"Camera Test\"\n */\n title?: string;\n /**\n * Background color of the browser\n * @since 0.1.0\n * @default BackgroundColor.BLACK\n */\n backgroundColor?: BackgroundColor;\n /**\n * If true, active the native navigation within the webview, Android only\n * @default false\n * @example\n * activeNativeNavigationForWebview: true,\n * disableGoBackOnNativeApplication: true\n * Test URL: https://capgo.app\n */\n activeNativeNavigationForWebview?: boolean;\n /**\n * Disable the possibility to go back on native application,\n * useful to force user to stay on the webview, Android only\n * @default false\n * @example\n * disableGoBackOnNativeApplication: true\n * Test URL: https://capgo.app\n */\n disableGoBackOnNativeApplication?: boolean;\n /**\n * Open url in a new window fullscreen\n * isPresentAfterPageLoad: if true, the browser will be presented after the page is loaded, if false, the browser will be presented immediately.\n * @since 0.1.0\n * @default false\n * @example\n * isPresentAfterPageLoad: true,\n * preShowScript: \"await import('https://unpkg.com/darkreader@4.9.89/darkreader.js');\\nDarkReader.enable({ brightness: 100, contrast: 90, sepia: 10 });\"\n * Test URL: https://capgo.app\n */\n isPresentAfterPageLoad?: boolean;\n /**\n * Whether the website in the webview is inspectable or not, ios only\n * @default false\n */\n isInspectable?: boolean;\n /**\n * Whether the webview opening is animated or not, ios only\n * @default true\n */\n isAnimated?: boolean;\n /**\n * Shows a reload button that reloads the web page\n * @since 1.0.15\n * @default false\n * @example\n * showReloadButton: true\n * Test URL: https://capgo.app\n */\n showReloadButton?: boolean;\n /**\n * CloseModal: if true a confirm will be displayed when user clicks on close button, if false the browser will be closed immediately.\n * @since 1.1.0\n * @default false\n * @example\n * closeModal: true,\n * closeModalTitle: 'Close Window',\n * closeModalDescription: 'Are you sure you want to close?',\n * closeModalOk: 'Yes, close',\n * closeModalCancel: 'No, stay'\n * Test URL: https://capgo.app\n */\n closeModal?: boolean;\n /**\n * CloseModalTitle: title of the confirm when user clicks on close button\n * @since 1.1.0\n * @default 'Close'\n */\n closeModalTitle?: string;\n /**\n * CloseModalDescription: description of the confirm when user clicks on close button\n * @since 1.1.0\n * @default 'Are you sure you want to close this window?'\n */\n closeModalDescription?: string;\n /**\n * CloseModalOk: text of the confirm button when user clicks on close button\n * @since 1.1.0\n * @default 'Close'\n */\n closeModalOk?: string;\n /**\n * CloseModalCancel: text of the cancel button when user clicks on close button\n * @since 1.1.0\n * @default 'Cancel'\n */\n closeModalCancel?: string;\n /**\n * visibleTitle: if true the website title would be shown else shown empty\n * @since 1.2.5\n * @default true\n */\n visibleTitle?: boolean;\n /**\n * toolbarColor: color of the toolbar in hex format\n * @since 1.2.5\n * @default '#ffffff'\n * @example\n * toolbarColor: '#FF5733'\n * Test URL: https://capgo.app\n */\n toolbarColor?: string;\n /**\n * toolbarTextColor: color of the buttons and title in the toolbar in hex format\n * When set, it overrides the automatic light/dark mode detection for text color\n * @since 6.10.0\n * @default calculated based on toolbarColor brightness\n * @example\n * toolbarTextColor: '#FFFFFF'\n * Test URL: https://capgo.app\n */\n toolbarTextColor?: string;\n /**\n * showArrow: if true an arrow would be shown instead of cross for closing the window\n * @since 1.2.5\n * @default false\n * @example\n * showArrow: true\n * Test URL: https://capgo.app\n */\n showArrow?: boolean;\n /**\n * ignoreUntrustedSSLError: if true, the webview will ignore untrusted SSL errors allowing the user to view the website.\n * @since 6.1.0\n * @default false\n */\n ignoreUntrustedSSLError?: boolean;\n /**\n * preShowScript: if isPresentAfterPageLoad is true and this variable is set the plugin will inject a script before showing the browser.\n * This script will be run in an async context. The plugin will wait for the script to finish (max 10 seconds)\n * @since 6.6.0\n * @example\n * preShowScript: \"await import('https://unpkg.com/darkreader@4.9.89/darkreader.js');\\nDarkReader.enable({ brightness: 100, contrast: 90, sepia: 10 });\"\n * Test URL: https://capgo.app\n */\n preShowScript?: string;\n /**\n * proxyRequests is a regex expression. Please see [this pr](https://github.com/Cap-go/capacitor-inappbrowser/pull/222) for more info. (Android only)\n * @since 6.9.0\n */\n proxyRequests?: string;\n /**\n * buttonNearDone allows for a creation of a custom button near the done/close button.\n * The button is only shown when toolbarType is not \"activity\", \"navigation\", or \"blank\".\n *\n * For Android:\n * - iconType must be \"asset\"\n * - icon path should be in the public folder (e.g. \"monkey.svg\")\n * - width and height are optional, defaults to 48dp\n * - button is positioned at the end of toolbar with 8dp margin\n *\n * For iOS:\n * - iconType can be \"sf-symbol\" or \"asset\"\n * - for sf-symbol, icon should be the symbol name\n * - for asset, icon should be the asset name\n * @since 6.7.0\n * @example\n * buttonNearDone: {\n * ios: {\n * iconType: 'sf-symbol',\n * icon: 'star.fill'\n * },\n * android: {\n * iconType: 'asset',\n * icon: 'public/monkey.svg',\n * width: 24,\n * height: 24\n * }\n * }\n * Test URL: https://capgo.app\n */\n buttonNearDone?: {\n ios: {\n iconType: \"sf-symbol\" | \"asset\";\n icon: string;\n };\n android: {\n iconType: \"asset\" | \"vector\";\n icon: string;\n width?: number;\n height?: number;\n };\n };\n /**\n * textZoom: sets the text zoom of the page in percent.\n * Allows users to increase or decrease the text size for better readability.\n * @since 7.6.0\n * @default 100\n * @example\n * textZoom: 120\n * Test URL: https://capgo.app\n */\n textZoom?: number;\n}\n\nexport interface InAppBrowserPlugin {\n /**\n * Open url in a new window fullscreen\n *\n * @since 0.1.0\n */\n open(options: OpenOptions): Promise<any>;\n\n /**\n * Clear cookies of url\n *\n * @since 0.5.0\n */\n clearCookies(options: ClearCookieOptions): Promise<any>;\n /**\n * Clear all cookies\n *\n * @since 6.5.0\n */\n clearAllCookies(): Promise<any>;\n\n /**\n * Clear cache\n *\n * @since 6.5.0\n */\n clearCache(): Promise<any>;\n\n /**\n * Get cookies for a specific URL.\n * @param options The options, including the URL to get cookies for.\n * @returns A promise that resolves with the cookies.\n */\n getCookies(options: GetCookieOptions): Promise<Record<string, string>>;\n /**\n * Close the webview.\n */\n close(): Promise<any>;\n /**\n * Open url in a new webview with toolbars, and enhanced capabilities, like camera access, file access, listen events, inject javascript, bi directional communication, etc.\n *\n * JavaScript Interface:\n * When you open a webview with this method, a JavaScript interface is automatically injected that provides:\n * - `window.mobileApp.close()`: Closes the webview from JavaScript\n * - `window.mobileApp.postMessage({detail: {message: 'myMessage'}})`: Sends a message from the webview to the app, detail object is the data you want to send to the webview\n *\n * @since 0.1.0\n */\n openWebView(options: OpenWebViewOptions): Promise<any>;\n /**\n * Injects JavaScript code into the InAppBrowser window.\n */\n executeScript({ code }: { code: string }): Promise<void>;\n /**\n * Sends an event to the webview(inappbrowser). you can listen to this event in the inappbrowser JS with window.addEventListener(\"messageFromNative\", listenerFunc: (event: Record<string, any>) => void)\n * detail is the data you want to send to the webview, it's a requirement of Capacitor we cannot send direct objects\n * Your object has to be serializable to JSON, so no functions or other non-JSON-serializable types are allowed.\n */\n postMessage(options: { detail: Record<string, any> }): Promise<void>;\n /**\n * Sets the URL of the webview.\n */\n setUrl(options: { url: string }): Promise<any>;\n /**\n * Listen for url change, only for openWebView\n *\n * @since 0.0.1\n */\n addListener(\n eventName: \"urlChangeEvent\",\n listenerFunc: UrlChangeListener,\n ): Promise<PluginListenerHandle>;\n\n addListener(\n eventName: \"buttonNearDoneClick\",\n listenerFunc: ButtonNearListener,\n ): Promise<PluginListenerHandle>;\n\n /**\n * Listen for close click only for openWebView\n *\n * @since 0.4.0\n */\n addListener(\n eventName: \"closeEvent\",\n listenerFunc: UrlChangeListener,\n ): Promise<PluginListenerHandle>;\n /**\n * Will be triggered when user clicks on confirm button when disclaimer is required\n *\n * @since 0.0.1\n */\n addListener(\n eventName: \"confirmBtnClicked\",\n listenerFunc: ConfirmBtnListener,\n ): Promise<PluginListenerHandle>;\n /**\n * Will be triggered when event is sent from webview(inappbrowser), to send an event to the main app use window.mobileApp.postMessage({ \"detail\": { \"message\": \"myMessage\" } })\n * detail is the data you want to send to the main app, it's a requirement of Capacitor we cannot send direct objects\n * Your object has to be serializable to JSON, no functions or other non-JSON-serializable types are allowed.\n *\n * This method is inject at runtime in the webview\n */\n addListener(\n eventName: \"messageFromWebview\",\n listenerFunc: (event: { detail: Record<string, any> }) => void,\n ): Promise<PluginListenerHandle>;\n\n /**\n * Will be triggered when page is loaded\n */\n addListener(\n eventName: \"browserPageLoaded\",\n listenerFunc: () => void,\n ): Promise<PluginListenerHandle>;\n\n /**\n * Will be triggered when page load error\n */\n addListener(\n eventName: \"pageLoadError\",\n listenerFunc: () => void,\n ): Promise<PluginListenerHandle>;\n /**\n * Remove all listeners for this plugin.\n *\n * @since 1.0.0\n */\n removeAllListeners(): Promise<void>;\n\n /**\n * Reload the current web page.\n *\n * @since 1.0.0\n */\n reload(): Promise<any>;\n}\n\n/**\n * JavaScript APIs available in the InAppBrowser WebView.\n *\n * These APIs are automatically injected into all webpages loaded in the InAppBrowser WebView.\n *\n * @example\n * // Closing the webview from JavaScript\n * window.mobileApp.close();\n *\n * // Sending a message from webview to the native app\n * window.mobileApp.postMessage({ key: 'value' });\n *\n * @since 6.10.0\n */\nexport interface InAppBrowserWebViewAPIs {\n /**\n * mobileApp - Global object injected into the WebView providing communication with the native app\n */\n mobileApp: {\n /**\n * Close the WebView from JavaScript\n *\n * @example\n * // Add a button to close the webview\n * const closeButton = document.createElement('button');\n * closeButton.textContent = 'Close WebView';\n * closeButton.addEventListener('click', () => {\n * window.mobileApp.close();\n * });\n * document.body.appendChild(closeButton);\n *\n * @since 6.10.0\n */\n close(): void;\n\n /**\n * Send a message from the WebView to the native app\n * The native app can listen for these messages with the \"messageFromWebview\" event\n *\n * @param message Object to send to the native app\n * @example\n * // Send data to native app\n * window.mobileApp.postMessage({\n * action: 'dataSubmitted',\n * data: { username: 'test', email: 'test@example.com' }\n * });\n *\n * @since 6.10.0\n */\n postMessage(message: Record<string, any>): void;\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAuBA,MAAM,CAAN,IAAY,eAGX;AAHD,WAAY,eAAe;IACzB,kCAAe,CAAA;IACf,kCAAe,CAAA;AACjB,CAAC,EAHW,eAAe,KAAf,eAAe,QAG1B;AACD,MAAM,CAAN,IAAY,WAgBX;AAhBD,WAAY,WAAW;IACrB;;;OAGG;IACH,oCAAqB,CAAA;IACrB;;;OAGG;IACH,wCAAyB,CAAA;IACzB;;;OAGG;IACH,8BAAe,CAAA;AACjB,CAAC,EAhBW,WAAW,KAAX,WAAW,QAgBtB","sourcesContent":["import type { PluginListenerHandle } from \"@capacitor/core\";\n\nexport interface UrlEvent {\n /**\n * Emit when the url changes\n *\n * @since 0.0.1\n */\n url: string;\n}\nexport interface BtnEvent {\n /**\n * Emit when a button is clicked.\n *\n * @since 0.0.1\n */\n url: string;\n}\n\nexport type UrlChangeListener = (state: UrlEvent) => void;\nexport type ConfirmBtnListener = (state: BtnEvent) => void;\nexport type ButtonNearListener = (state: object) => void;\n\nexport enum BackgroundColor {\n WHITE = \"white\",\n BLACK = \"black\",\n}\nexport enum ToolBarType {\n /**\n * Shows a simple toolbar with just a close button and share button\n * @since 0.1.0\n */\n ACTIVITY = \"activity\",\n /**\n * Shows a full navigation toolbar with back/forward buttons\n * @since 0.1.0\n */\n NAVIGATION = \"navigation\",\n /**\n * Shows no toolbar\n * @since 0.1.0\n */\n BLANK = \"blank\",\n}\n\nexport interface Headers {\n [key: string]: string;\n}\n\nexport interface GetCookieOptions {\n url: string;\n includeHttpOnly?: boolean;\n}\n\nexport interface ClearCookieOptions {\n url: string;\n}\n\nexport interface Credentials {\n username: string;\n password: string;\n}\n\nexport interface OpenOptions {\n /**\n * Target URL to load.\n * @since 0.1.0\n */\n url: string;\n /**\n * if true, the browser will be presented after the page is loaded, if false, the browser will be presented immediately.\n * @since 0.1.0\n */\n isPresentAfterPageLoad?: boolean;\n /**\n * if true the deeplink will not be opened, if false the deeplink will be opened when clicked on the link\n * @since 0.1.0\n */\n preventDeeplink?: boolean;\n}\n\nexport interface DisclaimerOptions {\n /**\n * Title of the disclaimer dialog\n * @default \"Title\"\n */\n title: string;\n /**\n * Message shown in the disclaimer dialog\n * @default \"Message\"\n */\n message: string;\n /**\n * Text for the confirm button\n * @default \"Confirm\"\n */\n confirmBtn: string;\n /**\n * Text for the cancel button\n * @default \"Cancel\"\n */\n cancelBtn: string;\n}\n\nexport interface OpenWebViewOptions {\n /**\n * Target URL to load.\n * @since 0.1.0\n * @example \"https://capgo.app\"\n */\n url: string;\n /**\n * Headers to send with the request.\n * @since 0.1.0\n * @example\n * headers: {\n * 'Custom-Header': 'test-value',\n * 'Authorization': 'Bearer test-token'\n * }\n * Test URL: https://www.whatismybrowser.com/detect/what-http-headers-is-my-browser-sending/\n */\n headers?: Headers;\n /**\n * Credentials to send with the request and all subsequent requests for the same host.\n * @since 6.1.0\n * @example\n * credentials: {\n * username: 'test-user',\n * password: 'test-pass'\n * }\n * Test URL: https://www.whatismybrowser.com/detect/what-http-headers-is-my-browser-sending/\n */\n credentials?: Credentials;\n /**\n * materialPicker: if true, uses Material Design theme for date and time pickers on Android.\n * This improves the appearance of HTML date inputs to use modern Material Design UI instead of the old style pickers.\n * @since 7.4.1\n * @default false\n * @example\n * materialPicker: true\n * Test URL: https://show-picker.glitch.me/demo.html\n */\n materialPicker?: boolean;\n /**\n * JavaScript Interface:\n * The webview automatically injects a JavaScript interface providing:\n * - `window.mobileApp.close()`: Closes the webview from JavaScript\n * - `window.mobileApp.postMessage(obj)`: Sends a message to the app (listen via \"messageFromWebview\" event)\n *\n * @example\n * // In your webpage loaded in the webview:\n * document.getElementById('closeBtn').addEventListener('click', () => {\n * window.mobileApp.close();\n * });\n *\n * // Send data to the app\n * window.mobileApp.postMessage({ action: 'login', data: { user: 'test' }});\n *\n * @since 6.10.0\n */\n jsInterface?: never; // This property doesn't exist, it's just for documentation\n /**\n * Share options for the webview. When provided, shows a disclaimer dialog before sharing content.\n * This is useful for:\n * - Warning users about sharing sensitive information\n * - Getting user consent before sharing\n * - Explaining what will be shared\n * - Complying with privacy regulations\n *\n * Note: shareSubject is required when using shareDisclaimer\n * @since 0.1.0\n * @example\n * shareDisclaimer: {\n * title: 'Disclaimer',\n * message: 'This is a test disclaimer',\n * confirmBtn: 'Accept',\n * cancelBtn: 'Decline'\n * }\n * Test URL: https://capgo.app\n */\n shareDisclaimer?: DisclaimerOptions;\n /**\n * Toolbar type determines the appearance and behavior of the browser's toolbar\n * - \"activity\": Shows a simple toolbar with just a close button and share button\n * - \"navigation\": Shows a full navigation toolbar with back/forward buttons\n * - \"blank\": Shows no toolbar\n * - \"\": Default toolbar with close button\n * @since 0.1.0\n * @default ToolBarType.DEFAULT\n * @example\n * toolbarType: ToolBarType.ACTIVITY,\n * title: 'Activity Toolbar Test'\n * Test URL: https://capgo.app\n */\n toolbarType?: ToolBarType;\n /**\n * Subject text for sharing. Required when using shareDisclaimer.\n * This text will be used as the subject line when sharing content.\n * @since 0.1.0\n * @example \"Share this page\"\n */\n shareSubject?: string;\n /**\n * Title of the browser\n * @since 0.1.0\n * @default 'New Window'\n * @example \"Camera Test\"\n */\n title?: string;\n /**\n * Background color of the browser\n * @since 0.1.0\n * @default BackgroundColor.BLACK\n */\n backgroundColor?: BackgroundColor;\n /**\n * If true, active the native navigation within the webview, Android only\n * @default false\n * @example\n * activeNativeNavigationForWebview: true,\n * disableGoBackOnNativeApplication: true\n * Test URL: https://capgo.app\n */\n activeNativeNavigationForWebview?: boolean;\n /**\n * Disable the possibility to go back on native application,\n * useful to force user to stay on the webview, Android only\n * @default false\n * @example\n * disableGoBackOnNativeApplication: true\n * Test URL: https://capgo.app\n */\n disableGoBackOnNativeApplication?: boolean;\n /**\n * Open url in a new window fullscreen\n * isPresentAfterPageLoad: if true, the browser will be presented after the page is loaded, if false, the browser will be presented immediately.\n * @since 0.1.0\n * @default false\n * @example\n * isPresentAfterPageLoad: true,\n * preShowScript: \"await import('https://unpkg.com/darkreader@4.9.89/darkreader.js');\\nDarkReader.enable({ brightness: 100, contrast: 90, sepia: 10 });\"\n * Test URL: https://capgo.app\n */\n isPresentAfterPageLoad?: boolean;\n /**\n * Whether the website in the webview is inspectable or not, ios only\n * @default false\n */\n isInspectable?: boolean;\n /**\n * Whether the webview opening is animated or not, ios only\n * @default true\n */\n isAnimated?: boolean;\n /**\n * Shows a reload button that reloads the web page\n * @since 1.0.15\n * @default false\n * @example\n * showReloadButton: true\n * Test URL: https://capgo.app\n */\n showReloadButton?: boolean;\n /**\n * CloseModal: if true a confirm will be displayed when user clicks on close button, if false the browser will be closed immediately.\n * @since 1.1.0\n * @default false\n * @example\n * closeModal: true,\n * closeModalTitle: 'Close Window',\n * closeModalDescription: 'Are you sure you want to close?',\n * closeModalOk: 'Yes, close',\n * closeModalCancel: 'No, stay'\n * Test URL: https://capgo.app\n */\n closeModal?: boolean;\n /**\n * CloseModalTitle: title of the confirm when user clicks on close button\n * @since 1.1.0\n * @default 'Close'\n */\n closeModalTitle?: string;\n /**\n * CloseModalDescription: description of the confirm when user clicks on close button\n * @since 1.1.0\n * @default 'Are you sure you want to close this window?'\n */\n closeModalDescription?: string;\n /**\n * CloseModalOk: text of the confirm button when user clicks on close button\n * @since 1.1.0\n * @default 'Close'\n */\n closeModalOk?: string;\n /**\n * CloseModalCancel: text of the cancel button when user clicks on close button\n * @since 1.1.0\n * @default 'Cancel'\n */\n closeModalCancel?: string;\n /**\n * visibleTitle: if true the website title would be shown else shown empty\n * @since 1.2.5\n * @default true\n */\n visibleTitle?: boolean;\n /**\n * toolbarColor: color of the toolbar in hex format\n * @since 1.2.5\n * @default '#ffffff'\n * @example\n * toolbarColor: '#FF5733'\n * Test URL: https://capgo.app\n */\n toolbarColor?: string;\n /**\n * toolbarTextColor: color of the buttons and title in the toolbar in hex format\n * When set, it overrides the automatic light/dark mode detection for text color\n * @since 6.10.0\n * @default calculated based on toolbarColor brightness\n * @example\n * toolbarTextColor: '#FFFFFF'\n * Test URL: https://capgo.app\n */\n toolbarTextColor?: string;\n /**\n * showArrow: if true an arrow would be shown instead of cross for closing the window\n * @since 1.2.5\n * @default false\n * @example\n * showArrow: true\n * Test URL: https://capgo.app\n */\n showArrow?: boolean;\n /**\n * ignoreUntrustedSSLError: if true, the webview will ignore untrusted SSL errors allowing the user to view the website.\n * @since 6.1.0\n * @default false\n */\n ignoreUntrustedSSLError?: boolean;\n /**\n * preShowScript: if isPresentAfterPageLoad is true and this variable is set the plugin will inject a script before showing the browser.\n * This script will be run in an async context. The plugin will wait for the script to finish (max 10 seconds)\n * @since 6.6.0\n * @example\n * preShowScript: \"await import('https://unpkg.com/darkreader@4.9.89/darkreader.js');\\nDarkReader.enable({ brightness: 100, contrast: 90, sepia: 10 });\"\n * Test URL: https://capgo.app\n */\n preShowScript?: string;\n /**\n * proxyRequests is a regex expression. Please see [this pr](https://github.com/Cap-go/capacitor-inappbrowser/pull/222) for more info. (Android only)\n * @since 6.9.0\n */\n proxyRequests?: string;\n /**\n * buttonNearDone allows for a creation of a custom button near the done/close button.\n * The button is only shown when toolbarType is not \"activity\", \"navigation\", or \"blank\".\n *\n * For Android:\n * - iconType must be \"asset\"\n * - icon path should be in the public folder (e.g. \"monkey.svg\")\n * - width and height are optional, defaults to 48dp\n * - button is positioned at the end of toolbar with 8dp margin\n *\n * For iOS:\n * - iconType can be \"sf-symbol\" or \"asset\"\n * - for sf-symbol, icon should be the symbol name\n * - for asset, icon should be the asset name\n * @since 6.7.0\n * @example\n * buttonNearDone: {\n * ios: {\n * iconType: 'sf-symbol',\n * icon: 'star.fill'\n * },\n * android: {\n * iconType: 'asset',\n * icon: 'public/monkey.svg',\n * width: 24,\n * height: 24\n * }\n * }\n * Test URL: https://capgo.app\n */\n buttonNearDone?: {\n ios: {\n iconType: \"sf-symbol\" | \"asset\";\n icon: string;\n };\n android: {\n iconType: \"asset\" | \"vector\";\n icon: string;\n width?: number;\n height?: number;\n };\n };\n /**\n * textZoom: sets the text zoom of the page in percent.\n * Allows users to increase or decrease the text size for better readability.\n * @since 7.6.0\n * @default 100\n * @example\n * textZoom: 120\n * Test URL: https://capgo.app\n */\n textZoom?: number;\n}\n\nexport interface InAppBrowserPlugin {\n /**\n * Open url in a new window fullscreen, on android it use chrome custom tabs, on ios it use SFSafariViewController\n *\n * @since 0.1.0\n */\n open(options: OpenOptions): Promise<any>;\n\n /**\n * Clear cookies of url\n *\n * @since 0.5.0\n */\n clearCookies(options: ClearCookieOptions): Promise<any>;\n /**\n * Clear all cookies\n *\n * @since 6.5.0\n */\n clearAllCookies(): Promise<any>;\n\n /**\n * Clear cache\n *\n * @since 6.5.0\n */\n clearCache(): Promise<any>;\n\n /**\n * Get cookies for a specific URL.\n * @param options The options, including the URL to get cookies for.\n * @returns A promise that resolves with the cookies.\n */\n getCookies(options: GetCookieOptions): Promise<Record<string, string>>;\n /**\n * Close the webview.\n */\n close(): Promise<any>;\n /**\n * Open url in a new webview with toolbars, and enhanced capabilities, like camera access, file access, listen events, inject javascript, bi directional communication, etc.\n *\n * JavaScript Interface:\n * When you open a webview with this method, a JavaScript interface is automatically injected that provides:\n * - `window.mobileApp.close()`: Closes the webview from JavaScript\n * - `window.mobileApp.postMessage({detail: {message: 'myMessage'}})`: Sends a message from the webview to the app, detail object is the data you want to send to the webview\n *\n * @since 0.1.0\n */\n openWebView(options: OpenWebViewOptions): Promise<any>;\n /**\n * Injects JavaScript code into the InAppBrowser window.\n */\n executeScript({ code }: { code: string }): Promise<void>;\n /**\n * Sends an event to the webview(inappbrowser). you can listen to this event in the inappbrowser JS with window.addEventListener(\"messageFromNative\", listenerFunc: (event: Record<string, any>) => void)\n * detail is the data you want to send to the webview, it's a requirement of Capacitor we cannot send direct objects\n * Your object has to be serializable to JSON, so no functions or other non-JSON-serializable types are allowed.\n */\n postMessage(options: { detail: Record<string, any> }): Promise<void>;\n /**\n * Sets the URL of the webview.\n */\n setUrl(options: { url: string }): Promise<any>;\n /**\n * Listen for url change, only for openWebView\n *\n * @since 0.0.1\n */\n addListener(\n eventName: \"urlChangeEvent\",\n listenerFunc: UrlChangeListener,\n ): Promise<PluginListenerHandle>;\n\n addListener(\n eventName: \"buttonNearDoneClick\",\n listenerFunc: ButtonNearListener,\n ): Promise<PluginListenerHandle>;\n\n /**\n * Listen for close click only for openWebView\n *\n * @since 0.4.0\n */\n addListener(\n eventName: \"closeEvent\",\n listenerFunc: UrlChangeListener,\n ): Promise<PluginListenerHandle>;\n /**\n * Will be triggered when user clicks on confirm button when disclaimer is required\n *\n * @since 0.0.1\n */\n addListener(\n eventName: \"confirmBtnClicked\",\n listenerFunc: ConfirmBtnListener,\n ): Promise<PluginListenerHandle>;\n /**\n * Will be triggered when event is sent from webview(inappbrowser), to send an event to the main app use window.mobileApp.postMessage({ \"detail\": { \"message\": \"myMessage\" } })\n * detail is the data you want to send to the main app, it's a requirement of Capacitor we cannot send direct objects\n * Your object has to be serializable to JSON, no functions or other non-JSON-serializable types are allowed.\n *\n * This method is inject at runtime in the webview\n */\n addListener(\n eventName: \"messageFromWebview\",\n listenerFunc: (event: { detail: Record<string, any> }) => void,\n ): Promise<PluginListenerHandle>;\n\n /**\n * Will be triggered when page is loaded\n */\n addListener(\n eventName: \"browserPageLoaded\",\n listenerFunc: () => void,\n ): Promise<PluginListenerHandle>;\n\n /**\n * Will be triggered when page load error\n */\n addListener(\n eventName: \"pageLoadError\",\n listenerFunc: () => void,\n ): Promise<PluginListenerHandle>;\n /**\n * Remove all listeners for this plugin.\n *\n * @since 1.0.0\n */\n removeAllListeners(): Promise<void>;\n\n /**\n * Reload the current web page.\n *\n * @since 1.0.0\n */\n reload(): Promise<any>;\n}\n\n/**\n * JavaScript APIs available in the InAppBrowser WebView.\n *\n * These APIs are automatically injected into all webpages loaded in the InAppBrowser WebView.\n *\n * @example\n * // Closing the webview from JavaScript\n * window.mobileApp.close();\n *\n * // Sending a message from webview to the native app\n * window.mobileApp.postMessage({ key: 'value' });\n *\n * @since 6.10.0\n */\nexport interface InAppBrowserWebViewAPIs {\n /**\n * mobileApp - Global object injected into the WebView providing communication with the native app\n */\n mobileApp: {\n /**\n * Close the WebView from JavaScript\n *\n * @example\n * // Add a button to close the webview\n * const closeButton = document.createElement('button');\n * closeButton.textContent = 'Close WebView';\n * closeButton.addEventListener('click', () => {\n * window.mobileApp.close();\n * });\n * document.body.appendChild(closeButton);\n *\n * @since 6.10.0\n */\n close(): void;\n\n /**\n * Send a message from the WebView to the native app\n * The native app can listen for these messages with the \"messageFromWebview\" event\n *\n * @param message Object to send to the native app\n * @example\n * // Send data to native app\n * window.mobileApp.postMessage({\n * action: 'dataSubmitted',\n * data: { username: 'test', email: 'test@example.com' }\n * });\n *\n * @since 6.10.0\n */\n postMessage(message: Record<string, any>): void;\n };\n}\n"]}
|
|
@@ -370,7 +370,6 @@ public class InAppBrowserPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
370
370
|
|
|
371
371
|
webViewController.source = .remote(url)
|
|
372
372
|
webViewController.leftNavigationBarItemTypes = []
|
|
373
|
-
webViewController.toolbarItemTypes = []
|
|
374
373
|
|
|
375
374
|
// Configure close button based on showArrow
|
|
376
375
|
let showArrow = call.getBool("showArrow", false)
|
|
@@ -653,6 +652,7 @@ public class InAppBrowserPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
653
652
|
|
|
654
653
|
let isInspectable = call.getBool("isInspectable", false)
|
|
655
654
|
let preventDeeplink = call.getBool("preventDeeplink", false)
|
|
655
|
+
self.isPresentAfterPageLoad = call.getBool("isPresentAfterPageLoad", false)
|
|
656
656
|
|
|
657
657
|
self.currentPluginCall = call
|
|
658
658
|
|
|
@@ -667,36 +667,52 @@ public class InAppBrowserPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
667
667
|
}
|
|
668
668
|
|
|
669
669
|
let headers = call.getObject("headers", [:]).mapValues { String(describing: $0 as Any) }
|
|
670
|
-
|
|
671
|
-
self.isPresentAfterPageLoad = call.getBool("isPresentAfterPageLoad", false)
|
|
672
|
-
|
|
673
670
|
let credentials = self.readCredentials(call)
|
|
674
671
|
|
|
675
672
|
DispatchQueue.main.async {
|
|
676
|
-
let url = URL(string: urlString)
|
|
673
|
+
guard let url = URL(string: urlString) else {
|
|
674
|
+
call.reject("Invalid URL format")
|
|
675
|
+
return
|
|
676
|
+
}
|
|
677
677
|
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
self.webViewController?.setCredentials(credentials: credentials)
|
|
684
|
-
self.webViewController?.setPreventDeeplink(preventDeeplink: preventDeeplink)
|
|
678
|
+
self.webViewController = WKWebViewController.init(url: url, headers: headers, isInspectable: isInspectable, credentials: credentials, preventDeeplink: preventDeeplink, blankNavigationTab: true)
|
|
679
|
+
|
|
680
|
+
guard let webViewController = self.webViewController else {
|
|
681
|
+
call.reject("Failed to initialize WebViewController")
|
|
682
|
+
return
|
|
685
683
|
}
|
|
686
684
|
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
self.navigationWebViewController = UINavigationController.init(rootViewController:
|
|
685
|
+
webViewController.source = .remote(url)
|
|
686
|
+
webViewController.leftNavigationBarItemTypes = [.back, .forward, .reload]
|
|
687
|
+
webViewController.capBrowserPlugin = self
|
|
688
|
+
webViewController.hasDynamicTitle = true
|
|
689
|
+
|
|
690
|
+
self.navigationWebViewController = UINavigationController.init(rootViewController: webViewController)
|
|
693
691
|
self.navigationWebViewController?.navigationBar.isTranslucent = false
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
self.navigationWebViewController?.
|
|
697
|
-
self.navigationWebViewController?.
|
|
692
|
+
|
|
693
|
+
// Ensure no lines or borders appear by default
|
|
694
|
+
self.navigationWebViewController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
|
|
695
|
+
self.navigationWebViewController?.navigationBar.shadowImage = UIImage()
|
|
696
|
+
self.navigationWebViewController?.navigationBar.setValue(true, forKey: "hidesShadow")
|
|
697
|
+
|
|
698
|
+
// Use system appearance
|
|
699
|
+
let isDarkMode = UITraitCollection.current.userInterfaceStyle == .dark
|
|
700
|
+
let backgroundColor = isDarkMode ? UIColor.black : UIColor.white
|
|
701
|
+
let textColor = isDarkMode ? UIColor.white : UIColor.black
|
|
702
|
+
|
|
703
|
+
// Apply colors
|
|
704
|
+
webViewController.setupStatusBarBackground(color: backgroundColor)
|
|
705
|
+
webViewController.tintColor = textColor
|
|
706
|
+
self.navigationWebViewController?.navigationBar.tintColor = textColor
|
|
707
|
+
self.navigationWebViewController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: textColor]
|
|
708
|
+
webViewController.statusBarStyle = isDarkMode ? .lightContent : .darkContent
|
|
709
|
+
webViewController.updateStatusBarStyle()
|
|
710
|
+
|
|
711
|
+
// Always hide toolbar to ensure no bottom bar
|
|
712
|
+
self.navigationWebViewController?.setToolbarHidden(true, animated: false)
|
|
698
713
|
|
|
699
714
|
self.navigationWebViewController?.modalPresentationStyle = .fullScreen
|
|
715
|
+
|
|
700
716
|
if !self.isPresentAfterPageLoad {
|
|
701
717
|
self.presentView()
|
|
702
718
|
}
|
|
@@ -165,7 +165,6 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
|
|
|
165
165
|
open var preShowScript: String?
|
|
166
166
|
open var leftNavigationBarItemTypes: [BarButtonItemType] = []
|
|
167
167
|
open var rightNavigaionBarItemTypes: [BarButtonItemType] = []
|
|
168
|
-
open var toolbarItemTypes: [BarButtonItemType] = [.back, .forward, .activity]
|
|
169
168
|
|
|
170
169
|
// Status bar style to be applied
|
|
171
170
|
open var statusBarStyle: UIStatusBarStyle = .default
|
|
@@ -374,14 +373,6 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
|
|
|
374
373
|
stopBarButtonItem.tintColor = tintColor
|
|
375
374
|
activityBarButtonItem.tintColor = tintColor
|
|
376
375
|
doneBarButtonItem.tintColor = tintColor
|
|
377
|
-
flexibleSpaceBarButtonItem.tintColor = tintColor
|
|
378
|
-
|
|
379
|
-
// Update toolbar items
|
|
380
|
-
if let items = toolbarItems {
|
|
381
|
-
for item in items {
|
|
382
|
-
item.tintColor = tintColor
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
376
|
|
|
386
377
|
// Update navigation items
|
|
387
378
|
if let leftItems = navigationItem.leftBarButtonItems {
|
|
@@ -433,13 +424,6 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
|
|
|
433
424
|
updateButtonTintColors()
|
|
434
425
|
}
|
|
435
426
|
}
|
|
436
|
-
|
|
437
|
-
if let toolbar = navigationController?.toolbar {
|
|
438
|
-
if toolbar.backgroundColor == UIColor.black || toolbar.backgroundColor == UIColor.white {
|
|
439
|
-
toolbar.backgroundColor = isDarkMode ? UIColor.black : UIColor.white
|
|
440
|
-
toolbar.tintColor = textColor
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
427
|
}
|
|
444
428
|
}
|
|
445
429
|
|
|
@@ -595,9 +579,7 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
|
|
|
595
579
|
// Don't force toolbar visibility
|
|
596
580
|
if self.viewHeightPortrait == nil {
|
|
597
581
|
self.viewHeightPortrait = self.view.safeAreaLayoutGuide.layoutFrame.size.height
|
|
598
|
-
|
|
599
|
-
self.viewHeightPortrait! += bottomPadding
|
|
600
|
-
}
|
|
582
|
+
self.viewHeightPortrait! += bottomPadding
|
|
601
583
|
if self.navigationController?.navigationBar.isHidden == true {
|
|
602
584
|
self.viewHeightPortrait! += topPadding
|
|
603
585
|
}
|
|
@@ -607,9 +589,7 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
|
|
|
607
589
|
// Don't force toolbar visibility
|
|
608
590
|
if self.viewHeightLandscape == nil {
|
|
609
591
|
self.viewHeightLandscape = self.view.safeAreaLayoutGuide.layoutFrame.size.height
|
|
610
|
-
|
|
611
|
-
self.viewHeightLandscape! += bottomPadding
|
|
612
|
-
}
|
|
592
|
+
self.viewHeightLandscape! += bottomPadding
|
|
613
593
|
if self.navigationController?.navigationBar.isHidden == true {
|
|
614
594
|
self.viewHeightLandscape! += topPadding
|
|
615
595
|
}
|
|
@@ -956,79 +936,6 @@ fileprivate extension WKWebViewController {
|
|
|
956
936
|
|
|
957
937
|
navigationItem.rightBarButtonItems = rightBarButtons
|
|
958
938
|
|
|
959
|
-
// Create toolbar items
|
|
960
|
-
if !toolbarItemTypes.isEmpty {
|
|
961
|
-
// Check if toolbar has back and forward buttons
|
|
962
|
-
let hasBackButton = toolbarItemTypes.contains(where: {
|
|
963
|
-
if case .back = $0 { return true }
|
|
964
|
-
return false
|
|
965
|
-
})
|
|
966
|
-
|
|
967
|
-
let hasForwardButton = toolbarItemTypes.contains(where: {
|
|
968
|
-
if case .forward = $0 { return true }
|
|
969
|
-
return false
|
|
970
|
-
})
|
|
971
|
-
|
|
972
|
-
let hasReloadButton = toolbarItemTypes.contains(where: {
|
|
973
|
-
if case .reload = $0 { return true }
|
|
974
|
-
return false
|
|
975
|
-
})
|
|
976
|
-
|
|
977
|
-
if hasBackButton && hasForwardButton {
|
|
978
|
-
// Create Android-like toolbar with evenly spaced buttons
|
|
979
|
-
var items: [UIBarButtonItem] = []
|
|
980
|
-
let flexSpace = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
|
|
981
|
-
|
|
982
|
-
// Add spacing before back button
|
|
983
|
-
items.append(flexSpace)
|
|
984
|
-
|
|
985
|
-
// Add back button
|
|
986
|
-
items.append(backBarButtonItem)
|
|
987
|
-
|
|
988
|
-
// Add spacing between buttons
|
|
989
|
-
items.append(flexSpace)
|
|
990
|
-
|
|
991
|
-
// Add forward button
|
|
992
|
-
items.append(forwardBarButtonItem)
|
|
993
|
-
|
|
994
|
-
// Add spacing between buttons
|
|
995
|
-
items.append(flexSpace)
|
|
996
|
-
|
|
997
|
-
// Add reload button if present
|
|
998
|
-
if hasReloadButton {
|
|
999
|
-
items.append(reloadBarButtonItem)
|
|
1000
|
-
items.append(flexSpace)
|
|
1001
|
-
}
|
|
1002
|
-
|
|
1003
|
-
setToolbarItems(items, animated: true)
|
|
1004
|
-
} else {
|
|
1005
|
-
// For other toolbar types, map the items directly
|
|
1006
|
-
let items = toolbarItemTypes.map { type -> UIBarButtonItem in
|
|
1007
|
-
switch type {
|
|
1008
|
-
case .back:
|
|
1009
|
-
return backBarButtonItem
|
|
1010
|
-
case .forward:
|
|
1011
|
-
return forwardBarButtonItem
|
|
1012
|
-
case .reload:
|
|
1013
|
-
return reloadBarButtonItem
|
|
1014
|
-
case .stop:
|
|
1015
|
-
return stopBarButtonItem
|
|
1016
|
-
case .activity:
|
|
1017
|
-
return activityBarButtonItem
|
|
1018
|
-
case .done:
|
|
1019
|
-
return doneBarButtonItem
|
|
1020
|
-
case .flexibleSpace:
|
|
1021
|
-
return flexibleSpaceBarButtonItem
|
|
1022
|
-
case .custom:
|
|
1023
|
-
return UIBarButtonItem()
|
|
1024
|
-
}
|
|
1025
|
-
}
|
|
1026
|
-
setToolbarItems(items, animated: true)
|
|
1027
|
-
}
|
|
1028
|
-
} else {
|
|
1029
|
-
setToolbarItems([], animated: false)
|
|
1030
|
-
}
|
|
1031
|
-
|
|
1032
939
|
// After all buttons are set up, apply tint color
|
|
1033
940
|
updateButtonTintColors()
|
|
1034
941
|
}
|
|
@@ -1052,11 +959,6 @@ fileprivate extension WKWebViewController {
|
|
|
1052
959
|
}
|
|
1053
960
|
|
|
1054
961
|
let isLoading = webView?.isLoading ?? false
|
|
1055
|
-
toolbarItems = toolbarItems?.map {
|
|
1056
|
-
barButtonItem -> UIBarButtonItem in
|
|
1057
|
-
return updateReloadBarButtonItem(barButtonItem, isLoading)
|
|
1058
|
-
}
|
|
1059
|
-
|
|
1060
962
|
navigationItem.leftBarButtonItems = navigationItem.leftBarButtonItems?.map {
|
|
1061
963
|
barButtonItem -> UIBarButtonItem in
|
|
1062
964
|
return updateReloadBarButtonItem(barButtonItem, isLoading)
|
|
@@ -1071,9 +973,8 @@ fileprivate extension WKWebViewController {
|
|
|
1071
973
|
func setUpState() {
|
|
1072
974
|
navigationController?.setNavigationBarHidden(false, animated: true)
|
|
1073
975
|
|
|
1074
|
-
//
|
|
1075
|
-
|
|
1076
|
-
navigationController?.setToolbarHidden(hideToolbar, animated: true)
|
|
976
|
+
// Always hide toolbar since we never want it
|
|
977
|
+
navigationController?.setToolbarHidden(true, animated: true)
|
|
1077
978
|
|
|
1078
979
|
// Set tint colors but don't override specific colors
|
|
1079
980
|
if tintColor == nil {
|
|
@@ -1082,12 +983,10 @@ fileprivate extension WKWebViewController {
|
|
|
1082
983
|
let textColor = isDarkMode ? UIColor.white : UIColor.black
|
|
1083
984
|
|
|
1084
985
|
navigationController?.navigationBar.tintColor = textColor
|
|
1085
|
-
navigationController?.toolbar.tintColor = textColor
|
|
1086
986
|
progressView?.progressTintColor = textColor
|
|
1087
987
|
} else {
|
|
1088
988
|
progressView?.progressTintColor = tintColor
|
|
1089
989
|
navigationController?.navigationBar.tintColor = tintColor
|
|
1090
|
-
navigationController?.toolbar.tintColor = tintColor
|
|
1091
990
|
}
|
|
1092
991
|
}
|
|
1093
992
|
|
|
@@ -1095,9 +994,7 @@ fileprivate extension WKWebViewController {
|
|
|
1095
994
|
progressView?.progress = 0
|
|
1096
995
|
|
|
1097
996
|
navigationController?.navigationBar.tintColor = previousNavigationBarState.tintColor
|
|
1098
|
-
navigationController?.toolbar.tintColor = previousToolbarState.tintColor
|
|
1099
997
|
|
|
1100
|
-
navigationController?.setToolbarHidden(previousToolbarState.hidden, animated: true)
|
|
1101
998
|
navigationController?.setNavigationBarHidden(previousNavigationBarState.hidden, animated: true)
|
|
1102
999
|
}
|
|
1103
1000
|
|