-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
๐ :: DesignSystem SMSSelectionControls ์ ์ #37
Changes from 10 commits
e70aa84
715d732
4fb864d
abab51c
6eef1cf
3d7d4ad
94053a1
e25c2a4
1a75279
6535fe1
80e8c8e
8c29c2a
1208295
fdc43eb
8a8091a
f326a31
97479aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import SwiftUI | ||
|
||
public struct RadioComponent<T: Hashable, Content: View>: View { | ||
private let value: RadioValue<T> | ||
private let content: () -> Content | ||
|
||
public init( | ||
selection: Binding<T?>, | ||
@ViewBuilder _ content: @escaping () -> Content, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. content ์ด ์น๊ตฌ label์ด ์ _ ์ธ๊ฑฐ์ฃ ? |
||
onTapReceive: ((T?) -> Void)? = nil | ||
) { | ||
self.value = RadioValue(selection: selection, onTapReceive: onTapReceive) | ||
self.content = content | ||
} | ||
|
||
public var body: some View { | ||
content() | ||
.environmentObject(value) | ||
} | ||
} | ||
|
||
class RadioValue<T: Hashable>: ObservableObject { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ์์ํ ์ฌ์ง๊ฐ ์์ผ๋ final๋ก ์ฒ๋ฆฌํ๋๊ฒ ์ข์ง ์์๊น์? |
||
typealias TapReceiveAction = (T?) -> Void | ||
|
||
@Binding var selection: T? | ||
var onTapReceive: (TapReceiveAction)? | ||
|
||
init(selection: Binding<T?>, onTapReceive: (TapReceiveAction)? = nil) { | ||
_selection = selection | ||
self.onTapReceive = onTapReceive | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import SwiftUI | ||
|
||
public struct SMSSelectionControls<T: Hashable>: View { | ||
@EnvironmentObject private var value: RadioValue<T> | ||
private var 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) | ||
} | ||
} | ||
.buttonStyle(CustomButtonStyle(isOn: tag == value.selection)) | ||
} | ||
} | ||
|
||
private struct CustomButtonStyle: ButtonStyle { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. private์ด๊ธด ํ์ง๋ง CustomButotnStyle๋ณด๋ค ๋ ์ง๊ด์ ์ธ ์ด๋ฆ์ ์์๊น์? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SMSelectionControlsStyle๋ก ์์ ํ ๊น์? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ์ด๊ฑฐ๋ ํน์ SelectionControl ๊ทธ ์์ฒด๋ณด๋ค๋ SelectionControl์ด ๋๋ ธ์ ๋ gray์์ด ์๊ธฐ๋ style์๋๊ฐ์? ์ข ๋ค๋ฅธ ์ด๋ฆ์ ์๋์? |
||
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) | ||
} | ||
} | ||
|
||
public struct RadioTag<T: Hashable>: ViewModifier { | ||
@EnvironmentObject private var value: RadioValue<T> | ||
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(.plain) | ||
} | ||
} | ||
|
||
extension View { | ||
public func radioTag<T: Hashable>(_ tag: T?) -> some View { | ||
self.modifier(RadioTag(tag)) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๊ทผ๋ฐ ์ด๊ฑฐ .radioTag๊ฐ
์ด๊ฑฐ๋ก ๊ฐ์ธ๊ณ SMSSelectionControls ํ๊ทธ๋
์ด๋ ๊ฒ ๊ฐ์ธ๋๋๊ฑฐ๋ฉด ์ ๋ฏธ๋ฌํ์ง ์์์?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๊ทธ ๋์์ด๋๋ถ์ด ๋ง์ํ์ ๊ฑธ๋ก๋ ๋ฒํผ๋ง ๋๋ฌ์ ธ์ผํ๋ค๊ณ ํ์๊ธธ๋ ์์ฒญ์ฌํญ๋๋ก ์์ ํ์ต๋๋ค
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์์ ๋ ์ฝ๋ ๋ง๋์?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๋ค.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ง๊ธ๋ text๋ ๊ฐ์ด ๋๋ฆฌ๋๋ฐ์?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ ์๋๋ค, ์ด๋ฌ ์ปค๋ฐ์ด ๋๋ฌด ์ฝ๋๊ฐ ํท๊ฐ๋ฆฌ๊ฒ ์ปค๋ฐ๋ผ์;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ฉ ์ฃ์กํจ๋ค