Fixed
Status Update
Comments
je...@google.com <je...@google.com> #2
Some notes from digging into this a bit:
- unexpected wrapping doesn't start until a TextView that line wraps runs it's line breaking logic.
- style doesn't seem to matter, so long as the line breaker is ran.
- Moving the
TextView
below the compose view so that it runs first makes the first draw not wrap in the compose text. Subsequent re-measures will start wrapping. - This may require a
StaticLayout
to run inTextView
beforeStaticLayout
runs inText
(BoringLayout
doesn't seem to cause this, but that doesn't have line breaking by definition), but I'm not certain.
- Inputs to
LineBreaker.computeLineBreaks
seem to have consistent arguments for repro and non-repro use cases. - Couldn't run in demo app, so the layouts/views may also be necessary to repro.
- Used a API 35 Pixel 9 Pro XL emulator to repro. Verified that using API 34 does not repro.
- Moving the
TextView
from the layout to anAndroidView
in ourComposeView
still repros.
ta...@gmail.com <ta...@gmail.com> #3
Able to repro from a blank project with only activity-compose, compose foundation, and the font files.
- Create new blank compose project. (should be target api 35 already)
- Replace
dependencies
inapp/build.gradle.kts
with the below and sync the dependencies. - Delete the
ui
source dirs (all the material related stuff). - Copy the font files from the
reprod.zip
in the description of this bug into the new project. - Replace the
MainActivity
file with the below code. - Run the app on a Pixel 9 Pro XL - API 35 emulator.
dependencies {
implementation("androidx.activity:activity-compose:1.10.0")
implementation("androidx.compose.foundation:foundation:1.7.6")
}
import android.os.Bundle
import android.widget.TextView
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.safeContentPadding
import androidx.compose.foundation.text.BasicText
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.Font
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.viewinterop.AndroidView
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent { Content() }
}
}
private val ReproFontFamily =
FontFamily(
Font(R.font.noto_ikea_latin_regular, FontWeight.Normal),
Font(R.font.noto_ikea_latin_bold, FontWeight.Bold)
)
@Composable
private fun Content() {
Column(
modifier = Modifier
.safeContentPadding()
.fillMaxWidth()
.padding(32.dp)
) {
AndroidView(factory = { ctx -> TextView(ctx).apply { text = "Line1\nLine2" } })
BasicText(
text = "ALEX",
style = TextStyle(
fontWeight = FontWeight.Bold,
color = Color.Black,
fontFamily = ReproFontFamily,
fontSize = 14.sp,
lineHeight = 22.sp,
),
modifier = Modifier.background(Color.Magenta),
)
}
}
je...@google.com <je...@google.com> #4
This actually does work in the demo app, I just forgot to change the target api. See
an...@google.com <an...@google.com>
ta...@gmail.com <ta...@gmail.com> #5
Maybe related, but not convinced:
ap...@google.com <ap...@google.com> #6
Nona, can you take a look?
je...@google.com <je...@google.com>
pr...@google.com <pr...@google.com> #7
Regarding "Seems to only be reproducible when using our custom font" this is not true for me. I'm having issues with Montserrat font where changing lineBreak setting helps, but also on a default font with settings:
fontSize = 12.sp
fontWeight = SemiBold
letterSpacing = 0
lineHeights = 16.sp
fontSize = 12.sp
fontWeight = SemiBold
letterSpacing = 0
lineHeights = 16.sp
Description
Jetpack Compose version:
BOM 2024.09.00
Jetpack Compose component(s) used:
Compose Testing (createComposeRule)
Android Studio Build:
Android Studio Meerkat | 2024.3.1 Canary 3 Build #AI-243.21565.193.2431.12691553, built on November 21, 2024 Runtime version: 21.0.5+-12651406-b631.16 aarch64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. Toolkit: sun.lwawt.macosx.LWCToolkit macOS 14.4.1
Steps to Reproduce or Code Sample to Reproduce:
Expected Behavior:
The default theme should prevent the ActionBar from overlapping the Compose content, as most users use themes without ActionBars in Compose-based projects. In fact, newly created Android projects use
android:Theme.Material.Light.NoActionBar
by default, which naturally avoids this issue. Updating the default testing environment to setwindowActionBar=false
would better align with typical use cases and expected behaviors.Actual Behavior:
The ActionBar is displayed and overlaps the Compose content. This leads to confusion, especially for beginners or developers trying to test simple layouts, as their content may not appear as expected.
Related links
Reproduced Repository:
https://github.com/takahirom/createComposeRule-ActionBar-Overrapping-issue/blob/main/module/src/androidTest/java/com/github/takahirom/module/ExampleInstrumentedTest.kt
Relevant Pull Request:
https://github.com/android/nowinandroid/pull/1719