Skip to content

Commit d9f1ce1

Browse files
committed
Only support Apple's 2020 OSs
1 parent 19040d4 commit d9f1ce1

4 files changed

Lines changed: 22 additions & 17 deletions

File tree

.github/workflows/swift.yml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,7 @@ jobs:
1818
uses: maxim-lobanov/setup-xcode@1.0
1919
with:
2020
xcode-version: 12.0
21-
- name: Build Xcode 12.0
21+
- name: Build
2222
run: swift build -v
23-
- name: Run tests Xcode 12.0
24-
run: swift test -v
25-
- name: Switch to Xcode 11.6
26-
uses: maxim-lobanov/setup-xcode@1.0
27-
with:
28-
xcode-version: 11.6
29-
- name: Build Xcode 11.6
30-
run: swift build -v
31-
- name: Run tests Xcode 11.6
23+
- name: Run tests
3224
run: swift test -v

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
// swift-tools-version:5.2
1+
// swift-tools-version:5.3
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription
55

66
let package = Package(
77
name: "NumericText",
8-
platforms: [.iOS(.v13), .macOS(.v10_15), .watchOS(.v6), .tvOS(.v13)],
8+
platforms: [.iOS(.v14), .macOS(.v10_16), .watchOS(.v7), .tvOS(.v14)],
99
products: [
1010
.library(
1111
name: "NumericText",

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var body: Some View {
3030

3131
## Installation
3232

33-
Use Swift Package Manager or just drag and drop the two source files into your project. It supports any of Apple's platforms that support SwiftUI's initial release. So iOS 13, macOS 10.15, tvOS 13, watchOS 6.
33+
Use Swift Package Manager or just drag and drop the two source files into your project. It supports iOS 14, macOS 10.16/11, tvOS 14, watchOS 7.
3434

3535
## Improvement ideas
3636
* Ditch `NSNumber?` as the bound value, and allow binding either `Int?` or `Double?`. I took a quick shot at this, but my generics skills weren't sufficient to figure it out.

Sources/NumericText/NumericTextField.swift

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ public struct NumericTextField: View {
3838
}
3939

4040
public var body: some View {
41-
TextField(title, text: $string, onEditingChanged: onEditingChanged, onCommit: onCommit)
42-
.keyboardType(isDecimalAllowed ? .decimalPad : .numberPad)
41+
return TextField(title, text: $string, onEditingChanged: onEditingChanged, onCommit: onCommit)
4342
.onChange(of: string, perform: numberChanged(newValue:))
43+
.modifier(KeyboardModifier(isDecimalAllowed: isDecimalAllowed))
4444
}
4545

4646
private func numberChanged(newValue: String) {
@@ -52,17 +52,30 @@ public struct NumericTextField: View {
5252
}
5353
}
5454

55+
private struct KeyboardModifier: ViewModifier {
56+
let isDecimalAllowed: Bool
57+
58+
func body(content: Content) -> some View {
59+
#if os(iOS)
60+
return content
61+
.keyboardType(isDecimalAllowed ? .decimalPad : .numberPad)
62+
#else
63+
return content
64+
#endif
65+
}
66+
}
67+
5568
struct NumericTextField_Previews: PreviewProvider {
5669
@State private static var int: NSNumber?
5770
@State private static var double: NSNumber?
5871

5972
static var previews: some View {
6073
VStack {
6174
NumericTextField("Int", number: $int, isDecimalAllowed: false)
62-
.textFieldStyle(RoundedBorderTextFieldStyle())
75+
.border(/*@START_MENU_TOKEN@*/Color.black/*@END_MENU_TOKEN@*/, width: /*@START_MENU_TOKEN@*/1/*@END_MENU_TOKEN@*/)
6376
.padding()
6477
NumericTextField("Double", number: $double, isDecimalAllowed: true)
65-
.textFieldStyle(RoundedBorderTextFieldStyle())
78+
.border(/*@START_MENU_TOKEN@*/Color.black/*@END_MENU_TOKEN@*/, width: /*@START_MENU_TOKEN@*/1/*@END_MENU_TOKEN@*/)
6679
.padding()
6780
}
6881
}

0 commit comments

Comments
 (0)