d
This commit is contained in:
@@ -7,11 +7,18 @@ extension BusUI {
|
|||||||
|
|
||||||
public init(
|
public init(
|
||||||
_ key: String,
|
_ key: String,
|
||||||
_ defaultValue: T
|
_ defaultValue: T,
|
||||||
|
_ id: String? = nil
|
||||||
) {
|
) {
|
||||||
v = defaultValue
|
v = defaultValue
|
||||||
|
|
||||||
|
var k = key
|
||||||
|
if let id {
|
||||||
|
k = k + id
|
||||||
|
}
|
||||||
|
|
||||||
Bus.receiveSync(
|
Bus.receiveSync(
|
||||||
[key],
|
[k],
|
||||||
{ [weak self] (_, v: T) in self?.v = v },
|
{ [weak self] (_, v: T) in self?.v = v },
|
||||||
&subscriptions
|
&subscriptions
|
||||||
)
|
)
|
||||||
|
|||||||
21
Modules/MeetupIdX/src/MeetupId.Component.swift
Normal file
21
Modules/MeetupIdX/src/MeetupId.Component.swift
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
extension MeetupId {
|
||||||
|
final class Component: ObservableObject {
|
||||||
|
var isJoinAvailable: BusUI.Value<Bool>
|
||||||
|
var isLoading: BusUI.Value<Bool>
|
||||||
|
var join: BusUI.Button
|
||||||
|
var textField: BusUI.TextField
|
||||||
|
|
||||||
|
deinit {
|
||||||
|
/**/print("ИГР MeetupIC.deinit")
|
||||||
|
}
|
||||||
|
|
||||||
|
public init(_ id: String) {
|
||||||
|
/**/print("ИГР MeetupIC.init")
|
||||||
|
isJoinAvailable = .init(K.isJoinAvailable, false, id)
|
||||||
|
isLoading = .init(K.isLoading, false, id)
|
||||||
|
join = .init(K.join)
|
||||||
|
textField = .init(K.textApp, K.textUI)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -3,39 +3,38 @@ import SwiftUI
|
|||||||
|
|
||||||
extension MeetupId {
|
extension MeetupId {
|
||||||
public struct V: View {
|
public struct V: View {
|
||||||
@StateObject var isJoinAvailable = BusUI.Value(K.isJoinAvailable, false)
|
@StateObject private var cmp: Component
|
||||||
@StateObject var isLoading = BusUI.Value(K.isLoading, false)
|
|
||||||
@StateObject var join = BusUI.Button(K.join)
|
|
||||||
@StateObject var textField = BusUI.TextField(K.textApp, K.textUI)
|
|
||||||
|
|
||||||
public init() {
|
public init(_ id: String) {
|
||||||
|
// https://stackoverflow.com/a/62636048
|
||||||
|
_cmp = StateObject(wrappedValue: Component(id))
|
||||||
}
|
}
|
||||||
|
|
||||||
public var body: some View {
|
public var body: some View {
|
||||||
VStack(spacing: 8) {
|
VStack(spacing: 8) {
|
||||||
HStack {
|
HStack {
|
||||||
TextField("Binding-3", value: $textField.v, formatter: BusUI.TextFieldSource())
|
TextField("Binding-3", value: $cmp.textField.v, formatter: BusUI.TextFieldSource())
|
||||||
.disabled(isLoading.v)
|
.disabled(cmp.isLoading.v)
|
||||||
.padding(8)
|
.padding(8)
|
||||||
.border(
|
.border(
|
||||||
!isLoading.v ? Color.black : Color.gray,
|
!cmp.isLoading.v ? Color.black : Color.gray,
|
||||||
width: !isLoading.v ? 2 : 1
|
width: !cmp.isLoading.v ? 2 : 1
|
||||||
)
|
)
|
||||||
if isLoading.v {
|
if cmp.isLoading.v {
|
||||||
ProgressView()
|
ProgressView()
|
||||||
.padding(8)
|
.padding(8)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Button(action: join.v.send) {
|
Button(action: cmp.join.v.send) {
|
||||||
Text("Join")
|
Text("Join")
|
||||||
.padding(8)
|
.padding(8)
|
||||||
.border(
|
.border(
|
||||||
isJoinAvailable.v ? Color.green : Color.gray,
|
cmp.isJoinAvailable.v ? Color.green : Color.gray,
|
||||||
width: isJoinAvailable.v ? 2 : 1
|
width: cmp.isJoinAvailable.v ? 2 : 1
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
.disabled(!isJoinAvailable.v)
|
.disabled(!cmp.isJoinAvailable.v)
|
||||||
}
|
}
|
||||||
.frame(width: 320)
|
.frame(width: 320)
|
||||||
.padding()
|
.padding()
|
||||||
|
|||||||
Reference in New Issue
Block a user