Skip to content
This repository was archived by the owner on Dec 27, 2024. It is now read-only.
This repository was archived by the owner on Dec 27, 2024. It is now read-only.

[Compose] [MotionLayout] Text with animated fontSize returns to its original bounding box after recomposition? #507

@CalamityDeadshot

Description

@CalamityDeadshot

I have the following ConstraintSets for the MotionLayout:

@Composable
private fun StartConstraintSet() = ConstraintSet(
	""" {
	title: {
		top: ['parent', 'top'],
		start: ['parent', 'start'],
		end: ['parent', 'end'],
		bottom: ['content', 'top', 24],
		custom: {
			fontSize: 32,
			fontWeight: 400
		}
	},
	options: { 
		end: ['parent', 'end', 0],
		bottom: ['content', 'top', 15]
	},
	content: {
		bottom: ['parent', 'bottom', 0]
	}
} """
)

@Composable
private fun EndConstraintSet() = ConstraintSet(
	""" {
	title: {
		top: ['parent', 'top', 0],
		start: ['parent', 'start', 16],
		bottom: ['content', 'top', 0],
		custom: {
			fontSize: 20,
			fontWeight: 500
        }
	},
	options: { 
		end: ['parent', 'end', 0],
		bottom: ['content', 'top', 0],
		top: ['parent', 'top', 0]
	},
	content: {
		bottom: ['parent', 'bottom', 0]
	}
                  
} """
)

and the following scene:

MotionLayout(
	start = StartConstraintSet(),
	end = EndConstraintSet(),
	progress = if (swipingState.progress.to == SwipingStates.COLLAPSED) swipingState.progress.fraction else 1f - swipingState.progress.fraction,
	modifier = Modifier
		.fillMaxWidth()
		.height(height)
) {
	Text(
		text = title,
		modifier = Modifier
			.layoutId("title")
			.wrapContentWidth(unbounded = true) // This is necessary because title's last letter was being clipped in both start and end
			.wrapContentHeight(),
		color = MaterialTheme.colors.onSurface,
		fontWeight = FontWeight(motionInt("title", "fontWeight")),
		fontSize = motionFontSize("title", "fontSize")
	)
	OptionsRow(
		options = options,
		modifier = Modifier
			.layoutId("options")
			.fillMaxWidth(.5f)
			.padding(end = 16.dp)
	)

	content(
		Modifier
			.layoutId("content")
	)

}

This is a correctly rendered StartConstraintSet:
image
And this is a correctly rendered EndConstraintSet:
image

However, after the whole app bar is recomposed, title obtains what looks like a margin:
image

This doesn't happen when simply scaling the text, so it must be its bounding box returning to 32sp value from before the transformation. I cannot explain this behavior with anything else.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions