-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add solution examples for
popBackStack()
blank screen issues
- Loading branch information
1 parent
13dda76
commit 9d4e0ed
Showing
11 changed files
with
490 additions
and
58 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
31 changes: 31 additions & 0 deletions
31
base/src/main/java/org/imaginativeworld/whynotcompose/base/extensions/ExtNavController.kt
This file contains 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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.imaginativeworld.whynotcompose.base.extensions | ||
|
||
import android.app.Activity | ||
import android.content.Context | ||
import androidx.lifecycle.Lifecycle | ||
import androidx.navigation.NavController | ||
|
||
/** | ||
* Attempts to pop the controller's back stack. | ||
* If the back stack is empty, it will finish the activity. | ||
* | ||
* @param context Activity context. | ||
*/ | ||
fun NavController.popBackStackOrFinish(context: Context) { | ||
if (!popBackStack()) { | ||
(context as Activity).finish() | ||
} | ||
} | ||
|
||
/** | ||
* Attempts to pop the controller's back stack. | ||
* It will check the current lifecycle and only allow the pop | ||
* if the current state is RESUMED. | ||
* | ||
* See [reference](https://github.com/google/accompanist/issues/1408#issuecomment-1673011548) | ||
*/ | ||
fun NavController.popBackStackOrIgnore() { | ||
if (currentBackStackEntry?.lifecycle?.currentState == Lifecycle.State.RESUMED) { | ||
popBackStack() | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
Oops, something went wrong.