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 pagerState = rememberPagerState { Int.MAX_VALUE } | |
LaunchedEffect(Unit) { | |
while (true) { | |
delay(1500) // The duration of the image on the screen | |
if (pagerState.currentPage >= YourEnumClass.entries.lastIndex - 1) { | |
pagerState.animateScrollToPage(0) // If it reaches the end of the list, it returns to the beginning | |
} else { | |
pagerState.animateScrollToPage(pagerState.currentPage + 1) | |
} |
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.runtime.Composable | |
import androidx.compose.runtime.getValue | |
import androidx.navigation.NavDestination | |
import androidx.navigation.NavDestination.Companion.hierarchy | |
import androidx.navigation.NavHostController | |
import androidx.navigation.compose.currentBackStackEntryAsState | |
@Composable | |
fun NavHostController.currentDestination(): NavDestination? { | |
val navBackStackEntry by currentBackStackEntryAsState() |
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
@Composable | |
fun Modifier.onFirstPlacement(onFirstPlacement: (LayoutCoordinates) -> Unit): Modifier { | |
var isFirstPlacement by remember { mutableStateOf(true) } | |
var currentPosition by remember { mutableStateOf(Offset.Zero) } | |
return onPlaced { | |
if (isFirstPlacement) { | |
onFirstPlacement(it) | |
if (currentPosition == it.positionInWindow()) { | |
isFirstPlacement = false |
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
@SuppressLint("ComposableModifierFactory") | |
@Composable | |
fun Modifier.bouncyClick(enabled: Boolean = true): Modifier { | |
return if (enabled) { | |
var clickState by remember { mutableStateOf(ClickState.Idle) } | |
val scale by animateFloatAsState( | |
targetValue = if (clickState == ClickState.Pressed) 0.925f else 1f, | |
animationSpec = spring( | |
dampingRatio = Spring.DampingRatioNoBouncy, | |
stiffness = Spring.StiffnessMedium |
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.foundation.clickable | |
import androidx.compose.foundation.layout.fillMaxWidth | |
import androidx.compose.foundation.layout.padding | |
import androidx.compose.foundation.text.KeyboardOptions | |
import androidx.compose.material3.Icon | |
import androidx.compose.material3.Text | |
import androidx.compose.runtime.Composable | |
import androidx.compose.runtime.getValue | |
import androidx.compose.runtime.mutableStateOf | |
import androidx.compose.runtime.remember |
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
inline fun <reified T : Any> DocumentSnapshot.toObjectWithConversion(): T? { | |
val instance = T::class.primaryConstructor?.callBy( | |
T::class.primaryConstructor!!.parameters.associateWith { parameter -> | |
val value = this.get(parameter.name.orEmpty()) | |
when { | |
parameter.type.classifier is KClass<*> && (parameter.type.classifier as KClass<*>).isSubclassOf(Enum::class) -> { | |
val enumClass = parameter.type.classifier as KClass<Enum<*>> | |
(value as? String)?.toEnumSafe(enumClass) | |
} |
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
/* | |
* In Kotlin, a functions marked with infix keyword can also be called using | |
* infix notation means calling without using parenthesis and dot. | |
*/ | |
// Call using dot and parenthesis | |
var result1 = a.shr(1) | |
// Call using infix notation | |
var result2 = a shr 2 |