-
-
Notifications
You must be signed in to change notification settings - Fork 143
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
10 changed files
with
191 additions
and
15 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
64 changes: 64 additions & 0 deletions
64
...les/android/src/main/java/cafe/adriel/voyager/sample/screenTransition/BaseSampleScreen.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,64 @@ | ||
package cafe.adriel.voyager.sample.screenTransition | ||
|
||
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 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 | ||
|
||
abstract class BaseSampleScreen : Screen { | ||
|
||
abstract val index: Int | ||
|
||
override val key: ScreenKey get() = "SampleScreen$index" | ||
|
||
@Composable | ||
override fun Content() { | ||
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( | ||
when { | ||
index % 2 == 0 -> NoCustomAnimationSampleScreen(index = index + 1) | ||
else -> FadeAnimationSampleScreen(index = index + 1) | ||
} | ||
) | ||
} | ||
) { | ||
Text(text = "Next") | ||
} | ||
|
||
Button( | ||
modifier = Modifier.fillMaxWidth(), | ||
onClick = { navigator.pop() } | ||
) { | ||
Text(text = "Back") | ||
} | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
samples/android/src/main/java/cafe/adriel/voyager/sample/screenTransition/FadeTransition.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,19 @@ | ||
package cafe.adriel.voyager.sample.screenTransition | ||
|
||
import androidx.compose.animation.EnterTransition | ||
import androidx.compose.animation.ExitTransition | ||
import androidx.compose.animation.core.tween | ||
import androidx.compose.animation.fadeIn | ||
import androidx.compose.animation.fadeOut | ||
import cafe.adriel.voyager.transitions.ScreenTransition | ||
|
||
class FadeTransition : ScreenTransition { | ||
|
||
override fun enter(isPop: Boolean): EnterTransition { | ||
return fadeIn(tween(500, delayMillis = 500)) | ||
} | ||
|
||
override fun exit(isPop: Boolean): ExitTransition { | ||
return fadeOut(tween(500)) | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
samples/android/src/main/java/cafe/adriel/voyager/sample/screenTransition/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,11 @@ | ||
package cafe.adriel.voyager.sample.screenTransition | ||
|
||
import cafe.adriel.voyager.transitions.ScreenTransition | ||
|
||
data class NoCustomAnimationSampleScreen( | ||
override val index: Int | ||
) : BaseSampleScreen() | ||
|
||
data class FadeAnimationSampleScreen( | ||
override val index: Int | ||
) : BaseSampleScreen(), ScreenTransition by FadeTransition() |
31 changes: 31 additions & 0 deletions
31
...oid/src/main/java/cafe/adriel/voyager/sample/screenTransition/ScreenTransitionActivity.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 cafe.adriel.voyager.sample.screenTransition | ||
|
||
import android.os.Bundle | ||
import androidx.activity.ComponentActivity | ||
import androidx.activity.compose.setContent | ||
import androidx.compose.runtime.Composable | ||
import cafe.adriel.voyager.navigator.Navigator | ||
import cafe.adriel.voyager.transitions.ScreenTransition | ||
|
||
class ScreenTransitionActivity : ComponentActivity() { | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
setContent { | ||
Content() | ||
} | ||
} | ||
|
||
@Composable | ||
fun Content() { | ||
Navigator( | ||
screen = NoCustomAnimationSampleScreen(0) | ||
) { | ||
ScreenTransition( | ||
navigator = it, | ||
defaultTransition = SlideTransition() | ||
) | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
samples/android/src/main/java/cafe/adriel/voyager/sample/screenTransition/SlideTransition.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,25 @@ | ||
package cafe.adriel.voyager.sample.screenTransition | ||
|
||
import androidx.compose.animation.EnterTransition | ||
import androidx.compose.animation.ExitTransition | ||
import androidx.compose.animation.slideIn | ||
import androidx.compose.animation.slideOut | ||
import androidx.compose.ui.unit.IntOffset | ||
import cafe.adriel.voyager.transitions.ScreenTransition | ||
|
||
class SlideTransition : ScreenTransition { | ||
|
||
override fun enter(isPop: Boolean): EnterTransition { | ||
return slideIn { size -> | ||
val x = if (isPop) -size.width else size.width | ||
IntOffset(x = x, y = 0) | ||
} | ||
} | ||
|
||
override fun exit(isPop: Boolean): ExitTransition { | ||
return slideOut { size -> | ||
val x = if (isPop) size.width else -size.width | ||
IntOffset(x = x, y = 0) | ||
} | ||
} | ||
} |
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