-
-
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
12 changed files
with
188 additions
and
149 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: 0 additions & 64 deletions
64
...les/android/src/main/java/cafe/adriel/voyager/sample/screenTransition/BaseSampleScreen.kt
This file was deleted.
Oops, something went wrong.
19 changes: 0 additions & 19 deletions
19
samples/android/src/main/java/cafe/adriel/voyager/sample/screenTransition/FadeTransition.kt
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
samples/android/src/main/java/cafe/adriel/voyager/sample/screenTransition/SampleScreen.kt
This file was deleted.
Oops, something went wrong.
68 changes: 68 additions & 0 deletions
68
samples/android/src/main/java/cafe/adriel/voyager/sample/screenTransition/SampleScreens.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,68 @@ | ||
package cafe.adriel.voyager.sample.screenTransition | ||
|
||
import androidx.compose.foundation.background | ||
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.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import cafe.adriel.voyager.core.screen.Screen | ||
import cafe.adriel.voyager.core.screen.ScreenKey | ||
import cafe.adriel.voyager.transitions.ScreenTransition | ||
|
||
private val colors = listOf( | ||
Color.Red, | ||
Color.Yellow, | ||
Color.Green, | ||
Color.Blue, | ||
Color.Black | ||
) | ||
|
||
abstract class BaseSampleScreen( | ||
private val transitionType: String | ||
) : Screen { | ||
|
||
abstract val index: Int | ||
|
||
override val key: ScreenKey get() = "SampleScreen$index" | ||
|
||
@Composable | ||
override fun Content() { | ||
Column( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.background(colors[index % colors.size].copy(alpha = 0.3f)) | ||
.padding(40.dp), | ||
verticalArrangement = Arrangement.Center, | ||
horizontalAlignment = Alignment.CenterHorizontally | ||
) { | ||
Text( | ||
text = "Screen $index", | ||
fontSize = 24.sp, | ||
fontWeight = FontWeight.Bold | ||
) | ||
Spacer(modifier = Modifier.height(8.dp)) | ||
Text( | ||
text = transitionType, | ||
fontSize = 18.sp | ||
) | ||
} | ||
} | ||
} | ||
|
||
data class NoCustomAnimationSampleScreen( | ||
override val index: Int | ||
) : BaseSampleScreen("Default transition") | ||
|
||
data class FadeAnimationSampleScreen( | ||
override val index: Int | ||
) : BaseSampleScreen("Fade transition"), ScreenTransition by FadeTransition() |
40 changes: 40 additions & 0 deletions
40
...es/android/src/main/java/cafe/adriel/voyager/sample/screenTransition/SampleTransitions.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,40 @@ | ||
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 androidx.compose.animation.slideIn | ||
import androidx.compose.animation.slideOut | ||
import androidx.compose.ui.unit.IntOffset | ||
import cafe.adriel.voyager.core.stack.StackEvent | ||
import cafe.adriel.voyager.transitions.ScreenTransition | ||
|
||
class FadeTransition : ScreenTransition { | ||
|
||
override fun enter(lastEvent: StackEvent): EnterTransition { | ||
return fadeIn(tween(500, delayMillis = 500)) | ||
} | ||
|
||
override fun exit(lastEvent: StackEvent): ExitTransition { | ||
return fadeOut(tween(500)) | ||
} | ||
} | ||
|
||
class SlideTransition : ScreenTransition { | ||
|
||
override fun enter(lastEvent: StackEvent): EnterTransition { | ||
return slideIn { size -> | ||
val x = if (lastEvent == StackEvent.Pop) -size.width else size.width | ||
IntOffset(x = x, y = 0) | ||
} | ||
} | ||
|
||
override fun exit(lastEvent: StackEvent): ExitTransition { | ||
return slideOut { size -> | ||
val x = if (lastEvent == StackEvent.Pop) 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
25 changes: 0 additions & 25 deletions
25
samples/android/src/main/java/cafe/adriel/voyager/sample/screenTransition/SlideTransition.kt
This file was deleted.
Oops, something went wrong.
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.