-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
31b6564
commit 044a67b
Showing
6 changed files
with
197 additions
and
142 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
4 changes: 0 additions & 4 deletions
4
.idea/shelf/Uncommitted_changes_before_Update_at_10_1_2024_11_20_AM__Changes_.xml
This file was deleted.
Oops, something went wrong.
155 changes: 155 additions & 0 deletions
155
app/src/main/kotlin/com/d4rk/cleaner/ui/components/CarouselLayout.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
package com.d4rk.cleaner.ui.components | ||
|
||
import androidx.compose.animation.core.FastOutSlowInEasing | ||
import androidx.compose.animation.core.Transition | ||
import androidx.compose.animation.core.animateDp | ||
import androidx.compose.animation.core.animateFloatAsState | ||
import androidx.compose.animation.core.tween | ||
import androidx.compose.animation.core.updateTransition | ||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.PaddingValues | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.foundation.layout.wrapContentWidth | ||
import androidx.compose.foundation.lazy.LazyRow | ||
import androidx.compose.foundation.pager.HorizontalPager | ||
import androidx.compose.foundation.pager.PagerState | ||
import androidx.compose.foundation.shape.CircleShape | ||
import androidx.compose.material3.Card | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.clip | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.graphics.graphicsLayer | ||
import androidx.compose.ui.unit.Dp | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.util.lerp | ||
import com.d4rk.cleaner.ui.components.animations.hapticPagerSwipe | ||
import kotlin.math.absoluteValue | ||
|
||
@Composable | ||
fun <T> CarouselLayout( | ||
items: List<T>, | ||
sidePadding: Dp, | ||
pagerState: PagerState, | ||
itemContent: @Composable (item: T) -> Unit | ||
) { | ||
Column( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
) { | ||
HorizontalPager( | ||
state = pagerState, | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.hapticPagerSwipe(pagerState), | ||
contentPadding = PaddingValues(horizontal = sidePadding), | ||
) { page -> | ||
val pageOffset = remember(pagerState.currentPage, page) { | ||
(pagerState.currentPage - page).absoluteValue.toFloat() | ||
} | ||
CarouselItem(items[page], pageOffset, itemContent) | ||
} | ||
|
||
Spacer(modifier = Modifier.height(16.dp)) | ||
|
||
DotsIndicator( | ||
modifier = Modifier | ||
.align(Alignment.CenterHorizontally) | ||
.padding(bottom = 8.dp), | ||
totalDots = items.size, | ||
selectedIndex = pagerState.currentPage, | ||
dotSize = 6.dp, | ||
) | ||
} | ||
} | ||
|
||
@Composable | ||
fun <T> CarouselItem( | ||
item: T, | ||
pageOffset: Float, | ||
itemContent: @Composable (item: T) -> Unit | ||
) { | ||
val scale = animateFloatAsState( | ||
targetValue = lerp(0.95f, 1f, 1f - pageOffset.coerceIn(0f, 1f)), | ||
animationSpec = tween(250), | ||
label = "Carousel Item Scale for Page $pageOffset" | ||
).value | ||
|
||
val alpha = lerp(0.5f, 1f, 1f - pageOffset.coerceIn(0f, 1f)) | ||
|
||
Card( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.graphicsLayer { | ||
scaleX = scale | ||
scaleY = scale | ||
this.alpha = alpha | ||
} | ||
) { | ||
itemContent(item) | ||
} | ||
} | ||
|
||
@Composable | ||
fun DotsIndicator( | ||
modifier: Modifier = Modifier, | ||
totalDots: Int, | ||
selectedIndex: Int, | ||
selectedColor: Color = MaterialTheme.colorScheme.primary, | ||
unSelectedColor: Color = Color.Gray, | ||
dotSize: Dp, | ||
animationDuration: Int = 300 | ||
) { | ||
val transition: Transition<Int> = | ||
updateTransition(targetState = selectedIndex, label = "Dot Transition") | ||
|
||
LazyRow( | ||
modifier = modifier | ||
.wrapContentWidth() | ||
.height(dotSize), | ||
verticalAlignment = Alignment.CenterVertically | ||
) { | ||
items(count = totalDots, key = { index -> index }) { index -> | ||
val animatedDotSize: Dp by transition.animateDp(transitionSpec = { | ||
tween(durationMillis = animationDuration, easing = FastOutSlowInEasing) | ||
}, label = "Dot Size Animation") { | ||
if (it == index) dotSize else dotSize / 1.4f | ||
} | ||
|
||
val isSelected: Boolean = index == selectedIndex | ||
val size: Dp = if (isSelected) animatedDotSize else animatedDotSize | ||
|
||
IndicatorDot( | ||
color = if (isSelected) selectedColor else unSelectedColor, size = size | ||
) | ||
|
||
if (index != totalDots - 1) { | ||
Spacer(modifier = Modifier.padding(horizontal = 2.dp)) | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
fun IndicatorDot( | ||
modifier: Modifier = Modifier, | ||
size: Dp, | ||
color: Color, | ||
) { | ||
Box( | ||
modifier = modifier | ||
.size(size) | ||
.clip(CircleShape) | ||
.background(color) | ||
) | ||
} |
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
23 changes: 23 additions & 0 deletions
23
app/src/main/kotlin/com/d4rk/cleaner/ui/screens/loading/LoadingScreen.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.d4rk.cleaner.ui.screens.loading | ||
|
||
import androidx.compose.animation.animateContentSize | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.material3.CircularProgressIndicator | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.alpha | ||
|
||
@Composable | ||
fun LoadingScreen(progressAlpha: Float) { | ||
Box( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.animateContentSize() | ||
.alpha(progressAlpha), | ||
contentAlignment = Alignment.Center | ||
) { | ||
CircularProgressIndicator() | ||
} | ||
} |
Oops, something went wrong.