-
-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* update screen transition * review related updates * review related updates
- Loading branch information
Showing
9 changed files
with
307 additions
and
29 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
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
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) | ||
} | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
...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,73 @@ | ||
package cafe.adriel.voyager.sample.screenTransition | ||
|
||
import android.os.Bundle | ||
import androidx.activity.ComponentActivity | ||
import androidx.activity.compose.setContent | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
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.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) | ||
) { navigator -> | ||
Box(modifier = Modifier.fillMaxSize()) { | ||
ScreenTransition( | ||
navigator = navigator, | ||
defaultTransition = SlideTransition() | ||
) | ||
|
||
Row( | ||
modifier = Modifier | ||
.align(Alignment.BottomCenter) | ||
.fillMaxWidth() | ||
.padding(40.dp), | ||
horizontalArrangement = Arrangement.spacedBy(20.dp) | ||
) { | ||
Button( | ||
onClick = { navigator.push(FadeAnimationSampleScreen(navigator.items.size)) }, | ||
modifier = Modifier.weight(1f) | ||
) { | ||
Text(text = "Fade") | ||
} | ||
|
||
Button( | ||
onClick = { navigator.push(NoCustomAnimationSampleScreen(navigator.items.size)) }, | ||
modifier = Modifier.weight(1f) | ||
) { | ||
Text(text = "Default") | ||
} | ||
|
||
Button( | ||
onClick = { navigator.pop() }, | ||
modifier = Modifier.weight(1f) | ||
) { | ||
Text(text = "Pop") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
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.