Thanks for the quick feedback.
In your image, the text is not entirely centered but right aligned.
To clarify myself, I removed the button corner radius and add the same button to the screen center.
You can see in my attached screenshot the default text alignment is different between the two buttons.
The button text in the toolbar is obviously right aligned (The last "m" is closer to the edge than the beginning "c").
I have tried a few different ToolBarItem placements. Placements like .confirmationAction or .navigationBarTrailing, etc. all have this behaviour.
In my opinion, it should be the button not the text that gets right aligned. If this is not a bug, what is the solution to this?
import SwiftUI
struct TestView: View {
var body: some View {
NavigationView {
ZStack {
Color(.black)
.ignoresSafeArea()
Text("Hello World")
.foregroundColor(.white)
.toolbarRole(.editor)
.toolbar {
ToolbarItem(placement: .confirmationAction) {
Button(action: {print("confirm.")}) {
Text("confirm")
}
.background(.yellow)
.foregroundColor(.white)
}
}
Button(action: {print("confirm.")}) {
Text("confirm")
}
.background(.yellow)
.foregroundColor(.white)
.offset(y: 20)
}
}
}
}
struct TestView_Previews: PreviewProvider {
static var previews: some View {
TestView()
}
}
Post
Replies
Boosts
Views
Activity
Following is a workaround which forces the center alignment to the text in the button of toolbar.
However, I still need to know if this is a bug.
Button(action: {print("confirm.")}) {
Text("confirm")
.alignmentGuide(HorizontalAlignment.center, computeValue: { d in
d[HorizontalAlignment.center]
})
}
I found this issue under the both swift-gRPC and swift-nio projects on github.
From the contributor disscusions, I can see the issue is likely caused by XCode since 2019.
I will file a bug to https://feedbackassistant.apple.com as they suggested.
The issue may have just been fixed.
Adding GRPC to the Link Binary with Libraries in test target works.
Yes, I have the same issue. It is super annoying.
The answer to this is in the documentation:
When configuring a scroll position, SwiftUI will attempt to keep that position stable. For an edge, that means keeping a top aligned scroll view scrolled to the top if the content size changes. For a point, SwiftUI won’t attempt to keep that exact offset scrolled when the content size changes nor will it update to a new offset when that changes.
In Xcode 16.1 beta, live preview fails in large (scheme) project, even for the simplest view such as hello world text. It takes very long time to build the view and eventually report over 15 seconds time limit.
I am pretty the such a simple view doesn't have reference to any other project files.
However, if I copy the view into a fresh created project, the live preview works.
This situation also applies to the live preview on device.