Skip to content

Instantly share code, notes, and snippets.

View mattrob33's full-sized avatar

Matt Robertson mattrob33

View GitHub Profile
@mattrob33
mattrob33 / gradle.properties
Created February 19, 2024 16:31
gradle.properties
org.gradle.jvmargs=-Xmx4g
org.gradle.caching=true
org.gradle.configuration-cache=true
org.gradle.parallel=true
@mattrob33
mattrob33 / build.yaml
Last active February 19, 2024 16:18
Example buildscript
on:
pull_request:
branches:
- main
- develop
jobs:
build:
runs-on: ubuntu-latest
@Composable
fun MaxSizeBox(
modifier: Modifier = Modifier,
contentAlignment: Alignment = Alignment.TopStart,
content: @Composable BoxScope.() -> Unit
) {
Box(
modifier = modifier.fillMaxSize(),
contentAlignment = contentAlignment,
) {
@Composable fun Screen() {
MaxSizeBox {
..
}
}
@Composable fun Screen() {
var pressedLocation by rememberState { null }
MaxSizeBox(
modifier = Modifier.onPress { pressedLocation = it }
) {
..
}
}
/**
* Intercept [MotionEvent.ACTION_DOWN] events.
*/
fun Modifier.onPress(pressHandler: (offset: Offset) -> Unit): Modifier {
return this.pointerInteropFilter { event ->
when (event.action) {
MotionEvent.ACTION_DOWN -> pressHandler(Offset(event.x, event.y))
else -> return@pointerInteropFilter false
}
true
@Composable fun Screen(
onDismiss: () -> Unit
) {
Topbar(
onDismiss = onDismiss,
modifier = Modifier.consumeTaps()
)
..
}
fun Modifier.consumeTaps(): Modifier = composed {
clickable(
indication = null,
interactionSource = remember { MutableInteractionSource() }
) {}
}
inline fun Modifier.noRippleClickable(crossinline onClick: () -> Unit): Modifier = composed {
clickable(
indication = null,
interactionSource = remember { MutableInteractionSource() }
) {
onClick()
}
}
@Composable fun ClickableText(
text: String,
onClick: () -> Unit
) {
Text(
text = text,
modifier = Modifier.clickable(onClick)
)
}