Skip to content

material3TopAppBar/preferCenterAlignedStyle not working... #271

@jeffc-dev

Description

@jeffc-dev

I have been unable to get preferCenterAlignedStyle (and material3TopAppBar) to work. It seems to be ignored, always aligning the title (text or image) to the left.

.toolbar {
	ToolbarItem(placement: .topBarLeading) {
		// Left button here...
	}

	// Center logo - doesn't center on Android even with preferCenterAlignedStyle: true
	ToolbarItem(placement: .principal) {
		Image(systemName: "star.fill")
	}

	ToolbarItem(placement: .topBarTrailing) {
		// Right button here...
	}
}

As I understand it, these modifiers are unusual in SwiftUI in that they must be placed outside of the view they affect. I've applied this in a number of places, including at the app root, to no avail.

#if SKIP
.material3TopAppBar { options in
	return options.copy(preferCenterAlignedStyle: true)
}
#endif

I have attached a screenshot and a simple code sample showing this behavior.

Image

toolbar-demo.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions