Skip to content

Commit

Permalink
Merge pull request #9 from brunomunizaf/dev
Browse files Browse the repository at this point in the history
Add FormCalendarItem
  • Loading branch information
brunomunizaf authored Oct 19, 2023
2 parents 23733c1 + bc9c1ea commit c3f119d
Show file tree
Hide file tree
Showing 7 changed files with 298 additions and 40 deletions.
4 changes: 2 additions & 2 deletions Example/Example/Views/FinishedScreenView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ final class FinishedScreenView: UIView {

init() {
super.init(frame: .zero)
backgroundColor = .white
backgroundColor = .systemBackground

addSubview(formView)
formView.translatesAutoresizingMaskIntoConstraints = false
Expand All @@ -36,7 +36,7 @@ private extension FormTextItem.Configuration {
text: "Horray! You finished the onboarding. 🎉",
attributes: [
.font: UIFont(name: "AvenirNext-DemiBold", size: 30)!,
.foregroundColor: UIColor.black,
.foregroundColor: UIColor.label,
.kern: 0.5,
],
spacingAfter: 20
Expand Down
18 changes: 9 additions & 9 deletions Example/Example/Views/PermissionsScreenView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class PermissionsScreenView: UIView {

init() {
super.init(frame: .zero)
backgroundColor = .white
backgroundColor = .systemBackground

addSubview(formView)
formView.translatesAutoresizingMaskIntoConstraints = false
Expand All @@ -47,7 +47,7 @@ private extension FormTextItem.Configuration {
text: "Manage Permissions",
attributes: [
.font: UIFont(name: "AvenirNext-DemiBold", size: 24)!,
.foregroundColor: UIColor.black,
.foregroundColor: UIColor.label,
.kern: 0.5
],
spacingAfter: 20
Expand All @@ -57,7 +57,7 @@ private extension FormTextItem.Configuration {
text: "Customize which features the app can access to enhance your user experience.",
attributes: [
.font: UIFont(name: "AvenirNext-Regular", size: 16)!,
.foregroundColor: UIColor.darkGray,
.foregroundColor: UIColor.secondaryLabel,
.kern: 0.2
],
spacingAfter: 20
Expand All @@ -68,10 +68,10 @@ private extension FormSwitchItem.Configuration {
static let first = FormSwitchItem.Configuration(
title: "Location Access",
titleFont: UIFont(name: "AvenirNext-Medium", size: 17)!,
titleColor: .black,
titleColor: .label,
subtitle: "Allow the app to access your location to enhance service delivery and improve user experience.",
subtitleFont: UIFont(name: "AvenirNext-Regular", size: 15)!,
subtitleColor: .gray,
subtitleColor: .secondaryLabel,
onColor: .systemBlue,
isOn: false,
spacingAfter: 25
Expand All @@ -80,10 +80,10 @@ private extension FormSwitchItem.Configuration {
static let second = FormSwitchItem.Configuration(
title: "Notifications",
titleFont: UIFont(name: "AvenirNext-Medium", size: 17)!,
titleColor: .black,
titleColor: .label,
subtitle: "Enable notifications to stay updated with the latest news, updates, and offers.",
subtitleFont: UIFont(name: "AvenirNext-Regular", size: 15)!,
subtitleColor: .gray,
subtitleColor: .secondaryLabel,
onColor: .systemGreen,
isOn: false,
spacingAfter: 25
Expand All @@ -92,10 +92,10 @@ private extension FormSwitchItem.Configuration {
static let third = FormSwitchItem.Configuration(
title: "Camera Access",
titleFont: UIFont(name: "AvenirNext-Medium", size: 17)!,
titleColor: .black,
titleColor: .label,
subtitle: "Grant permission to access your camera to take photos and videos within the app.",
subtitleFont: UIFont(name: "AvenirNext-Regular", size: 15)!,
subtitleColor: .gray,
subtitleColor: .secondaryLabel,
onColor: .systemRed,
isOn: false,
spacingAfter: 25
Expand Down
126 changes: 111 additions & 15 deletions Example/Example/Views/PersonalScreenView.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import Forms
import UIKit

typealias CalendarDelegate =
UICalendarViewDelegate &
UICalendarSelectionMultiDateDelegate &
UICalendarSelectionSingleDateDelegate

/// `PersonalScreenView` is a `UIView` subclass that sets up and
/// manages `FormItem's` included on the Personal Details UI flow.
///
Expand All @@ -10,9 +15,10 @@ final class PersonalScreenView: UIView {
lazy var formView = FormView(elements: [
FormTextItem(configuration: .title),
FormTextItem(configuration: .subtitle),
inputItem,
requiredInputItem,
numbersInputItem,
inputItem,
calendarItem,
FormSpacingItem(),
buttonItem
])
Expand All @@ -22,10 +28,11 @@ final class PersonalScreenView: UIView {
let requiredInputItem = MinimumFormInputItem(configuration: .second)
let numbersInputItem = RegexFormInputItem(configuration: .third)
let buttonItem = FormButtonItem(configuration: .personal)
lazy var calendarItem = FormCalendarItem(configuration: .personal(delegate: self))

init() {
super.init(frame: .zero)
backgroundColor = .white
backgroundColor = .systemBackground

addSubview(scrollView)
scrollView.addSubview(formView)
Expand Down Expand Up @@ -53,27 +60,84 @@ final class PersonalScreenView: UIView {
required init?(coder: NSCoder) { nil }
}

// MARK: - UICalendarSelectionSingleDateDelegate

extension PersonalScreenView: UICalendarSelectionSingleDateDelegate {
func dateSelection(
_ selection: UICalendarSelectionSingleDate,
didSelectDate dateComponents: DateComponents?
) {
if let day = dateComponents?.day,
let month = dateComponents?.month,
let year = dateComponents?.year {
print(">>> Did select \(day)/\(month)/\(year)")
}
}
}

// MARK: - UICalendarSelectionMultiDateDelegate

extension PersonalScreenView: UICalendarSelectionMultiDateDelegate {
func multiDateSelection(
_ selection: UICalendarSelectionMultiDate,
didSelectDate dateComponents: DateComponents
) {
if let day = dateComponents.day,
let month = dateComponents.month,
let year = dateComponents.year {
print(">>> Did select \(day)/\(month)/\(year)")
}
}

func multiDateSelection(
_ selection: UICalendarSelectionMultiDate,
didDeselectDate dateComponents: DateComponents
) {
if let day = dateComponents.day,
let month = dateComponents.month,
let year = dateComponents.year {
print(">>> Did de-select \(day)/\(month)/\(year)")
}
}
}

// MARK: - UICalendarViewDelegate

extension PersonalScreenView: UICalendarViewDelegate {
func calendarView(
_ calendarView: UICalendarView,
decorationFor dateComponents: DateComponents
) -> UICalendarView.Decoration? {
switch dateComponents.day {
case 5:
return .default(color: .systemRed, size: .small)
default:
return .default(color: .systemGreen, size: .small)
}
}
}

// MARK: - FormItem.Configuration

private extension FormTextItem.Configuration {
static let title = FormTextItem.Configuration(
text: "Your personal details",
attributes: [
.font: UIFont(name: "AvenirNext-DemiBold", size: 24)!,
.foregroundColor: UIColor.black,
.foregroundColor: UIColor.label,
.kern: 0.5
],
spacingAfter: 15
spacingAfter: 20
)

static let subtitle = FormTextItem.Configuration(
text: "Insert your personal information to keep your profile up to date.",
attributes: [
.font: UIFont(name: "AvenirNext-Regular", size: 16)!,
.foregroundColor: UIColor.darkGray,
.foregroundColor: UIColor.secondaryLabel,
.kern: 0.2
],
spacingAfter: 30
spacingAfter: 20
)
}

Expand All @@ -82,18 +146,18 @@ private extension FormInputItem.Configuration {
title: "Street Address",
titleAttributes: [
.font: UIFont(name: "AvenirNext-Medium", size: 16)!,
.foregroundColor: UIColor.black
.foregroundColor: UIColor.label
],
initialText: nil,
placeholder: "e.g. 5912 5th Avenue, New York, NY",
isSecure: false,
autocorrectionType: .no,
autocapitalizationType: .none,
font: UIFont(name: "AvenirNext-Regular", size: 16)!,
textColor: UIColor.darkGray,
textColor: UIColor.label,
cornerRadius: 8,
borderWidth: 1.0,
borderColor: UIColor.lightGray,
borderColor: UIColor.systemGray,
spacingAfter: 15,
didChange: nil
)
Expand All @@ -102,15 +166,15 @@ private extension FormInputItem.Configuration {
title: "Full Name",
titleAttributes: [
.font: UIFont(name: "AvenirNext-Medium", size: 16)!,
.foregroundColor: UIColor.black
.foregroundColor: UIColor.label
],
initialText: nil,
placeholder: "Required",
isSecure: false,
autocorrectionType: .default,
autocapitalizationType: .words,
font: UIFont(name: "AvenirNext-Regular", size: 16)!,
textColor: UIColor.darkGray,
textColor: UIColor.label,
cornerRadius: 8,
borderWidth: 1.0,
borderColor: UIColor.lightGray,
Expand All @@ -121,20 +185,20 @@ private extension FormInputItem.Configuration {
static let third = FormInputItem.Configuration(
title: "Phone Number",
titleAttributes: [
.font: UIFont(name: "AvenirNext-Medium", size: 16)!,
.foregroundColor: UIColor.black
.font: UIFont(name: "AvenirNext-Medium", size: 16)!,
.foregroundColor: UIColor.label
],
initialText: nil,
placeholder: "Only numbers allowed",
isSecure: false,
autocorrectionType: .no,
autocapitalizationType: .none,
font: UIFont(name: "AvenirNext-Regular", size: 16)!,
textColor: UIColor.darkGray,
textColor: UIColor.label,
cornerRadius: 8,
borderWidth: 1.0,
borderColor: UIColor.lightGray,
spacingAfter: 20,
spacingAfter: 15,
didChange: nil
)
}
Expand All @@ -155,3 +219,35 @@ private extension FormButtonItem.Configuration {
shouldBeEnabled: false
)
}

private extension FormCalendarItem.Configuration {
static func personal(
delegate: CalendarDelegate
) -> FormCalendarItem.Configuration {
FormCalendarItem.Configuration(
title: "Date of Birth",
calendar: .init(identifier: .gregorian),
tintColor: .label,
spacingAfter: 20,
availableRange: DateInterval(start: .distantPast, end: .now),
delegate: delegate,
selectionMultiDate: nil,
selectionSingleDate: .selectionSingleDate(delegate: delegate),
titleAttributes: [
.font: UIFont(name: "AvenirNext-Medium", size: 16)!,
.foregroundColor: UIColor.label
]
)
}
}

private extension FormCalendarItem.Configuration.SelectionSingleDate {
static func selectionSingleDate(
delegate: UICalendarSelectionSingleDateDelegate
) -> FormCalendarItem.Configuration.SelectionSingleDate {
FormCalendarItem.Configuration.SelectionSingleDate(
delegate: delegate,
selectedDate: DateComponents(year: 1995, month: 06, day: 01)
)
}
}
10 changes: 5 additions & 5 deletions Example/Example/Views/TermsScreenView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class TermsScreenView: UIView {

init() {
super.init(frame: .zero)
backgroundColor = .white
backgroundColor = .systemBackground

addSubview(formView)
formView.translatesAutoresizingMaskIntoConstraints = false
Expand All @@ -43,7 +43,7 @@ private extension FormTextItem.Configuration {
text: "Review Our Terms & Conditions",
attributes: [
.font: UIFont(name: "AvenirNext-DemiBold", size: 24)!,
.foregroundColor: UIColor.black,
.foregroundColor: UIColor.label,
.kern: 0.5
],
spacingAfter: 20
Expand All @@ -53,7 +53,7 @@ private extension FormTextItem.Configuration {
text: "Please read carefully to understand your rights and obligations while using our services.",
attributes: [
.font: UIFont(name: "AvenirNext-Regular", size: 16)!,
.foregroundColor: UIColor.darkGray,
.foregroundColor: UIColor.secondaryLabel,
.kern: 0.2
],
spacingAfter: 20
Expand All @@ -64,10 +64,10 @@ private extension FormCheckboxItem.Configuration {
static let terms = FormCheckboxItem.Configuration(
title: "Acceptance of Terms & Conditions",
titleFont: UIFont(name: "AvenirNext-Medium", size: 18)!,
titleColor: UIColor.black,
titleColor: UIColor.label,
subtitle: "By checking this box, you acknowledge that you have read, understood, and agree to abide by the terms and conditions outlined above.",
subtitleFont: UIFont(name: "AvenirNext-Regular", size: 14)!,
subtitleColor: UIColor.gray,
subtitleColor: UIColor.secondaryLabel,
checkedColor: UIColor.systemGreen,
uncheckedColor: UIColor.white,
borderWidth: 1.0,
Expand Down
Loading

0 comments on commit c3f119d

Please sign in to comment.