Skip to content

Commit

Permalink
Placeholder Highlight (#1038)
Browse files Browse the repository at this point in the history
* Import androidx accompanist placeholder code

* Enable data retrieval

* Simplify module structure with ktlint fixes

---------

Co-authored-by: Ashley Davies <[email protected]>
  • Loading branch information
ashdavies and ashdavies authored Jun 24, 2024
1 parent 6fb091c commit 44f63b5
Show file tree
Hide file tree
Showing 13 changed files with 493 additions and 39 deletions.
2 changes: 1 addition & 1 deletion after-party/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ kotlin {
implementation(projects.httpCommon)
implementation(projects.identityManager)
implementation(projects.pagingCompose)
implementation(projects.placeholderHighlight)
implementation(projects.platformScaffold)
implementation(projects.platformSupport)
implementation(projects.sqlCommon)
Expand Down Expand Up @@ -54,7 +55,6 @@ kotlin {
androidMain.dependencies {
implementation(libs.androidx.activity.compose)
implementation(libs.google.accompanist.flowlayout)
implementation(libs.google.accompanist.placeholderMaterial)
}

val androidDebug by registering {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package io.ashdavies.activity

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.AnimatedVisibilityScope
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
Expand Down Expand Up @@ -36,19 +41,28 @@ import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.slack.circuit.runtime.CircuitUiState
import com.slack.circuit.runtime.screen.Screen
import io.ashdavies.android.fade
import io.ashdavies.events.Event
import io.ashdavies.paging.LazyPagingItems
import io.ashdavies.parcelable.Parcelable
import io.ashdavies.parcelable.Parcelize
import io.ashdavies.placeholder.PlaceholderHighlight
import io.ashdavies.placeholder.fade
import io.ashdavies.placeholder.placeholder

private const val EMPTY_STRING = "No Data Available"
private const val PLACEHOLDER_COUNT = 8

@Parcelize
internal object ActivityScreen : Parcelable, Screen {
data class State(val pagingItems: LazyPagingItems<Event>) : CircuitUiState
}

@Composable
@OptIn(ExperimentalMaterialApi::class, ExperimentalMaterial3Api::class)
@OptIn(
ExperimentalFoundationApi::class,
ExperimentalMaterialApi::class,
ExperimentalMaterial3Api::class,
)
internal fun ActivityScreen(state: ActivityScreen.State, modifier: Modifier = Modifier) {
val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior()

Expand Down Expand Up @@ -76,18 +90,52 @@ internal fun ActivityScreen(state: ActivityScreen.State, modifier: Modifier = Mo
state = pullRefreshState,
)

LazyColumn(Modifier.fillMaxSize()) {
items(state.pagingItems.itemCount) {
EventSection(state.pagingItems[it])
FadeVisibility(state.pagingItems.itemCount > 0) {
LazyColumn(Modifier.fillMaxSize()) {
items(state.pagingItems.itemCount) {
EventSection(
event = state.pagingItems[it],
modifier = Modifier.animateItemPlacement(),
)
}
}
}

FadeVisibility(state.pagingItems.loadState.isRefreshing) {
LazyColumn(Modifier.fillMaxSize()) {
items(PLACEHOLDER_COUNT) {
EventSection(
event = null,
modifier = Modifier.animateItemPlacement(),
)
}
}
}
}
}
}

@Composable
private fun FadeVisibility(
visible: Boolean,
modifier: Modifier = Modifier,
content: @Composable AnimatedVisibilityScope.() -> Unit,
) {
AnimatedVisibility(
visible = visible,
modifier = modifier,
enter = fadeIn(),
exit = fadeOut(),
content = content,
)
}

@Composable
@ExperimentalMaterial3Api
private fun ActivityTopAppBar(text: String = "Events", modifier: Modifier = Modifier) {
private fun ActivityTopAppBar(
text: String = "Events",
modifier: Modifier = Modifier,
) {
TopAppBar(
title = {
Row {
Expand All @@ -105,8 +153,11 @@ private fun ActivityTopAppBar(text: String = "Events", modifier: Modifier = Modi
}

@Composable
private fun EventSection(event: Event?) {
Box(Modifier.padding(horizontal = 16.dp, vertical = 8.dp)) {
private fun EventSection(
event: Event?,
modifier: Modifier = Modifier,
) {
Box(modifier.padding(horizontal = 16.dp, vertical = 8.dp)) {
Button(
onClick = { },
modifier = Modifier.fillMaxWidth(),
Expand Down Expand Up @@ -159,13 +210,13 @@ internal fun PlaceholderText(
) {
Text(
overflow = TextOverflow.Ellipsis,
text = text ?: String(),
text = text ?: EMPTY_STRING,
style = style,
maxLines = 1,
modifier = modifier
.padding(vertical = verticalPadding)
.defaultMinSize(minWidth = Dp(style.fontSize.value * characters))
.fade(text == null),
.placeholder(text == null, highlight = PlaceholderHighlight.fade()),
)
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ import com.slack.circuit.runtime.CircuitUiEvent
import com.slack.circuit.runtime.CircuitUiState
import com.slack.circuit.runtime.screen.Screen
import io.ashdavies.android.FlowRow
import io.ashdavies.android.fade
import io.ashdavies.parcelable.Parcelize
import io.ashdavies.placeholder.PlaceholderHighlight
import io.ashdavies.placeholder.fade
import io.ashdavies.placeholder.placeholder
import kotlin.random.Random.Default.nextInt

@Parcelize
Expand Down Expand Up @@ -121,7 +123,7 @@ private fun StubLanyardFlow(until: Int = 30) {
.border(1.dp, Color.LightGray, CircleShape)
.size(64.dp, 64.dp)
.clip(CircleShape)
.fade(true)
.placeholder(true, highlight = PlaceholderHighlight.fade())
.padding(4.dp),
)
}
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ gitlive-firebase-app = { module = "dev.gitlive:firebase-app", version.ref = "git

google-accompanist-flowlayout = { module = "com.google.accompanist:accompanist-flowlayout", version.ref = "google-accompanist" }
google-accompanist-permissions = { module = "com.google.accompanist:accompanist-permissions", version.ref = "google-accompanist" }
google-accompanist-placeholderMaterial = { module = "com.google.accompanist:accompanist-placeholder-material", version.ref = "google-accompanist" }

google-android-identity = "com.google.android.libraries.identity.googleid:googleid:1.1.0"
google-android-location = "com.google.android.gms:play-services-location:21.3.0"
Expand Down
4 changes: 0 additions & 4 deletions http-common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,3 @@ openApiGenerate {
configOptions.put("library", "multiplatform")
configOptions.put("sourceFolder", ".")
}

detekt {
allRules = false
}
19 changes: 19 additions & 0 deletions placeholder-highlight/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
plugins {
id("com.android.library")
id("io.ashdavies.android")
id("io.ashdavies.compose")
kotlin("multiplatform")
}

android {
namespace = "io.ashdavies.placeholder"
}

kotlin {
sourceSets.commonMain.dependencies {
implementation(compose.material3)
implementation(compose.runtime)

implementation(libs.androidx.annotation)
}
}
Loading

0 comments on commit 44f63b5

Please sign in to comment.