|
import SwiftUI |
|
|
|
struct CoverWithBoolView: View { |
|
@State var presentCover: Bool = false |
|
|
|
var body: some View { |
|
GeometryReader { proxy in |
|
ZStack { |
|
if proxy.size.height > proxy.size.width { |
|
Color.gray |
|
PortraitView() |
|
} else { |
|
Color.pink |
|
LandscapeView() |
|
} |
|
} |
|
} |
|
} |
|
} |
|
|
|
struct PortraitView: View { |
|
var body: some View { |
|
HStack { |
|
SelectionView(landscape: false) |
|
DetailsView(landscape: false) |
|
} |
|
} |
|
} |
|
|
|
struct LandscapeView: View { |
|
var body: some View { |
|
HStack { |
|
SelectionView(landscape: true) |
|
DetailsView(landscape: true) |
|
} |
|
} |
|
} |
|
|
|
struct DetailsView: View { |
|
var landscape: Bool |
|
|
|
var body: some View { |
|
if landscape { |
|
DetailInfoView() |
|
} else { |
|
VStack { |
|
DetailInfoView() |
|
UserView(landscape: landscape) |
|
} |
|
} |
|
} |
|
} |
|
|
|
struct SelectionView: View { |
|
var landscape: Bool |
|
|
|
var body: some View { |
|
if landscape { |
|
VStack { |
|
UserView(landscape: landscape) |
|
CategoriesView() |
|
} |
|
} else { |
|
CategoriesView() |
|
} |
|
} |
|
} |
|
|
|
struct CategoriesView: View { |
|
let listOfCategories: [String] = ["A", "list", "of", "categories"] |
|
|
|
var body: some View { |
|
List(listOfCategories, id:\.self) { item in |
|
Text(item) |
|
} |
|
} |
|
} |
|
|
|
struct DetailInfoView: View { |
|
let listOfInfo: [String] = ["Details", "about", "the", "selected", "info", "category"] |
|
|
|
var body: some View { |
|
List(listOfInfo, id:\.self) { item in |
|
Text(item) |
|
} |
|
} |
|
} |
|
|
|
struct UserView: View { |
|
var landscape: Bool |
|
|
|
var body: some View { |
|
if landscape { |
|
HStack { |
|
AvatarImageView() |
|
ActionsView() |
|
} |
|
} else { |
|
VStack { |
|
AvatarImageView() |
|
ActionsView() |
|
} |
|
} |
|
} |
|
} |
|
|
|
struct ActionsView: View { |
|
var body: some View { |
|
Text("View with actions for users") |
|
} |
|
} |
|
|
|
struct AvatarImageView: View { |
|
@State var presentCover: Bool = false |
|
|
|
var body: some View { |
|
Button("Show detail") { |
|
presentCover = true |
|
} |
|
.fullScreenCover(isPresented: $presentCover, content: { |
|
Text("Detail") |
|
}) |
|
} |
|
} |
|
|
|
#Preview { |
|
CoverWithBoolView() |
|
} |
Here is another simple version where the overlay content is provided by the calling leaf view (could also be easily adjusted to move the detail content selection to the presenter, same idea):