Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ContentView.swift #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 50 additions & 16 deletions Onout Watch App/ContentView.swift
Original file line number Diff line number Diff line change
@@ -1,39 +1,73 @@
//
// ContentView.swift
// Onout Watch App
//
// Created by Никита Иванов on 03.10.2023.
//

import SwiftUI

struct ContentView: View {
@StateObject private var viewModel = BalanceViewModel()

@State private var inputString = ""
@State private var showingInputDialog = false

@State private var showWalletInputView = false

var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
Text("Hello, world!")
Text("Balance:")
.font(.headline)
.padding()
Text("$\(Int(viewModel.balance))")
.font(.title)
.padding()


Button("Add new wallet") {
showingInputDialog = true
}
.actionSheet(isPresented: $showingInputDialog) {
ActionSheet(title: Text("Choose input method"), buttons: [
.default(Text("Enter on iPhone")) {
showWalletInputView = true
},
.default(Text("Enter on Watch")) {
// Logic for watch input (if any)
},
.cancel()
])
}
.sheet(isPresented: $showWalletInputView) {
WalletInputView(viewModel: viewModel)
}
.padding()
}
.padding()
}
}

struct WalletInputView: View {
@ObservedObject var viewModel: BalanceViewModel
@State private var inputString = ""
@Environment(\.dismiss) var dismiss

var body: some View {
VStack {
TextField("Enter new wallet", text: $inputString, onCommit: {
viewModel.updateWallet(wallet: inputString)

dismiss()
})
.textFieldStyle(.plain)

.textFieldStyle(.roundedBorder)
.padding()

Button("Submit") {
viewModel.updateWallet(wallet: inputString)
dismiss()
}
.padding()
}
.padding()
}
}


#Preview {
ContentView()
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}