Skip to content

Commit

Permalink
screens switching example
Browse files Browse the repository at this point in the history
  • Loading branch information
igork-ramotion committed May 4, 2020
1 parent 938ecc0 commit b83c465
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions Example/Example/Screens/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,40 @@ import SwiftUI
import BlobMenu

struct ContentView: View {

enum Screen: Int {
case wallet
case exchange
case commerce
case stocks
}

@State var screen: Screen = .wallet
@Environment(\.blobMenuEnvironment) var menuEnvironment: BlobMenuEnvironment


var body: some View {
ZStack {
screenView.edgesIgnoringSafeArea(Edge.Set.all)
menuView
}
}

private var screenView: some View {
switch screen {
case .wallet: return Rectangle().fill(Color.red)
case .exchange: return Rectangle().fill(Color.green)
case .commerce: return Rectangle().fill(Color.gray)
case .stocks: return Rectangle().fill(Color.yellow)
}
}

private var menuView: some View {
VStack {
BlobMenuView.createMenu(items: MenuItem.all)
Spacer()
BlobMenuView.createMenu(items: MenuItem.all, selectedIndex: self.screen.rawValue).padding(.bottom, 30)
}.onReceive(menuEnvironment.$selectedIndex) { index in
print("index: \(index)")
guard let screen = Screen(rawValue: index) else { return }
self.screen = screen
}
}
}
Expand Down

0 comments on commit b83c465

Please sign in to comment.