@capawesome/capacitor-in-app-browser 0.0.1 → 0.0.2

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.
Files changed (26) hide show
  1. package/README.md +108 -48
  2. package/android/src/main/java/io/capawesome/capacitorjs/plugins/inappbrowser/InAppBrowser.java +25 -5
  3. package/android/src/main/java/io/capawesome/capacitorjs/plugins/inappbrowser/InAppBrowserPlugin.java +37 -10
  4. package/android/src/main/java/io/capawesome/capacitorjs/plugins/inappbrowser/classes/WebViewDialog.java +40 -2
  5. package/android/src/main/java/io/capawesome/capacitorjs/plugins/inappbrowser/classes/events/{MessageReceivedEvent.java → BrowserMessageReceivedEvent.java} +2 -2
  6. package/android/src/main/java/io/capawesome/capacitorjs/plugins/inappbrowser/classes/events/{BrowserPageNavigationCompletedEvent.java → BrowserNavigationCompletedEvent.java} +2 -2
  7. package/android/src/main/java/io/capawesome/capacitorjs/plugins/inappbrowser/classes/events/BrowserUrlChangedEvent.java +23 -0
  8. package/android/src/main/java/io/capawesome/capacitorjs/plugins/inappbrowser/classes/options/OpenInWebViewOptions.java +7 -0
  9. package/dist/docs.json +114 -24
  10. package/dist/esm/definitions.d.ts +62 -12
  11. package/dist/esm/definitions.js.map +1 -1
  12. package/dist/esm/web.d.ts +1 -0
  13. package/dist/esm/web.js +3 -0
  14. package/dist/esm/web.js.map +1 -1
  15. package/dist/plugin.cjs.js +3 -0
  16. package/dist/plugin.cjs.js.map +1 -1
  17. package/dist/plugin.js +3 -0
  18. package/dist/plugin.js.map +1 -1
  19. package/ios/Plugin/Classes/Events/{MessageReceivedEvent.swift → BrowserMessageReceivedEvent.swift} +1 -1
  20. package/ios/Plugin/Classes/Events/{BrowserPageNavigationCompletedEvent.swift → BrowserNavigationCompletedEvent.swift} +1 -1
  21. package/ios/Plugin/Classes/Events/BrowserUrlChangedEvent.swift +16 -0
  22. package/ios/Plugin/Classes/Options/OpenInWebViewOptions.swift +2 -0
  23. package/ios/Plugin/Classes/WebViewController.swift +18 -2
  24. package/ios/Plugin/InAppBrowser.swift +45 -4
  25. package/ios/Plugin/InAppBrowserPlugin.swift +25 -9
  26. package/package.json +2 -2
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # @capawesome/capacitor-in-app-browser
1
+ # Capacitor In-App Browser Plugin
2
2
 
3
3
  Capacitor plugin to open URLs in the external browser, the system browser or an embedded web view.
4
4
 
