mock up a list view for the OTPs

This commit is contained in:
2025-07-26 15:35:51 -05:00
parent 08795021ba
commit 41f615611f
4 changed files with 60 additions and 11 deletions

View File

@@ -8,18 +8,17 @@
import SwiftUI
struct ContentView: View {
struct MainScreen: View {
let otps = [
OTP(label: "howdy", code: 123456),
OTP(label: "y'all", code: 7890)
]
var body: some View {
VStack {
Image(systemName: "clock")
.imageScale(.large)
.foregroundStyle(.tint)
Text("OwnTP")
}
.padding()
OTPListView(otpList: otps)
}
}
#Preview {
ContentView()
#Preview("App Main Screen") {
MainScreen()
}

18
OwnTP/Models/OTP.swift Normal file
View File

@@ -0,0 +1,18 @@
//
// This Source Code Form is subject to the terms of the Mozilla Public License,
// v. 2.0. If a copy of the MPL was not distributed with this file, You can
// obtain one at https://mozilla.org/MPL/2.0/.
//
// Copyright 2025 Nicola Clark
//
import Foundation
struct OTP: Identifiable {
let id = UUID()
/// A human-readable label to identify the OTP
let label: String
/// The value of the OTP
let code: Int
}

View File

@@ -12,7 +12,7 @@ import SwiftUI
struct OwnTPApp: App {
var body: some Scene {
WindowGroup {
ContentView()
MainScreen()
}
}
}

View File

@@ -0,0 +1,32 @@
//
// This Source Code Form is subject to the terms of the Mozilla Public License,
// v. 2.0. If a copy of the MPL was not distributed with this file, You can
// obtain one at https://mozilla.org/MPL/2.0/.
//
// Copyright 2025 Nicola Clark
//
import SwiftUI
struct OTPListView: View {
let otpList: [OTP]
var body: some View {
List {
ForEach(otpList) { otp in
HStack {
Text(otp.label)
.bold()
Spacer()
Text(String(format: "%06i", otp.code))
}
}
}
}
}
@available(iOS 17.0, *)
#Preview("OTP List", traits: .sizeThatFitsLayout) {
OTPListView(otpList: [OTP(label: "howdy", code: 123456), OTP(label: "y'all", code: 7890)])
.frame(width: 300, height: 150)
}