Missing/Broken features in SwiftUI [List]

Hi guys, as many of you (I think), I have been busy learning SwiftUI as fast as I can. In my case for a new app I want to develop for personal purposes and probably for an App Store release.


In my (small) learning journey I have found a few things that SwiftUI is missing or just not working, but since there is not too much information yet I wanted to make a simple thread with all the things I have found at the moment. This can be useful for anyone who is learning SwiftUI or wants to check current SwiftUI status.


I promise to add my findings here and update this post as fast as I can.

Feel free to mention every feature you think is important to have in the list, any features you think is not a bug or broken/missing feature, or any solution you may find to one of this mentioned problems.


Ps: I know we have Xcode release notes but many of the current bugs of SwiftUI are not mentioned there.


SwiftUI missing/broken features (as of beta 3):


  • Can’t remove rows separator from List
  • Can’t push or pop without navigationView
  • Can’t display a modal in full screen (only in the new style)
  • No dismiss modal programatically available (environment safe keypath maybe is the correct solution?)
  • Custom Fonts are sometimes not rendered correctly on Xcode Previews (A little bit fixed in Beta 3 but still buggy)
  • Code Completion in some places is not working (haven’t found a specific way to reproduce the bug consistently but definitely happens)
  • Pinch to Zoom is not working in Xcode Previews
  • Switching between files that have or not have a cambas may cause the cambas to remain open
  • No way to remove the accessory item of a navigationLink inside a List
  • Cant hide navigation bar from NavigationView (There is a new modifier called navigationBarHidden but when the next view is pushed, the navigationBar returns. The modifier only works for the first view not pushed ones)
  • Cant add a custom navigation bar to NavigationView
  • Colors in foregroundColor modifier are not updating in Previews correctly. Sometimes they work but most of the time is the same black color (Working better in beta 3 but some objects including navigationView are still having problems)
  • TextFields do not have a way of setting their keyboard type.
  • TextFields do not have the equivalent of UIKit beginFirstResponder and resignFirstResponder. That means there is no way of programatically setting or removing the focus from a text field.
  • SecureField does not have a way of knowing when the field became active, or inactive (TextField does have onEditChange, but SecureField does not).
  • Popovers as of beta3 seem to be broken.
  • Slider seems broken in Beta 3. No longer increment by Stride
  • .onAppear and .onDisappear are not firing during navigation transitions
  • TextFields are not resized properly when multiline text is used


Solved problems

  • Forms are not available (Now available in Beta 2)
  • Published property wrapper is not fully functional (Available since Beta 2 in Xcode projects. Playgrounds not working)
  • Colors added directly to the xcassets are not working in dark mode (Working in beta 3)
  • LaunchScreen is sometimes stuck with old layouts (happens to me only in SwiftUI projects sometimes) (Working in Beta 3)
  • There is no simple way to change the main view background color (Use background modifier, see answer 3)

Replies

Good information, I'm bookmarking this topic. My short list of problems, as of beta 5:


  • Can't disable animation for when the contents of a List changes.
  • Can't change the List seperators
  • There is no callback or property binding for performing a task after an animation completes.
  • Can't set the keyboard type for TextFields
  • I haven't looked in depth, but I haven't found a way of adding an InputView to a TextField


TextField( self.placeholder, text: self.field )
    .inputView() {
        HStack {
        Spacer()
        Button( action: {...} { Text( "Prev" ) }
        Button( action: {...} { Text( "Next" ) }
   }
}

A few things I've hit (have filed Feedback for issues 2 and 3 below):


1. String(format: <format>, myVar)


For @Published vars, like myVar above, the following format mechanism doesn't work:


Text("\(String(format: "%.03f", model.myVar))")


2. Options spread across two Picker() do not update highlighting correctly


Previously (beta 3), when options were spread across two SegmentedControl() which update the same var in a BindableObject (now ObservableObject) and @EnvironmentObject is used in a View to read/update this var, the hightlight for one SegmentedControl() was updated (de-highlighted) when the other SegmentedControl() was tapped. This is no longer the case.


For example, consider SegmentedControlA() has options A,B,C,D and SegmentedControlB() has options E,F,G,H. These options are tied to $model.myVar. SegmentedControlA() option A is currently highlighted. Now the user taps SegmentedControlB() option G. In beta 3, option A was de-highlighted and option G was highlighted.


With beta 5, replacing SegmentedControl() with Picker(), we start with PickerA() option A highlighted. The user then taps PickerB() option G. In this case, model.myVar is updated, as expected, but the highlight is not removed from option A.


If, however, you either:


1) in a TabView() app, switch to a different Tab and then back to the Tab containing the Pickers() option A is now de-highlighted. Or,

2) background the app by switching to another app or going to the iDevice home screen and then foreground the app


Option A is now de-highlighted.