@@ -159,14 +159,17 @@ const addListeners = async () => {
159
159
  await InAppBrowser.addListener('browserClosed', () => {
160
160
  console.log('Browser closed');
161
161
  });
162
- await InAppBrowser.addListener('browserPageLoaded', () => {
163
- console.log('Browser page loaded');
162
+ await InAppBrowser.addListener('browserMessageReceived', event => {
163
+ console.log('Message received', event.data);
164
164
  });
165
- await InAppBrowser.addListener('browserPageNavigationCompleted', event => {
165
+ await InAppBrowser.addListener('browserNavigationCompleted', event => {
166
166
  console.log('Navigation completed', event.url);
167
167
  });
168
- await InAppBrowser.addListener('messageReceived', event => {
169
- console.log('Message received', event.data);
168
+ await InAppBrowser.addListener('browserPageLoaded', () => {
169
+ console.log('Browser page loaded');
170
+ });
171
+ await InAppBrowser.addListener('browserUrlChanged', event => {
172
+ console.log('URL changed', event.url);
170
173
  });
171
174
  };
172
175
  ```
@@ -184,10 +187,12 @@ const addListeners = async () => {
184
187
  * [`openInSystemBrowser(...)`](#openinsystembrowser)
185
188
  * [`openInWebView(...)`](#openinwebview)
186
189
  * [`postMessage(...)`](#postmessage)
190
+ * [`show()`](#show)
187
191
  * [`addListener('browserClosed', ...)`](#addlistenerbrowserclosed-)
192
+ * [`addListener('browserMessageReceived', ...)`](#addlistenerbrowsermessagereceived-)
193
+ * [`addListener('browserNavigationCompleted', ...)`](#addlistenerbrowsernavigationcompleted-)
188
194
  * [`addListener('browserPageLoaded', ...)`](#addlistenerbrowserpageloaded-)
189
- * [`addListener('browserPageNavigationCompleted', ...)`](#addlistenerbrowserpagenavigationcompleted-)
190
- * [`addListener('messageReceived', ...)`](#addlistenermessagereceived-)
195
+ * [`addListener('browserUrlChanged', ...)`](#addlistenerbrowserurlchanged-)
191
196
  * [`removeAllListeners()`](#removealllisteners)
192
197
  * [Interfaces](#interfaces)
193
198
  * [Type Aliases](#type-aliases)
@@ -375,6 +380,24 @@ Only available on Android and iOS.
375
380
  --------------------
376
381
 
377
382
 
383
+ ### show()
384
+
385
+ ```typescript
386
+ show() => Promise<void>
387
+ ```
388
+
389
+ Show the web view if it was opened with `visible: false`.
390
+
391
+ This method is only available for browsers opened with
392
+ `openInWebView(...)`.
393
+
394
+ Only available on Android and iOS.
395
+
396
+ **Since:** 0.1.0
397
+
398
+ --------------------
399
+
400
+
378
401
  ### addListener('browserClosed', ...)
379
402
 
380
403
  ```typescript
@@ -397,23 +420,23 @@ Only available on Android and iOS.
397
420
  --------------------
398
421
 
399
422
 
400
- ### addListener('browserPageLoaded', ...)
423
+ ### addListener('browserMessageReceived', ...)
401
424
 
402
425
  ```typescript
403
- addListener(eventName: 'browserPageLoaded', listenerFunc: () => void) => Promise<PluginListenerHandle>
426
+ addListener(eventName: 'browserMessageReceived', listenerFunc: (event: BrowserMessageReceivedEvent) => void) => Promise<PluginListenerHandle>
404
427
  ```
405
428
 
406
- Called when the initial page of the browser has finished loading.
429
+ Called when the web page posts a message to the app using the injected
430
+ `window.CapacitorInAppBrowser.postMessage(...)` function.
407
431
 
408
- On Android, this event is only emitted for browsers opened with
409
- `openInWebView(...)`.
432
+ This event is only emitted for browsers opened with `openInWebView(...)`.
410
433
 
411
434
  Only available on Android and iOS.
412
435
 
413
- | Param | Type |
414
- | ------------------ | -------------------------------- |
415
- | **`eventName`** | <code>'browserPageLoaded'</code> |
416
- | **`listenerFunc`** | <code>() =&gt; void</code> |
436
+ | Param | Type |
437
+ | ------------------ | ------------------------------------------------------------------------------------------------------- |
438
+ | **`eventName`** | <code>'browserMessageReceived'</code> |
439
+ | **`listenerFunc`** | <code>(event: <a href="#browsermessagereceivedevent">BrowserMessageReceivedEvent</a>) =&gt; void</code> |
417
440
 
418
441
  **Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>
419
442
 
@@ -422,10 +445,10 @@ Only available on Android and iOS.
422
445
  --------------------
423
446
 
424
447
 
425
- ### addListener('browserPageNavigationCompleted', ...)
448
+ ### addListener('browserNavigationCompleted', ...)
426
449
 
427
450
  ```typescript
428
- addListener(eventName: 'browserPageNavigationCompleted', listenerFunc: (event: BrowserPageNavigationCompletedEvent) => void) => Promise<PluginListenerHandle>
451
+ addListener(eventName: 'browserNavigationCompleted', listenerFunc: (event: BrowserNavigationCompletedEvent) => void) => Promise<PluginListenerHandle>
429
452
  ```
430
453
 
431
454
  Called when a page navigation has been completed in the web view.
@@ -434,10 +457,10 @@ This event is only emitted for browsers opened with `openInWebView(...)`.
434
457
 
435
458
  Only available on Android and iOS.
436
459
 
437
- | Param | Type |
438
- | ------------------ | ----------------------------------------------------------------------------------------------------------------------- |
439
- | **`eventName`** | <code>'browserPageNavigationCompleted'</code> |
440
- | **`listenerFunc`** | <code>(event: <a href="#browserpagenavigationcompletedevent">BrowserPageNavigationCompletedEvent</a>) =&gt; void</code> |
460
+ | Param | Type |
461
+ | ------------------ | --------------------------------------------------------------------------------------------------------------- |
462
+ | **`eventName`** | <code>'browserNavigationCompleted'</code> |
463
+ | **`listenerFunc`** | <code>(event: <a href="#browsernavigationcompletedevent">BrowserNavigationCompletedEvent</a>) =&gt; void</code> |
441
464
 
442
465
  **Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>
443
466
 
@@ -446,23 +469,52 @@ Only available on Android and iOS.
446
469
  --------------------
447
470
 
448
471
 
449
- ### addListener('messageReceived', ...)
472
+ ### addListener('browserPageLoaded', ...)
450
473
 
451
474
  ```typescript
452
- addListener(eventName: 'messageReceived', listenerFunc: (event: MessageReceivedEvent) => void) => Promise<PluginListenerHandle>
475
+ addListener(eventName: 'browserPageLoaded', listenerFunc: () => void) => Promise<PluginListenerHandle>
453
476
  ```
454
477
 
455
- Called when the web page posts a message to the app using the injected
456
- `window.CapacitorInAppBrowser.postMessage(...)` function.
478
+ Called when the initial page of the browser has finished loading.
479
+
480
+ On Android, this event is only emitted for browsers opened with
481
+ `openInWebView(...)`.
482
+
483
+ Only available on Android and iOS.
484
+
485
+ | Param | Type |
486
+ | ------------------ | -------------------------------- |
487
+ | **`eventName`** | <code>'browserPageLoaded'</code> |
488
+ | **`listenerFunc`** | <code>() =&gt; void</code> |
489
+
490
+ **Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>
491
+
492
+ **Since:** 0.1.0
493
+
494
+ --------------------
495
+
496
+
497
+ ### addListener('browserUrlChanged', ...)
498
+
499
+ ```typescript
500
+ addListener(eventName: 'browserUrlChanged', listenerFunc: (event: BrowserUrlChangedEvent) => void) => Promise<PluginListenerHandle>
501
+ ```
502
+
503
+ Called when the current URL of the web view changes, e.g. when the user
504
+ navigates to a new page, a server redirect occurs, or a single-page
505
+ application updates the browser history.
506
+
507
+ This event is also emitted for the initial URL and fires earlier than
508
+ `browserNavigationCompleted`.
457
509
 
458
510
  This event is only emitted for browsers opened with `openInWebView(...)`.
459
511
 
460
512
  Only available on Android and iOS.
461
513
 
462
- | Param | Type |
463
- | ------------------ | ----------------------------------------------------------------------------------------- |
464
- | **`eventName`** | <code>'messageReceived'</code> |
465
- | **`listenerFunc`** | <code>(event: <a href="#messagereceivedevent">MessageReceivedEvent</a>) =&gt; void</code> |
514
+ | Param | Type |
515
+ | ------------------ | --------------------------------------------------------------------------------------------- |
516
+ | **`eventName`** | <code>'browserUrlChanged'</code> |
517
+ | **`listenerFunc`** | <code>(event: <a href="#browserurlchangedevent">BrowserUrlChangedEvent</a>) =&gt; void</code> |
466
518
 
467
519
  **Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>
468
520
 
@@ -552,16 +604,17 @@ Remove all listeners for this plugin.
552
604
 
553
605
  #### OpenInWebViewOptions
554
606
 
555
- | Prop | Type | Description | Default | Since |
556
- | ------------------------------------- | ----------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ----- |
557
- | **`android`** | <code><a href="#openinwebviewandroidoptions">OpenInWebViewAndroidOptions</a></code> | Options that are only applied on Android. Only available on Android. | | 0.1.0 |
558
- | **`dataStore`** | <code><a href="#webviewdatastore">WebViewDataStore</a></code> | The data store to use for the web view. On Android, this option is ignored. The web view always uses the app-global (`shared`) data store. Only available on iOS. | <code>'shared'</code> | 0.1.0 |
559
- | **`headers`** | <code>{ [key: string]: string; }</code> | Additional HTTP headers to send with the initial request. | | 0.1.0 |
560
- | **`ios`** | <code><a href="#openinwebviewiosoptions">OpenInWebViewIosOptions</a></code> | Options that are only applied on iOS. Only available on iOS. | | 0.1.0 |
561
- | **`mediaPlaybackRequiresUserAction`** | <code>boolean</code> | Whether or not media playback requires user action. | <code>false</code> | 0.1.0 |
562
- | **`toolbar`** | <code><a href="#webviewtoolbaroptions">WebViewToolbarOptions</a></code> | Options for the toolbar of the web view. | | 0.1.0 |
563
- | **`url`** | <code>string</code> | The URL to open in the web view. | | 0.1.0 |
564
- | **`userAgent`** | <code>string</code> | The custom user agent to use for the web view. | | 0.1.0 |
607
+ | Prop | Type | Description | Default | Since |
608
+ | ------------------------------------- | ----------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------- | ----- |
609
+ | **`android`** | <code><a href="#openinwebviewandroidoptions">OpenInWebViewAndroidOptions</a></code> | Options that are only applied on Android. Only available on Android. | | 0.1.0 |
610
+ | **`dataStore`** | <code><a href="#webviewdatastore">WebViewDataStore</a></code> | The data store to use for the web view. On Android, this option is ignored. The web view always uses the app-global (`shared`) data store. Only available on iOS. | <code>'shared'</code> | 0.1.0 |
611
+ | **`headers`** | <code>{ [key: string]: string; }</code> | Additional HTTP headers to send with the initial request. | | 0.1.0 |
612
+ | **`ios`** | <code><a href="#openinwebviewiosoptions">OpenInWebViewIosOptions</a></code> | Options that are only applied on iOS. Only available on iOS. | | 0.1.0 |
613
+ | **`mediaPlaybackRequiresUserAction`** | <code>boolean</code> | Whether or not media playback requires user action. | <code>false</code> | 0.1.0 |
614
+ | **`toolbar`** | <code><a href="#webviewtoolbaroptions">WebViewToolbarOptions</a></code> | Options for the toolbar of the web view. | | 0.1.0 |
615
+ | **`url`** | <code>string</code> | The URL to open in the web view. | | 0.1.0 |
616
+ | **`userAgent`** | <code>string</code> | The custom user agent to use for the web view. | | 0.1.0 |
617
+ | **`visible`** | <code>boolean</code> | Whether or not the web view is presented when opened. If `false`, the web view loads the URL in the background and stays hidden until `show()` is called. The `browserPageLoaded` event is still emitted and `close()` can be called while the web view is hidden. | <code>true</code> | 0.1.0 |
565
618
 
566
619
 
567
620
  #### OpenInWebViewAndroidOptions
@@ -608,18 +661,25 @@ Remove all listeners for this plugin.
608
661
  | **`remove`** | <code>() =&gt; Promise&lt;void&gt;</code> |
609
662
 
610
663
 
611
- #### BrowserPageNavigationCompletedEvent
664
+ #### BrowserMessageReceivedEvent
665
+
666
+ | Prop | Type | Description | Since |
667
+ | ---------- | -------------------- | ---------------------------------------- | ----- |
668
+ | **`data`** | <code>unknown</code> | The message data posted by the web page. | 0.1.0 |
669
+
670
+
671
+ #### BrowserNavigationCompletedEvent
612
672
 
613
673
  | Prop | Type | Description | Since |
614
674
  | --------- | ------------------- | ------------------------------------------ | ----- |
615
675
  | **`url`** | <code>string</code> | The URL of the page that was navigated to. | 0.1.0 |
616
676
 
617
677
 
618
- #### MessageReceivedEvent
678
+ #### BrowserUrlChangedEvent
619
679
 
620
- | Prop | Type | Description | Since |
621
- | ---------- | -------------------- | ---------------------------------------- | ----- |
622
- | **`data`** | <code>unknown</code> | The message data posted by the web page. | 0.1.0 |
680
+ | Prop | Type | Description | Since |
681
+ | --------- | ------------------- | ---------------------------- | ----- |
682
+ | **`url`** | <code>string</code> | The new URL of the web view. | 0.1.0 |
623
683
 
624
684
 
625
685
  ### Type Aliases
@@ -661,7 +721,7 @@ The web page can post a message to the app using the injected `window.CapacitorI
661
721
  window.CapacitorInAppBrowser.postMessage({ name: 'Capawesome' });
662
722
  ```
663
723
 
664
- The app receives the message via the `messageReceived` event.
724
+ The app receives the message via the `browserMessageReceived` event.
665
725
 
666
726
  ### From the app to the web page
667
727
 
@@ -677,7 +737,7 @@ window.addEventListener('capacitorInAppBrowserMessage', event => {
677
737
 
678
738
  The three browser modes behave differently on each platform. Keep the following differences in mind:
679
739
 
680
- - **System browser**: Tracking the visited URLs is not possible by design. If you need the `browserPageNavigationCompleted` event, use the `openInWebView(...)` method instead. On Android, the `browserPageLoaded` event is not emitted for the system browser and the `browserClosed` event is emitted when the user returns to the app.
740
+ - **System browser**: Tracking the visited URLs is not possible by design. If you need the `browserNavigationCompleted` or `browserUrlChanged` event, use the `openInWebView(...)` method instead. On Android, the `browserPageLoaded` event is not emitted for the system browser and the `browserClosed` event is emitted when the user returns to the app.
681
741
  - **Embedded web view**: The web view always uses the app-global (`shared`) data store on Android. The `dataStore` option is only supported on iOS. On iOS, hiding the toolbar removes the close button, so the browser can then only be closed using the `close(...)` method.
682
742
  - **External browser**: The browser is opened in a separate app. For this reason, no events are emitted and the `close(...)` method has no effect.
683
743
 
@@ -11,8 +11,9 @@ import androidx.browser.customtabs.CustomTabColorSchemeParams;
11
11
  import androidx.browser.customtabs.CustomTabsIntent;
12
12
  import io.capawesome.capacitorjs.plugins.inappbrowser.classes.CustomExceptions;
13
13
  import io.capawesome.capacitorjs.plugins.inappbrowser.classes.WebViewDialog;
14
- import io.capawesome.capacitorjs.plugins.inappbrowser.classes.events.BrowserPageNavigationCompletedEvent;
15
- import io.capawesome.capacitorjs.plugins.inappbrowser.classes.events.MessageReceivedEvent;
14
+ import io.capawesome.capacitorjs.plugins.inappbrowser.classes.events.BrowserMessageReceivedEvent;
15
+ import io.capawesome.capacitorjs.plugins.inappbrowser.classes.events.BrowserNavigationCompletedEvent;
16
+ import io.capawesome.capacitorjs.plugins.inappbrowser.classes.events.BrowserUrlChangedEvent;
16
17
  import io.capawesome.capacitorjs.plugins.inappbrowser.classes.options.ExecuteScriptOptions;
17
18
  import io.capawesome.capacitorjs.plugins.inappbrowser.classes.options.GetCookiesOptions;
18
19
  import io.capawesome.capacitorjs.plugins.inappbrowser.classes.options.OpenInExternalBrowserOptions;
@@ -199,14 +200,19 @@ public class InAppBrowser {
199
200
  handleMessageReceived(data);
200
201
  }
201
202
 
203
+ @Override
204
+ public void onNavigationCompleted(@NonNull String url) {
205
+ plugin.notifyBrowserNavigationCompletedListeners(new BrowserNavigationCompletedEvent(url));
206
+ }
207
+
202
208
  @Override
203
209
  public void onPageLoaded() {
204
210
  plugin.notifyBrowserPageLoadedListeners();
205
211
  }
206
212
 
207
213
  @Override
208
- public void onPageNavigationCompleted(@NonNull String url) {
209
- plugin.notifyBrowserPageNavigationCompletedListeners(new BrowserPageNavigationCompletedEvent(url));
214
+ public void onUrlChanged(@NonNull String url) {
215
+ plugin.notifyBrowserUrlChangedListeners(new BrowserUrlChangedEvent(url));
210
216
  }
211
217
  }
212
218
  );
@@ -230,6 +236,20 @@ public class InAppBrowser {
230
236
  });
231
237
  }
232
238
 
239
+ public void show(@NonNull EmptyCallback callback) {
240
+ plugin
241
+ .getActivity()
242
+ .runOnUiThread(() -> {
243
+ WebViewDialog webViewDialog = this.webViewDialog;
244
+ if (webViewDialog == null) {
245
+ callback.error(CustomExceptions.NO_BROWSER_OPEN);
246
+ return;
247
+ }
248
+ webViewDialog.showWebView();
249
+ callback.success();
250
+ });
251
+ }
252
+
233
253
  private void handleMessageReceived(@NonNull String data) {
234
254
  Object value;
235
255
  try {
@@ -237,6 +257,6 @@ public class InAppBrowser {
237
257
  } catch (JSONException exception) {
238
258
  value = data;
239
259
  }
240
- plugin.notifyMessageReceivedListeners(new MessageReceivedEvent(value));
260
+ plugin.notifyBrowserMessageReceivedListeners(new BrowserMessageReceivedEvent(value));
241
261
  }
242
262
  }
@@ -9,8 +9,9 @@ import com.getcapacitor.PluginCall;
9
9
  import com.getcapacitor.PluginMethod;
10
10
  import com.getcapacitor.annotation.CapacitorPlugin;
11
11
  import io.capawesome.capacitorjs.plugins.inappbrowser.classes.CustomException;
12
- import io.capawesome.capacitorjs.plugins.inappbrowser.classes.events.BrowserPageNavigationCompletedEvent;
13
- import io.capawesome.capacitorjs.plugins.inappbrowser.classes.events.MessageReceivedEvent;
12
+ import io.capawesome.capacitorjs.plugins.inappbrowser.classes.events.BrowserMessageReceivedEvent;
13
+ import io.capawesome.capacitorjs.plugins.inappbrowser.classes.events.BrowserNavigationCompletedEvent;
14
+ import io.capawesome.capacitorjs.plugins.inappbrowser.classes.events.BrowserUrlChangedEvent;
14
15
  import io.capawesome.capacitorjs.plugins.inappbrowser.classes.options.ExecuteScriptOptions;
15
16
  import io.capawesome.capacitorjs.plugins.inappbrowser.classes.options.GetCookiesOptions;
16
17
  import io.capawesome.capacitorjs.plugins.inappbrowser.classes.options.OpenInExternalBrowserOptions;
@@ -27,9 +28,10 @@ import io.capawesome.capacitorjs.plugins.inappbrowser.interfaces.Result;
27
28
  public class InAppBrowserPlugin extends Plugin {
28
29
 
29
30
  public static final String EVENT_BROWSER_CLOSED = "browserClosed";
31
+ public static final String EVENT_BROWSER_MESSAGE_RECEIVED = "browserMessageReceived";
32
+ public static final String EVENT_BROWSER_NAVIGATION_COMPLETED = "browserNavigationCompleted";
30
33
  public static final String EVENT_BROWSER_PAGE_LOADED = "browserPageLoaded";
31
- public static final String EVENT_BROWSER_PAGE_NAVIGATION_COMPLETED = "browserPageNavigationCompleted";
32
- public static final String EVENT_MESSAGE_RECEIVED = "messageReceived";
34
+ public static final String EVENT_BROWSER_URL_CHANGED = "browserUrlChanged";
33
35
  public static final String TAG = "InAppBrowserPlugin";
34
36
 
35
37
  private static final String ERROR_UNKNOWN_ERROR = "An unknown error occurred.";
@@ -152,16 +154,20 @@ public class InAppBrowserPlugin extends Plugin {
152
154
  notifyListeners(EVENT_BROWSER_CLOSED, new JSObject());
153
155
  }
154
156
 
155
- public void notifyBrowserPageLoadedListeners() {
156
- notifyListeners(EVENT_BROWSER_PAGE_LOADED, new JSObject());
157
+ public void notifyBrowserMessageReceivedListeners(@NonNull BrowserMessageReceivedEvent event) {
158
+ notifyListeners(EVENT_BROWSER_MESSAGE_RECEIVED, event.toJSObject());
157
159
  }
158
160
 
159
- public void notifyBrowserPageNavigationCompletedListeners(@NonNull BrowserPageNavigationCompletedEvent event) {
160
- notifyListeners(EVENT_BROWSER_PAGE_NAVIGATION_COMPLETED, event.toJSObject());
161
+ public void notifyBrowserNavigationCompletedListeners(@NonNull BrowserNavigationCompletedEvent event) {
162
+ notifyListeners(EVENT_BROWSER_NAVIGATION_COMPLETED, event.toJSObject());
161
163
  }
162
164
 
163
- public void notifyMessageReceivedListeners(@NonNull MessageReceivedEvent event) {
164
- notifyListeners(EVENT_MESSAGE_RECEIVED, event.toJSObject());
165
+ public void notifyBrowserPageLoadedListeners() {
166
+ notifyListeners(EVENT_BROWSER_PAGE_LOADED, new JSObject());
167
+ }
168
+
169
+ public void notifyBrowserUrlChangedListeners(@NonNull BrowserUrlChangedEvent event) {
170
+ notifyListeners(EVENT_BROWSER_URL_CHANGED, event.toJSObject());
165
171
  }
166
172
 
167
173
  @PluginMethod
@@ -252,6 +258,27 @@ public class InAppBrowserPlugin extends Plugin {
252
258
  }
253
259
  }
254
260
 
261
+ @PluginMethod
262
+ public void show(PluginCall call) {
263
+ try {
264
+ EmptyCallback callback = new EmptyCallback() {
265
+ @Override
266
+ public void success() {
267
+ resolveCall(call);
268
+ }
269
+
270
+ @Override
271
+ public void error(@NonNull Exception exception) {
272
+ rejectCall(call, exception);
273
+ }
274
+ };
275
+
276
+ implementation.show(callback);
277
+ } catch (Exception exception) {
278
+ rejectCall(call, exception);
279
+ }
280
+ }
281
+
255
282
  @Override
256
283
  protected void handleOnPause() {
257
284
  implementation.handleOnPause();
@@ -12,7 +12,10 @@ import android.os.Bundle;
12
12
  import android.text.TextUtils;
13
13
  import android.util.TypedValue;
14
14
  import android.view.Gravity;
15
+ import android.view.View;
15
16
  import android.view.ViewGroup;
17
+ import android.view.Window;
18
+ import android.view.WindowManager;
16
19
  import android.webkit.JavascriptInterface;
17
20
  import android.webkit.PermissionRequest;
18
21
  import android.webkit.ValueCallback;
@@ -35,8 +38,9 @@ public class WebViewDialog extends Dialog {
35
38
  public interface Listener {
36
39
  void onClosed(@NonNull WebViewDialog dialog);
37
40
  void onMessageReceived(@NonNull String data);
41
+ void onNavigationCompleted(@NonNull String url);
38
42
  void onPageLoaded();
39
- void onPageNavigationCompleted(@NonNull String url);
43
+ void onUrlChanged(@NonNull String url);
40
44
  }
41
45
 
42
46
  private static final String BRIDGE_JAVASCRIPT =
@@ -52,6 +56,9 @@ public class WebViewDialog extends Dialog {
52
56
 
53
57
  private boolean initialLoadNotified = false;
54
58
 
59
+ @Nullable
60
+ private String lastNotifiedUrl;
61
+
55
62
  @NonNull
56
63
  private final Listener listener;
57
64
 
@@ -111,6 +118,15 @@ public class WebViewDialog extends Dialog {
111
118
  }
112
119
  }
113
120
 
121
+ public void showWebView() {
122
+ Window window = getWindow();
123
+ if (window == null) {
124
+ return;
125
+ }
126
+ window.clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
127
+ window.getDecorView().setVisibility(View.VISIBLE);
128
+ }
129
+
114
130
  @Override
115
131
  protected void onCreate(@Nullable Bundle savedInstanceState) {
116
132
  super.onCreate(savedInstanceState);
@@ -118,6 +134,9 @@ public class WebViewDialog extends Dialog {
118
134
  this.webView = webView;
119
135
  setContentView(createContentView(webView));
120
136
  setOnDismissListener(dialog -> handleDismiss());
137
+ if (!options.getVisible()) {
138
+ hideWebView();
139
+ }
121
140
  webView.loadUrl(options.getUri().toString(), options.getHeaders());
122
141
  }
123
142
 
@@ -223,6 +242,7 @@ public class WebViewDialog extends Dialog {
223
242
  @Override
224
243
  public void onPageStarted(WebView view, String url, Bitmap favicon) {
225
244
  injectBridgeJavaScript();
245
+ handleUrlChanged(url);
226
246
  }
227
247
 
228
248
  @Override
@@ -235,7 +255,7 @@ public class WebViewDialog extends Dialog {
235
255
  listener.onPageLoaded();
236
256
  }
237
257
  if (url != null) {
238
- listener.onPageNavigationCompleted(url);
258
+ listener.onNavigationCompleted(url);
239
259
  }
240
260
  }
241
261
 
@@ -243,6 +263,7 @@ public class WebViewDialog extends Dialog {
243
263
  public void doUpdateVisitedHistory(WebView view, String url, boolean isReload) {
244
264
  updateNavigationButtons();
245
265
  updateTitle();
266
+ handleUrlChanged(url);
246
267
  }
247
268
  }
248
269
  );
@@ -293,10 +314,27 @@ public class WebViewDialog extends Dialog {
293
314
  }
294
315
  }
295
316
 
317
+ private void handleUrlChanged(@Nullable String url) {
318
+ if (url == null || url.equals(lastNotifiedUrl)) {
319
+ return;
320
+ }
321
+ lastNotifiedUrl = url;
322
+ listener.onUrlChanged(url);
323
+ }
324
+
296
325
  private boolean hasPermission(@NonNull String permission) {
297
326
  return ContextCompat.checkSelfPermission(getContext(), permission) == PackageManager.PERMISSION_GRANTED;
298
327
  }
299
328
 
329
+ private void hideWebView() {
330
+ Window window = getWindow();
331
+ if (window == null) {
332
+ return;
333
+ }
334
+ window.addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
335
+ window.getDecorView().setVisibility(View.INVISIBLE);
336
+ }
337
+
300
338
  private void injectBridgeJavaScript() {
301
339
  WebView webView = this.webView;
302
340
  if (webView != null) {
@@ -4,12 +4,12 @@ import androidx.annotation.NonNull;
4
4
  import com.getcapacitor.JSObject;
5
5
  import io.capawesome.capacitorjs.plugins.inappbrowser.interfaces.Result;
6
6
 
7
- public class MessageReceivedEvent implements Result {
7
+ public class BrowserMessageReceivedEvent implements Result {
8
8
 
9
9
  @NonNull
10
10
  private final Object data;
11
11
 
12
- public MessageReceivedEvent(@NonNull Object data) {
12
+ public BrowserMessageReceivedEvent(@NonNull Object data) {
13
13
  this.data = data;
14
14
  }
15
15
 
@@ -4,12 +4,12 @@ import androidx.annotation.NonNull;
4
4
  import com.getcapacitor.JSObject;
5
5
  import io.capawesome.capacitorjs.plugins.inappbrowser.interfaces.Result;
6
6
 
7
- public class BrowserPageNavigationCompletedEvent implements Result {
7
+ public class BrowserNavigationCompletedEvent implements Result {
8
8
 
9
9
  @NonNull
10
10
  private final String url;
11
11
 
12
- public BrowserPageNavigationCompletedEvent(@NonNull String url) {
12
+ public BrowserNavigationCompletedEvent(@NonNull String url) {
13
13
  this.url = url;
14
14
  }
15
15
 
@@ -0,0 +1,23 @@
1
+ package io.capawesome.capacitorjs.plugins.inappbrowser.classes.events;
2
+
3
+ import androidx.annotation.NonNull;
4
+ import com.getcapacitor.JSObject;
5
+ import io.capawesome.capacitorjs.plugins.inappbrowser.interfaces.Result;
6
+
7
+ public class BrowserUrlChangedEvent implements Result {
8
+
9
+ @NonNull
10
+ private final String url;
11
+
12
+ public BrowserUrlChangedEvent(@NonNull String url) {
13
+ this.url = url;
14
+ }
15
+
16
+ @Override
17
+ @NonNull
18
+ public JSObject toJSObject() {
19
+ JSObject result = new JSObject();
20
+ result.put("url", url);
21
+ return result;
22
+ }
23
+ }
@@ -30,6 +30,8 @@ public class OpenInWebViewOptions {
30
30
  @Nullable
31
31
  private final String userAgent;
32
32
 
33
+ private final boolean visible;
34
+
33
35
  public OpenInWebViewOptions(@NonNull PluginCall call) throws Exception {
34
36
  JSObject androidOptions = call.getObject("android");
35
37
  this.allowZoom = androidOptions != null && androidOptions.optBoolean("allowZoom", false);
@@ -40,6 +42,7 @@ public class OpenInWebViewOptions {
40
42
  this.toolbar = new WebViewToolbarOptions(call.getObject("toolbar"));
41
43
  this.uri = OpenInWebViewOptions.getUriFromCall(call);
42
44
  this.userAgent = call.getString("userAgent");
45
+ this.visible = call.getBoolean("visible", true);
43
46
  }
44
47
 
45
48
  public boolean getAllowZoom() {
@@ -78,6 +81,10 @@ public class OpenInWebViewOptions {
78
81
  return userAgent;
79
82
  }
80
83
 
84
+ public boolean getVisible() {
85
+ return visible;
86
+ }
87
+
81
88
  @NonNull
82
89
  private static Map<String, String> getHeadersFromCall(@NonNull PluginCall call) {
83
90
  Map<String, String> headers = new HashMap<>();