Skip to content

Commit b2a169b

Browse files
authored
Merge pull request #2743 from brandonpage/fix_back_button
Make shouldShowBackButton value open.
2 parents e80d820 + afd5944 commit b2a169b

3 files changed

Lines changed: 28 additions & 21 deletions

File tree

libs/SalesforceSDK/src/com/salesforce/androidsdk/ui/LoginActivity.kt

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -603,26 +603,33 @@ open class LoginActivity : FragmentActivity() {
603603
}
604604
}
605605

606-
private fun handleBackBehavior() {
607-
// If app is using Native Login this activity is a fallback and can be dismissed.
608-
if (SalesforceSDKManager.getInstance().nativeLoginActivity != null) {
609-
setResult(RESULT_CANCELED)
610-
finish()
611-
return // If we don't call return here moveTaskToBack can also be called below.
612-
}
606+
internal fun handleBackBehavior() {
607+
with(SalesforceSDKManager.getInstance()) {
608+
// If app is using Native Login this activity is a fallback and can be dismissed.
609+
if (nativeLoginActivity != null) {
610+
setResult(RESULT_CANCELED)
611+
finish()
612+
return // If we don't call return here moveTaskToBack can also be called below.
613+
}
613614

614-
// Do nothing if locked
615-
if (SalesforceSDKManager.getInstance().biometricAuthenticationManager?.locked == false) {
616-
/*
617-
* If there are no accounts signed in, the login screen needs to go
618-
* away and go back to the home screen. However, if the login screen
619-
* has been brought up from the switcher screen, the back button
620-
* should take the user back to the previous screen.
621-
*/
622-
wasBackgrounded = true
623-
when (SalesforceSDKManager.getInstance().userAccountManager.authenticatedUsers) {
624-
null -> moveTaskToBack(true)
625-
else -> finish()
615+
// Do nothing if locked
616+
if (biometricAuthenticationManager?.locked == false) {
617+
/*
618+
* If there are no accounts signed in, the login screen needs to go
619+
* away and go back to the home screen. However, if the login screen
620+
* has been brought up from the switcher screen, the back button
621+
* should take the user back to the previous screen.
622+
*
623+
* shouldShowBackButton normally checks for authenticated users,
624+
* but trust the app if it has been overridden.
625+
*/
626+
wasBackgrounded = true
627+
if (userAccountManager.authenticatedUsers != null || viewModel.shouldShowBackButton) {
628+
setResult(RESULT_CANCELED)
629+
finish()
630+
} else {
631+
moveTaskToBack(true)
632+
}
626633
}
627634
}
628635
}

libs/SalesforceSDK/src/com/salesforce/androidsdk/ui/LoginViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ open class LoginViewModel(val bootConfig: BootConfig) : ViewModel() {
181181
open val singleServerCustomTabActivity = false
182182

183183
/** Value representing if the back button should be shown on the login view. */
184-
val shouldShowBackButton = with(SalesforceSDKManager.getInstance()) {
184+
open val shouldShowBackButton = with(SalesforceSDKManager.getInstance()) {
185185
!(userAccountManager.authenticatedUsers.isNullOrEmpty() || biometricAuthenticationManager?.locked ?: false)
186186
}
187187

libs/SalesforceSDK/src/com/salesforce/androidsdk/ui/components/LoginView.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ fun LoginView() {
151151
clearCookies = { viewModel.clearCookies() },
152152
reloadWebView = { viewModel.reloadWebView() },
153153
shouldShowBackButton = viewModel.shouldShowBackButton,
154-
finish = { activity.finish() },
154+
finish = { activity.handleBackBehavior() },
155155
)
156156
}
157157

0 commit comments

Comments
 (0)