This commit is contained in:
Михаил Капелько
2023-12-28 13:33:20 +03:00
parent a1ec08f280
commit 16026a7b47
21 changed files with 26 additions and 16 deletions

View File

@@ -0,0 +1,9 @@
public extension MeetupId {
enum K: String {
case meetupIdIsJoinAvailable
case meetupIdJoin
case meetupIdTextApp
case meetupIdTextUI
}
}

View File

@@ -0,0 +1,26 @@
import Foundation
public extension MeetupId {
static func onlyAllowJoin(_ s: String) -> Bool? {
s.hasPrefix("123")
}
static func onlyFormat(_ s: String) -> String? {
let digits = s.components(separatedBy: NSCharacterSet.decimalDigits.inverted).reduce("") { $0 + $1 }
var r = ""
var i = 0
// Делим каждые три цифры дефисом.
for v in digits {
r += String(v)
i = i + 1
if i % 3 == 0 {
r += "-"
}
}
// Исключаем дефис в конце.
if r.hasSuffix("-") {
r = String(r.dropLast(1))
}
return r
}
}

View File

@@ -0,0 +1 @@
public enum MeetupId { }

View File

@@ -0,0 +1,40 @@
import BusX
import CordX
import SwiftUI
extension MeetupId {
public struct V: View {
@StateObject var isJA = Cord.Receive(K.meetupIdIsJoinAvailable.rawValue, false)
@StateObject var join = Cord.Button(K.meetupIdJoin.rawValue)
@StateObject var txtF = Cord.TextField(K.meetupIdTextApp.rawValue, K.meetupIdTextUI.rawValue)
let test = Bus.Processor(K.meetupIdTextUI.rawValue, K.meetupIdIsJoinAvailable.rawValue, onlyAllowJoin)
public init() { }
public var body: some View {
VStack {
HStack {
Text("Check text field:")
Text("'\(txtF.value)'")
.fontWeight(.bold)
}
TextField("Binding-3", value: $txtF.value, formatter: Cord.TextFieldValueOwner())
.padding(8)
.border(Color.blue, width: 2)
Button(action: join.press.send) {
Text("Join")
.padding(8)
.border(
isJA.value ? Color.green : Color.gray,
width: isJA.value ? 4 : 1
)
}
.disabled(!isJA.value)
}
.frame(width: 320)
.padding()
}
}
}