Skip to content

Commit

Permalink
Merge pull request #7 from andylin2004/main
Browse files Browse the repository at this point in the history
Fix issue where this package was interfering with SwiftUI previews
  • Loading branch information
ApplebaumIan authored Jul 28, 2023
2 parents 8fd9fa0 + 7887b58 commit 9053d7c
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 49 deletions.
5 changes: 4 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import PackageDescription

let package = Package(
name: "SwiftUI Apple Watch Decimal Pad",
platforms: [.watchOS(.v7)],
platforms: [.watchOS(.v7),
.macOS(.v11),
.iOS(.v14),
.tvOS(.v14)],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
Expand Down
89 changes: 50 additions & 39 deletions Sources/SwiftUI Apple Watch Decimal Pad/DigetPadView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
import SwiftUI
#if os(watchOS)
@available(watchOS 6.0, *)
@available(macOS, unavailable)
@available(macCatalyst, unavailable)
@available(iOS, unavailable)
@available(tvOS, unavailable)
public struct DigiTextView: View {
private var locale: Locale
var style: KeyboardStyle
Expand Down Expand Up @@ -44,6 +48,10 @@ public struct DigiTextView: View {
}
}
@available(watchOS 6.0, *)
@available(macOS, unavailable)
@available(macCatalyst, unavailable)
@available(iOS, unavailable)
@available(tvOS, unavailable)
public struct EnteredText: View {
@Binding var text:String
@Binding var presentedAsModal: Bool
Expand Down Expand Up @@ -84,15 +92,21 @@ public struct EnteredText: View {
}
.toolbar(content: {
ToolbarItem(placement: .cancellationAction){
Button("Done"){
Button {
presentedAsModal.toggle()
} label: {
Label("Done", systemImage: "xmark")
}
}
})

}
}
@available(iOS 13.0, watchOS 6.0, *)
@available(watchOS 6.0, *)
@available(macOS, unavailable)
@available(macCatalyst, unavailable)
@available(iOS, unavailable)
@available(tvOS, unavailable)
public struct DigetPadView: View {
public var widthSpace: CGFloat = 1.0
@Binding var text:String
Expand Down Expand Up @@ -204,10 +218,42 @@ public struct EnteredText: View {
.font(.title2)
}
}

@available(iOS 13.0, watchOS 6.0, *)
struct TextViewStyle: ButtonStyle {
init(alignment: TextViewAlignment = .center) {
self.align = alignment
}


var align: TextViewAlignment
func makeBody(configuration: Configuration) -> some View {
HStack {
if align == .center || align == .trailing{
Spacer()
}
configuration.label
.font(/*@START_MENU_TOKEN@*/.body/*@END_MENU_TOKEN@*/)
.padding(.vertical, 11.0)
.padding(.horizontal)
if align == .center || align == .leading{
Spacer()
}
}
.background(
GeometryReader { geometry in
ZStack{
RoundedRectangle(cornerRadius: 7, style: .continuous)
.fill(configuration.isPressed ? Color.gray.opacity(0.1): Color.gray.opacity(0.2))
}
})

}

}
#endif

#if DEBUG
#if os(watchOS)
#if DEBUG && os(watchOS)
struct EnteredText_Previews: PreviewProvider {
static var previews: some View {
EnteredText( text: .constant(""), presentedAsModal: .constant(true), style: .numbers)
Expand Down Expand Up @@ -255,38 +301,3 @@ struct TextField_Previews: PreviewProvider {
}
}
#endif
#endif
#if os(watchOS)
@available(iOS 13.0, watchOS 6.0, *)
struct TextViewStyle: ButtonStyle {
init(alignment: TextViewAlignment = .center) {
self.align = alignment
}


var align: TextViewAlignment
func makeBody(configuration: Configuration) -> some View {
HStack {
if align == .center || align == .trailing{
Spacer()
}
configuration.label
.font(/*@START_MENU_TOKEN@*/.body/*@END_MENU_TOKEN@*/)
.padding(.vertical, 11.0)
.padding(.horizontal)
if align == .center || align == .leading{
Spacer()
}
}
.background(
GeometryReader { geometry in
ZStack{
RoundedRectangle(cornerRadius: 7, style: .continuous)
.fill(configuration.isPressed ? Color.gray.opacity(0.1): Color.gray.opacity(0.2))
}
})

}

}
#endif
26 changes: 17 additions & 9 deletions Sources/SwiftUI Apple Watch Decimal Pad/Modifiers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@

import Foundation
import SwiftUI
#if os(watchOS)
import WatchKit

@available(watchOS 6.0, *)
@available(macOS, unavailable)
@available(macCatalyst, unavailable)
@available(iOS, unavailable)
@available(tvOS, unavailable)
public struct DigitButtonModifier: ViewModifier {
public func body(content: Content) -> some View {
return content
Expand All @@ -18,14 +21,22 @@ public struct DigitButtonModifier: ViewModifier {
}
}


@available(watchOS 6.0, *)
@available(macOS, unavailable)
@available(macCatalyst, unavailable)
@available(iOS, unavailable)
@available(tvOS, unavailable)
public extension Button {
func digitKeyFrame() -> some View {
self.modifier(DigitButtonModifier())
}
}

@available(watchOS 6.0, *)
@available(macOS, unavailable)
@available(macCatalyst, unavailable)
@available(iOS, unavailable)
@available(tvOS, unavailable)
public struct DigitPadStyle: ButtonStyle {
public func makeBody(configuration: Configuration) -> some View {
GeometryReader(content: { geometry in
Expand Down Expand Up @@ -69,9 +80,7 @@ public struct DigitPadStyle: ButtonStyle {

}
}
#else
#error("This is a watchOS only library.")
#endif

public enum TextViewAlignment {
case trailing
case leading
Expand All @@ -82,8 +91,8 @@ public enum KeyboardStyle {
case decimal
case numbers
}
#if DEBUG
#if os(watchOS)

#if DEBUG && os(watchOS)
struct EnteredTextKeys_Previews: PreviewProvider {
static var previews: some View {
EnteredText( text: .constant(""), presentedAsModal: .constant(true), style: .numbers)
Expand All @@ -98,4 +107,3 @@ struct EnteredTextKeys_Previews: PreviewProvider {
}
}
#endif
#endif

0 comments on commit 9053d7c

Please sign in to comment.