Skip to content

Commit

Permalink
Merge pull request #5 from GoodRequest/feature/input-field
Browse files Browse the repository at this point in the history
feature: Hybrid input field for UIKit/SwiftUI
  • Loading branch information
plajdo authored Jul 3, 2024
2 parents e6e5f2c + 68a69a3 commit 7ce3cd4
Show file tree
Hide file tree
Showing 19 changed files with 1,997 additions and 33 deletions.
16 changes: 16 additions & 0 deletions GoodSwiftUI-Sample/GoodSwiftUI-Sample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
09794E3A2C295F4600023CD1 /* InputFieldViewConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09794E392C295F4600023CD1 /* InputFieldViewConfiguration.swift */; };
09794E3C2C2ADAFE00023CD1 /* InputFieldSampleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09794E3B2C2ADAFE00023CD1 /* InputFieldSampleView.swift */; };
3F9F28442A3AEC6000D92CA2 /* SamplesListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F9F28432A3AEC6000D92CA2 /* SamplesListView.swift */; };
3F9F28462A3AEC8B00D92CA2 /* GRAsyncImageSampleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F9F28452A3AEC8B00D92CA2 /* GRAsyncImageSampleView.swift */; };
3F9F28482A3AECC700D92CA2 /* GRAsyncImage in Frameworks */ = {isa = PBXBuildFile; productRef = 3F9F28472A3AECC700D92CA2 /* GRAsyncImage */; };
Expand All @@ -17,6 +19,8 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
09794E392C295F4600023CD1 /* InputFieldViewConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InputFieldViewConfiguration.swift; sourceTree = "<group>"; };
09794E3B2C2ADAFE00023CD1 /* InputFieldSampleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InputFieldSampleView.swift; sourceTree = "<group>"; };
3F9F28432A3AEC6000D92CA2 /* SamplesListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SamplesListView.swift; sourceTree = "<group>"; };
3F9F28452A3AEC8B00D92CA2 /* GRAsyncImageSampleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GRAsyncImageSampleView.swift; sourceTree = "<group>"; };
5D740EA929B0BE0100975B8C /* GoodSwiftUI-Sample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "GoodSwiftUI-Sample.app"; sourceTree = BUILT_PRODUCTS_DIR; };
Expand All @@ -40,11 +44,20 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
09794E382C295F3F00023CD1 /* Extensions */ = {
isa = PBXGroup;
children = (
09794E392C295F4600023CD1 /* InputFieldViewConfiguration.swift */,
);
path = Extensions;
sourceTree = "<group>";
};
3F9F28422A3AEC5200D92CA2 /* Screens */ = {
isa = PBXGroup;
children = (
3F9F28432A3AEC6000D92CA2 /* SamplesListView.swift */,
3F9F28452A3AEC8B00D92CA2 /* GRAsyncImageSampleView.swift */,
09794E3B2C2ADAFE00023CD1 /* InputFieldSampleView.swift */,
);
path = Screens;
sourceTree = "<group>";
Expand All @@ -70,6 +83,7 @@
5D740EAB29B0BE0100975B8C /* GoodSwiftUI-Sample */ = {
isa = PBXGroup;
children = (
09794E382C295F3F00023CD1 /* Extensions */,
3F9F28422A3AEC5200D92CA2 /* Screens */,
5D740EAC29B0BE0100975B8C /* AppDelegate.swift */,
5D740EB729B0BE0200975B8C /* Assets.xcassets */,
Expand Down Expand Up @@ -169,8 +183,10 @@
buildActionMask = 2147483647;
files = (
5D740EAD29B0BE0100975B8C /* AppDelegate.swift in Sources */,
09794E3A2C295F4600023CD1 /* InputFieldViewConfiguration.swift in Sources */,
3F9F28462A3AEC8B00D92CA2 /* GRAsyncImageSampleView.swift in Sources */,
3F9F28442A3AEC6000D92CA2 /* SamplesListView.swift in Sources */,
09794E3C2C2ADAFE00023CD1 /* InputFieldSampleView.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
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
}
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
}
}

}
Loading

0 comments on commit 7ce3cd4

Please sign in to comment.