-
-
Notifications
You must be signed in to change notification settings - Fork 8
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
Showing
10 changed files
with
267 additions
and
16 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
...d/src/androidMain/kotlin/dev/datlag/burningseries/common/PlatformExtendCompose.android.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,20 @@ | ||
package dev.datlag.burningseries.common | ||
|
||
import androidx.compose.foundation.ExperimentalFoundationApi | ||
import androidx.compose.foundation.combinedClickable | ||
import androidx.compose.ui.Modifier | ||
|
||
@OptIn(ExperimentalFoundationApi::class) | ||
actual fun Modifier.onClick( | ||
enabled: Boolean, | ||
onDoubleClick: (() -> Unit)?, | ||
onLongClick: (() -> Unit)?, | ||
onClick: () -> Unit | ||
): Modifier { | ||
return this.combinedClickable( | ||
enabled = enabled, | ||
onDoubleClick = onDoubleClick, | ||
onLongClick = onLongClick, | ||
onClick = onClick | ||
) | ||
} |
51 changes: 50 additions & 1 deletion
51
app/shared/src/commonMain/kotlin/dev/datlag/burningseries/common/ExtendCompose.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 |
---|---|---|
@@ -1,12 +1,61 @@ | ||
package dev.datlag.burningseries.common | ||
|
||
import androidx.compose.animation.core.animateFloatAsState | ||
import androidx.compose.foundation.gestures.awaitFirstDown | ||
import androidx.compose.foundation.gestures.waitForUpOrCancellation | ||
import androidx.compose.foundation.lazy.grid.GridItemSpan | ||
import androidx.compose.foundation.lazy.grid.LazyGridItemScope | ||
import androidx.compose.foundation.lazy.grid.LazyGridScope | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.* | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.composed | ||
import androidx.compose.ui.graphics.graphicsLayer | ||
import androidx.compose.ui.input.pointer.pointerInput | ||
|
||
inline fun Modifier.ifTrue(predicate: Boolean, builder: Modifier.() -> Modifier) = then(if (predicate) builder() else Modifier) | ||
inline fun Modifier.ifFalse(predicate: Boolean, builder: Modifier.() -> Modifier) = then(if (!predicate) builder() else Modifier) | ||
|
||
fun LazyGridScope.header( | ||
content: @Composable LazyGridItemScope.() -> Unit | ||
) { | ||
item(span = { GridItemSpan(this.maxLineSpan) }, content = content) | ||
} | ||
|
||
fun Modifier.bounceClick(minScale: Float = 0.9F) = composed { | ||
var buttonState by remember { mutableStateOf(false) } | ||
val scale by animateFloatAsState(if (buttonState) minScale else 1F) | ||
|
||
graphicsLayer { | ||
scaleX = scale | ||
scaleY = scale | ||
}.pointerInput(buttonState) { | ||
awaitPointerEventScope { | ||
buttonState = if (buttonState) { | ||
waitForUpOrCancellation() | ||
false | ||
} else { | ||
awaitFirstDown(false) | ||
true | ||
} | ||
} | ||
} | ||
} | ||
|
||
fun Modifier.pressClick(maxTranslation: Float = 10F) = composed { | ||
var buttonState by remember { mutableStateOf(false) } | ||
val translation by animateFloatAsState(if (buttonState) maxTranslation else 0F) | ||
|
||
graphicsLayer { | ||
translationY = translation | ||
}.pointerInput(buttonState) { | ||
awaitPointerEventScope { | ||
buttonState = if (buttonState) { | ||
waitForUpOrCancellation() | ||
false | ||
} else { | ||
awaitFirstDown(false) | ||
true | ||
} | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
app/shared/src/commonMain/kotlin/dev/datlag/burningseries/common/PlatformExtendCompose.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,10 @@ | ||
package dev.datlag.burningseries.common | ||
|
||
import androidx.compose.ui.Modifier | ||
|
||
expect fun Modifier.onClick( | ||
enabled: Boolean = true, | ||
onDoubleClick: (() -> Unit)? = null, | ||
onLongClick: (() -> Unit)? = null, | ||
onClick: () -> Unit | ||
) : Modifier |
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
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
71 changes: 71 additions & 0 deletions
71
...commonMain/kotlin/dev/datlag/burningseries/ui/screen/initial/home/component/SeriesItem.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,71 @@ | ||
package dev.datlag.burningseries.ui.screen.initial.home.component | ||
|
||
import androidx.compose.foundation.ExperimentalFoundationApi | ||
import androidx.compose.foundation.Image | ||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.* | ||
import androidx.compose.foundation.lazy.grid.LazyGridItemScope | ||
import androidx.compose.material3.* | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.clip | ||
import androidx.compose.ui.layout.ContentScale | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.unit.dp | ||
import dev.datlag.burningseries.common.bounceClick | ||
import dev.datlag.burningseries.common.onClick | ||
import dev.datlag.burningseries.model.BSUtil | ||
import dev.datlag.burningseries.model.Home | ||
import io.kamel.core.Resource | ||
import io.kamel.image.asyncPainterResource | ||
|
||
@OptIn(ExperimentalFoundationApi::class) | ||
@Composable | ||
fun LazyGridItemScope.SeriesItem(series: Home.Series, onClick: () -> Unit) { | ||
ElevatedCard( | ||
modifier = Modifier.animateItemPlacement().height(200.dp).bounceClick().onClick { | ||
onClick() | ||
} | ||
) { | ||
Row( | ||
horizontalArrangement = Arrangement.spacedBy(8.dp) | ||
) { | ||
Surface( | ||
shape = CardDefaults.elevatedShape | ||
) { | ||
series.coverHref?.let { cover -> | ||
when (val resource = asyncPainterResource(BSUtil.getBurningSeriesLink(cover))) { | ||
is Resource.Loading, is Resource.Failure -> { | ||
Box( | ||
modifier = Modifier | ||
.aspectRatio(1F, true) | ||
.clip(CardDefaults.elevatedShape) | ||
.background(MaterialTheme.colorScheme.tertiaryContainer) | ||
) | ||
} | ||
is Resource.Success -> { | ||
Image( | ||
painter = resource.value, | ||
contentScale = ContentScale.FillWidth, | ||
contentDescription = series.title, | ||
modifier = Modifier.aspectRatio(1F, true) | ||
) | ||
} | ||
} | ||
} | ||
} | ||
Column( | ||
modifier = Modifier.padding(16.dp), | ||
verticalArrangement = Arrangement.spacedBy(8.dp) | ||
) { | ||
Text( | ||
text = series.title, | ||
fontWeight = FontWeight.SemiBold, | ||
style = MaterialTheme.typography.titleLarge, | ||
modifier = Modifier.padding(bottom = 8.dp), | ||
maxLines = 3 | ||
) | ||
} | ||
} | ||
} | ||
} |
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
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
20 changes: 20 additions & 0 deletions
20
...d/src/desktopMain/kotlin/dev/datlag/burningseries/common/PlatformExtendCompose.desktop.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,20 @@ | ||
package dev.datlag.burningseries.common | ||
|
||
import androidx.compose.foundation.ExperimentalFoundationApi | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.foundation.onClick | ||
|
||
@OptIn(ExperimentalFoundationApi::class) | ||
actual fun Modifier.onClick( | ||
enabled: Boolean, | ||
onDoubleClick: (() -> Unit)?, | ||
onLongClick: (() -> Unit)?, | ||
onClick: () -> Unit | ||
): Modifier { | ||
return this.onClick( | ||
enabled = enabled, | ||
onDoubleClick = onDoubleClick, | ||
onLongClick = onLongClick, | ||
onClick = onClick | ||
) | ||
} |
20 changes: 20 additions & 0 deletions
20
app/shared/src/iosMain/kotlin/dev/datlag/burningseries/common/PlatformExtendCompose.ios.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,20 @@ | ||
package dev.datlag.burningseries.common | ||
|
||
import androidx.compose.foundation.ExperimentalFoundationApi | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.foundation.onClick | ||
|
||
@OptIn(ExperimentalFoundationApi::class) | ||
actual fun Modifier.onClick( | ||
enabled: Boolean, | ||
onDoubleClick: (() -> Unit)?, | ||
onLongClick: (() -> Unit)?, | ||
onClick: () -> Unit | ||
): Modifier { | ||
return this.onClick( | ||
enabled = enabled, | ||
onDoubleClick = onDoubleClick, | ||
onLongClick = onLongClick, | ||
onClick = onClick | ||
) | ||
} |