Skip to content

Instantly share code, notes, and snippets.

View pauloaapereira's full-sized avatar

Paulo Pereira pauloaapereira

View GitHub Profile
@pauloaapereira
pauloaapereira / drawer_5.kt
Created March 16, 2021 19:05
Jetpack Compose — Drawer Pushing Content - 5
@Composable
fun DrawerContainer(
modifier: Modifier = Modifier,
isDrawerOpened: Boolean = false,
drawerWidth: Dp = 200.dp,
onSwipe: (Boolean) -> Unit = {},
content: @Composable () -> Unit
) {
val transition = updateTransition(targetState = isDrawerOpened)
@pauloaapereira
pauloaapereira / drawer_4.kt
Created March 16, 2021 19:05
Jetpack Compose — Drawer Pushing Content - 4
@Composable
fun DrawerContainer(
modifier: Modifier = Modifier,
isDrawerOpened: Boolean = false,
drawerWidth: Dp = 200.dp,
onSwipe: (Boolean) -> Unit = {},
content: @Composable () -> Unit
) {
...
}
@pauloaapereira
pauloaapereira / drawer_3.kt
Created March 16, 2021 19:04
Jetpack Compose — Drawer Pushing Content - 3
// Set the size of the layout as big as it can
layout(constraints.maxWidth, constraints.maxHeight) {
// Track the y co-ord we have placed children up to
var yPosition = 0
// Place children in the parent layout
placeables.forEach { placeable ->
// Position item on the screen
placeable.place(x = 0, y = yPosition)
@pauloaapereira
pauloaapereira / drawer_2.kt
Created March 16, 2021 19:03
Jetpack Compose — Drawer Pushing Content - 2
// List of measured children
val placeables = measurables.map { measurable ->
// Measure each children
measurable.measure(constraints.copy(minHeight = 0))
}
@pauloaapereira
pauloaapereira / drawer_1.kt
Created March 16, 2021 19:03
Jetpack Compose — Drawer Pushing Content - 1
@Composable
fun MyBasicColumn(
modifier: Modifier = Modifier,
content: @Composable() () -> Unit
) {
Layout(
modifier = modifier,
content = content
) { measurables, constraints ->
// List of measured children
@pauloaapereira
pauloaapereira / pendulum_6.kt
Created March 16, 2021 19:02
Jetpack Compose - Pendulum Effect - 6
Pendulum {
Surface(
modifier = Modifier.size(24.dp),
shape = CircleShape,
color = Color.Blue,
content = {})
}
@pauloaapereira
pauloaapereira / pendulum_5.kt
Created March 16, 2021 19:02
Jetpack Compose - Pendulum Effect - 5
@Composable
fun Pendulum(
modifier: Modifier = Modifier,
swingDuration: Int = 1500,
startX: Float = .2f,
endX: Float = .8f,
topY: Float = .2f,
bottomY: Float = .4f,
content: @Composable () -> Unit
) {
@pauloaapereira
pauloaapereira / pendulum_4.kt
Created March 16, 2021 19:01
Jetpack Compose - Pendulum Effect - 4
val y by infiniteTransition.animateFloat(
initialValue = top.value,
targetValue = bottom.value,
animationSpec = infiniteRepeatable(
animation = tween(swingDuration / 2, easing = LinearOutSlowInEasing),
repeatMode = RepeatMode.Reverse
)
)
@pauloaapereira
pauloaapereira / pendulum_3.kt
Created March 16, 2021 19:01
Jetpack Compose - Pendulum Effect - 3
val x by infiniteTransition.animateFloat(
initialValue = start.value,
targetValue = end.value,
animationSpec = infiniteRepeatable(
animation = tween(swingDuration, easing = LinearEasing),
repeatMode = RepeatMode.Reverse
)
)
@pauloaapereira
pauloaapereira / pendulum_2.kt
Created March 16, 2021 19:01
Jetpack Compose - Pendulum Effect - 2
@Composable
fun Pendulum(
modifier: Modifier = Modifier,
startX: Float = .2f,
endX: Float = .8f,
topY: Float = .2f,
bottomY: Float = .4f,
...
) {
val infiniteTransition = rememberInfiniteTransition()