-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Reader] Implement "Tags" feed horizontal posts list item component loading #20634
Merged
RenanLukas
merged 12 commits into
feature/tags-ia
from
issue/20268-implement-horizontal-post-list-ui-shimmer
Apr 18, 2024
Merged
Changes from 7 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
65cee90
Implement HorizontalPostListItemLoading
RenanLukas 1834b15
Implement shimmer effect, update Compose preview
RenanLukas 53b507c
Merge branch 'issue/20587-implement-horizontal-posts-list-ui-componen…
RenanLukas b970e1d
Remove blog avatar from loading
RenanLukas 96225d2
Merge branch 'issue/20587-implement-horizontal-posts-list-ui-componen…
RenanLukas 907d5df
Fix detekt, remove extra padding
RenanLukas bb34a6f
Merge branch 'issue/20587-implement-horizontal-posts-list-ui-componen…
RenanLukas 212400e
Move shimmer color to generic component
RenanLukas 4a8a19a
Change shimmer implementation
RenanLukas 429fcbf
Fix detekt
RenanLukas 3ae8b58
Remove shimmer effect
RenanLukas c54757c
Fix detekt
RenanLukas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
WordPress/src/main/java/org/wordpress/android/ui/compose/components/shimmer/Shimmer.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,85 @@ | ||
package org.wordpress.android.ui.compose.components.shimmer | ||
|
||
import androidx.compose.animation.core.LinearEasing | ||
import androidx.compose.animation.core.RepeatMode | ||
import androidx.compose.animation.core.animateFloat | ||
import androidx.compose.animation.core.infiniteRepeatable | ||
import androidx.compose.animation.core.rememberInfiniteTransition | ||
import androidx.compose.animation.core.tween | ||
import androidx.compose.foundation.background | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.composed | ||
import androidx.compose.ui.geometry.Offset | ||
import androidx.compose.ui.graphics.Brush | ||
import androidx.compose.ui.graphics.Color | ||
import org.wordpress.android.ui.compose.theme.AppColor | ||
|
||
/** | ||
* Taken from https://github.com/canerkaseler/jetpack-compose-shimmer-loading-animation | ||
*/ | ||
internal fun Modifier.shimmerLoadingAnimation( | ||
isLoadingCompleted: Boolean = true, | ||
isLightModeActive: Boolean = true, | ||
widthOfShadowBrush: Int = 500, | ||
angleOfAxisY: Float = 270f, | ||
durationMillis: Int = 1000, | ||
): Modifier { | ||
if (isLoadingCompleted) { | ||
return this | ||
} else { | ||
return composed { | ||
val shimmerColors = ShimmerAnimationData(isLightMode = isLightModeActive).getColours() | ||
|
||
val transition = rememberInfiniteTransition(label = "") | ||
|
||
val translateAnimation = transition.animateFloat( | ||
initialValue = 0f, | ||
targetValue = (durationMillis + widthOfShadowBrush).toFloat(), | ||
animationSpec = infiniteRepeatable( | ||
animation = tween( | ||
durationMillis = durationMillis, | ||
easing = LinearEasing, | ||
), | ||
repeatMode = RepeatMode.Restart, | ||
), | ||
label = "Shimmer loading animation", | ||
) | ||
|
||
this.background( | ||
brush = Brush.linearGradient( | ||
colors = shimmerColors, | ||
start = Offset(x = translateAnimation.value - widthOfShadowBrush, y = 0.0f), | ||
end = Offset(x = translateAnimation.value, y = angleOfAxisY), | ||
), | ||
) | ||
} | ||
} | ||
} | ||
|
||
internal data class ShimmerAnimationData( | ||
private val isLightMode: Boolean | ||
) { | ||
fun getColours(): List<Color> { | ||
return if (isLightMode) { | ||
val color = AppColor.White | ||
|
||
listOf( | ||
color.copy(alpha = 0.3f), | ||
color.copy(alpha = 0.5f), | ||
color.copy(alpha = 1.0f), | ||
color.copy(alpha = 0.5f), | ||
color.copy(alpha = 0.3f), | ||
) | ||
} else { | ||
val color = AppColor.Black | ||
|
||
listOf( | ||
color.copy(alpha = 0.0f), | ||
color.copy(alpha = 0.3f), | ||
color.copy(alpha = 0.5f), | ||
color.copy(alpha = 0.3f), | ||
color.copy(alpha = 0.0f), | ||
) | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
WordPress/src/main/java/org/wordpress/android/ui/compose/components/shimmer/ShimmerBox.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,26 @@ | ||
package org.wordpress.android.ui.compose.components.shimmer | ||
|
||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
|
||
@Composable | ||
fun ShimmerBox( | ||
modifier: Modifier = Modifier, | ||
isLoadingCompleted: Boolean = true, | ||
isLightModeActive: Boolean = true, | ||
widthOfShadowBrush: Int = 500, | ||
angleOfAxisY: Float = 270f, | ||
durationMillis: Int = 1000, | ||
) { | ||
Box( | ||
modifier = modifier | ||
.shimmerLoadingAnimation( | ||
isLoadingCompleted = isLoadingCompleted, | ||
isLightModeActive = isLightModeActive, | ||
widthOfShadowBrush = widthOfShadowBrush, | ||
angleOfAxisY = angleOfAxisY, | ||
durationMillis = durationMillis, | ||
) | ||
) | ||
} |
133 changes: 133 additions & 0 deletions
133
...press/android/ui/reader/views/compose/horizontalpostlist/HorizontalPostListItemLoading.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,133 @@ | ||
package org.wordpress.android.ui.reader.views.compose.horizontalpostlist | ||
|
||
import android.content.res.Configuration | ||
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.Row | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxHeight | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.width | ||
import androidx.compose.foundation.lazy.LazyRow | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.clip | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import org.wordpress.android.ui.compose.components.shimmer.ShimmerBox | ||
import org.wordpress.android.ui.compose.theme.AppColor | ||
import org.wordpress.android.ui.compose.theme.AppTheme | ||
import org.wordpress.android.ui.compose.unit.Margin | ||
|
||
@Composable | ||
fun HorizontalPostListItemLoading() { | ||
val loadingColor = AppColor.Black.copy( | ||
alpha = 0.08F | ||
) | ||
Column( | ||
modifier = Modifier | ||
.width(240.dp) | ||
.height(340.dp), | ||
) { | ||
Row( | ||
modifier = Modifier.fillMaxWidth(), | ||
verticalAlignment = Alignment.CenterVertically, | ||
) { | ||
ShimmerBox( | ||
modifier = Modifier | ||
.width(99.dp) | ||
.height(8.dp) | ||
.clip(shape = RoundedCornerShape(16.dp)) | ||
.background(loadingColor), | ||
isLoadingCompleted = false, | ||
) | ||
} | ||
ShimmerBox( | ||
modifier = Modifier | ||
.padding(top = Margin.Large.value) | ||
.width(204.dp) | ||
.height(18.dp) | ||
.clip(shape = RoundedCornerShape(16.dp)) | ||
.background(loadingColor), | ||
isLoadingCompleted = false, | ||
) | ||
ShimmerBox( | ||
modifier = Modifier | ||
.padding(top = Margin.Large.value) | ||
.width(140.dp) | ||
.height(18.dp) | ||
.clip(shape = RoundedCornerShape(16.dp)) | ||
.background(loadingColor), | ||
isLoadingCompleted = false, | ||
) | ||
ShimmerBox( | ||
modifier = Modifier | ||
.padding(top = Margin.Large.value) | ||
.fillMaxWidth() | ||
.height(150.dp) | ||
.clip(shape = RoundedCornerShape(8.dp)) | ||
.background(loadingColor), | ||
isLoadingCompleted = false, | ||
) | ||
ShimmerBox( | ||
modifier = Modifier | ||
.padding( | ||
start = Margin.Small.value, | ||
top = Margin.Large.value, | ||
) | ||
.width(170.dp) | ||
.height(8.dp) | ||
.clip(shape = RoundedCornerShape(16.dp)) | ||
.background(loadingColor), | ||
isLoadingCompleted = false, | ||
) | ||
ShimmerBox( | ||
modifier = Modifier | ||
.padding( | ||
start = Margin.Small.value, | ||
top = Margin.Large.value, | ||
) | ||
.width(170.dp) | ||
.height(8.dp) | ||
.clip(shape = RoundedCornerShape(16.dp)) | ||
.background(loadingColor), | ||
isLoadingCompleted = false, | ||
) | ||
} | ||
} | ||
|
||
@Preview | ||
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES) | ||
@Composable | ||
fun HorizontalPostListItemLoadingPreview() { | ||
AppTheme { | ||
Box( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.fillMaxHeight() | ||
) { | ||
LazyRow( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(top = 16.dp, bottom = 16.dp), | ||
contentPadding = PaddingValues(horizontal = 12.dp), | ||
) { | ||
item { | ||
HorizontalPostListItemLoading() | ||
Spacer(Modifier.width(12.dp)) | ||
HorizontalPostListItemLoading() | ||
Spacer(Modifier.width(12.dp)) | ||
HorizontalPostListItemLoading() | ||
Spacer(Modifier.width(12.dp)) | ||
HorizontalPostListItemLoading() | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe nitpick - I see creation of ShimmerBox instances with similar modifiers. Is there a way to further abstract these calls?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@daniloercoli I think the color and shape repeats in many cases. The shape is not always the same, though, so maybe I can move the color to the
ShimmerBox
component? WDYT?(Edit)
I've extracted the shimmer background color to the generic component.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Feel free to merge this PR.