Skip to content

Commit

Permalink
feat: Support macOS 12.0 ~
Browse files Browse the repository at this point in the history
  • Loading branch information
hhhello0507 committed Jun 22, 2024
1 parent bfc41db commit 6e917fd
Show file tree
Hide file tree
Showing 19 changed files with 74 additions and 52 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import PackageDescription

let package = Package(
name: "ADS",
platforms: [.iOS(.v15)],
platforms: [.iOS(.v15), .macOS(.v12)],
products: [
.library(
name: "ADS",
Expand Down
7 changes: 7 additions & 0 deletions Sources/ADS/Component/BottomTabBar/AlimoBottomTabBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ public struct AlimoBottomTabBar<C>: View where C: View {
.ignoresSafeArea()
}
}

#if os(iOS)
@Environment(\.safeAreaInsets) private var safeAreaInsets
#endif

@ViewBuilder
private var bottomBarBar: some View {
Expand All @@ -43,15 +46,19 @@ public struct AlimoBottomTabBar<C>: 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
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions Sources/ADS/Component/Button/AlimoRadioButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 15 additions & 3 deletions Sources/ADS/Component/Shape/RoundedCornerShape.swift
Original file line number Diff line number Diff line change
@@ -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
}
Expand Down
17 changes: 14 additions & 3 deletions Sources/ADS/Component/Shape/View+cornerRadius.swift
Original file line number Diff line number Diff line change
@@ -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<Content>(_ 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<Content>(_ 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<Content>(_ 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)
Expand All @@ -15,3 +23,6 @@ public extension View {
}
}
}
#Preview {
Rectangle()
}
4 changes: 3 additions & 1 deletion Sources/ADS/Component/TextField/AlimoTextEditor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions Sources/ADS/Component/TextField/AlimoTextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ struct AlimoTextFieldStyle: TextFieldStyle {
func _body(configuration: TextField<Self._Label>) -> some View {
let radius: CGFloat = isRounded ? 26 : 12
return configuration
#if os(iOS)
.textInputAutocapitalization(.never)
#endif
.autocorrectionDisabled()
.textContentType(.init(rawValue: ""))
.focused($isFocused)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import SwiftUI

#if os(iOS)
public extension View {
func textEditorBackground(_ content: Color) -> some View {
if #available(iOS 16.0, *) {
Expand All @@ -10,3 +11,4 @@ public extension View {
}
}
}
#endif
4 changes: 4 additions & 0 deletions Sources/ADS/Component/TopAppBar/AlimoLogoTopAppBar.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import SwiftUI

@available(macOS 13.0, *)
public struct AlimoLogoTopAppBar<C>: View where C: View {

@Environment(\.dismiss) private var dismiss
Expand Down Expand Up @@ -40,6 +41,7 @@ public struct AlimoLogoTopAppBar<C>: View where C: View {
}
}

@available(macOS 13.0, *)
public extension View {
func alimoLogoTopAppBar<TC>(
background: SementicColor = AlimoColor.Background.alt,
Expand All @@ -53,13 +55,15 @@ public extension View {
}
}

@available(macOS 13.0, *)
#Preview {
Text("Hello Alimo")
.alimoColor(AlimoColor.Label.normal)
.alimoLogoTopAppBar()
.preview(background: AlimoColor.Background.alt)
}

@available(macOS 13.0, *)
#Preview("AlimoLogoTopAppBarDark") {
Text("Hello Alimo")
.alimoColor(AlimoColor.Label.normal)
Expand Down
6 changes: 6 additions & 0 deletions Sources/ADS/Component/TopAppBar/AlimoTopAppBar.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import SwiftUI

@available(macOS 13.0, *)
public struct AlimoTopAppBar<C>: View where C: View {

@Environment(\.dismiss) private var dismiss
Expand Down Expand Up @@ -60,6 +61,7 @@ public struct AlimoTopAppBar<C>: View where C: View {
}
}

@available(macOS 13.0, *)
public extension View {
func alimoTopAppBar<TC>(
_ title: String,
Expand All @@ -78,27 +80,31 @@ public extension View {
}
}

@available(macOS 13.0, *)
#Preview {
Text("Hello Alimo")
.alimoColor(AlimoColor.Label.normal)
.alimoTopAppBar("프로필")
.preview(background: AlimoColor.Background.alt)
}

@available(macOS 13.0, *)
#Preview {
Text("Hello Alimo")
.alimoColor(AlimoColor.Label.normal)
.alimoTopAppBar("프로필", backButtonAction: {})
.preview(background: AlimoColor.Background.alt)
}

@available(macOS 13.0, *)
#Preview("AlimoTopAppBarDark") {
Text("Hello Alimo")
.alimoColor(AlimoColor.Label.normal)
.alimoTopAppBar("프로필")
.preview(isDarkTheme: true, background: AlimoColor.Background.alt)
}

@available(macOS 13.0, *)
#Preview("AlimoTopAppBarDark") {
Text("Hello Alimo")
.alimoColor(AlimoColor.Label.normal)
Expand Down
2 changes: 2 additions & 0 deletions Sources/ADS/Foundation/Elevation/AlimoElevation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ public enum AlimoElevation {
}
}

