8

It looks like Apple's TabView supports rearrangements automatically, but it quickly loses a rearrangement after you click on a tab.

Here's my playground code.

import SwiftUI
import PlaygroundSupport

struct ContentView: View {
    @State var arr = ["1","2","3","4","5","6"]
    var body: some View {
        TabView {
            ForEach(self.arr, id: \.self) { name in
                Text("Tab \(name) content")
                    .tabItem {
                        Image(systemName: "\(name).square.fill")
                        Text(name)
                    }
            }
        }
        .font(.headline)
    }
}

PlaygroundPage.current.setLiveView(ContentView())

Here's the steps I go through in the gif.

  1. I start on tab "1"
  2. I go to the "more" tab and then click "edit"
  3. I swap tab "2" with tab "3"
  4. Close the rearrange screen
  5. Then when I click tab "2" (which is now in position 3), the app resets the tabs back to their original order!

Demo of issue

I'm not sure if this is a SwiftUI bug or if there's a onRearrange hook I should have been listening to or what.

joehinkle11
  • 491
  • 1
  • 4
  • 9

0 Answers0