Skip to content

Commit

Permalink
[JetNews] Align the card height of popular items without using a hard… (
Browse files Browse the repository at this point in the history
  • Loading branch information
mlykotom authored Sep 14, 2023
2 parents 7a0b44c + 7388459 commit 7eaaae6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.IntrinsicSize
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
Expand All @@ -39,9 +41,8 @@ import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
Expand Down Expand Up @@ -535,11 +536,14 @@ private fun PostListPopularSection(
text = stringResource(id = R.string.home_popular_section_title),
style = MaterialTheme.typography.titleLarge
)
LazyRow(
contentPadding = PaddingValues(horizontal = 16.dp),
Row(
modifier = Modifier
.horizontalScroll(rememberScrollState())
.height(IntrinsicSize.Max)
.padding(horizontal = 16.dp),
horizontalArrangement = Arrangement.spacedBy(8.dp)
) {
items(posts) { post ->
for (post in posts) {
PostCardPopular(
post,
navigateToArticle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ package com.example.jetnews.ui.home
import android.content.res.Configuration.UI_MODE_NIGHT_YES
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Column
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.width
import androidx.compose.material3.Card
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
Expand Down Expand Up @@ -59,7 +60,7 @@ fun PostCardPopular(
onClick = { navigateToArticle(post.id) },
shape = MaterialTheme.shapes.medium,
modifier = modifier
.size(280.dp, 240.dp)
.width(280.dp)
) {
Column {
Image(
Expand All @@ -78,6 +79,7 @@ fun PostCardPopular(
maxLines = 2,
overflow = TextOverflow.Ellipsis
)
Spacer(modifier = Modifier.weight(1f))
Text(
text = post.metadata.author.name,
maxLines = 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.example.jetnews

import androidx.compose.ui.test.hasText
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.onNodeWithText
Expand Down Expand Up @@ -50,11 +51,11 @@ class JetnewsTests {
fun app_opensArticle() {

println(composeTestRule.onRoot().printToString())
composeTestRule.onNodeWithText(text = "Manuel Vivo", substring = true).performClick()
composeTestRule.onAllNodes(hasText("Manuel Vivo", substring = true))[0].performClick()

println(composeTestRule.onRoot().printToString())
try {
composeTestRule.onNodeWithText("3 min read", substring = true).assertExists()
composeTestRule.onAllNodes(hasText("3 min read", substring = true))[0].assertExists()
} catch (e: AssertionError) {
println(composeTestRule.onRoot().printToString())
throw e
Expand Down

0 comments on commit 7eaaae6

Please sign in to comment.