-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from GoodRequest/feature/input-field
feature: Hybrid input field for UIKit/SwiftUI
- Loading branch information
Showing
19 changed files
with
1,997 additions
and
33 deletions.
There are no files selected for viewing
This file contains 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
32 changes: 32 additions & 0 deletions
32
...le/GoodSwiftUI-Sample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
This file contains 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,32 @@ | ||
{ | ||
"pins" : [ | ||
{ | ||
"identity" : "combineext", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/CombineCommunity/CombineExt.git", | ||
"state" : { | ||
"revision" : "d7b896fa9ca8b47fa7bcde6b43ef9b70bf8c1f56", | ||
"version" : "1.8.1" | ||
} | ||
}, | ||
{ | ||
"identity" : "goodextensions-ios", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/goodrequest/goodextensions-ios", | ||
"state" : { | ||
"branch" : "main", | ||
"revision" : "0db99c0d3b49828a7d6189786215f3abfeb4de6f" | ||
} | ||
}, | ||
{ | ||
"identity" : "swift-syntax", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/apple/swift-syntax.git", | ||
"state" : { | ||
"revision" : "64889f0c732f210a935a0ad7cda38f77f876262d", | ||
"version" : "509.1.1" | ||
} | ||
} | ||
], | ||
"version" : 2 | ||
} |
77 changes: 77 additions & 0 deletions
77
GoodSwiftUI-Sample/GoodSwiftUI-Sample/Extensions/InputFieldViewConfiguration.swift
This file contains 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,77 @@ | ||
// | ||
// InputFieldViewConfiguration.swift | ||
// GoodSwiftUI-Sample | ||
// | ||
// Created by Filip Šašala on 24/06/2024. | ||
// | ||
|
||
import UIKit | ||
import GRInputField | ||
|
||
extension InputFieldView { | ||
|
||
static func configureAppearance() { | ||
let customAppearance = InputFieldAppearance( | ||
titleFont: UIFont.preferredFont(for: .caption1, weight: .regular, defaultSize: 12.0), | ||
titleColor: UIColor.systemBlue, | ||
textFieldTintColor: UIColor.systemBlue, | ||
textFieldFont: UIFont.preferredFont(for: .body, weight: .regular, defaultSize: 17.0), | ||
hintFont: UIFont.preferredFont(for: .caption1, weight: .regular, defaultSize: 12.0), | ||
borderWidth: 1, | ||
cornerRadius: 16, | ||
height: 56, | ||
eyeImageHidden: UIImage(systemName: "eye"), | ||
eyeImageVisible: UIImage(systemName: "eye.slash"), | ||
enabled: InputFieldViewStateAppearance( | ||
placeholderColor: UIColor.darkGray, | ||
contentBackgroundColor: UIColor.white, | ||
textFieldTextColor: UIColor.systemBlue, | ||
borderColor: UIColor.gray, | ||
hintColor: UIColor.darkGray | ||
), | ||
selected: InputFieldViewStateAppearance( | ||
placeholderColor: UIColor.darkGray, | ||
contentBackgroundColor: UIColor.white, | ||
textFieldTextColor: UIColor.systemBlue, | ||
borderColor: UIColor.gray, | ||
hintColor: UIColor.darkGray | ||
), | ||
disabled: InputFieldViewStateAppearance( | ||
placeholderColor: UIColor.darkGray, | ||
contentBackgroundColor: UIColor.lightGray, | ||
textFieldTextColor: UIColor.darkGray, | ||
borderColor: UIColor.gray, | ||
hintColor: UIColor.darkGray | ||
), | ||
failed: InputFieldViewStateAppearance( | ||
placeholderColor: UIColor.darkGray, | ||
contentBackgroundColor: UIColor.white, | ||
textFieldTextColor: UIColor.systemBlue, | ||
borderColor: UIColor.systemRed, | ||
hintColor: UIColor.systemRed | ||
) | ||
) | ||
|
||
InputFieldView.defaultAppearance = customAppearance | ||
} | ||
|
||
} | ||
|
||
extension UIFont { | ||
|
||
static func preferredFont(for style: TextStyle, weight: Weight, defaultSize: CGFloat) -> UIFont { | ||
let font = UIFont.systemFont(ofSize: defaultSize, weight: weight).with([.traitUIOptimized]) | ||
return UIFontMetrics(forTextStyle: style).scaledFont(for: font) | ||
} | ||
|
||
func with(_ traits: UIFontDescriptor.SymbolicTraits...) -> UIFont { | ||
if let descriptor = fontDescriptor.withSymbolicTraits( | ||
UIFontDescriptor.SymbolicTraits(traits).union(fontDescriptor.symbolicTraits) | ||
) { | ||
return UIFont(descriptor: descriptor, size: 0) | ||
} else { | ||
return self | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.