View material-design-colors-for-compose.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
import androidx.compose.ui.graphics.Color | |
// reds | |
val md_red_50 = Color(0xFFFFEBEE) | |
val md_red_100 = Color(0xFFFFCDD2) | |
val md_red_200 = Color(0xFFEF9A9A) | |
val md_red_300 = Color(0xFFE57373) | |
val md_red_400 = Color(0xFFEF5350) | |
val md_red_500 = Color(0xFFF44336) | |
val md_red_600 = Color(0xFFE53935) |
View livedata-compose.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
/** | |
* Based on https://medium.com/swlh/android-mvi-with-jetpack-compose-b0890f5156ac | |
* Adapted for 0.1.0-dev04 | |
*/ | |
@Composable | |
fun <T> observe(data: LiveData<T>): T? { | |
var result by state { data.value } | |
val observer = remember { Observer<T> { result = it } } | |
onCommit(data) { |
View dating-card-ui-props-instances.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
// Scaled down to 0% (not visible) | |
private val queued = Props( | |
scale = 0f, | |
) | |
// Scaled down to 85% | |
private val bottom = Props( | |
scale = 0.85f, | |
) |
View dating-cards-promote-all.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
internal class PromoteAll<T : Any> : CardsOperation<T> { | |
override fun invoke(elements: CardsElements<T>): CardsElements<T> = | |
elements.map { | |
it.transitionTo( | |
// This uses State.next() we defined earlier: | |
newTargetState = it.targetState.next(), | |
operation = this | |
) | |
} |
View dating-card-transition-handler.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
class CardsTransitionHandler<T>( | |
private val transitionSpec: TransitionSpec<Cards.State, Float> = { | |
spring(stiffness = Spring.StiffnessVeryLow) | |
} | |
) : ModifierTransitionHandler<T, Cards.State>() { | |
private fun Cards.State.toProps() = | |
when (this) { | |
is Queued -> queued | |
is Bottom -> bottom |
View dating-card-ui-props.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
data class Props( | |
val offsetX: Dp = 0.dp, | |
val scale: Float = 1f, | |
val rotationZ: Float = 0f, | |
val zIndex: Float = 0f, | |
) |
View dating-cards-instance.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
val cards = Cards( | |
initialItems = listOf( | |
Routing.ProfileCard(0, "Lara"), // Will be top | |
Routing.ProfileCard(1, "Kate"), // Will be bottom | |
Routing.ProfileCard(2, "Brad"), // Queued = 0 | |
Routing.ProfileCard(3, "Megan"), // ...etc. | |
Routing.ProfileCard(4, "Michael"), | |
Routing.ProfileCard(0, "Lara"), | |
Routing.ProfileCard(1, "Kate"), | |
Routing.ProfileCard(2, "Brad"), |
View dating-cards-demo.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
lifecycle.coroutineScope.launchWhenStarted { | |
delay(1000) | |
repeat(3) { | |
delay(2000) | |
cards.indicateLike() | |
delay(1000) | |
cards.indicatePass() | |
delay(1000) | |
cards.votePass() | |
delay(1000) |
View dating-card-ui-props-mapping.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
private fun Cards.State.toProps() = | |
when (this) { | |
is Queued -> queued | |
is Bottom -> bottom | |
is Top -> top | |
is VoteLike -> voteLike | |
is VotePass -> votePass | |
} |
View dating-cards-vote-like.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
class VoteLike<T : Any> internal constructor() : CardsOperation<T> { | |
// Returns a modified list of elements with new target states applied | |
override fun invoke(elements: CardsElements<T>): CardsElements<T> = | |
elements.map { element -> | |
if (element.targetState == Cards.State.Top) { | |
element.transitionTo( | |
newTargetState = Cards.State.VoteLike, | |
operation = this | |
) |
NewerOlder