Repository navigation
fix(browser): only fire browserFinished when the Custom Tab actually terminates #2561
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
49a3964
fix(browser): only fire browserFinished when the Custom Tab actually …
OS-ruimoreiramendes 58d0413
Merge branch 'main' into fix/browser-android-launcher
OS-ruimoreiramendes 1276c03
chore(browser): format java code
OS-ruimoreiramendes f558f06
Merge branch 'main' into fix/browser-android-launcher
OS-pedrogustavobilro 94f0190
Merge branch 'main' into fix/browser-android-launcher
OS-ruimoreiramendes c7ef3c1
clear implementation reference in onDestroy
OS-ruimoreiramendes a7081cf
Merge branch 'main' into fix/browser-android-launcher
OS-pedrogustavobilro d058f53
fix an issue on android <14
OS-ruimoreiramendes 810fc54
Merge branch 'main' into fix/browser-android-launcher
OS-ruimoreiramendes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 31 additions & 14 deletions
45
browser/android/src/main/java/com/capacitorjs/plugins/browser/BrowserControllerActivity.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,52 +1,69 @@ | ||
| package com.capacitorjs.plugins.browser; | ||
|
|
||
| import android.app.Activity; | ||
| import android.content.Intent; | ||
| import android.net.Uri; | ||
| import android.os.Build; | ||
| import android.os.Bundle; | ||
| import androidx.activity.ComponentActivity; | ||
| import androidx.activity.result.ActivityResultLauncher; | ||
| import androidx.activity.result.contract.ActivityResultContracts; | ||
| import androidx.annotation.Nullable; | ||
|
|
||
| public class BrowserControllerActivity extends Activity { | ||
| public class BrowserControllerActivity extends ComponentActivity { | ||
|
|
||
| private boolean isCustomTabsOpen = false; | ||
| private ActivityResultLauncher<Intent> customTabLauncher; | ||
| private Browser implementation; | ||
|
OS-pedrogustavobilro marked this conversation as resolved.
|
||
| private boolean isFirstResume = true; | ||
|
|
||
| @Override | ||
| protected void onCreate(@Nullable Bundle savedInstanceState) { | ||
| super.onCreate(savedInstanceState); | ||
| isCustomTabsOpen = false; | ||
|
|
||
| customTabLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), (result) -> { | ||
| if (implementation != null) { | ||
| implementation.notifyBrowserFinished(); | ||
| } | ||
| finish(); | ||
| }); | ||
|
|
||
| if (BrowserPlugin.browserControllerListener != null) { | ||
| BrowserPlugin.browserControllerListener.onControllerReady(this); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| protected void onNewIntent(Intent intent) { | ||
| super.onNewIntent(intent); | ||
| if (intent.hasExtra("close")) { | ||
| protected void onResume() { | ||
| super.onResume(); | ||
| // On Android <14 the ActivityResult callback is not reliably delivered | ||
| // when the Custom Tab is dismissed from PiP, leaving this launcher | ||
| // stranded on top of the task and freezing the app UI. Finishing on | ||
| // the second resume (fires when control returns from the Custom Tab) releases | ||
| // the task. Skipped on 14+ where the ActivityResult callback handles it. | ||
| if (isFirstResume) { | ||
| isFirstResume = false; | ||
| } else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { | ||
| finish(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| protected void onResume() { | ||
| super.onResume(); | ||
| if (isCustomTabsOpen) { | ||
| isCustomTabsOpen = false; | ||
| protected void onNewIntent(Intent intent) { | ||
| super.onNewIntent(intent); | ||
| if (intent.hasExtra("close")) { | ||
| finish(); | ||
| } else { | ||
| isCustomTabsOpen = true; | ||
| } | ||
| } | ||
|
|
||
| public void open(Browser implementation, Uri url, Integer toolbarColor) { | ||
| this.implementation = implementation; | ||
| implementation.setCustomTabLauncher(customTabLauncher); | ||
| implementation.open(url, toolbarColor); | ||
| } | ||
|
|
||
| @Override | ||
| protected void onDestroy() { | ||
| super.onDestroy(); | ||
| isCustomTabsOpen = false; | ||
| implementation = null; | ||
| BrowserPlugin.setBrowserControllerListener(null); | ||
| } | ||
| } | ||
45 changes: 0 additions & 45 deletions
45
browser/android/src/main/java/com/capacitorjs/plugins/browser/EventGroup.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.