material3TopAppBar/preferCenterAlignedStyle not working...
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 330
- Forks
- 76
- Avg merge
- 3h 6m
- Merged PRs (30d)
- 1
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the attached toolbar-demo.zip and reproduce the alignment on Android using the ToolbarItem placements shown. Trace how material3TopAppBar and preferCenterAlignedStyle are applied to the toolbar, then verify that the principal text or image is centered when the option is enabled.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, swift
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100