-
Notifications
You must be signed in to change notification settings - Fork 108
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
Fix textoverflow on top appbar for components with long names #240
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.airbnb.android.showkase.ui | ||
|
||
import androidx.compose.ui.semantics.SemanticsPropertyKey | ||
import androidx.compose.ui.semantics.SemanticsPropertyReceiver | ||
|
||
object SemanticsUtils { | ||
val LineCountKey = SemanticsPropertyKey<Int>("lineCount") | ||
var SemanticsPropertyReceiver.lineCountVal by LineCountKey | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ import androidx.compose.foundation.layout.Column | |
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material.Icon | ||
import androidx.compose.material.IconButton | ||
|
@@ -21,17 +20,20 @@ import androidx.compose.runtime.Composable | |
import androidx.compose.runtime.CompositionLocalProvider | ||
import androidx.compose.runtime.MutableState | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.graphics.graphicsLayer | ||
import androidx.compose.ui.platform.LocalConfiguration | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.platform.testTag | ||
import androidx.compose.ui.semantics.semantics | ||
import androidx.compose.ui.text.TextStyle | ||
import androidx.compose.ui.text.font.FontFamily | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.text.style.TextOverflow | ||
import androidx.compose.ui.unit.sp | ||
import androidx.navigation.NavHostController | ||
import androidx.navigation.compose.NavHost | ||
|
@@ -46,6 +48,7 @@ import com.airbnb.android.showkase.models.ShowkaseBrowserTypography | |
import com.airbnb.android.showkase.models.ShowkaseCategory | ||
import com.airbnb.android.showkase.models.ShowkaseCurrentScreen | ||
import com.airbnb.android.showkase.models.insideGroup | ||
import com.airbnb.android.showkase.ui.SemanticsUtils.lineCountVal | ||
|
||
@Composable | ||
internal fun ShowkaseBrowserApp( | ||
|
@@ -91,8 +94,7 @@ internal fun ShowkaseAppBar( | |
Row( | ||
Modifier.fillMaxWidth() | ||
.graphicsLayer(shadowElevation = 4f) | ||
.padding(padding2x) | ||
.height(64.dp), | ||
.padding(padding2x), | ||
horizontalArrangement = Arrangement.SpaceBetween, | ||
verticalAlignment = Alignment.CenterVertically | ||
) { | ||
|
@@ -186,19 +188,32 @@ private fun ShowkaseAppBarTitle( | |
} | ||
} | ||
|
||
|
||
@Composable | ||
fun ToolbarTitle( | ||
string: String, | ||
modifier: Modifier | ||
) { | ||
val lineCount = remember { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not ideal to have test logic live in the component directly but I guess that happens pretty often in Compose due to how semantics are setup with some hooks into testing. Don't have a better idea on testing this so might be fine for now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Totally agree with you on that! I think this can work for now :) |
||
mutableStateOf(0) | ||
} | ||
|
||
Text( | ||
text = string, | ||
modifier = modifier, | ||
modifier = modifier then Modifier | ||
.semantics { | ||
lineCountVal = lineCount.value | ||
}, | ||
style = TextStyle( | ||
fontSize = 20.sp, | ||
fontFamily = FontFamily.Monospace, | ||
fontWeight = FontWeight.Bold | ||
) | ||
), | ||
maxLines = 3, | ||
overflow = TextOverflow.Ellipsis, | ||
onTextLayout = { | ||
lineCount.value = it.lineCount | ||
} | ||
) | ||
} | ||
|
||
|
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.
we might want to add a maxSize for the height but I'm curious to see the screenshots before that
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.
hmm yeah maybe you're right 🤔 Is it also maybe a bit weird that it spans 3 lines instead of 2? What do you think? :)