SwiftUI-Games

Форк
0
/
MenuView.swift 
68 строк · 1.9 Кб
1
//
2
//  SwiftUIView.swift
3
//  TBS
4
//
5
//  Created by Damir Minnegalimov on 28.05.2021.
6
//  Copyright © 2021 Damirka. All rights reserved.
7
//
8

9
import SwiftUI
10

11

12
struct MenuView: View {
13
  @State private var showingGame = false
14
  @State private var currentGame: Game?
15
  
16
  var body: some View {
17
    // ZStack it is just a bad workaround for GCVirtualController.
18
    // Earlier I used `fullScreenCover`, but GCVirtualController appears BELOW it.
19
    // So keep GCVirtualController in View, not Overlay/Modal/Sheet containers
20
    ZStack {
21
      List(Games, id: \.name) { game in
22
        Button {
23
          withAnimation {
24
            currentGame = game
25
            showingGame.toggle()
26
          }
27
        } label: {
28
          HStack {
29
            Image(systemName: game.iconName)
30
              .resizable()
31
              .scaledToFit()
32
              .frame(width: 100, height: 100)
33
              .padding()
34

35
            VStack(alignment: .leading) {
36
              Text(game.name)
37
                .font(.title2.weight(.heavy))
38
                .foregroundColor(.primary)
39

40
              Text(game.description)
41
                .font(.body.weight(.bold))
42
                .foregroundColor(.secondary)
43
            }
44
          }
45
        }
46
        .padding(.horizontal, -5)
47
      }
48
      .listStyle(.plain)
49

50
      if showingGame {
51
        switch currentGame {
52
        case let currentGame as MinimalDemo:
53
          MinimalDemoView(game: currentGame, showing: $showingGame)
54
        case let currentGame as TBSGame:
55
          TBSGameView(game: currentGame, showing: $showingGame)
56
        case let currentGame as TogetherGame:
57
          TogetherGameView(game: currentGame, showing: $showingGame)
58
        case let currentGame as DarkGame:
59
          DarkGameView(game: currentGame, showing: $showingGame)
60
        case let currentGame as JumpGame:
61
          JumpGameView(game: currentGame, showing: $showingGame)
62
        default:
63
          EmptyView()
64
        }
65
      }
66
    }
67
  }
68
}
69

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.