From e70aa847b6cf887958dd33439b45db72f229d10e Mon Sep 17 00:00:00 2001 From: Sunghun Kim <81547954+kimsh153@users.noreply.github.com> Date: Tue, 9 May 2023 13:45:57 +0900 Subject: [PATCH 01/14] =?UTF-8?q?:lipstick:=20SMSSelectionControls=20?= =?UTF-8?q?=EC=A0=9C=EC=9E=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SMSSelectionControls.swift | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Projects/Core/DesignSystem/Sources/SelectionControls/SMSSelectionControls.swift diff --git a/Projects/Core/DesignSystem/Sources/SelectionControls/SMSSelectionControls.swift b/Projects/Core/DesignSystem/Sources/SelectionControls/SMSSelectionControls.swift new file mode 100644 index 00000000..58d3645b --- /dev/null +++ b/Projects/Core/DesignSystem/Sources/SelectionControls/SMSSelectionControls.swift @@ -0,0 +1,29 @@ +import SwiftUI + +public struct SMSSelectionControls: View { + @Binding var isOn: Bool + @Environment(\.isEnabled) private var isEnabled: Bool + + public init(isOn: Binding) { + _isOn = isOn + } + + public var body: some View { + Button { + self.isOn.toggle() + } label: { + ZStack { + Group { + Circle() + .stroke(isOn ? Color.sms(.primary(.p2)) : Color.sms(.neutral(.n20)), lineWidth: 2) + .frame(width: 20, height: 20) + + Circle() + .fill(isOn ? Color.sms(.primary(.p2)) : .clear) + .frame(width: 12, height: 12) + } + .opacity(isEnabled ? 1.0 : 0.5) + } + } + } +} From 715d7325dd6849390d1430b23bd4930f866bdc3a Mon Sep 17 00:00:00 2001 From: Sunghun Kim <81547954+kimsh153@users.noreply.github.com> Date: Tue, 9 May 2023 20:08:02 +0900 Subject: [PATCH 02/14] :recycle: SMSSelctionControls --- .../SelectionControls/SMSSelectionControls.swift | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Projects/Core/DesignSystem/Sources/SelectionControls/SMSSelectionControls.swift b/Projects/Core/DesignSystem/Sources/SelectionControls/SMSSelectionControls.swift index 58d3645b..3a23d84c 100644 --- a/Projects/Core/DesignSystem/Sources/SelectionControls/SMSSelectionControls.swift +++ b/Projects/Core/DesignSystem/Sources/SelectionControls/SMSSelectionControls.swift @@ -2,7 +2,6 @@ import SwiftUI public struct SMSSelectionControls: View { @Binding var isOn: Bool - @Environment(\.isEnabled) private var isEnabled: Bool public init(isOn: Binding) { _isOn = isOn @@ -22,8 +21,21 @@ public struct SMSSelectionControls: View { .fill(isOn ? Color.sms(.primary(.p2)) : .clear) .frame(width: 12, height: 12) } - .opacity(isEnabled ? 1.0 : 0.5) } } + .buttonStyle(CustomButtonStyle()) + } + +} + +private struct CustomButtonStyle: ButtonStyle { + @ViewBuilder + func makeBody(configuration: Configuration) -> some View { + Circle() + .fill(configuration.isPressed ? Color.sms(.neutral(.n20)) : Color.clear) + .overlay { + configuration.label + } + .frame(width: 32, height: 32) } } From 4fb864d040158576ed587a1fdaca5973b4ab7028 Mon Sep 17 00:00:00 2001 From: Sunghun Kim <81547954+kimsh153@users.noreply.github.com> Date: Tue, 9 May 2023 20:10:12 +0900 Subject: [PATCH 03/14] =?UTF-8?q?:recycle:=20Group=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SelectionControls/SMSSelectionControls.swift | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/Projects/Core/DesignSystem/Sources/SelectionControls/SMSSelectionControls.swift b/Projects/Core/DesignSystem/Sources/SelectionControls/SMSSelectionControls.swift index 3a23d84c..c8b42b95 100644 --- a/Projects/Core/DesignSystem/Sources/SelectionControls/SMSSelectionControls.swift +++ b/Projects/Core/DesignSystem/Sources/SelectionControls/SMSSelectionControls.swift @@ -12,15 +12,13 @@ public struct SMSSelectionControls: View { self.isOn.toggle() } label: { ZStack { - Group { - Circle() - .stroke(isOn ? Color.sms(.primary(.p2)) : Color.sms(.neutral(.n20)), lineWidth: 2) - .frame(width: 20, height: 20) + Circle() + .stroke(isOn ? Color.sms(.primary(.p2)) : Color.sms(.neutral(.n20)), lineWidth: 2) + .frame(width: 20, height: 20) - Circle() - .fill(isOn ? Color.sms(.primary(.p2)) : .clear) - .frame(width: 12, height: 12) - } + Circle() + .fill(isOn ? Color.sms(.primary(.p2)) : .clear) + .frame(width: 12, height: 12) } } .buttonStyle(CustomButtonStyle()) From abab51ca33aa9f710760cc4845a638f7a1ea92c1 Mon Sep 17 00:00:00 2001 From: Sunghun Kim <81547954+kimsh153@users.noreply.github.com> Date: Tue, 16 May 2023 00:21:34 +0900 Subject: [PATCH 04/14] :lipstick: RadioButtonComponent --- .../DesignSystem/Demo/Sources/DemoView.swift | 20 ++++-- .../SelectionControls/RadioComponent.swift | 31 ++++++++ .../SMSSelectionControls.swift | 70 ++++++++++++++++--- 3 files changed, 104 insertions(+), 17 deletions(-) create mode 100644 Projects/Core/DesignSystem/Sources/SelectionControls/RadioComponent.swift diff --git a/Projects/Core/DesignSystem/Demo/Sources/DemoView.swift b/Projects/Core/DesignSystem/Demo/Sources/DemoView.swift index ccd00c8d..aebe73cf 100644 --- a/Projects/Core/DesignSystem/Demo/Sources/DemoView.swift +++ b/Projects/Core/DesignSystem/Demo/Sources/DemoView.swift @@ -1,14 +1,22 @@ import DesignSystem import SwiftUI -struct DemoView: View { - var body: some View { +public struct DemoView: View { + @State var isOn = true + @State var selection: Int? = 0 + + public var body: some View { VStack { Group { - CTAButton(text: "CTA Default", style: .default) - CTAButton(text: "CTA Outline", style: .outline) - FillButton(text: "Fill Default", style: .default) - FillButton(text: "Fill Default", style: .outline) + RadioComponent(selection: $selection) { + ForEach(0..<4) { index in + HStack { + SMSSelectionControls(tag: index) + Text("asdfasdf") + } + .radioTag(index) + } + } } .padding(8) } diff --git a/Projects/Core/DesignSystem/Sources/SelectionControls/RadioComponent.swift b/Projects/Core/DesignSystem/Sources/SelectionControls/RadioComponent.swift new file mode 100644 index 00000000..fb950643 --- /dev/null +++ b/Projects/Core/DesignSystem/Sources/SelectionControls/RadioComponent.swift @@ -0,0 +1,31 @@ +import SwiftUI + +public struct RadioComponent: View { + + private let value: RadioValue + private let content: () -> Content + + public var body: some View { + content() + .environmentObject(value) + } +} + +extension RadioComponent where T: Hashable, Content: View { + public init( + selection: Binding, + @ViewBuilder _ content: @escaping () -> Content + ) { + self.value = RadioValue(selection: selection) + self.content = content + } + + public init( + selection: Binding, + @ViewBuilder _ content: @escaping () -> Content, + onTapReceive: ((T?) -> Void)? + ) { + self.value = RadioValue(selection: selection, onTapReceive: onTapReceive) + self.content = content + } +} diff --git a/Projects/Core/DesignSystem/Sources/SelectionControls/SMSSelectionControls.swift b/Projects/Core/DesignSystem/Sources/SelectionControls/SMSSelectionControls.swift index c8b42b95..07d8e785 100644 --- a/Projects/Core/DesignSystem/Sources/SelectionControls/SMSSelectionControls.swift +++ b/Projects/Core/DesignSystem/Sources/SelectionControls/SMSSelectionControls.swift @@ -1,39 +1,87 @@ import SwiftUI -public struct SMSSelectionControls: View { - @Binding var isOn: Bool - - public init(isOn: Binding) { - _isOn = isOn - } +public struct SMSSelectionControls: View { + @EnvironmentObject private var value: RadioValue + private var tag: T? public var body: some View { Button { - self.isOn.toggle() + value.selection = tag + value.onTapReceive?(tag) } label: { ZStack { Circle() - .stroke(isOn ? Color.sms(.primary(.p2)) : Color.sms(.neutral(.n20)), lineWidth: 2) + .stroke(tag == value.selection ? Color.sms(.primary(.p2)) : Color.sms(.neutral(.n20)), lineWidth: 2) .frame(width: 20, height: 20) Circle() - .fill(isOn ? Color.sms(.primary(.p2)) : .clear) + .fill(tag == value.selection ? Color.sms(.primary(.p2)) : .clear) .frame(width: 12, height: 12) } } - .buttonStyle(CustomButtonStyle()) + .buttonStyle(CustomButtonStyle(isOn: tag == value.selection)) } +} +public extension SMSSelectionControls where T: Hashable { + init(tag: T) { + self.tag = tag + } } private struct CustomButtonStyle: ButtonStyle { + var isOn: Bool + + init(isOn: Bool) { + self.isOn = isOn + } + @ViewBuilder func makeBody(configuration: Configuration) -> some View { Circle() - .fill(configuration.isPressed ? Color.sms(.neutral(.n20)) : Color.clear) + .fill(self.isOn && configuration.isPressed ? Color.sms(.neutral(.n20)) : Color.clear) .overlay { configuration.label } .frame(width: 32, height: 32) } } + +public struct RadioTag: ViewModifier { + @EnvironmentObject private var value: RadioValue + private var tag: T? + + public func body(content: Content) -> some View { + Button { + value.selection = tag + value.onTapReceive?(tag) + } label: { + content + } + .buttonStyle(.plain) + } +} + +public extension RadioTag where T: Hashable { + init(_ tag: T?) { + self.tag = tag + } +} + +extension View { + public func radioTag(_ tag: T?) -> some View { + self.modifier(RadioTag(tag)) + } +} + +class RadioValue: ObservableObject { + typealias TapReceiveAction = (T?) -> Void + + @Binding var selection: T? + var onTapReceive: (TapReceiveAction)? + + init(selection: Binding, onTapReceive: (TapReceiveAction)? = nil) { + _selection = selection + self.onTapReceive = onTapReceive + } +} From 3d7d4ad2ccac9ab60bdae23715ff7089b5af8f6f Mon Sep 17 00:00:00 2001 From: Sunghun Kim <81547954+kimsh153@users.noreply.github.com> Date: Tue, 16 May 2023 00:33:33 +0900 Subject: [PATCH 05/14] =?UTF-8?q?:fire:=20=EC=9D=B4=EC=83=81=ED=95=9C=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=A7=80=EC=9A=B0=EA=B8=B0=20=3D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DesignSystem/Demo/Sources/DemoView.swift | 23 ------------------- 1 file changed, 23 deletions(-) diff --git a/Projects/Core/DesignSystem/Demo/Sources/DemoView.swift b/Projects/Core/DesignSystem/Demo/Sources/DemoView.swift index 9a60c3f3..fbf53ce3 100644 --- a/Projects/Core/DesignSystem/Demo/Sources/DemoView.swift +++ b/Projects/Core/DesignSystem/Demo/Sources/DemoView.swift @@ -18,30 +18,7 @@ public struct DemoView: View { } } } - .padding(8) - - NavigationLink { - AView() - } label: { - Text("A") - } } - .smsBottomSheet(isShowing: $isPresentedBottomSheet) { - RoundedRectangle(cornerRadius: 8) - .fill(Color.sms(.neutral(.n20))) - .frame(maxWidth: .infinity) - .frame(height: 500) - .padding(.horizontal) - } - } -} - -struct AView: View { - @Environment(\.dismiss) var dismiss - - var body: some View { - Text("A") - .smsBackButton(dismiss: dismiss) } } From e25c2a4be587346c131ea3edcf0c1cd4a09f6b0b Mon Sep 17 00:00:00 2001 From: Sunghun Kim <81547954+kimsh153@users.noreply.github.com> Date: Mon, 22 May 2023 13:15:33 +0900 Subject: [PATCH 06/14] =?UTF-8?q?:recycle:=20Comment=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SelectionControls/RadioComponent.swift | 13 ++++++++++- .../SMSSelectionControls.swift | 22 ++++--------------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/Projects/Core/DesignSystem/Sources/SelectionControls/RadioComponent.swift b/Projects/Core/DesignSystem/Sources/SelectionControls/RadioComponent.swift index fb950643..49944b8e 100644 --- a/Projects/Core/DesignSystem/Sources/SelectionControls/RadioComponent.swift +++ b/Projects/Core/DesignSystem/Sources/SelectionControls/RadioComponent.swift @@ -1,7 +1,6 @@ import SwiftUI public struct RadioComponent: View { - private let value: RadioValue private let content: () -> Content @@ -29,3 +28,15 @@ extension RadioComponent where T: Hashable, Content: View { self.content = content } } + +public class RadioValue: ObservableObject { + typealias TapReceiveAction = (T?) -> Void + + @Binding var selection: T? + var onTapReceive: (TapReceiveAction)? + + init(selection: Binding, onTapReceive: (TapReceiveAction)? = nil) { + _selection = selection + self.onTapReceive = onTapReceive + } +} diff --git a/Projects/Core/DesignSystem/Sources/SelectionControls/SMSSelectionControls.swift b/Projects/Core/DesignSystem/Sources/SelectionControls/SMSSelectionControls.swift index 07d8e785..ec093e7a 100644 --- a/Projects/Core/DesignSystem/Sources/SelectionControls/SMSSelectionControls.swift +++ b/Projects/Core/DesignSystem/Sources/SelectionControls/SMSSelectionControls.swift @@ -51,6 +51,10 @@ public struct RadioTag: ViewModifier { @EnvironmentObject private var value: RadioValue private var tag: T? + init(_ tag: T?) { + self.tag = tag + } + public func body(content: Content) -> some View { Button { value.selection = tag @@ -62,26 +66,8 @@ public struct RadioTag: ViewModifier { } } -public extension RadioTag where T: Hashable { - init(_ tag: T?) { - self.tag = tag - } -} - extension View { public func radioTag(_ tag: T?) -> some View { self.modifier(RadioTag(tag)) } } - -class RadioValue: ObservableObject { - typealias TapReceiveAction = (T?) -> Void - - @Binding var selection: T? - var onTapReceive: (TapReceiveAction)? - - init(selection: Binding, onTapReceive: (TapReceiveAction)? = nil) { - _selection = selection - self.onTapReceive = onTapReceive - } -} From 1a752790b39302c0c192374e917651dde1274066 Mon Sep 17 00:00:00 2001 From: Sunghun Kim <81547954+kimsh153@users.noreply.github.com> Date: Mon, 22 May 2023 13:30:22 +0900 Subject: [PATCH 07/14] =?UTF-8?q?:recycle:=20init=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SelectionControls/RadioComponent.swift | 24 ++++++------------- .../SMSSelectionControls.swift | 10 ++++---- 2 files changed, 11 insertions(+), 23 deletions(-) diff --git a/Projects/Core/DesignSystem/Sources/SelectionControls/RadioComponent.swift b/Projects/Core/DesignSystem/Sources/SelectionControls/RadioComponent.swift index 49944b8e..9b876350 100644 --- a/Projects/Core/DesignSystem/Sources/SelectionControls/RadioComponent.swift +++ b/Projects/Core/DesignSystem/Sources/SelectionControls/RadioComponent.swift @@ -4,32 +4,22 @@ public struct RadioComponent: View { private let value: RadioValue private let content: () -> Content - public var body: some View { - content() - .environmentObject(value) - } -} - -extension RadioComponent where T: Hashable, Content: View { - public init( - selection: Binding, - @ViewBuilder _ content: @escaping () -> Content - ) { - self.value = RadioValue(selection: selection) - self.content = content - } - public init( selection: Binding, @ViewBuilder _ content: @escaping () -> Content, - onTapReceive: ((T?) -> Void)? + onTapReceive: ((T?) -> Void)? = nil ) { self.value = RadioValue(selection: selection, onTapReceive: onTapReceive) self.content = content } + + public var body: some View { + content() + .environmentObject(value) + } } -public class RadioValue: ObservableObject { +class RadioValue: ObservableObject { typealias TapReceiveAction = (T?) -> Void @Binding var selection: T? diff --git a/Projects/Core/DesignSystem/Sources/SelectionControls/SMSSelectionControls.swift b/Projects/Core/DesignSystem/Sources/SelectionControls/SMSSelectionControls.swift index ec093e7a..a6b1cbff 100644 --- a/Projects/Core/DesignSystem/Sources/SelectionControls/SMSSelectionControls.swift +++ b/Projects/Core/DesignSystem/Sources/SelectionControls/SMSSelectionControls.swift @@ -4,6 +4,10 @@ public struct SMSSelectionControls: View { @EnvironmentObject private var value: RadioValue private var tag: T? + init(tag: T) { + self.tag = tag + } + public var body: some View { Button { value.selection = tag @@ -23,12 +27,6 @@ public struct SMSSelectionControls: View { } } -public extension SMSSelectionControls where T: Hashable { - init(tag: T) { - self.tag = tag - } -} - private struct CustomButtonStyle: ButtonStyle { var isOn: Bool From 6535fe1ec633bb038c68f2761e2e3ffbcd4931b4 Mon Sep 17 00:00:00 2001 From: Sunghun Kim <81547954+kimsh153@users.noreply.github.com> Date: Mon, 22 May 2023 13:41:25 +0900 Subject: [PATCH 08/14] =?UTF-8?q?:recycle:=20Public=20=EC=A0=84=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/SelectionControls/SMSSelectionControls.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Projects/Core/DesignSystem/Sources/SelectionControls/SMSSelectionControls.swift b/Projects/Core/DesignSystem/Sources/SelectionControls/SMSSelectionControls.swift index a6b1cbff..4fa6e808 100644 --- a/Projects/Core/DesignSystem/Sources/SelectionControls/SMSSelectionControls.swift +++ b/Projects/Core/DesignSystem/Sources/SelectionControls/SMSSelectionControls.swift @@ -4,7 +4,7 @@ public struct SMSSelectionControls: View { @EnvironmentObject private var value: RadioValue private var tag: T? - init(tag: T) { + public init(tag: T) { self.tag = tag } From 80e8c8e9adb17dcba14dccce34228431daf071cb Mon Sep 17 00:00:00 2001 From: Sunghun Kim <81547954+kimsh153@users.noreply.github.com> Date: Mon, 22 May 2023 14:36:15 +0900 Subject: [PATCH 09/14] =?UTF-8?q?:recycle:=20Comment=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/SelectionControls/SMSSelectionControls.swift | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/Projects/Core/DesignSystem/Sources/SelectionControls/SMSSelectionControls.swift b/Projects/Core/DesignSystem/Sources/SelectionControls/SMSSelectionControls.swift index 4fa6e808..6e9b962a 100644 --- a/Projects/Core/DesignSystem/Sources/SelectionControls/SMSSelectionControls.swift +++ b/Projects/Core/DesignSystem/Sources/SelectionControls/SMSSelectionControls.swift @@ -54,13 +54,7 @@ public struct RadioTag: ViewModifier { } public func body(content: Content) -> some View { - Button { - value.selection = tag - value.onTapReceive?(tag) - } label: { - content - } - .buttonStyle(.plain) + content } } From 1208295e1370b68853fe1a865b4327e1ee78255a Mon Sep 17 00:00:00 2001 From: Sunghun Kim <81547954+kimsh153@users.noreply.github.com> Date: Mon, 22 May 2023 15:38:00 +0900 Subject: [PATCH 10/14] =?UTF-8?q?:recycle:=20Commnet=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DesignSystem/Demo/Sources/DemoView.swift | 2 +- .../SelectionControls/RadioComponent.swift | 2 +- .../Sources/SelectionControls/RadioTag.swift | 26 +++++++++++ .../SMSSelectionControls.swift | 45 +++++-------------- 4 files changed, 38 insertions(+), 37 deletions(-) create mode 100644 Projects/Core/DesignSystem/Sources/SelectionControls/RadioTag.swift diff --git a/Projects/Core/DesignSystem/Demo/Sources/DemoView.swift b/Projects/Core/DesignSystem/Demo/Sources/DemoView.swift index fbf53ce3..e97d8261 100644 --- a/Projects/Core/DesignSystem/Demo/Sources/DemoView.swift +++ b/Projects/Core/DesignSystem/Demo/Sources/DemoView.swift @@ -12,9 +12,9 @@ public struct DemoView: View { ForEach(0..<4) { index in HStack { SMSSelectionControls(tag: index) + .radioTag(index) Text("asdfasdf") } - .radioTag(index) } } } diff --git a/Projects/Core/DesignSystem/Sources/SelectionControls/RadioComponent.swift b/Projects/Core/DesignSystem/Sources/SelectionControls/RadioComponent.swift index 9b876350..187a1b42 100644 --- a/Projects/Core/DesignSystem/Sources/SelectionControls/RadioComponent.swift +++ b/Projects/Core/DesignSystem/Sources/SelectionControls/RadioComponent.swift @@ -19,7 +19,7 @@ public struct RadioComponent: View { } } -class RadioValue: ObservableObject { +final class RadioValue: ObservableObject { typealias TapReceiveAction = (T?) -> Void @Binding var selection: T? diff --git a/Projects/Core/DesignSystem/Sources/SelectionControls/RadioTag.swift b/Projects/Core/DesignSystem/Sources/SelectionControls/RadioTag.swift new file mode 100644 index 00000000..4b8ef636 --- /dev/null +++ b/Projects/Core/DesignSystem/Sources/SelectionControls/RadioTag.swift @@ -0,0 +1,26 @@ +import SwiftUI + +public struct RadioTag: ViewModifier { + @EnvironmentObject private var value: RadioValue + private var tag: T? + + init(_ tag: T?) { + self.tag = tag + } + + public func body(content: Content) -> some View { + Button { + value.selection = tag + value.onTapReceive?(tag) + } label: { + content + } + .buttonStyle(CustomButtonStyle.init(isOn: tag == value.selection)) + } +} + +extension View { + public func radioTag(_ tag: T?) -> some View { + self.modifier(RadioTag(tag)) + } +} diff --git a/Projects/Core/DesignSystem/Sources/SelectionControls/SMSSelectionControls.swift b/Projects/Core/DesignSystem/Sources/SelectionControls/SMSSelectionControls.swift index 6e9b962a..6e58a51c 100644 --- a/Projects/Core/DesignSystem/Sources/SelectionControls/SMSSelectionControls.swift +++ b/Projects/Core/DesignSystem/Sources/SelectionControls/SMSSelectionControls.swift @@ -4,30 +4,24 @@ public struct SMSSelectionControls: View { @EnvironmentObject private var value: RadioValue private var tag: T? - public init(tag: T) { + public init(tag: T?) { self.tag = tag } public var body: some View { - Button { - value.selection = tag - value.onTapReceive?(tag) - } label: { - ZStack { - Circle() - .stroke(tag == value.selection ? Color.sms(.primary(.p2)) : Color.sms(.neutral(.n20)), lineWidth: 2) - .frame(width: 20, height: 20) - - Circle() - .fill(tag == value.selection ? Color.sms(.primary(.p2)) : .clear) - .frame(width: 12, height: 12) - } + ZStack { + Circle() + .stroke(tag == value.selection ? Color.sms(.primary(.p2)) : Color.sms(.neutral(.n20)), lineWidth: 2) + .frame(width: 20, height: 20) + + Circle() + .fill(tag == value.selection ? Color.sms(.primary(.p2)) : .clear) + .frame(width: 12, height: 12) } - .buttonStyle(CustomButtonStyle(isOn: tag == value.selection)) } } -private struct CustomButtonStyle: ButtonStyle { +struct CustomButtonStyle: ButtonStyle { var isOn: Bool init(isOn: Bool) { @@ -44,22 +38,3 @@ private struct CustomButtonStyle: ButtonStyle { .frame(width: 32, height: 32) } } - -public struct RadioTag: ViewModifier { - @EnvironmentObject private var value: RadioValue - private var tag: T? - - init(_ tag: T?) { - self.tag = tag - } - - public func body(content: Content) -> some View { - content - } -} - -extension View { - public func radioTag(_ tag: T?) -> some View { - self.modifier(RadioTag(tag)) - } -} From fdc43ebe5f4943a9428bc1fc4e38f854d8cb5966 Mon Sep 17 00:00:00 2001 From: Sunghun Kim <81547954+kimsh153@users.noreply.github.com> Date: Mon, 22 May 2023 15:42:19 +0900 Subject: [PATCH 11/14] =?UTF-8?q?:recycle:=20=EB=94=B0=EB=A1=9C=20?= =?UTF-8?q?=EB=85=B8=EB=8A=94=EA=B1=B0=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Core/DesignSystem/Sources/SelectionControls/RadioTag.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Projects/Core/DesignSystem/Sources/SelectionControls/RadioTag.swift b/Projects/Core/DesignSystem/Sources/SelectionControls/RadioTag.swift index 4b8ef636..6c7cb889 100644 --- a/Projects/Core/DesignSystem/Sources/SelectionControls/RadioTag.swift +++ b/Projects/Core/DesignSystem/Sources/SelectionControls/RadioTag.swift @@ -15,7 +15,7 @@ public struct RadioTag: ViewModifier { } label: { content } - .buttonStyle(CustomButtonStyle.init(isOn: tag == value.selection)) + .buttonStyle(CustomButtonStyle(isOn: tag == value.selection)) } } From 8a8091a4b174e37859de12668040dee968c2d867 Mon Sep 17 00:00:00 2001 From: Sunghun Kim <81547954+kimsh153@users.noreply.github.com> Date: Mon, 22 May 2023 15:45:13 +0900 Subject: [PATCH 12/14] =?UTF-8?q?:recycle:=20=EB=94=B0=EB=A1=9C=20?= =?UTF-8?q?=EB=85=B8=EB=8A=94=EA=B1=B0=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/SelectionControls/RadioTag.swift | 18 ++++++++++++++++++ .../SMSSelectionControls.swift | 18 ------------------ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Projects/Core/DesignSystem/Sources/SelectionControls/RadioTag.swift b/Projects/Core/DesignSystem/Sources/SelectionControls/RadioTag.swift index 6c7cb889..5058150d 100644 --- a/Projects/Core/DesignSystem/Sources/SelectionControls/RadioTag.swift +++ b/Projects/Core/DesignSystem/Sources/SelectionControls/RadioTag.swift @@ -24,3 +24,21 @@ extension View { self.modifier(RadioTag(tag)) } } + +private struct CustomButtonStyle: ButtonStyle { + var isOn: Bool + + init(isOn: Bool) { + self.isOn = isOn + } + + @ViewBuilder + func makeBody(configuration: Configuration) -> some View { + Circle() + .fill(self.isOn && configuration.isPressed ? Color.sms(.neutral(.n20)) : Color.clear) + .overlay { + configuration.label + } + .frame(width: 32, height: 32) + } +} diff --git a/Projects/Core/DesignSystem/Sources/SelectionControls/SMSSelectionControls.swift b/Projects/Core/DesignSystem/Sources/SelectionControls/SMSSelectionControls.swift index 6e58a51c..ae840a33 100644 --- a/Projects/Core/DesignSystem/Sources/SelectionControls/SMSSelectionControls.swift +++ b/Projects/Core/DesignSystem/Sources/SelectionControls/SMSSelectionControls.swift @@ -20,21 +20,3 @@ public struct SMSSelectionControls: View { } } } - -struct CustomButtonStyle: ButtonStyle { - var isOn: Bool - - init(isOn: Bool) { - self.isOn = isOn - } - - @ViewBuilder - func makeBody(configuration: Configuration) -> some View { - Circle() - .fill(self.isOn && configuration.isPressed ? Color.sms(.neutral(.n20)) : Color.clear) - .overlay { - configuration.label - } - .frame(width: 32, height: 32) - } -} From f326a31c5d9dddf370c8747e8d64dbaa444175aa Mon Sep 17 00:00:00 2001 From: Sunghun Kim <81547954+kimsh153@users.noreply.github.com> Date: Mon, 22 May 2023 17:52:41 +0900 Subject: [PATCH 13/14] =?UTF-8?q?:boom:=20=EA=B2=B0=EA=B5=AD=20=ED=95=B4?= =?UTF-8?q?=EA=B2=B0=EC=B1=85=EC=9D=84=20=EC=B0=BE=EC=A7=80=20=EB=AA=BB?= =?UTF-8?q?=ED=95=98=EA=B3=A0=20=EC=B2=98=EC=9D=8C=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=8F=8C=EC=95=84=EC=99=94=EC=8A=B5=EB=8B=88=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DesignSystem/Demo/Sources/DemoView.swift | 7 +-- .../SelectionControls/RadioComponent.swift | 32 ------------- .../Sources/SelectionControls/RadioTag.swift | 44 ----------------- .../SMSSelectionControls.swift | 48 +++++++++++++------ 4 files changed, 36 insertions(+), 95 deletions(-) delete mode 100644 Projects/Core/DesignSystem/Sources/SelectionControls/RadioComponent.swift delete mode 100644 Projects/Core/DesignSystem/Sources/SelectionControls/RadioTag.swift diff --git a/Projects/Core/DesignSystem/Demo/Sources/DemoView.swift b/Projects/Core/DesignSystem/Demo/Sources/DemoView.swift index e97d8261..f32d0145 100644 --- a/Projects/Core/DesignSystem/Demo/Sources/DemoView.swift +++ b/Projects/Core/DesignSystem/Demo/Sources/DemoView.swift @@ -2,22 +2,19 @@ import DesignSystem import SwiftUI public struct DemoView: View { - @State var isOn = true + @State var isSeleted = true @State var selection: Int? = 0 public var body: some View { VStack { Group { - RadioComponent(selection: $selection) { ForEach(0..<4) { index in HStack { - SMSSelectionControls(tag: index) - .radioTag(index) + SMSSelectionControls(isSeleted: $isSeleted) Text("asdfasdf") } } } - } } } } diff --git a/Projects/Core/DesignSystem/Sources/SelectionControls/RadioComponent.swift b/Projects/Core/DesignSystem/Sources/SelectionControls/RadioComponent.swift deleted file mode 100644 index 187a1b42..00000000 --- a/Projects/Core/DesignSystem/Sources/SelectionControls/RadioComponent.swift +++ /dev/null @@ -1,32 +0,0 @@ -import SwiftUI - -public struct RadioComponent: View { - private let value: RadioValue - private let content: () -> Content - - public init( - selection: Binding, - @ViewBuilder _ content: @escaping () -> Content, - onTapReceive: ((T?) -> Void)? = nil - ) { - self.value = RadioValue(selection: selection, onTapReceive: onTapReceive) - self.content = content - } - - public var body: some View { - content() - .environmentObject(value) - } -} - -final class RadioValue: ObservableObject { - typealias TapReceiveAction = (T?) -> Void - - @Binding var selection: T? - var onTapReceive: (TapReceiveAction)? - - init(selection: Binding, onTapReceive: (TapReceiveAction)? = nil) { - _selection = selection - self.onTapReceive = onTapReceive - } -} diff --git a/Projects/Core/DesignSystem/Sources/SelectionControls/RadioTag.swift b/Projects/Core/DesignSystem/Sources/SelectionControls/RadioTag.swift deleted file mode 100644 index 5058150d..00000000 --- a/Projects/Core/DesignSystem/Sources/SelectionControls/RadioTag.swift +++ /dev/null @@ -1,44 +0,0 @@ -import SwiftUI - -public struct RadioTag: ViewModifier { - @EnvironmentObject private var value: RadioValue - private var tag: T? - - init(_ tag: T?) { - self.tag = tag - } - - public func body(content: Content) -> some View { - Button { - value.selection = tag - value.onTapReceive?(tag) - } label: { - content - } - .buttonStyle(CustomButtonStyle(isOn: tag == value.selection)) - } -} - -extension View { - public func radioTag(_ tag: T?) -> some View { - self.modifier(RadioTag(tag)) - } -} - -private struct CustomButtonStyle: ButtonStyle { - var isOn: Bool - - init(isOn: Bool) { - self.isOn = isOn - } - - @ViewBuilder - func makeBody(configuration: Configuration) -> some View { - Circle() - .fill(self.isOn && configuration.isPressed ? Color.sms(.neutral(.n20)) : Color.clear) - .overlay { - configuration.label - } - .frame(width: 32, height: 32) - } -} diff --git a/Projects/Core/DesignSystem/Sources/SelectionControls/SMSSelectionControls.swift b/Projects/Core/DesignSystem/Sources/SelectionControls/SMSSelectionControls.swift index ae840a33..88c51452 100644 --- a/Projects/Core/DesignSystem/Sources/SelectionControls/SMSSelectionControls.swift +++ b/Projects/Core/DesignSystem/Sources/SelectionControls/SMSSelectionControls.swift @@ -1,22 +1,42 @@ import SwiftUI -public struct SMSSelectionControls: View { - @EnvironmentObject private var value: RadioValue - private var tag: T? +public struct SMSSelectionControls: View { + @Binding var isSeleted: Bool - public init(tag: T?) { - self.tag = tag + public init(isSeleted: Binding) { + _isSeleted = isSeleted } - public var body: some View { - ZStack { - Circle() - .stroke(tag == value.selection ? Color.sms(.primary(.p2)) : Color.sms(.neutral(.n20)), lineWidth: 2) - .frame(width: 20, height: 20) - - Circle() - .fill(tag == value.selection ? Color.sms(.primary(.p2)) : .clear) - .frame(width: 12, height: 12) + Button { + self.isSeleted.toggle() + } label: { + ZStack { + Circle() + .stroke(isSeleted ? Color.sms(.primary(.p2)) : Color.sms(.neutral(.n20)), lineWidth: 2) + .frame(width: 20, height: 20) + Circle() + .fill(isSeleted ? Color.sms(.primary(.p2)) : .clear) + .frame(width: 12, height: 12) + } } + .buttonStyle(CustomButtonStyle(isSeleted: isSeleted)) + } +} + +private struct CustomButtonStyle: ButtonStyle { + var isSeleted: Bool + + init(isSeleted: Bool) { + self.isSeleted = isSeleted + } + + @ViewBuilder + func makeBody(configuration: Configuration) -> some View { + Circle() + .fill(self.isSeleted && configuration.isPressed ? Color.sms(.neutral(.n20)) : Color.clear) + .overlay { + configuration.label + } + .frame(width: 32, height: 32) } } From 97479aae0657e59e0b30902615f387465bfdb242 Mon Sep 17 00:00:00 2001 From: Sunghun Kim <81547954+kimsh153@users.noreply.github.com> Date: Mon, 22 May 2023 17:54:48 +0900 Subject: [PATCH 14/14] :recycle: PressedSelectionButtonStyle --- .../Sources/SelectionControls/SMSSelectionControls.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Projects/Core/DesignSystem/Sources/SelectionControls/SMSSelectionControls.swift b/Projects/Core/DesignSystem/Sources/SelectionControls/SMSSelectionControls.swift index 88c51452..be8c8005 100644 --- a/Projects/Core/DesignSystem/Sources/SelectionControls/SMSSelectionControls.swift +++ b/Projects/Core/DesignSystem/Sources/SelectionControls/SMSSelectionControls.swift @@ -19,11 +19,11 @@ public struct SMSSelectionControls: View { .frame(width: 12, height: 12) } } - .buttonStyle(CustomButtonStyle(isSeleted: isSeleted)) + .buttonStyle(PressedSelectionButtonStyle(isSeleted: isSeleted)) } } -private struct CustomButtonStyle: ButtonStyle { +private struct PressedSelectionButtonStyle: ButtonStyle { var isSeleted: Bool init(isSeleted: Bool) {