Questions tagged [swiftui-tabview]

For questions about TabView - a component in Apple's SwiftUI framework that switches between multiple child views using interactive user interface elements. When using this tag also include the more generic [swiftui] tag where possible.

Links:

  • Apple Developer Documentation for TabView.
325 questions
30
votes
3 answers

OnAppear calls unexpectedly when Keyboard Appears in SwiftUI

I am experiencing very odd behavior in SwiftUI 2.0 and iOS14. When the keyboard appears on the screen, the OnAppear method of other tab's view called automatically. However, this works fine Xcode 11.7 Here is the issue in action. Here is the code…
Malav Soni
  • 2,739
  • 1
  • 23
  • 52
21
votes
2 answers

How can I get rid of index dots on TabView with PageTabViewStyle in SwiftUI?

I have the following code but can't seem to remove the dots at the bottom of the TabView. struct ContentView: View { @Environment(\.managedObjectContext) private var viewContext @State var users = ["Janice", "Emily", "Candice",…
alionthego
  • 8,508
  • 9
  • 52
  • 125
16
votes
7 answers

SwiftUI Hide TabView bar inside NavigationLink views

I have a TabView and separate NavigationView stacks for every Tab item. It works well but when I open any NavigationLink the TabView bar is still displayed. I'd like it to disappear whenever I click on any NavigationLink. struct MainView: View { …
pawello2222
  • 46,897
  • 22
  • 145
  • 209
15
votes
4 answers

SwiftUI TabView PageTabViewStyle prevent changing tab?

I have a TabView in SwiftUI in the PageViewTabStyle so i can swipe from page to page. I'd like to have a setting that "locks" the current view in place, so the user cannot swipe. Googling and reading docs isn't turning up anything obvious for me, so…
Hoopes
  • 3,943
  • 4
  • 44
  • 60
11
votes
3 answers

SwiftUI TabView: how to detect click on a tab?

I would like to run a function each time a tab is tapped. On the code below (by using onTapGesture) when I tap on a new tab, myFunction is called, but the tabview is not changed. struct DetailView: View { var model: MyModel @State var…
Daniele B
  • 19,801
  • 29
  • 115
  • 173
10
votes
1 answer

SwiftUI: NavigationLink pops out immediately on WatchOS 8.1RC in Tabview

I have discovered a regression in watchOS 8.1RC with NavigationLink triggered from a TabView. It's immediately dismissed. It was working in watchOS 8.0 or in Simulator (watchOS 8.0). Do you know a workaround ? Thanks Sample code: import…
10
votes
2 answers

SwiftUI - detecting Long Press while keeping TabView swipable

I'm trying to detect a Long Press gesture on TabView that's swipable. The issue is that it disables TabView's swipable behavior at the moment. Applying the gesture on individual VStacks didn't work either - the long press doesn't get detected if I…
Kirill
  • 738
  • 10
  • 26
10
votes
0 answers

How to use TabView or ScrollView for carousel?

I'm trying to create a carousel like some of Apple's apps. The TabView has the paged style but it doesn't "peek" at the previous and next elements. The ScrollView(.horizontal) doesn't snap. I'm hoping for a mixture of the two behaviours without…
TruMan1
  • 33,665
  • 59
  • 184
  • 335
10
votes
1 answer

Why is makeUIView being called multiple times when within TabView?

My app has a TabView (PageTabViewStyle) and within each tab is a UIViewRepresentable. I have simplified the code to produce a minimum reproducible example below. The problem is that makeUIView is being called multiple times when it appears, and…
nicksarno
  • 3,850
  • 1
  • 13
  • 33
9
votes
1 answer

Navigation + Tabview + Sheet broken in iOS 15

It looks like Navigation + TabView + Sheet is broken in iOS 15. When I do this: ContentView -> DetailView -> Bottom Sheet When the bottom sheet comes up, the Detail view is automatically popped off the…
9
votes
1 answer

iOS14 SwiftUI How to Disable Scroll on TabView

TabView(selection: $vm.selectedTab) { PlanCard_PositiveDay(vm: vm).tag(0) PlanCard_CountdownDay().tag(1) PlanCard_Basalkcal().tag(2) PlanCard_ActivityDiet().tag(3) PlanCard_Schedule().tag(4) …
wanbo
  • 868
  • 9
  • 24
8
votes
1 answer

SwiftUI TabView Updating Selection Does Not Update Selected Tab

For some reason updating the selection does not update the selected tab in this very simple example. My expectation would be that it would show Tab 1 initially, and when I press the Toggle Tab button, it should slide over to Tab 0. Instead I have…
skajake
  • 438
  • 1
  • 6
  • 12
8
votes
1 answer

SwiftUI navigation titles within TabView

For the reason outlined in the answer outlined in this question SwiftUI TabView brightness views vertical location the menu structure for my app is NavigationView -> TabView -> sub view with varying navigation titles. The problem is that…
8
votes
2 answers

Add shadow above SwiftUI's TabView

I'm trying to implement TabView in SwiftUI that has the same color as screen background but also has a shadow above it like in this picture: So far I've been able to properly display color, but I don't know how to add the shadow. This is my…
Ella Gogo
  • 1,051
  • 1
  • 11
  • 17
8
votes
2 answers

SwiftUI how to keep track of page index in PageTabViewStyle?

I'm trying to keep track of what page the user is on in a TabView that is PageTabViewStyle in SwiftUI but I can't figure out the best way to keep track of the page index? Using .onAppear doesn't work well as it gets called multiple times and pages…
GarySabo
  • 5,806
  • 5
  • 49
  • 124
1
2 3
21 22