Skip to content

Commit c774aad

Browse files
author
Johann Blake
committed
Replaced navigateBackImmediately with onNavigateBack to support more options on navigating back. Added support for caching screens.
1 parent eba6417 commit c774aad

File tree

8 files changed

+276
-121
lines changed

8 files changed

+276
-121
lines changed

README.md

Lines changed: 58 additions & 18 deletions
Large diffs are not rendered by default.

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ android {
4343
dependencies {
4444

4545
def lifecycle_version = "2.4.0-alpha01"
46-
def activity_version = "1.3.0-alpha06"
46+
def activity_version = "1.3.0-alpha07"
4747
def retrofit_version = "2.9.0"
48-
def paging_version = "3.0.0-beta03"
48+
def paging_version = "3.0.0-rc01"
4949

5050
implementation 'androidx.core:core-ktx:1.6.0-alpha01'
5151
implementation 'androidx.appcompat:appcompat:1.3.0-rc01'

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22
buildscript {
33
ext {
4-
compose_version = '1.0.0-beta04'
4+
compose_version = '1.0.0-beta05'
55
}
66
repositories {
77
google()

navigation/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ android {
3535
}
3636

3737
dependencies {
38-
def lifecycle_version = "2.3.0"
38+
def lifecycle_version = "2.4.0-alpha01"
3939

40-
implementation 'androidx.core:core-ktx:1.5.0-beta01'
40+
implementation 'androidx.core:core-ktx:1.6.0-alpha02'
4141
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version"
4242
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
43-
implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha03'
43+
implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha04'
4444
}

navigation/src/main/java/dev/wirespec/navigation/NavigationInfo.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ data class NavigationInfo(
2121
var screen: Any? = null,
2222

2323
/**
24-
* Any data that is communicated to the screen from the previous screen. This is typically used
25-
* to pass data that the screen needs to display its data.
24+
* Any data that is communicated to the screen from the previous screen. This is typically used to pass data that
25+
* the screen needs to display its data.
2626
*/
2727
var screenData: Any? = null,
2828

2929
/**
30-
* An optional viewmodel that is associated with the screen. Pass in a reference to a class that
31-
* inherits from ViewModel and not a reference to an actual instance. Navigation Manager will
32-
* create the viewmodel when the user navigates to the screen and will remove it from the navigation
33-
* stack when the user navigates to the previous screen.
30+
* An optional viewmodel that is associated with the screen. Pass in a reference to a class that inherits from
31+
* ViewModel and not a reference to an actual instance. Navigation Manager will create the viewmodel when the user
32+
* navigates to the screen and will remove it from the navigation stack when the user navigates to the previous
33+
* screen.
3434
*/
3535
var viewmodel: ViewModel? = null,
3636

@@ -43,9 +43,9 @@ data class NavigationInfo(
4343
internal var _onCloseScreen: MutableLiveData<Boolean>? = null,
4444

4545
/**
46-
* Used to notify clients to close their screens. In Jetpack Compose, this typically means
47-
* preventing the screen from being displayed such as setting the visible property of AnimatedVisibility
48-
* to false or if no animations are used, just to prevent the composable from generating the UI.
46+
* Used to notify clients to close their screens. In Jetpack Compose, this typically means preventing the screen
47+
* from being displayed such as setting the visible property of AnimatedVisibility to false or if no animations
48+
* are used, just to prevent the composable from generating the UI.
4949
*/
5050
var onCloseScreen: LiveData<Boolean>? = null
5151
)

navigation/src/main/java/dev/wirespec/navigation/NavigationManager.kt

Lines changed: 169 additions & 83 deletions
Large diffs are not rendered by default.
Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,34 @@
11
package dev.wirespec.navigation
22

33
interface NavigationManagerHelper {
4-
fun navigateBackImmediately(): Boolean
4+
fun onNavigateBack(): NavigateBackOptions
5+
}
6+
7+
enum class NavigateBackOptions {
8+
/**
9+
* Causes the Navigation Manager to navigate to the previous screen without checking to see if the onNavigateBack
10+
* interface function is defined.
11+
*/
12+
GoBackImmediately,
13+
14+
/**
15+
* Same as GoBackImmediately but the navigation info for the current screen is cached so that it can be re-used
16+
* later on. The nav info only gets cached if it isn't in the cache already. In order to be cached, the id
17+
* parameter of the navigateTo function must be provided. If it is not provided, an exception is thrown. Note: The
18+
* cache is not the same thing as the navigation stack. The cache is a separate cache used to keep an instance of
19+
* the nav info when moving back. The nav info is removed from the navigation stack when navigating back.
20+
*/
21+
GoBackImmediatelyAndCacheScreen,
22+
23+
/**
24+
* Same as GoBackImmediately but the navigation info for the current screen is removed from the cache (if it exist
25+
* in the cache). In order to be removed from the cache, the id parameter of the navigateTo function must be
26+
* provided. If it is not provided, an exception is thrown.
27+
*/
28+
GoBackImmediatelyAndRemoveCachedScreen,
29+
30+
/**
31+
* Cancels navigating to the previous screen.
32+
*/
33+
Cancel
534
}

navigation/src/main/java/dev/wirespec/navigation/ScreenInfo.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ package dev.wirespec.navigation
55
*/
66
open class ScreenInfo<T>(
77
/**
8-
* Identifies the type of screen. It is recommended to use objects based on a sealed class to create a quasi
9-
* enum, although using regular enums or even constants are also valid.
8+
* Identifies the type of screen. It is recommended to use objects based on a sealed class to create a quasi enum,
9+
* although using regular enums or even constants are also valid.
1010
*/
1111
val screen: Any,
1212

1313
/**
1414
* The viewmodel that should be associated with the screen. This is optional. A screen is not required to use a
15-
* viewmodel and can even manage its own viewmodel. If a viewmodel class is provided and the client navigates to
16-
* a screen, the Navigation Manager will create the viewmodel and remove it when the user navigates either backwards
15+
* viewmodel and can even manage its own viewmodel. If a viewmodel class is provided and the client navigates to a
16+
* screen, the Navigation Manager will create the viewmodel and remove it when the user navigates either backwards
1717
* or navigates to the home screen.
1818
*/
1919
val viewmodel: Class<T>? = null,

0 commit comments

Comments
 (0)