@@ -66,8 +66,8 @@ struct CategoryManageView: View {
6666 . navigationTitle ( String ( localized: " nav_todo_manage " ) )
6767 . navigationBarTitleDisplayMode ( . inline)
6868 . navigationBarBackButtonHidden ( )
69- . sheet ( item: $store. scope ( state: \. categorySheet, action: \. categorySheet) ) { store in
70- CategoryManageSheet ( store : store )
69+ . sheet ( item: $store. scope ( state: \. categorySheet, action: \. categorySheet) ) { sheetStore in
70+ sheetContent ( sheetStore )
7171 }
7272 . alert ( $store. scope ( state: \. alert, action: \. alert) )
7373 . toolbar {
@@ -91,10 +91,17 @@ struct CategoryManageView: View {
9191 }
9292 . presentationDragIndicator ( . visible)
9393 }
94+
95+ @ViewBuilder
96+ private func sheetContent(
97+ _ sheetStore: Store < CategoryManageFeature . CategorySheetState , CategoryManageFeature . Action . CategorySheet >
98+ ) -> some View {
99+ CategoryManageSheet ( store: sheetStore)
100+ }
94101}
95102
96103private struct CategoryManageSheet : View {
97- let store : Store < CategoryManageFeature . CategorySheetState , CategoryManageFeature . Action . CategorySheet >
104+ @ Bindable var store : Store < CategoryManageFeature . CategorySheetState , CategoryManageFeature . Action . CategorySheet >
98105
99106 var body : some View {
100107 NavigationStack {
@@ -103,10 +110,7 @@ private struct CategoryManageSheet: View {
103110 HStack ( spacing: 8 ) {
104111 TextField (
105112 " " ,
106- text: Binding (
107- get: { store. category. name } ,
108- set: { store. send ( . setCategoryName( $0) ) }
109- ) ,
113+ text: $store. category. name,
110114 prompt: Text ( store. placeholder) . foregroundStyle ( . secondary)
111115 )
112116 . frame ( height: UIFont . preferredFont ( forTextStyle: . body) . lineHeight)
@@ -119,21 +123,14 @@ private struct CategoryManageSheet: View {
119123 }
120124
121125 Section {
122- let color = Color ( hexString: store. category. colorHex) ?? . randomValue
123- ColorPicker ( selection: Binding (
124- get: { color } ,
125- set: {
126- guard let hexValue = $0. hexValue else { return }
127- store. send ( . setCategoryColor( hexValue) )
128- }
129- ) , supportsOpacity: false ) {
126+ ColorPicker ( selection: $store. category. colorHex. colorValue, supportsOpacity: false ) {
130127 Text ( store. category. colorHex. isEmpty ? " # " : store. category. colorHex)
131128 . overlay ( alignment: . bottom) {
132129 Rectangle ( )
133130 . frame ( height: 1 )
134131 . offset ( y: 1 )
135132 }
136- . foregroundStyle ( color )
133+ . foregroundStyle ( store . category . colorHex . colorValue )
137134 . onTapGesture {
138135 store. send ( . tapRandomColorButton)
139136 }
@@ -160,3 +157,14 @@ private struct CategoryManageSheet: View {
160157 }
161158 }
162159}
160+
161+ private extension String {
162+ var colorValue : Color {
163+ get { Color ( hexString: self ) ?? . randomValue }
164+ set {
165+ if let hexValue = newValue. hexValue {
166+ self = hexValue
167+ }
168+ }
169+ }
170+ }
0 commit comments