SwiftUI iOS17 - Toolbar Bugs
Asked Answered
A

0

6

Since iOS 17, certain things in the toolbar do not work anymore.

In this example it is the following:

  • rotationEffect, scaleEffect, rotationEffect3D, foregroundStyle, foregroundColor and probably more on a button label do not work in iOS 17 but have the correct behavior in iOS 16
  • ToolbarItem(placement: .keyboard) does not work in iOS 17, works in iOS 16

Here is the minimal example:

struct ContentView: View {
    @State private var buttonRotation: CGFloat = 0
    @State private var isActive: Bool = false
    @State private var text: String = ""
    
    var body: some View {
        NavigationStack {
            VStack {
                Text("Hello, world!")
                TextField("Text here", text: $text)
            }
            .padding()
            .toolbar {
                ToolbarItem(placement: .topBarTrailing) {
                    Button(action: {
                        buttonRotation += 30
                        isActive.toggle()
                    }) {
                        Label("Info", systemImage: "info.circle")
                        // `rotationEffect` does not work in iOS 17, works in iOS 16
                        // the same for `scaleEffect`, `rotationEffect3D` and probably more
                            .rotationEffect(.degrees(buttonRotation))
                        // `foregroundStyle` & `foregroundColor` do not work in iOS 17, works in iOS 16
                            .foregroundStyle(isActive ? .purple : .accentColor)
                    }
                    // `tint` works in iOS 17 & 16
                    .tint(isActive ? .purple : .accentColor)
                }
                // `ToolbarItem(placement: .keyboard)` does not work in iOS 17, works in iOS 16
                ToolbarItem(placement: .keyboard) {
                    Button(action: { }) {
                        Text("Button")
                    }
                }
            }
        }
    }
}

If the button in the topBarTrailing is clicked first, the keyboard will show up in iOS 17, but not if the Textfield is clicked first.

(First Image iOS 16.2; Second iOS 17.0)

iOS 16.2 iOS 17.0

Does anyone know workarounds?

I also posted this on the Apple Forum (https://developer.apple.com/forums/thread/740315) and filed a feedback (FB13302279)

Alexandria answered 26/10, 2023 at 7:46 Comment(2)
Did you manage to get this working? I'm having the same issueCuster
Nope, I removed the animations and the keyboard toolbar button. Unfortunately having this experience with apple a lot. I can‘t understand how such things won’t get fixed as soon as possible.Alexandria

© 2022 - 2024 — McMap. All rights reserved.