diff --git a/Package.swift b/Package.swift index 17dcbc6..8375cb5 100644 --- a/Package.swift +++ b/Package.swift @@ -5,7 +5,7 @@ import PackageDescription let package = Package( name: "ADS", - platforms: [.iOS(.v15)], + platforms: [.iOS(.v15), .macOS(.v12)], products: [ .library( name: "ADS", diff --git a/Sources/ADS/Component/BottomTabBar/AlimoBottomTabBar.swift b/Sources/ADS/Component/BottomTabBar/AlimoBottomTabBar.swift index e1473aa..ee05af4 100644 --- a/Sources/ADS/Component/BottomTabBar/AlimoBottomTabBar.swift +++ b/Sources/ADS/Component/BottomTabBar/AlimoBottomTabBar.swift @@ -25,7 +25,10 @@ public struct AlimoBottomTabBar: View where C: View { .ignoresSafeArea() } } + + #if os(iOS) @Environment(\.safeAreaInsets) private var safeAreaInsets + #endif @ViewBuilder private var bottomBarBar: some View { @@ -43,15 +46,19 @@ public struct AlimoBottomTabBar: View where C: View { } Spacer() } + #if os(iOS) .padding(.bottom, safeAreaInsets.bottom) + #endif .padding(.vertical, 8) .padding(.horizontal, 8) .alimoBackground(AlimoColor.Background.normal) .cornerRadius(16, corners: [.topLeft, .topRight]) .stroke(16, corners: [.topLeft, .topRight], content: colorProvider.color(AlimoColor.Label.back)) .onChange(of: selectedTab) { _ in + #if os(iOS) let impactMed = UIImpactFeedbackGenerator(style: .rigid) impactMed.impactOccurred() + #endif } } } diff --git a/Sources/ADS/Component/Button/AlimoRadioButton.swift b/Sources/ADS/Component/Button/AlimoRadioButton.swift index d8cf50a..a39af01 100644 --- a/Sources/ADS/Component/Button/AlimoRadioButton.swift +++ b/Sources/ADS/Component/Button/AlimoRadioButton.swift @@ -30,8 +30,10 @@ public struct AlimoRadioButton: View { Button { action() + #if os(iOS) let impactMed = UIImpactFeedbackGenerator(style: .rigid) impactMed.impactOccurred() + #endif } label: { HStack(spacing: 6) { Image(icon: isSelected ? selectedIcon : unselectedIcon) diff --git a/Sources/ADS/Component/Shape/RoundedCornerShape.swift b/Sources/ADS/Component/Shape/RoundedCornerShape.swift index 3ba96b9..b168c73 100644 --- a/Sources/ADS/Component/Shape/RoundedCornerShape.swift +++ b/Sources/ADS/Component/Shape/RoundedCornerShape.swift @@ -1,11 +1,23 @@ import SwiftUI -public struct RoundedCornerShape: Shape { +public struct RoundedCornerShape : Shape { + + public enum RectCorner : Sendable { + case topLeft + case topRight + case bottomLeft + case bottomRight + case allCorners + } private let radius: CGFloat - private let corners: UIRectCorner + private let corners: [RectCorner] + + public init(radius: CGFloat = .zero, corners: RectCorner = .allCorners) { + self.init(radius: radius, corners: [corners]) + } - public init(radius: CGFloat = .zero, corners: UIRectCorner = .allCorners) { + public init(radius: CGFloat = .zero, corners: [RectCorner]) { self.radius = radius self.corners = corners } diff --git a/Sources/ADS/Component/Shape/View+cornerRadius.swift b/Sources/ADS/Component/Shape/View+cornerRadius.swift index f24bda9..519f641 100644 --- a/Sources/ADS/Component/Shape/View+cornerRadius.swift +++ b/Sources/ADS/Component/Shape/View+cornerRadius.swift @@ -1,11 +1,19 @@ import SwiftUI public extension View { - func cornerRadius(_ radius: CGFloat, corners: UIRectCorner) -> some View { - clipShape(RoundedCornerShape(radius: radius, corners: corners)) + func cornerRadius(_ radius: CGFloat, corners: RoundedCornerShape.RectCorner = .allCorners) -> some View { + self.clipShape(RoundedCornerShape(radius: radius, corners: corners)) } - func stroke(_ radius: CGFloat, corners: UIRectCorner = .allCorners, content: Content, lineWidth: CGFloat = 1) -> some View where Content: ShapeStyle { + func cornerRadius(_ radius: CGFloat, corners: [RoundedCornerShape.RectCorner]) -> some View { + self.clipShape(RoundedCornerShape(radius: radius, corners: corners)) + } + + func stroke(_ radius: CGFloat, corners: RoundedCornerShape.RectCorner = .allCorners, content: Content, lineWidth: CGFloat = 1) -> some View where Content: ShapeStyle { + self.stroke(radius, corners: [corners], content: content, lineWidth: lineWidth) + } + + func stroke(_ radius: CGFloat, corners: [RoundedCornerShape.RectCorner], content: Content, lineWidth: CGFloat = 1) -> some View where Content: ShapeStyle { let roundedCorner = RoundedCornerShape(radius: radius, corners: corners) return self .clipShape(roundedCorner) @@ -15,3 +23,6 @@ public extension View { } } } +#Preview { + Rectangle() +} diff --git a/Sources/ADS/Component/TextField/AlimoTextEditor.swift b/Sources/ADS/Component/TextField/AlimoTextEditor.swift index 1a42a07..6a67900 100644 --- a/Sources/ADS/Component/TextField/AlimoTextEditor.swift +++ b/Sources/ADS/Component/TextField/AlimoTextEditor.swift @@ -39,10 +39,12 @@ public struct AlimoTextEditor: View { let radius: CGFloat = isRounded ? 26 : 12 TextEditor(text: $text) .disabled(!isEnabled) + #if os(iOS) .textInputAutocapitalization(.never) + .textEditorBackground(.clear) + #endif .autocorrectionDisabled() .textContentType(.init(rawValue: "")) - .textEditorBackground(.clear) .focused($isFocused) .alimoFont(.bodyM) .cornerRadius(radius, corners: .allCorners) diff --git a/Sources/ADS/Component/TextField/AlimoTextField.swift b/Sources/ADS/Component/TextField/AlimoTextField.swift index 5049796..c66cb0f 100644 --- a/Sources/ADS/Component/TextField/AlimoTextField.swift +++ b/Sources/ADS/Component/TextField/AlimoTextField.swift @@ -100,7 +100,9 @@ struct AlimoTextFieldStyle: TextFieldStyle { func _body(configuration: TextField) -> some View { let radius: CGFloat = isRounded ? 26 : 12 return configuration + #if os(iOS) .textInputAutocapitalization(.never) + #endif .autocorrectionDisabled() .textContentType(.init(rawValue: "")) .focused($isFocused) diff --git a/Sources/ADS/Component/TextField/View+textEditorBackground.swift b/Sources/ADS/Component/TextField/View+textEditorBackground.swift index 22c80dd..2d9b08b 100644 --- a/Sources/ADS/Component/TextField/View+textEditorBackground.swift +++ b/Sources/ADS/Component/TextField/View+textEditorBackground.swift @@ -1,5 +1,6 @@ import SwiftUI +#if os(iOS) public extension View { func textEditorBackground(_ content: Color) -> some View { if #available(iOS 16.0, *) { @@ -10,3 +11,4 @@ public extension View { } } } +#endif diff --git a/Sources/ADS/Component/TopAppBar/AlimoLogoTopAppBar.swift b/Sources/ADS/Component/TopAppBar/AlimoLogoTopAppBar.swift index ea31d79..edb4c3c 100644 --- a/Sources/ADS/Component/TopAppBar/AlimoLogoTopAppBar.swift +++ b/Sources/ADS/Component/TopAppBar/AlimoLogoTopAppBar.swift @@ -1,5 +1,6 @@ import SwiftUI +@available(macOS 13.0, *) public struct AlimoLogoTopAppBar: View where C: View { @Environment(\.dismiss) private var dismiss @@ -40,6 +41,7 @@ public struct AlimoLogoTopAppBar: View where C: View { } } +@available(macOS 13.0, *) public extension View { func alimoLogoTopAppBar( background: SementicColor = AlimoColor.Background.alt, @@ -53,6 +55,7 @@ public extension View { } } +@available(macOS 13.0, *) #Preview { Text("Hello Alimo") .alimoColor(AlimoColor.Label.normal) @@ -60,6 +63,7 @@ public extension View { .preview(background: AlimoColor.Background.alt) } +@available(macOS 13.0, *) #Preview("AlimoLogoTopAppBarDark") { Text("Hello Alimo") .alimoColor(AlimoColor.Label.normal) diff --git a/Sources/ADS/Component/TopAppBar/AlimoTopAppBar.swift b/Sources/ADS/Component/TopAppBar/AlimoTopAppBar.swift index f9833b1..f21ad69 100644 --- a/Sources/ADS/Component/TopAppBar/AlimoTopAppBar.swift +++ b/Sources/ADS/Component/TopAppBar/AlimoTopAppBar.swift @@ -1,5 +1,6 @@ import SwiftUI +@available(macOS 13.0, *) public struct AlimoTopAppBar: View where C: View { @Environment(\.dismiss) private var dismiss @@ -60,6 +61,7 @@ public struct AlimoTopAppBar: View where C: View { } } +@available(macOS 13.0, *) public extension View { func alimoTopAppBar( _ title: String, @@ -78,6 +80,7 @@ public extension View { } } +@available(macOS 13.0, *) #Preview { Text("Hello Alimo") .alimoColor(AlimoColor.Label.normal) @@ -85,6 +88,7 @@ public extension View { .preview(background: AlimoColor.Background.alt) } +@available(macOS 13.0, *) #Preview { Text("Hello Alimo") .alimoColor(AlimoColor.Label.normal) @@ -92,6 +96,7 @@ public extension View { .preview(background: AlimoColor.Background.alt) } +@available(macOS 13.0, *) #Preview("AlimoTopAppBarDark") { Text("Hello Alimo") .alimoColor(AlimoColor.Label.normal) @@ -99,6 +104,7 @@ public extension View { .preview(isDarkTheme: true, background: AlimoColor.Background.alt) } +@available(macOS 13.0, *) #Preview("AlimoTopAppBarDark") { Text("Hello Alimo") .alimoColor(AlimoColor.Label.normal) diff --git a/Sources/ADS/Foundation/Elevation/AlimoElevation.swift b/Sources/ADS/Foundation/Elevation/AlimoElevation.swift index ffb09b1..444ba8f 100644 --- a/Sources/ADS/Foundation/Elevation/AlimoElevation.swift +++ b/Sources/ADS/Foundation/Elevation/AlimoElevation.swift @@ -33,7 +33,9 @@ public enum AlimoElevation { } } + #if os(iOS) var uiColor: UIColor { UIColor(color) } + #endif } diff --git a/Sources/ADS/Foundation/Elevation/View+myElevation.swift b/Sources/ADS/Foundation/Elevation/View+myElevation.swift index 5095cee..b1f90e6 100644 --- a/Sources/ADS/Foundation/Elevation/View+myElevation.swift +++ b/Sources/ADS/Foundation/Elevation/View+myElevation.swift @@ -1,7 +1,9 @@ +#if os(iOS) import SwiftUI import UIKit // MARK: - SwiftUI +@available(iOS 13.0, *) public extension View { func alimoElevation(_ ev: AlimoElevation) -> some View { self @@ -16,3 +18,4 @@ public extension UIView { // .shadow(color: ev.uiColor, radius: ev.radius, opacity: ev.uiColor.alpha) } } +#endif diff --git a/Sources/ADS/Foundation/Typography/AlimoFont.swift b/Sources/ADS/Foundation/Typography/AlimoFont.swift index d2fd828..cdc91d7 100644 --- a/Sources/ADS/Foundation/Typography/AlimoFont.swift +++ b/Sources/ADS/Foundation/Typography/AlimoFont.swift @@ -1,5 +1,4 @@ import SwiftUI -import UIKit public enum AlimoFont: CaseIterable { case title1B diff --git a/Sources/ADS/Foundation/Typography/Pretendard.swift b/Sources/ADS/Foundation/Typography/Pretendard.swift index 785c60d..227e303 100644 --- a/Sources/ADS/Foundation/Typography/Pretendard.swift +++ b/Sources/ADS/Foundation/Typography/Pretendard.swift @@ -1,5 +1,4 @@ import SwiftUI -import UIKit public struct Pretendard { @@ -14,6 +13,7 @@ public struct Pretendard { case SemiBold case Thin + #if os(iOS) var weight: UIFont.Weight { switch self { case .Black: .black @@ -27,6 +27,7 @@ public struct Pretendard { case .Thin: .thin } } + #endif } public static func register() { diff --git a/Sources/ADS/Foundation/Typography/UIKit/UIFont+.swift b/Sources/ADS/Foundation/Typography/UIKit/UIFont+.swift index 2120170..dcda214 100644 --- a/Sources/ADS/Foundation/Typography/UIKit/UIFont+.swift +++ b/Sources/ADS/Foundation/Typography/UIKit/UIFont+.swift @@ -1,3 +1,4 @@ +#if os(iOS) import UIKit public extension UIFont { @@ -33,3 +34,5 @@ public extension AlimoFont { } } } + +#endif diff --git a/Sources/ADS/Util/UIViewController+Preview.swift b/Sources/ADS/Util/UIViewController+Preview.swift deleted file mode 100644 index a68ea9e..0000000 --- a/Sources/ADS/Util/UIViewController+Preview.swift +++ /dev/null @@ -1,39 +0,0 @@ -import UIKit -import SwiftUI - -#if DEBUG -extension UIViewController { - private struct Preview: UIViewControllerRepresentable { - let viewController: UIViewController - - func makeUIViewController(context: Context) -> UIViewController { - return viewController - } - - func updateUIViewController(_ uiViewController: UIViewController, context: Context) { - } - } - - func toPreview() -> some View { - Preview(viewController: self) - } -} - -extension UIView { - private struct Preview: UIViewRepresentable { - - let view: UIView - - func makeUIView(context: Context) -> some UIView { - return view - } - - func updateUIView(_ uiView: UIViewType, context: Context) {} - } - - func toPreview() -> some View { - Preview(view: self) - } -} - -#endif diff --git a/Sources/ADS/Util/View+.swift b/Sources/ADS/Util/View+.swift index a2e4f87..5e0b355 100644 --- a/Sources/ADS/Util/View+.swift +++ b/Sources/ADS/Util/View+.swift @@ -23,6 +23,7 @@ public extension View { } } +#if os(iOS) public extension View { func hideKeyboardWhenTap() -> some View { onAppear(perform: UIApplication.shared.hideKeyboard) @@ -48,3 +49,5 @@ extension UIApplication: UIGestureRecognizerDelegate { return false } } + +#endif diff --git a/Sources/ADS/Util/View+to.swift b/Sources/ADS/Util/View+to.swift index 0ba2559..ce471a2 100644 --- a/Sources/ADS/Util/View+to.swift +++ b/Sources/ADS/Util/View+to.swift @@ -1,5 +1,4 @@ import SwiftUI -import UIKit public extension View { func toLeading() -> some View { @@ -45,7 +44,6 @@ public extension View { public extension View { func frame(size: CGFloat) -> some View { - self - .frame(width: size, height: size) + self.frame(width: size, height: size) } } diff --git a/Sources/ADS/Util/safeAreaInsets.swift b/Sources/ADS/Util/safeAreaInsets.swift index 712070a..49b0f24 100644 --- a/Sources/ADS/Util/safeAreaInsets.swift +++ b/Sources/ADS/Util/safeAreaInsets.swift @@ -1,4 +1,6 @@ +#if os(iOS) import SwiftUI +import UIKit public struct SafeAreaInsetsKey: EnvironmentKey { public static var defaultValue: EdgeInsets { @@ -17,3 +19,5 @@ private extension UIEdgeInsets { EdgeInsets(top: top, leading: left, bottom: bottom, trailing: right) } } + +#endif