Skip to content

Instantly share code, notes, and snippets.

@hisetu
Last active July 3, 2022 10:06
Show Gist options
  • Save hisetu/710dd3275d3d04fb47eea517238e80d0 to your computer and use it in GitHub Desktop.
Save hisetu/710dd3275d3d04fb47eea517238e80d0 to your computer and use it in GitHub Desktop.
Jetpack Compose Modifier
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.selection.selectable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.composed
inline fun Modifier.noRippleClickable(crossinline onClick: () -> Unit): Modifier = composed {
clickable(indication = null,
interactionSource = remember { MutableInteractionSource() }) {
onClick()
}
}
inline fun Modifier.selectableNoRipple(selected: Boolean, noinline onClick: () -> Unit): Modifier =
composed {
selectable(
selected = selected,
onClick = onClick,
interactionSource = remember { MutableInteractionSource() },
indication = null
)
}
fun Modifier.tabIndicatorOffsetNoAnim(
currentTabPosition: TabPosition
): Modifier = composed(
inspectorInfo = debugInspectorInfo {
name = "tabIndicatorOffset"
value = currentTabPosition
}
) {
fillMaxWidth()
.wrapContentSize(Alignment.BottomStart)
.offset(x = currentTabPosition.left)
.width(currentTabPosition.width)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment