Skip to content

Instantly share code, notes, and snippets.

@Abhimanyu14
Abhimanyu14 / gist:d6d27df93e027f4e7c7bd1b542e143c9
Created July 30, 2023 17:31
How to move to a fork after cloning
1. Fork their repo on Github
2. In your local, rename your origin remote to upstream
git remote rename origin upstream
3. Add a new origin
git remote add origin [email protected]
4. Fetch & push
suspend fun changeFloatValueOverTime(
initialValue: Float,
targetValue: Float,
durationMillis: Int,
onUpdate: (Float) -> Unit,
) {
val startTime = System.currentTimeMillis()
while (System.currentTimeMillis() - startTime < durationMillis) {
val elapsedTime = System.currentTimeMillis() - startTime
val fraction = elapsedTime.toFloat() / durationMillis
@Immutable
enum class MyPullToRefreshIndicatorState {
DEFAULT, // No user interaction and no refreshing
PULL, // User is pull the UI
RELEASE, // User released the pull, but did not cross the threshold to refresh
REFRESHING, // User crossed the threshold to refresh and released the pull
REFRESH_COMPLETED, // Refreshing is completed - to perform state reset
}
@Immutable
@OptIn(ExperimentalMaterialApi::class)
@Composable
fun MyPullToRefreshLayout(
modifier: Modifier = Modifier,
isRefreshing: Boolean,
widthFraction: Float = 0.2F,
animationSpeedFactor: Int = 4,
defaultAnimationDuration: Int = 300,
iconPath: (Float) -> Path,
onRefresh: () -> Unit,
fun generateHeartIcon(sizeFactor: Float): Path {
val path = Path().apply {
moveTo(sizeFactor * 12.5f, sizeFactor * 19.491f)
lineTo(sizeFactor * 9.577f, sizeFactor * 16.491f)
lineTo(sizeFactor * 6.677f, sizeFactor * 13.491f)
cubicTo(sizeFactor * 5.108f, sizeFactor * 11.833f, sizeFactor * 5.108f, sizeFactor * 9.238f, sizeFactor * 6.677f, sizeFactor * 7.58f)
cubicTo(sizeFactor * 7.445f, sizeFactor * 6.842f, sizeFactor * 8.485f, sizeFactor * 6.456f, sizeFactor * 9.549f, sizeFactor * 6.515f)
cubicTo(sizeFactor * 10.613f, sizeFactor * 6.574f, sizeFactor * 11.605f, sizeFactor * 7.072f, sizeFactor * 12.287f, sizeFactor * 7.891f)
lineTo(sizeFactor * 12.5f, sizeFactor * 8.1f)
lineTo(sizeFactor * 12.711f, sizeFactor * 7.882f)
@Composable
fun ScrollingTextWithMaxLinesDemo() {
val textMeasurer = rememberTextMeasurer()
val density = LocalDensity.current
val textHeight = with(density) {
textMeasurer.measure(
text = randomText,
maxLines = 10,
style = TextStyle(),
).size.height.toDp()
@Composable
fun VerticalAndHorizontalScrollingWithFixedHeightAndWidthTextDemo() {
Text(
text = randomText,
modifier = Modifier
.height(300.dp)
.width(300.dp)
.verticalScroll(rememberScrollState())
.horizontalScroll(rememberScrollState())
)
@Composable
fun HorizontalScrollingWithFixedWidthTextDemo() {
Text(
text = randomText,
modifier = Modifier
.width(300.dp)
.horizontalScroll(rememberScrollState())
)
}
@Composable
fun VerticalScrollingWithFixedHeightTextDemo() {
Text(
text = randomText,
modifier = Modifier
.height(300.dp)
.verticalScroll(rememberScrollState())
)
}
@Composable
fun VerticalAndHorizontalScrollingTextDemo() {
Text(
text = randomText,
modifier = Modifier
.verticalScroll(rememberScrollState())
.horizontalScroll(rememberScrollState())
)
}