Hi im doing an app for iPad an iPhone so I have a condition to detect the screen size .regular o .compact then I show an iPad navigation view or a tabview on iPhone or .compact view. import SwiftUI
struct NavigationViewForiPhone : View{
var body: some View{
TabView{
Text("Hi im on iphone or landscape on iPhone no plus")
.tabItem {
Image(systemName: "house.fill")
Text("Inicio")
}
Text("Hi im on iphone or landscape on iphone plus")
.tabItem {
Image(systemName: "house.fill")
Text("Second")
}
}
.background(Color.blue)
.navigationBarTitle("iPhone View")
}
}
struct NavigationViewForiPad : View{
var body: some View{
NavigationView{
List{
NavigationLink(destination: Text("Text hi")){
HStack{
Text("hi im a menu")
}
}
NavigationLink(destination: Text("Text hi")){
HStack{
Text("hi im a menu")
}
}
NavigationLink(destination: Text("Text hi")){
HStack{
Text("hi im a menu")
}
}
NavigationLink(destination: Text("Text hi")){
HStack{
Text("hi im a menu")
}
}
.navigationBarTitle("iPad View")
}
VStack{
Text("Hi im on ipad")
Text("Hi im on iPad or iPhone plus")
Text("Hi im on ipad")
}
.navigationViewStyle(DoubleColumnNavigationViewStyle())
}
.background(Color.red)
}
}
struct ContentView: View {
// MARK: - Detectar el tamaño de la pantalla
@Environment(\.horizontalSizeClass) var sizeClass
var body: some View{
Group{
// MARK: - Mostrar navegacion con pestañas en iPhone
if self.sizeClass == .compact
{
withAnimation(.easeInOut(duration: 1) ){
return NavigationViewForiPhone()
}
}
else
{
withAnimation(.easeInOut(duration: 1) ){
return NavigationViewForiPad()
}
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
so the problem is that when on the iPhone (plus size and max size) change to landscape or portrait the views changes is not smooth I try a lot of thing to animate the transition but I don't find the way.
Any idea or suggestion?