-
Notifications
You must be signed in to change notification settings - Fork 0
Common files has been moved #18
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8a49c16
common files has been moved
husbig 32119f2
Update Sources/INCommons/SwiftUI/ColorPickerButton.swift
husbig dfaeaf4
Color picker example has been added
husbig a7a40fb
fix clear button
husbig 81d9abb
Update Sources/INCommons/Swift/Extensions/String+Manipulation.swift
SvenKorset File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
INCommonsExample/INCommonsExample/Screens/ColorPickerExample.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import SwiftUI | ||
| import INCommons | ||
|
|
||
| struct ColorPickerExample: View { | ||
| @State var showColorPicker: Bool = false | ||
| @State var selectedColor: Color = .green | ||
| var body: some View { | ||
| ColorPickerButton(color: selectedColor) { | ||
| showColorPicker.toggle() | ||
| } | ||
| .colorPickerSheet( | ||
| isPresented: $showColorPicker, | ||
| selection: $selectedColor, | ||
| supportsAlpha: false, | ||
| title: "Color Picker Example", | ||
| animated: true | ||
| ) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import UIKit | ||
|
|
||
| /// The interface of the `ApplicationManager` which can be used to inject different implementations. | ||
| /// Normally code should not be directly dependent upon the `UIApplication` because that might break UnitTests | ||
| /// when running the tests on a device / simulator which differs from the test's expectations. | ||
| /// Therefore, code should get the `UIApplication` instance being injected and for tests it should be mocked. | ||
| /// It's expected that the implementation informs the `ObservableObject` of any value changes. | ||
| @MainActor | ||
| public protocol ApplicationManager { | ||
| /// A boolean which refers `isIdleTimerDisabled`on UIApplication | ||
| var isScreenLockEnabled: Bool { get } | ||
|
|
||
| /// Disables screen dimming automatically | ||
| func disableScreenLock() | ||
|
|
||
| /// Enables screen dimming automatically | ||
| func enableScreenLock() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import UIKit | ||
|
|
||
| /// A concrete implementation of the `ApplicationManager` protocol which can be used in app code | ||
| /// to return the corresponding values from `UIApplication`. | ||
| @available(iOSApplicationExtension, unavailable) | ||
| public final class ApplicationManagerLogic: ApplicationManager { | ||
| public var isScreenLockEnabled: Bool { | ||
| !UIApplication.shared.isIdleTimerDisabled | ||
| } | ||
|
|
||
| public func disableScreenLock() { | ||
| UIApplication.shared.isIdleTimerDisabled = true | ||
| } | ||
|
|
||
| public func enableScreenLock() { | ||
| UIApplication.shared.isIdleTimerDisabled = false | ||
| } | ||
|
|
||
| public init() {} | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import SwiftUI | ||
|
|
||
| /// A re-created button view which looks like Apple's color picker button. | ||
| /// The problem with Apple's color picker is that it's directly linked to the color picker view, | ||
| /// so there is no way to navigate first to a different screen before showing Apple's color picker. | ||
| /// To by-pass this shortcoming we can use this custom button. | ||
| public struct ColorPickerButton: View { | ||
husbig marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| enum Constants { | ||
| static let colorButtonSize: CGSize = .init(width: 36, height: 36) | ||
| static let colorButtonInnerCircleSize: CGSize = .init(width: 26, height: 26) | ||
| static let colorButtonEndAngle: CGFloat = 360 | ||
| static let colorButtonStrokeWidth: CGFloat = 3 | ||
| static let colorButtonGradient = Gradient( | ||
| colors: [ | ||
| Color(uiColor: UIColor(hex: "E7E040") ?? .clear), | ||
| Color(uiColor: UIColor(hex: "EEAA3C") ?? .clear), | ||
| Color(uiColor: UIColor(hex: "E8403B") ?? .clear), | ||
| Color(uiColor: UIColor(hex: "B33ED5") ?? .clear), | ||
| Color(uiColor: UIColor(hex: "694AE8") ?? .clear), | ||
| Color(uiColor: UIColor(hex: "3CCAE7") ?? .clear), | ||
| Color(uiColor: UIColor(hex: "3CE885") ?? .clear), | ||
| Color(uiColor: UIColor(hex: "89E743") ?? .clear), | ||
| Color(uiColor: UIColor(hex: "E7E040") ?? .clear) | ||
| ] | ||
| ) | ||
| } | ||
|
|
||
| private let color: Color | ||
| private let action: () -> Void | ||
| public init(color: Color, action: @escaping () -> Void) { | ||
| self.color = color | ||
| self.action = action | ||
| } | ||
|
|
||
| public var body: some View { | ||
| Button { | ||
| action() | ||
| } label: { | ||
| ZStack { | ||
| Circle() | ||
| .frame(size: Constants.colorButtonInnerCircleSize) | ||
| .foregroundStyle(color) | ||
| Circle() | ||
| .strokeBorder( | ||
| AngularGradient( | ||
| gradient: Constants.colorButtonGradient, | ||
| center: .center, | ||
| startAngle: .zero, | ||
| endAngle: .degrees(Constants.colorButtonEndAngle) | ||
| ), | ||
| lineWidth: Constants.colorButtonStrokeWidth | ||
| ) | ||
| } | ||
| .frame(size: Constants.colorButtonSize) | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| import SwiftUI | ||
|
|
||
| public extension View { | ||
husbig marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| func colorPickerSheet( | ||
| isPresented: Binding<Bool>, | ||
| selection: Binding<Color>, | ||
| supportsAlpha: Bool = true, | ||
| title: String? = nil, | ||
| animated: Bool = true | ||
| ) -> some View { | ||
| background( | ||
| ColorPickerSheet( | ||
| isPresented: isPresented, | ||
| selection: selection, | ||
| supportsAlpha: supportsAlpha, | ||
| title: title, | ||
| animated: animated | ||
| ) | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| private struct ColorPickerSheet: UIViewRepresentable { | ||
| @Binding var isPresented: Bool | ||
| @Binding var selection: Color | ||
| let supportsAlpha: Bool | ||
| let title: String? | ||
| let animated: Bool | ||
| func makeCoordinator() -> Coordinator { | ||
| Coordinator(selection: $selection, isPresented: $isPresented) | ||
| } | ||
|
|
||
| class Coordinator: NSObject, UIColorPickerViewControllerDelegate, UIAdaptivePresentationControllerDelegate { | ||
| @Binding var selection: Color | ||
| @Binding var isPresented: Bool | ||
| var didPresent = false | ||
|
|
||
| init(selection: Binding<Color>, isPresented: Binding<Bool>) { | ||
| _selection = selection | ||
| _isPresented = isPresented | ||
| } | ||
|
|
||
| func colorPickerViewControllerDidSelectColor(_ viewController: UIColorPickerViewController) { | ||
| selection = Color(viewController.selectedColor) | ||
| } | ||
|
|
||
| func colorPickerViewControllerDidFinish(_: UIColorPickerViewController) { | ||
| isPresented = false | ||
| didPresent = false | ||
| } | ||
|
|
||
| func presentationControllerDidDismiss(_: UIPresentationController) { | ||
| isPresented = false | ||
| didPresent = false | ||
| } | ||
| } | ||
|
|
||
| func getTopViewController(from view: UIView) -> UIViewController? { | ||
| guard var top = view.window?.rootViewController else { | ||
| return nil | ||
| } | ||
| while let next = top.presentedViewController { | ||
| top = next | ||
| } | ||
| return top | ||
| } | ||
|
|
||
| func makeUIView(context _: Context) -> UIView { | ||
| let view = UIView() | ||
| view.isHidden = true | ||
| return view | ||
| } | ||
|
|
||
| func updateUIView(_ uiView: UIView, context: Context) { | ||
| if isPresented, !context.coordinator.didPresent { | ||
| let modal = UIColorPickerViewController() | ||
| modal.sheetPresentationController?.detents = [.medium(), .large()] | ||
| modal.selectedColor = UIColor(selection) | ||
| modal.supportsAlpha = supportsAlpha | ||
| modal.title = title | ||
| modal.delegate = context.coordinator | ||
| modal.presentationController?.delegate = context.coordinator | ||
| let top = getTopViewController(from: uiView) | ||
| top?.present(modal, animated: true) | ||
| context.coordinator.didPresent = true | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.