|
As Paul Hudson noted in one of his articles: "It’s common to want to use NavigationView and TabView at the same time, but you should be careful: TabView should be the parent view, with the tabs inside it having a NavigationView as necessary, rather than the other way around." Nevertheless, I need the tabbar to disappear once a chat is open. So I currently have a NavigationView as the parent of TabView, hidden on all tabs but the "Chats" one. This NavigationView holds the NavigationLinks within a List that displays a chat view. It works althogh there are some bugs and concernings (e.g. adding an EditButton to List, make it show but doesn't work). Hence I would like to know if someone could figure out another way of making my UI with better code. In case I didn't express myself clearly, I want to achieve a design similar to Whatsapp or Telegram. My code nowadays is similar to this:
Thank you in advance. |
|
Hi I been thinking about this and refering back to Paul statement about TabView and NavigationView. I thought this might be one solution. Create the enum
Then create a TabView
Then create ChatView
Then add in ContentView this code
When run it hids the Nav Bar until you open a chat and then the Tab bar disappear and Nav Bar appears Hope that some ideas |
|
I appreciate the help, but the suggested implementation by @NigelGee has several problems:
All the highlighted issues are mainly resolved by using native views. Otherwise either the development time is generally increased or delivered products have lower quality. So I am asking for an answer that relies only or mainly on native elements. Whenever possible the concerns should not be considerable if having to create custom views. |
|
I am sorry that @RubeDEV do not like the solution. But I will address the comments
I will also put what Paul said "TabView should be the parent view, with the tabs inside it having a NavigationView as necessary, rather than the other way around." Good Luck with finding a native views. |
|
I mean you must actually change the code to adap it to your needs. That's not good practice, instead you should deliver code that can be adaptable when using it. E.g: You can use
whatever n you want (up to 10 due to ViewBuilder restrictions). That's not possible with the code you provided. Instead you should rewrite TabView implementation if you wanted two tabs with different number of elements.
Again, changing the items shown on the bar require you to change TabView code, whereas native About ContentView: it is responsible of showing the view corresponding to the tapped item, which is different of how native TabView works; it only exposes the selected tab in order to let you check in case you would like to perform actions when changed.
Also, the best option is to use I know it kind of work, but consider how many changes you should make given that you wanted to add or remove tabs. These are not good coding practices. PS: I just want to point out all of these objections I made arise from the purpose of spreading good code practices which lead to easier and lighter work in the long-term. |
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.