-
-
Notifications
You must be signed in to change notification settings - Fork 134
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
12 changed files
with
272 additions
and
17 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
39 changes: 39 additions & 0 deletions
39
...s/android/src/main/java/cafe/adriel/voyager/sample/disposeSample/DisposeSampleActivity.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,39 @@ | ||
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 | ||
|
||
open class DisposeSampleActivity( | ||
private val disposeStepsBehavior: DisposeStepsBehavior | ||
) : ComponentActivity() { | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
setContent { | ||
Content() | ||
} | ||
} | ||
|
||
@Composable | ||
fun Content() { | ||
Navigator( | ||
screen = SampleScreen(0), | ||
disposeBehavior = NavigatorDisposeBehavior( | ||
disposeStepsBehavior = disposeStepsBehavior | ||
) | ||
) { | ||
SlideTransition( | ||
navigator = it, | ||
animationSpec = tween(1000) | ||
) | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...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,5 @@ | ||
package cafe.adriel.voyager.sample.disposeSample | ||
|
||
import cafe.adriel.voyager.navigator.DisposeStepsBehavior | ||
|
||
class DisposeWhenStackChangedSampleActivity : DisposeSampleActivity(DisposeStepsBehavior.DisposeWhenStackChanged) |
7 changes: 7 additions & 0 deletions
7
...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,7 @@ | ||
package cafe.adriel.voyager.sample.disposeSample | ||
|
||
import cafe.adriel.voyager.navigator.DisposeStepsBehavior | ||
|
||
class DisposeWhenTransitionFinishedSampleActivity : DisposeSampleActivity( | ||
DisposeStepsBehavior.DisposeWhenTransitionFinished | ||
) |
84 changes: 84 additions & 0 deletions
84
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,84 @@ | ||
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
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
Oops, something went wrong.