d
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import MeetupIdX
|
||||
import UIKit
|
||||
|
||||
@UIApplicationMain
|
||||
@@ -11,7 +12,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate
|
||||
) -> Bool {
|
||||
window = UIWindow(frame: UIScreen.main.bounds)
|
||||
let vc = UIViewController()
|
||||
addSwiftUIViewAsChild(swiftUIView: V(), parent: vc.view)
|
||||
addSwiftUIViewAsChild(swiftUIView: MeetupId.V(), parent: vc.view)
|
||||
vc.view.backgroundColor = .white
|
||||
window?.rootViewController = vc
|
||||
window?.backgroundColor = UIColor.white
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
import Combine
|
||||
import Foundation
|
||||
|
||||
enum MeetupId {
|
||||
enum K: String {
|
||||
case meetupIdTextApp
|
||||
case meetupIdTextUI
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
/// Пропускаем лишь значения от UI
|
||||
///
|
||||
/// - Returns: Значение без префиксов "a:"/"u:"
|
||||
func onlyUIText(_ s: String) -> String? {
|
||||
guard s.hasPrefix("u:") else { return nil }
|
||||
return String(s.dropFirst(2))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
36
src/V.swift
36
src/V.swift
@@ -1,36 +0,0 @@
|
||||
import BusX
|
||||
import CordX
|
||||
import SwiftUI
|
||||
|
||||
struct V: View {
|
||||
@StateObject var isJoinAvailable = Cord.Receive("joinAvailable", false)
|
||||
@StateObject var join = Cord.Button("join")
|
||||
@StateObject var textF = Cord.TextField("text.app", "text.ui")
|
||||
let test = Bus.Processor("text.ui", "joinAvailable", MeetupId.onlyAllowJoin)
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
HStack {
|
||||
Text("Check text field:")
|
||||
Text("'\(textF.value)'")
|
||||
.fontWeight(.bold)
|
||||
}
|
||||
|
||||
TextField("Binding-3", value: $textF.value, formatter: Cord.TextFieldValueOwner())
|
||||
.padding(8)
|
||||
.border(Color.blue, width: 2)
|
||||
|
||||
Button(action: join.press.send) {
|
||||
Text("Join")
|
||||
.padding(8)
|
||||
.border(
|
||||
isJoinAvailable.value ? Color.green : Color.gray,
|
||||
width: isJoinAvailable.value ? 4 : 1
|
||||
)
|
||||
}
|
||||
.disabled(!isJoinAvailable.value)
|
||||
}
|
||||
.frame(width: 320)
|
||||
.padding()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user