Example:

  
 
class FooModel: ObservableObject {
    @Published var foo:Double = 1.0
}
struct Foo : View {
    var body: some View {
            VStack {
                ChooseFooLo()
                ChooseFooHi()
        }
    }
}

struct ChooseFooLo : View {
    @EnvironmentObject var model: FooModel
    var body: some View {
         Picker(selection: $model.foo, label: Text("")) {
            Text("A").tag(1.0)
            Text("B").tag(10.0)
            Text("C").tag(100.0)
            Text("D").tag(1000.0)
        }.pickerStyle(SegmentedPickerStyle())
    }
}
struct ChooseFooHi : View {
    @EnvironmentObject var model: FooModel
    var body: some View {<br>
         Picker(selection: $model.foo, label: Text("")) {
            Text("E").tag(10000.0)
            Text("F").tag(20000.0)
            Text("G").tag(30000.0)
            Text("H").tag(40000.0)
        }.pickerStyle(SegmentedPickerStyle())
    }
}
As an aside, I wonder why Picker() requires label: ... I've tried setting label: .nil and that doesn't work. Sigh.


3. Stepper() with Slider() and .cornerRadius.

If a Stepper() and Slider() each control the same var and they are both included in a VStack, and .cornerRadius() is applied to the VStack, the Stepper() no longer works when tapped. Remove .cornerRadius() and everything works as expected. Below is an example. Remove .cornerRadius() and Stepper() works. Add it, and Stepper() no longer works (the example below removes .font() and .background(), since these are not required to reproduce. I've tried various things like changing the size of .cornerRadius(), adding a (e.g.) smaller .cornerRadius() to the Stepper() directly, etc.

  
 
struct ChooseFooSize : View {
     @EnvironmentObject var model: FooModel
     var body: some View {
          VStack {
             Stepper(value: $model.foo_size, in: 64...9216) {
                 Text("Foo size: \(Int(self.model.foo_size))")
             }
             Slider(value: $model.foo_size, in: 64...9216, step: 1)
         }.cornerRadius(10)
     }
}

You cant as of yet build catalyst Applications using SwiftUI (which is a Know Issue with SwiftUI)

can't get/set current scroll position in a List (or ScrollView)

Now it's easy to set keyboard type on a TextField.

TextField("Number", text: someNumber).keyboardType(UIKeyboardType.numbersAndPunctuation)

Unable to change Popover view size on iPad.

Bug Report: FB7465491


struct ContentView: View {
    @State var showPopover: Bool = false
   
    var body: some View {
        Button(action: {
            self.showPopover.toggle()
        }) {
            Text("View Popover")
        }
            .popover(isPresented: $showPopover) {
                Text("Popover")
                    .background(Color.red)
                    .frame(width: 100, height: 100)
            }
    }
}

Yes, but this runs you right into another problem: For some of those keyboards (numberPad, decimalPad, and others) there's no way to dismiss them and capture whatever the user typed into the bound variable.

SelectionShapeStyle (macOS only) is not usable, since it has no public initializers.

Bug Report: FB7511755

Unable to set List row appear/disappear animation.

Another bug: you are unable to rearrange the tab order in TabView without SwiftUI undoing the rearranging.

https://stackoverflow.com/questions/59255398/swiftui-tabview-rearrange-tab-order-preservation

Big problems with SwiftUI Navigation:


- you cannot use gestures (double tap, swipe) to trigger navigationlink. I'd like to tap once to go to detail view, tap twice to edit current row -- you cannot do this with navigationlink, but you could do this with the old UINavigationController;

- you cannot push or pop using gestures;

- after using NavigationLink and you go back, it stops working in Simulator (this bug still exists in 11.3.1);

You might be able to override the gestures in a navigation link by assigning your own gestures to it with a GestureMask of .gesture. That would disable the gestures registered on the NavigationLink itself. Of course, the gesture it's receiving may be part of the List implementation, so it may or may not work. That would be my first try, anyway. Then you'd define the link using one of the other initializers: init(destination:isActive:label:) or init(destination:tag:selection:label:). You'd then be able to use your gestures to set the appropriate values in some state variables, and the links bound to those would fire.

TextEditor is not as customizable as TextField and does not auto-size itself.
This topic is relatively old and relates to the previous version, but I think it would be very helpful to update it or have a separate list that relates to Xcode 12.
  • TextField on macOS needs a label and not only a placeholder (all label in forms on macOS should auto align)

  • Sliders and Labels on macOS seems to have a wrong vertical alignment

  • TouchBar is linked to the control that has the focus. More often it makes sense to show the TouchBar when the window appears or the app launches

  • Missing alignment guide for SwiftUI controls having labels. You can either have the leading, trailing or center but not the position behind the label where the control starts

  • The layout of SwiftUI elements on macOS have still some issues