Skip to content
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

Showing a checkmark on the selected option #61

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
import SwiftUI
import KamaalUI
import KamaalLogger
import KamaalNavigation
import KamaalAlgorithms

private let logger = KamaalLogger(from: PreferenceOptionsScreen.self)

struct PreferenceOptionsScreen: View {
@Environment(\.presentationMode) private var presentationMode: Binding<PresentationMode>

@EnvironmentObject private var navigator: Navigator<ScreenSelection>

Check warning on line 19 in Sources/KamaalSettings/Internal/Views/Screens/PreferenceOptionsScreen.swift

View check run for this annotation

Codecov / codecov/patch

Sources/KamaalSettings/Internal/Views/Screens/PreferenceOptionsScreen.swift#L19

Added line #L19 was not covered by tests

let preference: Preference

init(preference: Preference) {
Expand All @@ -29,12 +32,23 @@
searchFilter: self.searchFilter,
onItemPress: self.onPreferenceOptionChange
) { option in
AppText(string: option.label)
.bold()
.ktakeWidthEagerly(alignment: .leading)
HStack {
AppText(string: option.label)
.bold()
Spacer()
if isSelected(option) {
Image(systemName: "checkmark")
.kBold()
}
}
.ktakeWidthEagerly(alignment: .leading)

Check warning on line 44 in Sources/KamaalSettings/Internal/Views/Screens/PreferenceOptionsScreen.swift

View check run for this annotation

Codecov / codecov/patch

Sources/KamaalSettings/Internal/Views/Screens/PreferenceOptionsScreen.swift#L35-L44

Added lines #L35 - L44 were not covered by tests
}
}

private func isSelected(_ option: Preference.Option) -> Bool {
preference.selectedOption == option
}

Check warning on line 50 in Sources/KamaalSettings/Internal/Views/Screens/PreferenceOptionsScreen.swift

View check run for this annotation

Codecov / codecov/patch

Sources/KamaalSettings/Internal/Views/Screens/PreferenceOptionsScreen.swift#L48-L50

Added lines #L48 - L50 were not covered by tests

private func searchFilter(_ option: Preference.Option, _ searchText: String) -> Bool {
option.label.fuzzyMatch(searchText)
}
Expand All @@ -43,6 +57,11 @@
let newPreference = self.preference.setOption(option)
NotificationCenter.default.post(name: .preferenceChanged, object: newPreference)
logger.info("preference changed to \(newPreference)")
#if os(macOS)
self.navigator.goBack()
#else
self.presentationMode.wrappedValue.dismiss()
#endif

Check warning on line 64 in Sources/KamaalSettings/Internal/Views/Screens/PreferenceOptionsScreen.swift

View check run for this annotation

Codecov / codecov/patch

Sources/KamaalSettings/Internal/Views/Screens/PreferenceOptionsScreen.swift#L60-L64

Added lines #L60 - L64 were not covered by tests
}
}

Expand Down