@@ -194,31 +194,51 @@ struct SingleAddressForm: View {
194194 ///
195195 @State private var showStateSelector = false
196196
197+ /// Stores shared value derived from max title width among all the fields.
198+ ///
199+ @State private var titleWidth : CGFloat ? = nil
200+
197201 var body : some View {
202+ content
203+ . onPreferenceChange ( MaxWidthPreferenceKey . self) { value in
204+ if let value = value {
205+ titleWidth = value
206+ }
207+ }
208+ }
209+
210+ @ViewBuilder
211+ var content : some View {
198212 ListHeaderView ( text: Localization . detailsSection, alignment: . left)
199213 . padding ( . horizontal, insets: safeAreaInsets)
200214 . accessibility ( addTraits: . isHeader)
201215 VStack ( spacing: 0 ) {
202216 TitleAndTextFieldRow ( title: Localization . firstNameField,
217+ titleWidth: $titleWidth,
203218 placeholder: " " ,
204219 text: $fields. firstName,
205220 symbol: nil ,
221+ fieldAlignment: . leading,
206222 keyboardType: . default)
207223 Divider ( )
208224 . padding ( . leading, Constants . dividerPadding)
209225 TitleAndTextFieldRow ( title: Localization . lastNameField,
226+ titleWidth: $titleWidth,
210227 placeholder: " " ,
211228 text: $fields. lastName,
212229 symbol: nil ,
230+ fieldAlignment: . leading,
213231 keyboardType: . default)
214232 Divider ( )
215233 . padding ( . leading, Constants . dividerPadding)
216234
217235 if showEmailField {
218236 TitleAndTextFieldRow ( title: Localization . emailField,
237+ titleWidth: $titleWidth,
219238 placeholder: " " ,
220239 text: $fields. email,
221240 symbol: nil ,
241+ fieldAlignment: . leading,
222242 keyboardType: . emailAddress)
223243 . autocapitalization ( . none)
224244 Divider ( )
@@ -227,9 +247,11 @@ struct SingleAddressForm: View {
227247 }
228248
229249 TitleAndTextFieldRow ( title: Localization . phoneField,
250+ titleWidth: $titleWidth,
230251 placeholder: " " ,
231252 text: $fields. phone,
232253 symbol: nil ,
254+ fieldAlignment: . leading,
233255 keyboardType: . phonePad)
234256 }
235257 . padding ( . horizontal, insets: safeAreaInsets)
@@ -242,37 +264,47 @@ struct SingleAddressForm: View {
242264 VStack ( spacing: 0 ) {
243265 Group {
244266 TitleAndTextFieldRow ( title: Localization . companyField,
267+ titleWidth: $titleWidth,
245268 placeholder: Localization . placeholderOptional,
246269 text: $fields. company,
247270 symbol: nil ,
271+ fieldAlignment: . leading,
248272 keyboardType: . default)
249273 Divider ( )
250274 . padding ( . leading, Constants . dividerPadding)
251275 TitleAndTextFieldRow ( title: Localization . address1Field,
276+ titleWidth: $titleWidth,
252277 placeholder: " " ,
253278 text: $fields. address1,
254279 symbol: nil ,
280+ fieldAlignment: . leading,
255281 keyboardType: . default)
256282 Divider ( )
257283 . padding ( . leading, Constants . dividerPadding)
258284 TitleAndTextFieldRow ( title: Localization . address2Field,
285+ titleWidth: $titleWidth,
259286 placeholder: Localization . placeholderOptional,
260287 text: $fields. address2,
261288 symbol: nil ,
289+ fieldAlignment: . leading,
262290 keyboardType: . default)
263291 Divider ( )
264292 . padding ( . leading, Constants . dividerPadding)
265293 TitleAndTextFieldRow ( title: Localization . cityField,
294+ titleWidth: $titleWidth,
266295 placeholder: " " ,
267296 text: $fields. city,
268297 symbol: nil ,
298+ fieldAlignment: . leading,
269299 keyboardType: . default)
270300 Divider ( )
271301 . padding ( . leading, Constants . dividerPadding)
272302 TitleAndTextFieldRow ( title: Localization . postcodeField,
303+ titleWidth: $titleWidth,
273304 placeholder: " " ,
274305 text: $fields. postcode,
275306 symbol: nil ,
307+ fieldAlignment: . leading,
276308 keyboardType: . default)
277309 Divider ( )
278310 . padding ( . leading, Constants . dividerPadding)
@@ -326,9 +358,11 @@ struct SingleAddressForm: View {
326358 }
327359 } else {
328360 TitleAndTextFieldRow ( title: Localization . stateField,
361+ titleWidth: $titleWidth,
329362 placeholder: " " ,
330363 text: $fields. state,
331364 symbol: nil ,
365+ fieldAlignment: . leading,
332366 keyboardType: . default)
333367 }
334368 }
0 commit comments