skiptools / skiptools/skip-ui

material3TopAppBar/preferCenterAlignedStyle not working...

Open
#271 0 comments 0 reactions 0 assignees View on GitHub

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.

Image

toolbar-demo.zip

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.