Skip to content

Commit

Permalink
Update + Comment
Browse files Browse the repository at this point in the history
  • Loading branch information
1998code committed Jan 25, 2023
1 parent 196f0d9 commit c07972d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
28 changes: 23 additions & 5 deletions Demo/NFC Read-Write/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,29 @@ import SwiftUI
import SwiftNFC

struct ContentView: View {
// MARK: - You can use either Reader / Writer or both in your application.
@ObservedObject var NFCR = NFCReader()
@ObservedObject var NFCW = NFCWriter()

// MARK: - Editor for I/O Message
var editor: some View {
TextEditor(text: $NFCR.msg)
.font(.title)
.padding(.top, 50)
.padding(15)
.background(Color.accentColor.opacity(0.5))
}
// MARK: - Show Read Message Raw Data
var editorRaw: some View {
TextEditor(text: $NFCR.raw)
.padding(15)
.background(Color.red.opacity(0.5))
}

// MARK: - Detect whether the keyboard shown on screen or not.
@State var keyboard: Bool = false

// MARK: - Main App Content
var body: some View {
VStack(spacing: 0) {
VStack(spacing: 0) {
Expand All @@ -45,31 +52,42 @@ struct ContentView: View {
.frame(height: 75)
}
.ignoresSafeArea(.all)
.onReceive(NotificationCenter.default.publisher(for: UIResponder.keyboardWillShowNotification)) { _ in
keyboard = true
}
.onReceive(NotificationCenter.default.publisher(for: UIResponder.keyboardWillHideNotification)) { _ in
keyboard = false
}
.onTapGesture(count: 2) {
// MARK: Double Tap anywhere can hide the keyboard
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
}
}

// MARK: - Select NFC Option(s)
var option: some View {
HStack {
Picker(selection: $NFCW.type, label: Text("Type Picker")) {
Text("Text").tag("T")
Text("Link").tag("U")
}
Spacer()
Button(action: {
if keyboard {
Button(action: {
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
}) {
Text("Close Keyboard")
}) {
Text("Close Keyboard")
}
}
}.padding(.horizontal)
}

// MARK: - Action Buttons
var action: some View {
HStack(spacing: 0) {
Button (action: { read() }) {
ZStack {
Color.blue.opacity(0.85)
Color.pink.opacity(0.85)
Label("Read NFC", systemImage: "wave.3.left.circle.fill")
.foregroundColor(.white)
.padding(.top, 15)
Expand All @@ -88,10 +106,10 @@ struct ContentView: View {
}
}

// MARK: - Sample I/O Functions
func read() {
NFCR.read()
}

func write() {
NFCW.msg = NFCR.msg
NFCW.write()
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ iOS | 16 | > 14
Compatible with Xcode Cloud ☁️

## Guide
Available later this week.
Medium

## Demo
Path: `./Demo` (Xcode Project in SwiftUI)
Expand Down

0 comments on commit c07972d

Please sign in to comment.