#if os(iOS)
var uiColor: UIColor {
UIColor(color)
}
#endif
}
3 changes: 3 additions & 0 deletions Sources/ADS/Foundation/Elevation/View+myElevation.swift
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,3 +18,4 @@ public extension UIView {
// .shadow(color: ev.uiColor, radius: ev.radius, opacity: ev.uiColor.alpha)
}
}
#endif
1 change: 0 additions & 1 deletion Sources/ADS/Foundation/Typography/AlimoFont.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import SwiftUI
import UIKit

public enum AlimoFont: CaseIterable {
case title1B
Expand Down
3 changes: 2 additions & 1 deletion Sources/ADS/Foundation/Typography/Pretendard.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import SwiftUI
import UIKit

public struct Pretendard {

Expand All @@ -14,6 +13,7 @@ public struct Pretendard {
case SemiBold
case Thin

#if os(iOS)
var weight: UIFont.Weight {
switch self {
case .Black: .black
Expand All @@ -27,6 +27,7 @@ public struct Pretendard {
case .Thin: .thin
}
}
#endif
}

public static func register() {
Expand Down
3 changes: 3 additions & 0 deletions Sources/ADS/Foundation/Typography/UIKit/UIFont+.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if os(iOS)
import UIKit

public extension UIFont {
Expand Down Expand Up @@ -33,3 +34,5 @@ public extension AlimoFont {
}
}
}

#endif
39 changes: 0 additions & 39 deletions Sources/ADS/Util/UIViewController+Preview.swift

This file was deleted.

3 changes: 3 additions & 0 deletions Sources/ADS/Util/View+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public extension View {
}
}

#if os(iOS)
public extension View {
func hideKeyboardWhenTap() -> some View {
onAppear(perform: UIApplication.shared.hideKeyboard)
Expand All @@ -48,3 +49,5 @@ extension UIApplication: UIGestureRecognizerDelegate {
return false
}
}

#endif
4 changes: 1 addition & 3 deletions Sources/ADS/Util/View+to.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import SwiftUI
import UIKit

public extension View {
func toLeading() -> some View {
Expand Down Expand Up @@ -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)
}
}
4 changes: 4 additions & 0 deletions Sources/ADS/Util/safeAreaInsets.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#if os(iOS)
import SwiftUI
import UIKit

public struct SafeAreaInsetsKey: EnvironmentKey {
public static var defaultValue: EdgeInsets {
Expand All @@ -17,3 +19,5 @@ private extension UIEdgeInsets {
EdgeInsets(top: top, leading: left, bottom: bottom, trailing: right)
}
}

#endif

0 comments on commit 6e917fd

Please sign in to comment.