-
-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
262 additions
and
6 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
37 changes: 37 additions & 0 deletions
37
...in/java/cafe/adriel/voyager/sample/disposeSample/DisposeWhenStackChangedSampleActivity.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,37 @@ | ||
package cafe.adriel.voyager.sample.disposeSample | ||
|
||
import android.os.Bundle | ||
import androidx.activity.ComponentActivity | ||
import androidx.activity.compose.setContent | ||
import androidx.compose.animation.core.tween | ||
import androidx.compose.runtime.Composable | ||
import cafe.adriel.voyager.navigator.DisposeStepsBehavior | ||
import cafe.adriel.voyager.navigator.Navigator | ||
import cafe.adriel.voyager.navigator.NavigatorDisposeBehavior | ||
import cafe.adriel.voyager.transitions.SlideTransition | ||
|
||
class DisposeWhenStackChangedSampleActivity : ComponentActivity() { | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
setContent { | ||
Content() | ||
} | ||
} | ||
|
||
@Composable | ||
fun Content() { | ||
Navigator( | ||
screen = SampleScreen(0), | ||
disposeBehavior = NavigatorDisposeBehavior( | ||
disposeStepsBehavior = DisposeStepsBehavior.DisposeWhenStackChanged | ||
) | ||
) { | ||
SlideTransition( | ||
navigator = it, | ||
animationSpec = tween(1000) | ||
) | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...a/cafe/adriel/voyager/sample/disposeSample/DisposeWhenTransitionFinishedSampleActivity.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,37 @@ | ||
package cafe.adriel.voyager.sample.disposeSample | ||
|
||
import android.os.Bundle | ||
import androidx.activity.ComponentActivity | ||
import androidx.activity.compose.setContent | ||
import androidx.compose.animation.core.tween | ||
import androidx.compose.runtime.Composable | ||
import cafe.adriel.voyager.navigator.DisposeStepsBehavior | ||
import cafe.adriel.voyager.navigator.Navigator | ||
import cafe.adriel.voyager.navigator.NavigatorDisposeBehavior | ||
import cafe.adriel.voyager.transitions.SlideTransition | ||
|
||
class DisposeWhenTransitionFinishedSampleActivity : ComponentActivity() { | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
setContent { | ||
Content() | ||
} | ||
} | ||
|
||
@Composable | ||
fun Content() { | ||
Navigator( | ||
screen = SampleScreen(0), | ||
disposeBehavior = NavigatorDisposeBehavior( | ||
disposeStepsBehavior = DisposeStepsBehavior.DisposeWhenTransitionFinished | ||
) | ||
) { | ||
SlideTransition( | ||
navigator = it, | ||
animationSpec = tween(1000) | ||
) | ||
} | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
samples/android/src/main/java/cafe/adriel/voyager/sample/disposeSample/SampleScreen.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,86 @@ | ||
package cafe.adriel.voyager.sample.disposeSample | ||
|
||
import android.util.Log | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material.Button | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.dp | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import androidx.lifecycle.viewmodel.compose.viewModel | ||
import cafe.adriel.voyager.core.screen.Screen | ||
import cafe.adriel.voyager.core.screen.ScreenKey | ||
import cafe.adriel.voyager.navigator.LocalNavigator | ||
import cafe.adriel.voyager.navigator.currentOrThrow | ||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.launch | ||
|
||
class SampleScreenModel : ViewModel() { | ||
|
||
init { | ||
Log.d("SampleScreenModel", "start doing job") | ||
viewModelScope.launch { | ||
while (true) { | ||
Log.d("SampleScreenModel", "Doing job") | ||
delay(1000) | ||
} | ||
} | ||
} | ||
|
||
override fun onCleared() { | ||
Log.d("SampleScreenModel", "Disposed") | ||
} | ||
} | ||
|
||
data class SampleScreen( | ||
private val index: Int, | ||
) : Screen { | ||
|
||
override val key: ScreenKey = "SampleScreen$index" | ||
|
||
@Composable | ||
override fun Content() { | ||
|
||
if (index == 1) { | ||
viewModel(key = key) { SampleScreenModel() } | ||
} | ||
|
||
val navigator = LocalNavigator.currentOrThrow | ||
|
||
Column( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.padding(40.dp), | ||
horizontalAlignment = Alignment.CenterHorizontally, | ||
verticalArrangement = Arrangement.Center, | ||
) { | ||
|
||
Text(text = "Screen $index") | ||
|
||
Spacer(modifier = Modifier.height(20.dp)) | ||
|
||
Button( | ||
modifier = Modifier.fillMaxWidth(), | ||
onClick = { navigator.push(SampleScreen(index = index + 1)) } | ||
) { | ||
Text(text = "Next") | ||
} | ||
|
||
Button( | ||
modifier = Modifier.fillMaxWidth(), | ||
onClick = { navigator.pop() } | ||
) { | ||
Text(text = "Back") | ||
} | ||
} | ||
} | ||
} |
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