From c24745bb2c34688381236d73c43fe5b8059e0bea Mon Sep 17 00:00:00 2001 From: Noxon <2914674+noxonsu@users.noreply.github.com> Date: Wed, 18 Oct 2023 11:17:37 +0300 Subject: [PATCH 1/2] Update ContentView.swift --- Onout Watch App/ContentView.swift | 43 ++++++++++++++++++------------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/Onout Watch App/ContentView.swift b/Onout Watch App/ContentView.swift index 238010e..b3cdc29 100644 --- a/Onout Watch App/ContentView.swift +++ b/Onout Watch App/ContentView.swift @@ -1,10 +1,3 @@ -// -// ContentView.swift -// Onout Watch App -// -// Created by Никита Иванов on 03.10.2023. -// - import SwiftUI struct ContentView: View { @@ -12,28 +5,42 @@ struct ContentView: View { @State private var inputString = "" @State private var showingInputDialog = 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() - - TextField("Enter new wallet", text: $inputString, onCommit: { - viewModel.updateWallet(wallet: inputString) - - }) - .textFieldStyle(.plain) - + + Button("Add new wallet") { + showingInputDialog = true + } + .actionSheet(isPresented: $showingInputDialog) { + ActionSheet(title: Text("Choose input method"), buttons: [ + .default(Text("Enter on iPhone")) { + // Present a view or a screen on iPhone for input + }, + .default(Text("Enter on Watch")) { + // Here you can retain the existing logic or modify as needed for the watch input + }, + .cancel() + ]) + } .padding() } + .padding() } } - -#Preview { - ContentView() +struct ContentView_Previews: PreviewProvider { + static var previews: some View { + ContentView() + } } From c1f56882ae1570a611e85c68a907db6de9c941c9 Mon Sep 17 00:00:00 2001 From: Noxon <2914674+noxonsu@users.noreply.github.com> Date: Wed, 18 Oct 2023 11:19:29 +0300 Subject: [PATCH 2/2] Update ContentView.swift --- Onout Watch App/ContentView.swift | 33 ++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/Onout Watch App/ContentView.swift b/Onout Watch App/ContentView.swift index b3cdc29..049f97b 100644 --- a/Onout Watch App/ContentView.swift +++ b/Onout Watch App/ContentView.swift @@ -3,8 +3,8 @@ 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 { @@ -25,14 +25,41 @@ struct ContentView: View { .actionSheet(isPresented: $showingInputDialog) { ActionSheet(title: Text("Choose input method"), buttons: [ .default(Text("Enter on iPhone")) { - // Present a view or a screen on iPhone for input + showWalletInputView = true }, .default(Text("Enter on Watch")) { - // Here you can retain the existing logic or modify as needed for the watch input + // 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(.roundedBorder) + .padding() + + Button("Submit") { + viewModel.updateWallet(wallet: inputString) + dismiss() + } .padding() } .padding()