Skip to content

Commit

Permalink
Merge pull request #116 from Automattic/hamorillo/113-remove-expandab…
Browse files Browse the repository at this point in the history
…le-components

Remove ExpandableText and replace it uses with a Text composable
  • Loading branch information
hamorillo authored Apr 18, 2024
2 parents 6c97f35 + 6599d07 commit b4a9c80
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 116 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.gravatar.ui.components.atomic

import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import com.gravatar.api.models.UserProfile

Expand All @@ -10,19 +12,27 @@ import com.gravatar.api.models.UserProfile
*
* @param profile The user's profile information
* @param modifier Composable modifier
* @param maxLines The maximum number of lines to display before truncating the text
* @param dialogContent The content to display in a dialog when the truncated text is clicked
* @param content Composable to display the user's about me description
*/
@Composable
public fun AboutMe(
profile: UserProfile,
modifier: Modifier = Modifier,
maxLines: Int = 2,
dialogContent: @Composable ((String) -> Unit)? = { DefaultDialogContent(text = it) },
content: @Composable ((String, Modifier) -> Unit) = { userInfo, contentModifier ->
AboutMeDefaultContent(userInfo, contentModifier)
},
) {
ExpandableText(profile.aboutMe.orEmpty(), modifier, maxLines, dialogContent)
content(profile.aboutMe.orEmpty(), modifier)
}

@Composable
private fun AboutMeDefaultContent(userInfo: String, modifier: Modifier) = Text(
userInfo,
modifier = modifier,
maxLines = 2,
overflow = TextOverflow.Ellipsis,
)

@Preview
@Composable
private fun AboutMePreview() {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.gravatar.ui.components.atomic

import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import com.gravatar.api.models.UserProfile

Expand All @@ -11,19 +13,27 @@ import com.gravatar.api.models.UserProfile
*
* @param profile The user's profile information
* @param modifier Composable modifier
* @param maxLines Maximum number of lines to display
* @param dialogContent Content to display in a dialog when the text is clicked
* @param content Composable to display the user location
*/
@Composable
public fun Location(
profile: UserProfile,
modifier: Modifier = Modifier,
maxLines: Int = 1,
dialogContent: @Composable ((String) -> Unit)? = { DefaultDialogContent(text = it) },
content: @Composable ((String, Modifier) -> Unit) = { location, contentModifier ->
LocationDefaultContent(location, contentModifier)
},
) {
ExpandableText(profile.currentLocation.orEmpty(), modifier, maxLines, dialogContent)
content(profile.currentLocation.orEmpty(), modifier)
}

@Composable
private fun LocationDefaultContent(location: String, modifier: Modifier) = Text(
location,
modifier = modifier,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)

@Preview
@Composable
private fun LocationPreview() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.gravatar.ui.components.atomic

import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import com.gravatar.api.models.UserProfile
import com.gravatar.extensions.formattedUserInfo
Expand All @@ -13,21 +15,27 @@ import com.gravatar.extensions.formattedUserInfo
*
* @param profile The user's profile information
* @param modifier Composable modifier
* @param maxLines The maximum number of lines to display before truncating the text
* @param dialogContent The content to display in a dialog when the truncated text is clicked
* @param content Composable to display the formatted user information
*/
@Composable
public fun UserInfo(
profile: UserProfile,
modifier: Modifier = Modifier,
maxLines: Int = 2,
dialogContent: @Composable ((String) -> Unit)? = { DefaultDialogContent(text = it) },
content: @Composable ((String, Modifier) -> Unit) = { userInfo, contentModifier ->
UserInfoDefaultContent(userInfo, contentModifier)
},
) {
// TODO this doesn't work with one Text field due. If the job_title and the company line is too long,
// it will to break the layout
ExpandableText(profile.formattedUserInfo(), modifier, maxLines, dialogContent)
content(profile.formattedUserInfo(), modifier)
}

@Composable
private fun UserInfoDefaultContent(userInfo: String, modifier: Modifier) = Text(
userInfo,
modifier = modifier,
maxLines = 2,
overflow = TextOverflow.Ellipsis,
)

@Preview
@Composable
private fun UserInfoPreview() {
Expand Down

0 comments on commit b4a9c80

Please sign in to comment.