Status Update
Comments
am...@google.com <am...@google.com>
am...@gmail.com <am...@gmail.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.
am...@google.com <am...@google.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),
)
}
}
ni...@gmail.com <ni...@gmail.com> #4
This actually does work in the demo app, I just forgot to change the target api. See
ni...@gmail.com <ni...@gmail.com> #5
Maybe related, but not convinced:
ar...@google.com <ar...@google.com> #7
fontSize = 12.sp
fontWeight = SemiBold
letterSpacing = 0
lineHeights = 16.sp
[Deleted User] <[Deleted User]> #8
[Deleted User] <[Deleted User]> #9
I don't recommend this, but if you really need a workaround right now, here it is. This is probably quite brittle, slow, and I have not tested it other than checking that it does fix the bug. Use at your own risk. The actual fix for this is expected in 1.8.0-beta02
.
A very hacky workaround would be adding this modifier to the end of your Text
's modifier chain:
/** Intercept pre-layout to manually recycle `StaticLayout.Builder.useBoundsForWidth`. */
private fun Modifier.unexpectedTextWrappingWorkaround(): Modifier =
layout { measurable, constraints ->
if (Build.VERSION.SDK_INT >= 35) {
Api35Helper.resetStaticLayoutBuilderUseBoundsForWidth()
}
val placeable = measurable.measure(constraints)
layout(placeable.width, placeable.height) { placeable.place(0, 0) }
}
@RequiresApi(35)
private object Api35Helper {
@JvmStatic
fun resetStaticLayoutBuilderUseBoundsForWidth() {
StaticLayout.Builder.obtain("a", 0, 1, TextPaint(), 1024)
.setUseBoundsForWidth(false)
.build() // recycles the StaticLayout.
}
}
[Deleted User] <[Deleted User]> #10
Project: platform/frameworks/support
Branch: androidx-main
Author: Seigo Nonaka <
Link:
Fix unexpected enabling of useBoundsForWidth
Expand for full commit details
Fix unexpected enabling of useBoundsForWidth
This fixes a bug where a text may wrap to a second line where it is unnecessary.
Bug: 391378120
Test: Manual tests to ensure the unexpected wrapping stops after the fix is applied
Test: StaticLayoutFactoryTest#create_useBoundsForWidth_disabled
Test: BasicTextUnexpectedWrappingRegressionTest
Change-Id: I1b40c5816f2b4c1e787de05d5332db6fc0efad14
Files:
- A
compose/foundation/foundation/src/androidInstrumentedTest/assets/font/overshoot_test.ttx
- A
compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/text/BasicTextUnexpectedWrappingRegressionTest.kt
- A
compose/foundation/foundation/src/androidInstrumentedTest/res/font/overshoot_test.ttf
- M
compose/ui/ui-text/src/androidInstrumentedTest/kotlin/androidx/compose/ui/text/android/StaticLayoutFactoryTest.kt
- M
compose/ui/ui-text/src/androidMain/kotlin/androidx/compose/ui/text/android/StaticLayoutFactory.android.kt
Hash: 7d19be04e9c2af237f0605a148605bf52f607497
Date: Thu Jan 23 17:40:54 2025
[Deleted User] <[Deleted User]> #11
[Deleted User] <[Deleted User]> #12
This will be targeting 1.8
, likely landing in beta02
.
1.7.*
targets android API 34, and this fix requires API 35. Upgrading 1.7
to android api 35 is too large of a change for a 1.7.x
version.
as...@gmail.com <as...@gmail.com> #13
Separate note, an upstream fix in the android platform is expected in api level 36, so this issue should only occur when API level is 35 and compose version is below 1.8.
ka...@gmail.com <ka...@gmail.com> #14
Saw that beta02
is out but there is no mention of this issue being fixed in the release notes. Were you able to land the fix in beta02 or it got pushed to a future version?
ge...@gmail.com <ge...@gmail.com> #15
Looks like it actually went out in beta01
.
Description
Version used: 25.1.0
Devices/Android versions reproduced on: All
The DetailsFragment crashes when update background.
Steps to reproduce:
/**
* {@inheritDoc}
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
BackgroundManager backgroundManager = BackgroundManager.getInstance(context);
backgroundManager.attach(context.getWindow());
Target mBackgroundTarget = new PicassoBackgroundManagerTarget(backgroundManager);
DisplayMetrics mMetrics = new DisplayMetrics();
context.getWindowManager().getDefaultDisplay().getMetrics(mMetrics);
Picasso.with(context)
.load(uri)
.centerCrop()
.resize(mMetrics.widthPixels, mMetrics.heightPixels)
.error(R.drawable.default_background)
.into(mBackgroundTarget);
}
Stack trace:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v17.leanback.app.BackgroundManager$TranslucentLayerDrawable.setWrapperAlpha(int, int)' on a null object reference
1android.support.v17.leanback.app.BackgroundManager$2.onAnimationUpdate(BackgroundManager.java:433)
2 android.animation.ValueAnimator.animateValue(ValueAnimator.java:1374)
3 android.animation.ValueAnimator.animationFrame(ValueAnimator.java:1298)
4 android.animation.ValueAnimator.doAnimationFrame(ValueAnimator.java:1339)
5 android.animation.ValueAnimator$AnimationHandler.doAnimationFrame(ValueAnimator.java:715)
6 android.animation.ValueAnimator$AnimationHandler.run(ValueAnimator.java:738)
7 android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
8 android.view.Choreographer.doCallbacks(Choreographer.java:580)
9 android.view.Choreographer.doFrame(Choreographer.java:549)
10 android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
11 android.os.Handler.handleCallback(Handler.java:739)
12 android.os.Handler.dispatchMessage(Handler.java:95)
13 android.os.Looper.loop(Looper.java:135)
14 android.app.ActivityThread.main(ActivityThread.java:5302)
15 java.lang.reflect.Method.invoke(Native Method)
16 java.lang.reflect.Method.invoke(Method.java:372)
17 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:917)
18 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:712)