From 0e2a4acf3df971c92eb14c54875a39be86993960 Mon Sep 17 00:00:00 2001 From: Alexandr Romanov Date: Thu, 26 Sep 2024 21:37:54 +0300 Subject: [PATCH 01/30] Add Platform and minor bug fixes --- README.md | 2 +- .../Controls/ContentView/ContentView.swift | 2 - .../Controls/Divider/Separator.swift | 36 +++-- .../Controls/PageControl/PageIndexView.swift | 6 +- .../Controls/PriceField/PriceField.swift | 10 +- Sources/OversizeUI/Controls/Row/Row.swift | 13 +- .../ScrollView/ScrollViewWithOffset.swift | 16 +- .../OversizeUI/Controls/Surface/Surface.swift | 28 +++- .../TextField/FieldHelperViewModifier.swift | 36 +++-- .../TextField/LabeledTextFieldStyle.swift | 152 ++++++++++++++---- .../Controls/URLField/URLField.swift | 7 +- Sources/OversizeUI/Core/EdgeSpaceInsets.swift | 7 + .../Core/EnvironmentKeys/Platform.swift | 53 ++++++ Sources/OversizeUI/Core/Radius.swift | 4 + Sources/OversizeUI/Core/Space.swift | 5 + Sources/OversizeUI/Core/Typography.swift | 2 +- .../Color/Color+RawRepresentable.swift | 2 +- .../Extensions/Image/Image+Extensions.swift | 12 +- .../Extensions/Spacing/Spacing.swift | 12 ++ .../BackgroundTertiary.colorset/Contents.json | 6 +- 20 files changed, 308 insertions(+), 103 deletions(-) create mode 100644 Sources/OversizeUI/Core/EnvironmentKeys/Platform.swift diff --git a/README.md b/README.md index b9d7f64..054c8d3 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # OversizeUI -[![Build Example](https://github.com/oversizedev/OversizeUI/actions/workflows/build-example.yml/badge.svg)](https://github.com/oversizedev/OversizeUI/actions/workflows/build-example.yml) [![Deploy DocC](https://github.com/oversizedev/OversizeUI/actions/workflows/publish-docc.yml/badge.svg)](https://github.com/oversizedev/OversizeUI/actions/workflows/publish-docc.yml) +[![Build Example](https://github.com/oversizedev/OversizeUI/actions/workflows/build-example.yml/badge.svg)](https://github.com/oversizedev/OversizeUI/actions/workflows/ci-release.yml) Yet another component library on SwiftUI diff --git a/Sources/OversizeUI/Controls/ContentView/ContentView.swift b/Sources/OversizeUI/Controls/ContentView/ContentView.swift index f7290bd..93b4d0f 100644 --- a/Sources/OversizeUI/Controls/ContentView/ContentView.swift +++ b/Sources/OversizeUI/Controls/ContentView/ContentView.swift @@ -88,7 +88,6 @@ extension ContentView { #if os(macOS) .controlSize(.large) #endif - case .back: Button(action: { dismiss() }) { @@ -247,7 +246,6 @@ extension ContentView { .buttonStyle(.tertiary) #endif .disabled(true) - case .none: EmptyView() } diff --git a/Sources/OversizeUI/Controls/Divider/Separator.swift b/Sources/OversizeUI/Controls/Divider/Separator.swift index cc1f04c..fb7f655 100644 --- a/Sources/OversizeUI/Controls/Divider/Separator.swift +++ b/Sources/OversizeUI/Controls/Divider/Separator.swift @@ -24,24 +24,40 @@ public struct Separator: View { return Rectangle() .fill(Color.border) - .frame(width: isHorizontal ? nil : 0.5, - height: isHorizontal ? 0.5 : nil) + .frame( + width: isHorizontal ? nil : lineWidth, + height: isHorizontal ? lineWidth : nil + ) + #if !os(macOS) .padding(insets(isHorizontal)) + #endif } private func insets(_ isHorizontal: Bool) -> EdgeInsets { if isHorizontal { - EdgeInsets(top: 0.5, - leading: padding.rawValue, - bottom: 0, - trailing: padding.rawValue) + EdgeInsets( + top: 0.5, + leading: padding.rawValue, + bottom: 0, + trailing: padding.rawValue + ) } else { - EdgeInsets(top: padding.rawValue, - leading: 0.5, - bottom: padding.rawValue, - trailing: 0) + EdgeInsets( + top: padding.rawValue, + leading: 0.5, + bottom: padding.rawValue, + trailing: 0 + ) } } + + var lineWidth: CGFloat { + #if os(macOS) + return 1 + #else + return 0.5 + #endif + } } struct Separator_Preview: PreviewProvider { diff --git a/Sources/OversizeUI/Controls/PageControl/PageIndexView.swift b/Sources/OversizeUI/Controls/PageControl/PageIndexView.swift index b549095..72d48c3 100644 --- a/Sources/OversizeUI/Controls/PageControl/PageIndexView.swift +++ b/Sources/OversizeUI/Controls/PageControl/PageIndexView.swift @@ -6,11 +6,11 @@ import SwiftUI public struct PageIndexView: View { - @Binding private var index: Int + private var index: Int private let maxIndex: Int - public init(_ index: Binding, maxIndex: Int) { - _index = index + public init(_ index: Int, maxIndex: Int) { + self.index = index self.maxIndex = maxIndex } diff --git a/Sources/OversizeUI/Controls/PriceField/PriceField.swift b/Sources/OversizeUI/Controls/PriceField/PriceField.swift index 3d1a48b..8495391 100644 --- a/Sources/OversizeUI/Controls/PriceField/PriceField.swift +++ b/Sources/OversizeUI/Controls/PriceField/PriceField.swift @@ -22,17 +22,16 @@ public struct PriceField: View { return formatter } - private var strValue2: String { value.components(separatedBy: CharacterSet(charactersIn: "0123456789").inverted).joined() } // value.filter { !$0.isWhitespace } } - private var doubleValue2: Double { .init((Double(strValue2) ?? 0) / 100.0) ?? 0 } + private var stringValue2: String { value.components(separatedBy: CharacterSet(charactersIn: "0123456789").inverted).joined() } + private var doubleValue2: Double { .init((Double(stringValue2) ?? 0) / 100.0) ?? 0 } - private var strValue3: String { value.components(separatedBy: CharacterSet(charactersIn: "0123456789").inverted).joined() } // value.filter { !$0.isWhitespace } } - private var doubleValue3: Double { .init((Double(strValue3) ?? 0) * 100) ?? 0 } + private var stringValue3: String { value.components(separatedBy: CharacterSet(charactersIn: "0123456789").inverted).joined() } + private var doubleValue3: Double { .init((Double(stringValue3) ?? 0) * 100) ?? 0 } private var strValue: String { value.filter { !$0.isWhitespace } } private var doubleValue: Double { .init(strValue) ?? 0 } private var formattedValue: String { let value = doubleValue - return formatter.string(for: value) ?? "" } @@ -80,7 +79,6 @@ public struct PriceField: View { .padding(.leading, .xSmall) Text(dispalySymbol) - .onChange(of: currency) { _ in validate() } diff --git a/Sources/OversizeUI/Controls/Row/Row.swift b/Sources/OversizeUI/Controls/Row/Row.swift index f04c98f..95f0e65 100644 --- a/Sources/OversizeUI/Controls/Row/Row.swift +++ b/Sources/OversizeUI/Controls/Row/Row.swift @@ -47,12 +47,13 @@ public struct Row: View where LeadingLabel: View, T (subtitle?.isEmpty) != nil } - public init(_ title: String, - subtitle: String? = nil, - action: (() -> Void)? = nil, - @ViewBuilder leading: () -> LeadingLabel, - @ViewBuilder trailing: () -> TrailingLabel) - { + public init( + _ title: String, + subtitle: String? = nil, + action: (() -> Void)? = nil, + @ViewBuilder leading: () -> LeadingLabel, + @ViewBuilder trailing: () -> TrailingLabel + ) { self.title = title self.subtitle = subtitle self.action = action diff --git a/Sources/OversizeUI/Controls/ScrollView/ScrollViewWithOffset.swift b/Sources/OversizeUI/Controls/ScrollView/ScrollViewWithOffset.swift index 4c87040..ecf8804 100644 --- a/Sources/OversizeUI/Controls/ScrollView/ScrollViewWithOffset.swift +++ b/Sources/OversizeUI/Controls/ScrollView/ScrollViewWithOffset.swift @@ -6,6 +6,14 @@ import SwiftUI public struct ScrollViewWithOffsetTracking: View { + public typealias ScrollAction = (_ offset: CGPoint) -> Void + + private let axes: Axis.Set + private let showsIndicators: Bool + private let cordinateSpaceName: String + private let onScroll: ScrollAction + private let content: () -> Content + public init( _ axes: Axis.Set = .vertical, showsIndicators: Bool = true, @@ -20,14 +28,6 @@ public struct ScrollViewWithOffsetTracking: View { self.content = content } - public typealias ScrollAction = (_ offset: CGPoint) -> Void - - private let axes: Axis.Set - private let showsIndicators: Bool - private let cordinateSpaceName: String - private let onScroll: ScrollAction - private let content: () -> Content - public var body: some View { ScrollView(axes, showsIndicators: showsIndicators) { ScrollViewOffsetTracker { diff --git a/Sources/OversizeUI/Controls/Surface/Surface.swift b/Sources/OversizeUI/Controls/Surface/Surface.swift index 39ede1c..cd13ba9 100644 --- a/Sources/OversizeUI/Controls/Surface/Surface.swift +++ b/Sources/OversizeUI/Controls/Surface/Surface.swift @@ -69,17 +69,29 @@ public struct Surface: View { .padding(.leading, forceContentInsets?.leading ?? contentInsets.leading) .padding(.trailing, forceContentInsets?.trailing ?? contentInsets.trailing) .background( - RoundedRectangle(cornerRadius: surfaceRadius, style: .continuous) - .fill(surfaceBackgroundColor) - .overlay( - RoundedRectangle(cornerRadius: surfaceRadius, style: .continuous) - .strokeBorder(strokeBorderColor, lineWidth: strokeBorderLineWidth) - ) - .shadowElevaton(elevation) + RoundedRectangle( + cornerRadius: surfaceRadius, + style: .continuous + ) + .fill(surfaceBackgroundColor) + .shadowElevaton(elevation) + ) + .overlay( + RoundedRectangle( + cornerRadius: surfaceRadius, + style: .continuous + ) + .strokeBorder( + strokeBorderColor, + lineWidth: strokeBorderLineWidth + ) ) .if(isSurfaceClipped) { view in view.clipShape( - RoundedRectangle(cornerRadius: surfaceRadius, style: .continuous) + RoundedRectangle( + cornerRadius: surfaceRadius, + style: .continuous + ) ) } } diff --git a/Sources/OversizeUI/Controls/TextField/FieldHelperViewModifier.swift b/Sources/OversizeUI/Controls/TextField/FieldHelperViewModifier.swift index 78672a2..fa1edce 100644 --- a/Sources/OversizeUI/Controls/TextField/FieldHelperViewModifier.swift +++ b/Sources/OversizeUI/Controls/TextField/FieldHelperViewModifier.swift @@ -14,6 +14,7 @@ public enum FieldHelperStyle { public struct FieldHelperViewModifier: ViewModifier { @Environment(\.theme) private var theme: ThemeSettings + @Environment(\.platform) private var platform: Platform @Binding public var helperText: String @Binding public var helperStyle: FieldHelperStyle public init(helperText: Binding, helperStyle: Binding) { @@ -22,24 +23,29 @@ public struct FieldHelperViewModifier: ViewModifier { } public func body(content: Content) -> some View { - VStack(alignment: .leading) { + VStack(alignment: .leading, spacing: platform == .mac ? .xxxSmall : .xSmall) { content - if helperText != "" { - if helperStyle == .helperText { - Text(helperText) - .subheadline(.semibold) - .foregroundColor(.onSurfaceMediumEmphasis) - } else if helperStyle == .errorText { - Text(helperText) - .subheadline(.semibold) - .foregroundColor(.error) - } else if helperStyle == .sussesText { - Text(helperText) - .subheadline(.semibold) - .foregroundColor(.success) - } + if helperText.isEmpty == false, helperStyle != .none { + Text(helperText) + .subheadline(.medium) + .foregroundColor(helperForegroundColor) + .offset(x: platform == .mac ? 4 : 0) } } + .animation(.easeIn(duration: 0.15), value: helperStyle) + } + + private var helperForegroundColor: Color { + switch helperStyle { + case .helperText: + Color.onSurfaceMediumEmphasis + case .errorText: + Color.error + case .sussesText: + Color.success + case .none: + Color.clear + } } } diff --git a/Sources/OversizeUI/Controls/TextField/LabeledTextFieldStyle.swift b/Sources/OversizeUI/Controls/TextField/LabeledTextFieldStyle.swift index 3972a36..a88d016 100644 --- a/Sources/OversizeUI/Controls/TextField/LabeledTextFieldStyle.swift +++ b/Sources/OversizeUI/Controls/TextField/LabeledTextFieldStyle.swift @@ -10,7 +10,8 @@ public struct LabeledTextFieldStyle: TextFieldStyle { @Environment(\.theme) private var theme: ThemeSettings @Environment(\.fieldLabelPosition) private var fieldPlaceholderPosition: FieldLabelPosition @Environment(\.fieldPosition) private var fieldPosition: FieldPosition - @FocusState var isFocused: Bool + @Environment(\.platform) private var platform: Platform + @FocusState private var isFocused: Bool @Binding private var text: String private let placeholder: String @@ -20,58 +21,112 @@ public struct LabeledTextFieldStyle: TextFieldStyle { } public func _body(configuration: TextField) -> some View { - VStack(alignment: .leading, spacing: .xSmall) { + VStack(alignment: .leading, spacing: platform == .mac ? .xxxSmall : .xSmall) { if fieldPlaceholderPosition == .adjacent { - HStack { - Text(placeholder) - .subheadline(.medium) - .foregroundColor(.onSurfaceHighEmphasis) - Spacer() - } + Text(placeholder) + .subheadline(.medium) + .foregroundColor(platform == .mac ? .onSurfaceMediumEmphasis : .onSurfaceHighEmphasis) + .frame(maxWidth: .infinity, alignment: .leading) + .offset(x: platform == .mac ? 4 : 0) } ZStack(alignment: .leading) { labelTextView configuration .headline(.medium) .foregroundColor(.onSurfaceHighEmphasis) + .padding(padding) .offset(y: fieldOffset) .focused($isFocused) #if os(macOS) - .textFieldStyle(.plain) - .padding(.xxSmall) - #else - .padding(.vertical, fieldPlaceholderPosition == .overInput ? .xxxSmall : .zero) - .padding() - + .if(fieldPlaceholderPosition == .adjacent) { + $0.textFieldStyle(.roundedBorder).controlSize(.large) + } + .if(fieldPlaceholderPosition != .adjacent) { + $0.textFieldStyle(.plain) + } #endif } .background(fieldBackground) .overlay(overlay) } - .animation(.easeIn(duration: 0.15), value: text) + .animation(.easeIn(duration: 0.10), value: text) + } + + private var padding: EdgeInsets { + switch fieldPlaceholderPosition { + case .default: + #if os(macOS) + return .init(.xxSmall) + #else + return .init(.small) + #endif + case .overInput: + #if os(macOS) + return .init(horizontal: .xxSmall, vertical: .xSmall) + #else + return .init( + top: Space.xxxSmall.rawValue + Space.small.rawValue, + leading: Space.small.rawValue, + bottom: Space.xxxSmall.rawValue + Space.small.rawValue, + trailing: Space.small.rawValue + ) + #endif + case .adjacent: + #if os(macOS) + return .init(.zero) + #else + return .init(.small) + #endif + } } @ViewBuilder private var fieldBackground: some View { switch fieldPosition { case .default: + #if canImport(UIKit) RoundedRectangle( - cornerRadius: Radius.medium, + cornerRadius: fieldRadius, style: .continuous ) .fill(isFocused ? Color.surfacePrimary : Color.surfaceSecondary) + #else + if fieldPlaceholderPosition != .adjacent { + RoundedRectangle( + cornerRadius: fieldRadius, + style: .continuous + ) + .fill(isFocused ? Color.surfacePrimary : Color.surfaceSecondary) + } + #endif case .top, .bottom, .center: - #if os(iOS) - RoundedRectangleCorner(radius: Radius.medium, corners: backgroundShapeCorners) + #if canImport(UIKit) + RoundedRectangleCorner( + radius: fieldRadius, + corners: backgroundShapeCorners + ) + .fill(isFocused ? Color.surfacePrimary : Color.surfaceSecondary) + #else + if fieldPlaceholderPosition != .adjacent { + RoundedRectangle( + cornerRadius: fieldRadius, + style: .continuous + ) .fill(isFocused ? Color.surfacePrimary : Color.surfaceSecondary) + } #endif } } - #if os(iOS) - @available(macOS, unavailable) - @available(watchOS, unavailable) - @available(tvOS, unavailable) + var fieldRadius: Radius { + #if os(macOS) + return .xSmall + #else + return .medium + #endif + } + + #if canImport(UIKit) private var backgroundShapeCorners: UIRectCorner { switch fieldPosition { case .default: @@ -88,12 +143,14 @@ public struct LabeledTextFieldStyle: TextFieldStyle { private var fieldOffset: CGFloat { switch fieldPlaceholderPosition { - case .default: - 0 - case .adjacent: - 0 + case .default, .adjacent: + .zero case .overInput: + #if os(macOS) + text.isEmpty ? 0 : 8 + #else text.isEmpty ? 0 : 10 + #endif } } @@ -101,21 +158,37 @@ public struct LabeledTextFieldStyle: TextFieldStyle { private var overlay: some View { switch fieldPosition { case .default: + #if canImport(UIKit) RoundedRectangle( - cornerRadius: Radius.medium, + cornerRadius: fieldRadius, style: .continuous ) .stroke(overlayBorderColor, lineWidth: isFocused ? 2 : CGFloat(theme.borderSize)) - case .top, .bottom, .center: - #if os(iOS) - RoundedRectangleCorner(radius: Radius.medium, corners: backgroundShapeCorners) + #else + if fieldPlaceholderPosition != .adjacent { + RoundedRectangle( + cornerRadius: fieldRadius, + style: .continuous + ) .stroke(overlayBorderColor, lineWidth: isFocused ? 2 : CGFloat(theme.borderSize)) + } + #endif + + case .top, .bottom, .center: + #if canImport(UIKit) + RoundedRectangleCorner(radius: fieldRadius, corners: backgroundShapeCorners) + .stroke( + overlayBorderColor, + lineWidth: isFocused ? 2 : CGFloat(theme.borderSize) + ) #else - RoundedRectangle( - cornerRadius: Radius.medium, - style: .continuous - ) - .stroke(overlayBorderColor, lineWidth: isFocused ? 2 : CGFloat(theme.borderSize)) + if fieldPlaceholderPosition != .adjacent { + RoundedRectangle( + cornerRadius: fieldRadius, + style: .continuous + ) + .stroke(overlayBorderColor, lineWidth: isFocused ? 2 : CGFloat(theme.borderSize)) + } #endif } } @@ -129,7 +202,11 @@ public struct LabeledTextFieldStyle: TextFieldStyle { .subheadline() .onSurfaceDisabledForegroundColor() .opacity(0.7) + #if os(macOS) + .padding(.xSmall) + #else .padding(.small) + #endif } case .adjacent: EmptyView() @@ -138,8 +215,13 @@ public struct LabeledTextFieldStyle: TextFieldStyle { .font(text.isEmpty ? .headline : .subheadline) .fontWeight(text.isEmpty ? .medium : .semibold) .onSurfaceDisabledForegroundColor() + #if os(macOS) + .padding(.xSmall) + .offset(y: text.isEmpty ? 0 : -10) + #else .padding(.small) .offset(y: text.isEmpty ? 0 : -13) + #endif .opacity(text.isEmpty ? 0 : 1) } } diff --git a/Sources/OversizeUI/Controls/URLField/URLField.swift b/Sources/OversizeUI/Controls/URLField/URLField.swift index c3a42f3..341c6de 100644 --- a/Sources/OversizeUI/Controls/URLField/URLField.swift +++ b/Sources/OversizeUI/Controls/URLField/URLField.swift @@ -7,6 +7,7 @@ import SwiftUI #if os(iOS) || os(macOS) @available(iOS 15.0, *) +@available(macOS 14.0, *) @available(watchOS, unavailable) @available(tvOS, unavailable) public struct URLField: View { @@ -37,7 +38,7 @@ public struct URLField: View { if state { textFieldHelper = .none - } else if let url = URL(string: urlString) { + } else if let url = URL(string: urlString), NSWorkspace.shared.urlForApplication(toOpen: url) != nil { textFieldHelper = .none self.url = url } else { @@ -55,7 +56,7 @@ public struct URLField: View { textFieldHelper = .errorText } #else - if let url = URL(string: urlString) { + if let url = URL(string: urlString), NSWorkspace.shared.urlForApplication(toOpen: url) != nil { textFieldHelper = .none self.url = url } else { @@ -66,8 +67,8 @@ public struct URLField: View { #if os(iOS) .keyboardType(.URL) .textInputAutocapitalization(.never) - .textContentType(.URL) #endif + .textContentType(.URL) .autocorrectionDisabled() .fieldHelper(.constant("Invalid URL"), style: $textFieldHelper) } diff --git a/Sources/OversizeUI/Core/EdgeSpaceInsets.swift b/Sources/OversizeUI/Core/EdgeSpaceInsets.swift index 9419a6f..f3fcf0b 100644 --- a/Sources/OversizeUI/Core/EdgeSpaceInsets.swift +++ b/Sources/OversizeUI/Core/EdgeSpaceInsets.swift @@ -24,4 +24,11 @@ public struct EdgeSpaceInsets { bottom = vertical trailing = horizontal } + + public init(_ all: Space) { + top = all + leading = all + bottom = all + trailing = all + } } diff --git a/Sources/OversizeUI/Core/EnvironmentKeys/Platform.swift b/Sources/OversizeUI/Core/EnvironmentKeys/Platform.swift new file mode 100644 index 0000000..6405bd7 --- /dev/null +++ b/Sources/OversizeUI/Core/EnvironmentKeys/Platform.swift @@ -0,0 +1,53 @@ +// +// Copyright © 2024 Alexander Romanov +// Platform.swift, created on 07.09.2024 +// + +import SwiftUI +#if canImport(UIKit) +import UIKit +#endif + +public enum Platform { + case iPhone, iPad, mac, tv, watch, vision, carPlay, other +} + +private struct PlatformKey: EnvironmentKey { + static let defaultValue: Platform = { + #if canImport(UIKit) + switch UIDevice.current.userInterfaceIdiom { + case .phone: + return .iPhone + case .pad: + return .iPad + case .tv: + return .tv + case .carPlay: + return .carPlay + case .mac: + return .mac + case .vision: + return .vision + case .unspecified: + return .other + @unknown default: + return .other + } + #elseif os(watchOS) + return .watch + #elseif os(visionOS) + return .vision + #elseif os(macOS) || targetEnvironment(macCatalyst) + return .mac + #else + return .other + #endif + }() +} + +public extension EnvironmentValues { + var platform: Platform { + get { self[PlatformKey.self] } + set { self[PlatformKey.self] = newValue } + } +} diff --git a/Sources/OversizeUI/Core/Radius.swift b/Sources/OversizeUI/Core/Radius.swift index 947f6c4..51d37e3 100644 --- a/Sources/OversizeUI/Core/Radius.swift +++ b/Sources/OversizeUI/Core/Radius.swift @@ -12,6 +12,8 @@ public enum Radius { /// 0 case zero + /// 4 + case xSmall /// 8 case small /// 12 @@ -25,6 +27,8 @@ public enum Radius { switch self { case .zero: .zero + case .xSmall: + CGFloat(theme.radius / 2) case .small: CGFloat(theme.radius) case .medium: diff --git a/Sources/OversizeUI/Core/Space.swift b/Sources/OversizeUI/Core/Space.swift index 1b193f0..4704e29 100644 --- a/Sources/OversizeUI/Core/Space.swift +++ b/Sources/OversizeUI/Core/Space.swift @@ -21,8 +21,13 @@ public enum Space: CGFloat { /// 16 case small = 16 + #if os(macOS) + /// 20 + case medium = 20 + #else /// 24 case medium = 24 + #endif /// 32 case large = 32 diff --git a/Sources/OversizeUI/Core/Typography.swift b/Sources/OversizeUI/Core/Typography.swift index 818cc89..12a9631 100644 --- a/Sources/OversizeUI/Core/Typography.swift +++ b/Sources/OversizeUI/Core/Typography.swift @@ -40,7 +40,7 @@ public struct Typography: ViewModifier { content .font(.system(fontStyle, design: fontDesign).weight(fontWeight).leading(.tight)) .frame(minHeight: lineHeight) - // .lineSpacing(lineHeight) + .lineSpacing(lineHeight * 0.2) } private var lineHeight: CGFloat { diff --git a/Sources/OversizeUI/Extensions/Color/Color+RawRepresentable.swift b/Sources/OversizeUI/Extensions/Color/Color+RawRepresentable.swift index 8d2657e..3af7df7 100644 --- a/Sources/OversizeUI/Extensions/Color/Color+RawRepresentable.swift +++ b/Sources/OversizeUI/Extensions/Color/Color+RawRepresentable.swift @@ -8,7 +8,7 @@ import Foundation import SwiftUI import UIKit -extension Color: RawRepresentable { +extension Color: @retroactive RawRepresentable { @available(macOS, unavailable) @available(watchOS, unavailable) @available(tvOS, unavailable) diff --git a/Sources/OversizeUI/Extensions/Image/Image+Extensions.swift b/Sources/OversizeUI/Extensions/Image/Image+Extensions.swift index 053df9c..f89ef12 100644 --- a/Sources/OversizeUI/Extensions/Image/Image+Extensions.swift +++ b/Sources/OversizeUI/Extensions/Image/Image+Extensions.swift @@ -16,6 +16,13 @@ public extension Image { public extension Image { func icon(_ color: Color = Color.onSurfaceHighEmphasis) -> some View { renderingMode(.template) + #if os(macOS) + .resizable() + .frame( + width: IconSizes.medium.rawValue, + height: IconSizes.medium.rawValue + ) + #endif .foregroundColor(color) } } @@ -24,7 +31,10 @@ public extension Image { func icon(_ color: Color = Color.onSurfaceHighEmphasis, size: IconSizes) -> some View { renderingMode(.template) .resizable() - .frame(width: size.rawValue, height: size.rawValue) + .frame( + width: size.rawValue, + height: size.rawValue + ) .foregroundColor(color) } } diff --git a/Sources/OversizeUI/Extensions/Spacing/Spacing.swift b/Sources/OversizeUI/Extensions/Spacing/Spacing.swift index 588a019..ea583fd 100644 --- a/Sources/OversizeUI/Extensions/Spacing/Spacing.swift +++ b/Sources/OversizeUI/Extensions/Spacing/Spacing.swift @@ -59,3 +59,15 @@ public extension EdgeInsets { self = .init(top: top.rawValue, leading: leading.rawValue, bottom: bottom.rawValue, trailing: trailing.rawValue) } } + +public extension EdgeInsets { + init(_ all: Space) { + self = .init(top: all.rawValue, leading: all.rawValue, bottom: all.rawValue, trailing: all.rawValue) + } +} + +public extension EdgeInsets { + init(horizontal: Space, vertical: Space) { + self = .init(top: vertical.rawValue, leading: horizontal.rawValue, bottom: vertical.rawValue, trailing: horizontal.rawValue) + } +} diff --git a/Sources/OversizeUI/Resources/Colors.xcassets/Background/BackgroundTertiary.colorset/Contents.json b/Sources/OversizeUI/Resources/Colors.xcassets/Background/BackgroundTertiary.colorset/Contents.json index d2f2378..2924543 100644 --- a/Sources/OversizeUI/Resources/Colors.xcassets/Background/BackgroundTertiary.colorset/Contents.json +++ b/Sources/OversizeUI/Resources/Colors.xcassets/Background/BackgroundTertiary.colorset/Contents.json @@ -5,9 +5,9 @@ "color-space" : "srgb", "components" : { "alpha" : "1.000", - "blue" : "0.902", - "green" : "0.902", - "red" : "0.902" + "blue" : "0xE6", + "green" : "0xE6", + "red" : "0xE6" } }, "idiom" : "universal" From 94505bc7283e3f884671a27803ebd88a3d10861d Mon Sep 17 00:00:00 2001 From: Alexandr Romanov Date: Thu, 26 Sep 2024 21:53:00 +0300 Subject: [PATCH 02/30] Up CI devices --- .github/workflows/ci-pull-request.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci-pull-request.yml b/.github/workflows/ci-pull-request.yml index ba40e0e..b38d5d9 100644 --- a/.github/workflows/ci-pull-request.yml +++ b/.github/workflows/ci-pull-request.yml @@ -22,7 +22,7 @@ jobs: uses: oversizedev/GithubWorkflows/.github/workflows/build-app.yml@main strategy: matrix: - destination: ['platform=iOS Simulator,name=iPhone 15 Pro,OS=17.2', 'platform=iOS Simulator,name=iPad Pro (12.9-inch) (6th generation),OS=17.2'] + destination: ['platform=iOS Simulator,name=iPhone 16 Pro,OS=18.0', 'platform=iOS Simulator,name=iPad (10th generation),OS=18.0'] with: path: Example/Example scheme: Example (iOS) @@ -45,7 +45,7 @@ jobs: uses: oversizedev/GithubWorkflows/.github/workflows/build-app.yml@main strategy: matrix: - destination: ['platform=tvOS Simulator,name=Apple TV 4K (3rd generation) (at 1080p),OS=17.2', 'platform=tvOS Simulator,name=Apple TV 4K (3rd generation) (at 1080p),OS=16.4'] + destination: ['platform=tvOS Simulator,name=Apple TV 4K (3rd generation) (at 1080p),OS=18.0', 'platform=tvOS Simulator,name=Apple TV 4K (3rd generation),OS=18.0'] with: path: Example/Example scheme: Example (tvOS) @@ -58,7 +58,7 @@ jobs: uses: oversizedev/GithubWorkflows/.github/workflows/build-app.yml@main strategy: matrix: - destination: ['platform=watchOS Simulator,name=Apple Watch SE (44mm) (2nd generation),OS=10.5'] + destination: ['platform=watchOS Simulator,name=Apple Watch Series 10 (42mm),OS=11.0'] with: path: Example/Example scheme: Example (watchOS) From b8cf6bc7d5c7cc41a2de093225455a6bb97bb300 Mon Sep 17 00:00:00 2001 From: Alexandr Romanov Date: Thu, 26 Sep 2024 22:09:42 +0300 Subject: [PATCH 03/30] Fix platform --- .../OversizeUI/Core/EnvironmentKeys/Platform.swift | 14 +++++++------- .../OversizeUI/Shapes/RoundedRectangleCorner.swift | 11 +---------- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/Sources/OversizeUI/Core/EnvironmentKeys/Platform.swift b/Sources/OversizeUI/Core/EnvironmentKeys/Platform.swift index 6405bd7..853b23b 100644 --- a/Sources/OversizeUI/Core/EnvironmentKeys/Platform.swift +++ b/Sources/OversizeUI/Core/EnvironmentKeys/Platform.swift @@ -14,7 +14,13 @@ public enum Platform { private struct PlatformKey: EnvironmentKey { static let defaultValue: Platform = { - #if canImport(UIKit) + #if os(macOS) || targetEnvironment(macCatalyst) + return .mac + #elseif os(watchOS) + return .watch + #elseif os(visionOS) + return .vision + #elseif canImport(UIKit) switch UIDevice.current.userInterfaceIdiom { case .phone: return .iPhone @@ -33,12 +39,6 @@ private struct PlatformKey: EnvironmentKey { @unknown default: return .other } - #elseif os(watchOS) - return .watch - #elseif os(visionOS) - return .vision - #elseif os(macOS) || targetEnvironment(macCatalyst) - return .mac #else return .other #endif diff --git a/Sources/OversizeUI/Shapes/RoundedRectangleCorner.swift b/Sources/OversizeUI/Shapes/RoundedRectangleCorner.swift index bb14bbe..4de13c5 100644 --- a/Sources/OversizeUI/Shapes/RoundedRectangleCorner.swift +++ b/Sources/OversizeUI/Shapes/RoundedRectangleCorner.swift @@ -3,28 +3,19 @@ // RoundedRectangleCorner.swift, created on 11.09.2021 // -#if os(iOS) +#if canImport(UIKit) import SwiftUI -@available(watchOS, unavailable) -@available(tvOS, unavailable) -@available(macOS, unavailable) public struct RoundedRectangleCorner: Shape { private var radius: CGFloat = .infinity private var corners: UIRectCorner = .allCorners - @available(watchOS, unavailable) - @available(tvOS, unavailable) - @available(macOS, unavailable) public init(radius: CGFloat, corners: UIRectCorner) { self.radius = radius self.corners = corners } - @available(watchOS, unavailable) - @available(tvOS, unavailable) - @available(macOS, unavailable) public init(radius: Radius, corners: UIRectCorner) { self.radius = radius.rawValue self.corners = corners From b0aa8aa5a631edc4d11ebd02cb57b5bef7dc2818 Mon Sep 17 00:00:00 2001 From: Alexandr Romanov Date: Thu, 26 Sep 2024 22:16:12 +0300 Subject: [PATCH 04/30] Fix ci --- .github/workflows/ci-pull-request.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/ci-pull-request.yml b/.github/workflows/ci-pull-request.yml index b38d5d9..a2a91bb 100644 --- a/.github/workflows/ci-pull-request.yml +++ b/.github/workflows/ci-pull-request.yml @@ -3,9 +3,6 @@ on: pull_request: branches: - main - push: - branches: - - develop workflow_dispatch: jobs: From 676d05b5316eaf7541099cc7982f427975e6f9ed Mon Sep 17 00:00:00 2001 From: Alexandr Romanov Date: Thu, 26 Sep 2024 22:23:38 +0300 Subject: [PATCH 05/30] Update ci-pull-request.yml --- .github/workflows/ci-pull-request.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-pull-request.yml b/.github/workflows/ci-pull-request.yml index a2a91bb..ae6f8c7 100644 --- a/.github/workflows/ci-pull-request.yml +++ b/.github/workflows/ci-pull-request.yml @@ -55,7 +55,7 @@ jobs: uses: oversizedev/GithubWorkflows/.github/workflows/build-app.yml@main strategy: matrix: - destination: ['platform=watchOS Simulator,name=Apple Watch Series 10 (42mm),OS=11.0'] + destination: ['platform=watchOS Simulator,name=Apple Watch SE (40mm) (2nd generation),OS=11.0'] with: path: Example/Example scheme: Example (watchOS) From 852d398f569155597a19bcf115af82abf38d4297 Mon Sep 17 00:00:00 2001 From: Alexandr Romanov Date: Thu, 26 Sep 2024 23:06:48 +0300 Subject: [PATCH 06/30] Update ci-pull-request.yml --- .github/workflows/ci-pull-request.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/ci-pull-request.yml b/.github/workflows/ci-pull-request.yml index ae6f8c7..9cbd2b3 100644 --- a/.github/workflows/ci-pull-request.yml +++ b/.github/workflows/ci-pull-request.yml @@ -9,8 +9,16 @@ jobs: build-swiftpm: name: Build SwiftPM uses: oversizedev/GithubWorkflows/.github/workflows/build-swiftpm.yml@main + strategy: + matrix: + destination: + - platform=iOS Simulator,name=iPhone 16,OS=18.0 + - platform=watchOS Simulator,name=Apple Watch SE (40mm) (2nd generation),OS=11.0 + - platform=tvOS Simulator,name=Apple TV 4K (3rd generation) (at 1080p),OS=18.0 + - platform=macOS,arch=arm64 with: package: OversizeUI + destination: ${{ matrix.destination }} secrets: inherit build-iOS-example: From 718b80a8174041b82dd60963a555594cb9fae370 Mon Sep 17 00:00:00 2001 From: Alexandr Romanov Date: Thu, 26 Sep 2024 23:10:44 +0300 Subject: [PATCH 07/30] Update ci-pull-request.yml --- .github/workflows/ci-pull-request.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci-pull-request.yml b/.github/workflows/ci-pull-request.yml index 9cbd2b3..f606ecc 100644 --- a/.github/workflows/ci-pull-request.yml +++ b/.github/workflows/ci-pull-request.yml @@ -27,7 +27,9 @@ jobs: uses: oversizedev/GithubWorkflows/.github/workflows/build-app.yml@main strategy: matrix: - destination: ['platform=iOS Simulator,name=iPhone 16 Pro,OS=18.0', 'platform=iOS Simulator,name=iPad (10th generation),OS=18.0'] + destination: + - platform=iOS Simulator,name=iPhone 16 Pro,OS=18.0 + - platform=iOS Simulator,name=iPad (10th generation),OS=18.0 with: path: Example/Example scheme: Example (iOS) @@ -50,7 +52,9 @@ jobs: uses: oversizedev/GithubWorkflows/.github/workflows/build-app.yml@main strategy: matrix: - destination: ['platform=tvOS Simulator,name=Apple TV 4K (3rd generation) (at 1080p),OS=18.0', 'platform=tvOS Simulator,name=Apple TV 4K (3rd generation),OS=18.0'] + destination: + - platform=tvOS Simulator,name=Apple TV 4K (3rd generation) (at 1080p),OS=18.0 + - platform=tvOS Simulator,name=Apple TV 4K (3rd generation),OS=18.0 with: path: Example/Example scheme: Example (tvOS) @@ -63,7 +67,8 @@ jobs: uses: oversizedev/GithubWorkflows/.github/workflows/build-app.yml@main strategy: matrix: - destination: ['platform=watchOS Simulator,name=Apple Watch SE (40mm) (2nd generation),OS=11.0'] + destination: + - platform=watchOS Simulator,name=Apple Watch SE (40mm) (2nd generation),OS=11.0 with: path: Example/Example scheme: Example (watchOS) From fcb58f6707b3b1274f81da5af542d870431dae93 Mon Sep 17 00:00:00 2001 From: Alexandr Romanov Date: Thu, 26 Sep 2024 23:32:30 +0300 Subject: [PATCH 08/30] Update CI # Conflicts: # .github/workflows/ci-pull-request.yml --- .github/workflows/ci-pull-request.yml | 34 +++++++++-- .github/workflows/ci-release.yml | 81 --------------------------- .github/workflows/publish-docc.yml | 37 ------------ 3 files changed, 30 insertions(+), 122 deletions(-) delete mode 100644 .github/workflows/ci-release.yml delete mode 100644 .github/workflows/publish-docc.yml diff --git a/.github/workflows/ci-pull-request.yml b/.github/workflows/ci-pull-request.yml index f606ecc..34ca7d1 100644 --- a/.github/workflows/ci-pull-request.yml +++ b/.github/workflows/ci-pull-request.yml @@ -1,8 +1,13 @@ -name: CI - Pull Request +name: CI on: pull_request: + types: + - closed branches: - main + push: + branches: + - '**' workflow_dispatch: jobs: @@ -27,7 +32,7 @@ jobs: uses: oversizedev/GithubWorkflows/.github/workflows/build-app.yml@main strategy: matrix: - destination: + destination: - platform=iOS Simulator,name=iPhone 16 Pro,OS=18.0 - platform=iOS Simulator,name=iPad (10th generation),OS=18.0 with: @@ -52,7 +57,7 @@ jobs: uses: oversizedev/GithubWorkflows/.github/workflows/build-app.yml@main strategy: matrix: - destination: + destination: - platform=tvOS Simulator,name=Apple TV 4K (3rd generation) (at 1080p),OS=18.0 - platform=tvOS Simulator,name=Apple TV 4K (3rd generation),OS=18.0 with: @@ -67,10 +72,31 @@ jobs: uses: oversizedev/GithubWorkflows/.github/workflows/build-app.yml@main strategy: matrix: - destination: + destination: - platform=watchOS Simulator,name=Apple Watch SE (40mm) (2nd generation),OS=11.0 with: path: Example/Example scheme: Example (watchOS) destination: ${{ matrix.destination }} secrets: inherit + + bump: + name: Bump version + if: github.ref == 'refs/heads/main' + needs: + - build-swiftpm + - build-iOS-example + - build-macOS-example + - build-tvOS-example + - build-watchOS-example + + uses: oversizedev/GithubWorkflows/.github/workflows/bump.yml@main + secrets: inherit + + publish-docc: + name: Publish docc + if: github.ref == 'refs/heads/main' + needs: bump + uses: ./.github/workflows/publish-docc.yml + secrets: inherit + diff --git a/.github/workflows/ci-release.yml b/.github/workflows/ci-release.yml deleted file mode 100644 index 6bc476a..0000000 --- a/.github/workflows/ci-release.yml +++ /dev/null @@ -1,81 +0,0 @@ -name: CI - Release -on: - pull_request: - types: - - closed - branches: - - main - workflow_dispatch: - -jobs: - build-swiftpm: - name: Build SwiftPM - uses: oversizedev/GithubWorkflows/.github/workflows/build-swiftpm.yml@main - strategy: - matrix: - packages: [OversizeUI] - with: - package: ${{ matrix.packages }} - secrets: inherit - - build-iOS-example: - name: Build iOS example - needs: build-swiftpm - uses: oversizedev/GithubWorkflows/.github/workflows/build-app.yml@main - strategy: - matrix: - destination: ['platform=iOS Simulator,name=iPhone 15 Pro,OS=17.2', 'platform=iOS Simulator,name=iPad Pro (12.9-inch) (6th generation),OS=17.2'] - with: - path: Example/Example - scheme: Example (iOS) - destination: ${{ matrix.destination }} - secrets: inherit - - build-macOS-example: - name: Build macOS examples - needs: build-swiftpm - uses: oversizedev/GithubWorkflows/.github/workflows/build-app.yml@main - with: - path: Example/Example - scheme: Example (macOS) - destination: platform=macOS,arch=arm64 - secrets: inherit - - build-tvOS-example: - name: Build tvOS examples - needs: build-swiftpm - uses: oversizedev/GithubWorkflows/.github/workflows/build-app.yml@main - strategy: - matrix: - destination: ['platform=tvOS Simulator,name=Apple TV 4K (3rd generation) (at 1080p),OS=17.2', 'platform=tvOS Simulator,name=Apple TV 4K (3rd generation) (at 1080p),OS=16.4'] - with: - path: Example/Example - scheme: Example (tvOS) - destination: ${{ matrix.destination }} - secrets: inherit - - build-watchOS-example: - name: Build watchOS examples - needs: build-swiftpm - uses: oversizedev/GithubWorkflows/.github/workflows/build-app.yml@main - strategy: - matrix: - destination: ['platform=watchOS Simulator,name=Apple Watch SE (44mm) (2nd generation),OS=10.5'] - with: - path: Example/Example - scheme: Example (watchOS) - destination: ${{ matrix.destination }} - secrets: inherit - - bump: - name: Bump version - needs: [build-swiftpm, build-iOS-example, build-macOS-example, build-tvOS-example, build-watchOS-example] - uses: oversizedev/GithubWorkflows/.github/workflows/bump.yml@main - secrets: inherit - - publish-docc: - name: Publish docc - needs: bump - uses: ./.github/workflows/publish-docc.yml - secrets: inherit - diff --git a/.github/workflows/publish-docc.yml b/.github/workflows/publish-docc.yml deleted file mode 100644 index d461258..0000000 --- a/.github/workflows/publish-docc.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: Deploy DocC -on: - workflow_dispatch: - workflow_call: -permissions: - contents: read - pages: write - id-token: write -concurrency: - group: "pages" - cancel-in-progress: true -jobs: - deploy: - environment: - name: github-pages - url: ${{ steps.deployment.outputs.page_url }} - runs-on: macos-14 - steps: - - name: Checkout 🛎️ - uses: actions/checkout@v3 - - name: Build DocC - run: | - xcodebuild docbuild -scheme -skipPackagePluginValidation OversizeUI \ - -derivedDataPath /tmp/docbuild \ - -destination 'generic/platform=iOS'; - $(xcrun --find docc) process-archive \ - transform-for-static-hosting /tmp/docbuild/Build/Products/Debug-iphoneos/OversizeUI.doccarchive \ - --hosting-base-path OversizeUI \ - --output-path docs; - echo "" > docs/index.html; - - name: Upload artifact - uses: actions/upload-pages-artifact@v1 - with: - path: 'docs' - - name: Deploy to GitHub Pages - id: deployment - uses: actions/deploy-pages@v1 From 718d93b800270aa7c25ed6000b5fbaf0e0528946 Mon Sep 17 00:00:00 2001 From: Alexandr Romanov Date: Thu, 26 Sep 2024 23:34:06 +0300 Subject: [PATCH 09/30] Update ci-pull-request.yml --- .github/workflows/ci-pull-request.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.github/workflows/ci-pull-request.yml b/.github/workflows/ci-pull-request.yml index 34ca7d1..af8f61b 100644 --- a/.github/workflows/ci-pull-request.yml +++ b/.github/workflows/ci-pull-request.yml @@ -92,11 +92,4 @@ jobs: uses: oversizedev/GithubWorkflows/.github/workflows/bump.yml@main secrets: inherit - - publish-docc: - name: Publish docc - if: github.ref == 'refs/heads/main' - needs: bump - uses: ./.github/workflows/publish-docc.yml - secrets: inherit From fb8c56c017c653871ca0e3206f41a20e75bbab24 Mon Sep 17 00:00:00 2001 From: Alexandr Romanov Date: Thu, 26 Sep 2024 23:44:57 +0300 Subject: [PATCH 10/30] Update steps # Conflicts: # .github/workflows/ci-pull-request.yml --- .github/workflows/ci-pull-request.yml | 95 --------------------------- .github/workflows/ci.yml | 66 +++++++++++++++++++ 2 files changed, 66 insertions(+), 95 deletions(-) delete mode 100644 .github/workflows/ci-pull-request.yml create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci-pull-request.yml b/.github/workflows/ci-pull-request.yml deleted file mode 100644 index af8f61b..0000000 --- a/.github/workflows/ci-pull-request.yml +++ /dev/null @@ -1,95 +0,0 @@ -name: CI -on: - pull_request: - types: - - closed - branches: - - main - push: - branches: - - '**' - workflow_dispatch: - -jobs: - build-swiftpm: - name: Build SwiftPM - uses: oversizedev/GithubWorkflows/.github/workflows/build-swiftpm.yml@main - strategy: - matrix: - destination: - - platform=iOS Simulator,name=iPhone 16,OS=18.0 - - platform=watchOS Simulator,name=Apple Watch SE (40mm) (2nd generation),OS=11.0 - - platform=tvOS Simulator,name=Apple TV 4K (3rd generation) (at 1080p),OS=18.0 - - platform=macOS,arch=arm64 - with: - package: OversizeUI - destination: ${{ matrix.destination }} - secrets: inherit - - build-iOS-example: - name: Build iOS example - needs: build-swiftpm - uses: oversizedev/GithubWorkflows/.github/workflows/build-app.yml@main - strategy: - matrix: - destination: - - platform=iOS Simulator,name=iPhone 16 Pro,OS=18.0 - - platform=iOS Simulator,name=iPad (10th generation),OS=18.0 - with: - path: Example/Example - scheme: Example (iOS) - destination: ${{ matrix.destination }} - secrets: inherit - - build-macOS-example: - name: Build macOS examples - needs: build-swiftpm - uses: oversizedev/GithubWorkflows/.github/workflows/build-app.yml@main - with: - path: Example/Example - scheme: Example (macOS) - destination: platform=macOS,arch=arm64 - secrets: inherit - - build-tvOS-example: - name: Build tvOS examples - needs: build-swiftpm - uses: oversizedev/GithubWorkflows/.github/workflows/build-app.yml@main - strategy: - matrix: - destination: - - platform=tvOS Simulator,name=Apple TV 4K (3rd generation) (at 1080p),OS=18.0 - - platform=tvOS Simulator,name=Apple TV 4K (3rd generation),OS=18.0 - with: - path: Example/Example - scheme: Example (tvOS) - destination: ${{ matrix.destination }} - secrets: inherit - - build-watchOS-example: - name: Build watchOS examples - needs: build-swiftpm - uses: oversizedev/GithubWorkflows/.github/workflows/build-app.yml@main - strategy: - matrix: - destination: - - platform=watchOS Simulator,name=Apple Watch SE (40mm) (2nd generation),OS=11.0 - with: - path: Example/Example - scheme: Example (watchOS) - destination: ${{ matrix.destination }} - secrets: inherit - - bump: - name: Bump version - if: github.ref == 'refs/heads/main' - needs: - - build-swiftpm - - build-iOS-example - - build-macOS-example - - build-tvOS-example - - build-watchOS-example - - uses: oversizedev/GithubWorkflows/.github/workflows/bump.yml@main - secrets: inherit - diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..733075d --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,66 @@ +name: CI +on: + pull_request: + types: + - closed + branches: + - main + push: + branches: + - '**' + workflow_dispatch: + +jobs: + build-swiftpm: + name: Build SwiftPM + uses: oversizedev/GithubWorkflows/.github/workflows/build-swiftpm.yml@main + strategy: + matrix: + destination: + - platform=iOS Simulator,name=iPhone 16,OS=18.0 + - platform=watchOS Simulator,name=Apple Watch SE (40mm) (2nd generation),OS=11.0 + - platform=tvOS Simulator,name=Apple TV 4K (3rd generation) (at 1080p),OS=18.0 + - platform=macOS,arch=arm64 + with: + package: OversizeUI + destination: ${{ matrix.destination }} + secrets: inherit + + build-app: + name: Build examples + needs: build-swiftpm + uses: oversizedev/GithubWorkflows/.github/workflows/build-app.yml@main + strategy: + matrix: + platform: + - { name: "iOS Simulator", os: "iPhone 16,OS=18.0", scheme: "Example (iOS)" } + - { name: "iPad (10th generation)", os: "OS=18.0", scheme: "Example (iOS)" } + - { name: "watchOS Simulator", os: "Apple Watch SE (40mm) (2nd generation),OS=11.0", scheme: "Example (watchOS)" } + - { name: "tvOS Simulator", os: "Apple TV 4K (3rd generation) (at 1080p),OS=18.0", scheme: "Example (tvOS)" } + - { name: "macOS", os: "macOS,arch=arm64", scheme: "Example (macOS)" } + with: + path: Example/Example + scheme: ${{ matrix.platform.scheme }} + destination: platform=${{ matrix.platform.os }} + secrets: inherit + + bump: + name: Bump version + if: github.ref == 'refs/heads/main' + needs: + - build-swiftpm + - build-iOS-example + - build-macOS-example + - build-tvOS-example + - build-watchOS-example + + uses: oversizedev/GithubWorkflows/.github/workflows/bump.yml@main + secrets: inherit + + publish-docc: + name: Publish docc + if: github.ref == 'refs/heads/main' + needs: bump + uses: ./.github/workflows/publish-docc.yml + secrets: inherit + From 51a6825647a6ad723b9ca659c3139010c486184e Mon Sep 17 00:00:00 2001 From: Alexandr Romanov Date: Thu, 26 Sep 2024 23:47:31 +0300 Subject: [PATCH 11/30] Update ci.yml --- .github/workflows/ci.yml | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 733075d..ce5bf65 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -48,19 +48,6 @@ jobs: name: Bump version if: github.ref == 'refs/heads/main' needs: - - build-swiftpm - - build-iOS-example - - build-macOS-example - - build-tvOS-example - - build-watchOS-example - + - build-app uses: oversizedev/GithubWorkflows/.github/workflows/bump.yml@main secrets: inherit - - publish-docc: - name: Publish docc - if: github.ref == 'refs/heads/main' - needs: bump - uses: ./.github/workflows/publish-docc.yml - secrets: inherit - From d0c835469d4e861d041e7334c35f96540c4b1e50 Mon Sep 17 00:00:00 2001 From: Alexandr Romanov Date: Thu, 26 Sep 2024 23:55:33 +0300 Subject: [PATCH 12/30] Revert changes --- .github/workflows/ci.yml | 63 +++++++++++++++++++++++++++++++++------- 1 file changed, 52 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ce5bf65..ddb0340 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,28 +26,69 @@ jobs: destination: ${{ matrix.destination }} secrets: inherit - build-app: - name: Build examples + build-iOS-example: + name: Build iOS example needs: build-swiftpm uses: oversizedev/GithubWorkflows/.github/workflows/build-app.yml@main strategy: matrix: - platform: - - { name: "iOS Simulator", os: "iPhone 16,OS=18.0", scheme: "Example (iOS)" } - - { name: "iPad (10th generation)", os: "OS=18.0", scheme: "Example (iOS)" } - - { name: "watchOS Simulator", os: "Apple Watch SE (40mm) (2nd generation),OS=11.0", scheme: "Example (watchOS)" } - - { name: "tvOS Simulator", os: "Apple TV 4K (3rd generation) (at 1080p),OS=18.0", scheme: "Example (tvOS)" } - - { name: "macOS", os: "macOS,arch=arm64", scheme: "Example (macOS)" } + destination: + - platform=iOS Simulator,name=iPhone 16 Pro,OS=18.0 + - platform=iOS Simulator,name=iPad (10th generation),OS=18.0 + with: + path: Example/Example + scheme: Example (iOS) + destination: ${{ matrix.destination }} + secrets: inherit + + build-macOS-example: + name: Build macOS examples + needs: build-swiftpm + uses: oversizedev/GithubWorkflows/.github/workflows/build-app.yml@main with: path: Example/Example - scheme: ${{ matrix.platform.scheme }} - destination: platform=${{ matrix.platform.os }} + scheme: Example (macOS) + destination: platform=macOS,arch=arm64 + secrets: inherit + + build-tvOS-example: + name: Build tvOS examples + needs: build-swiftpm + uses: oversizedev/GithubWorkflows/.github/workflows/build-app.yml@main + strategy: + matrix: + destination: + - platform=tvOS Simulator,name=Apple TV 4K (3rd generation) (at 1080p),OS=18.0 + - platform=tvOS Simulator,name=Apple TV 4K (3rd generation),OS=18.0 + with: + path: Example/Example + scheme: Example (tvOS) + destination: ${{ matrix.destination }} + secrets: inherit + + build-watchOS-example: + name: Build watchOS examples + needs: build-swiftpm + uses: oversizedev/GithubWorkflows/.github/workflows/build-app.yml@main + strategy: + matrix: + destination: + - platform=watchOS Simulator,name=Apple Watch SE (40mm) (2nd generation),OS=11.0 + with: + path: Example/Example + scheme: Example (watchOS) + destination: ${{ matrix.destination }} secrets: inherit bump: name: Bump version if: github.ref == 'refs/heads/main' needs: - - build-app + - build-swiftpm + - build-iOS-example + - build-macOS-example + - build-tvOS-example + - build-watchOS-example + uses: oversizedev/GithubWorkflows/.github/workflows/bump.yml@main secrets: inherit From 65f14edce7da2393fdca01d0c636ddb4009883f0 Mon Sep 17 00:00:00 2001 From: Alexandr Romanov Date: Sun, 6 Oct 2024 11:46:38 +0400 Subject: [PATCH 13/30] Add RoundedRectangleCorner for macOS, update filed position and etc --- .../OversizeUI/Controls/Avatar/Avatar.swift | 31 ++++++- .../Controls/Avatar/AvatarModifiers.swift | 3 +- .../Controls/Button/FieldButtonStyle.swift | 23 ++--- .../Controls/IconPicker/IconPicker.swift | 5 +- .../Controls/PageControl/PageIndexView.swift | 4 + .../OversizeUI/Controls/PageView/Page.swift | 2 +- .../Controls/PriceField/PriceField.swift | 2 +- .../Controls/Select/MultiSelect.swift | 5 ++ .../OversizeUI/Controls/Select/Select.swift | 5 ++ .../OversizeUI/Controls/TextBox/TextBox.swift | 45 ++++++---- .../TextEditorPlaceholderViewModifier.swift | 74 +++++++++++++--- .../TextField/FieldHelperViewModifier.swift | 4 +- .../TextField/LabeledTextFieldStyle.swift | 88 +++++++++++-------- .../Core/Appearance/ThemeSettings.swift | 6 ++ .../FieldPositionEnvironment.swift | 10 +-- .../Core/EnvironmentKeys/Platform.swift | 14 +-- Sources/OversizeUI/Core/Typography.swift | 42 ++++++++- Sources/OversizeUI/Deprecated/PageView.swift | 16 ++++ .../Extensions/View/View+CornerRadius.swift | 14 ++- .../Shapes/RoundedRectangleCorner.swift | 84 ++++++++++++++++-- 20 files changed, 365 insertions(+), 112 deletions(-) diff --git a/Sources/OversizeUI/Controls/Avatar/Avatar.swift b/Sources/OversizeUI/Controls/Avatar/Avatar.swift index 9c1d2fb..80449be 100644 --- a/Sources/OversizeUI/Controls/Avatar/Avatar.swift +++ b/Sources/OversizeUI/Controls/Avatar/Avatar.swift @@ -41,6 +41,9 @@ public struct Avatar: View { /// Sets a stroke color for the Avatar. var strokeColor: Color = .clear + /// Sets a stroke width for the Avatar. + var strokeLineWidth: CGFloat = 2 + /// Sets a custom background color for the Avatar. var background: AvatarBackgroundType = .color(.surfaceSecondary) @@ -82,13 +85,23 @@ public struct Avatar: View { .scaledToFill() .frame(width: avatarSize, height: avatarSize) .clipShape(Circle()) - .overlay(Circle().stroke(strokeColor, lineWidth: 2)) + .overlay( + Circle().stroke( + strokeColor, + lineWidth: strokeLineWidth + ) + ) } else { ZStack { avatarSurface .frame(width: avatarSize, height: avatarSize) - .overlay(Circle().stroke(strokeColor, lineWidth: 2)) + .overlay( + Circle().stroke( + strokeColor, + lineWidth: strokeLineWidth + ) + ) avatarLabel } @@ -106,13 +119,23 @@ public struct Avatar: View { .scaledToFill() .frame(width: Space.xxxLarge.rawValue, height: Space.xxxLarge.rawValue) .clipShape(Circle()) - .overlay(Circle().stroke(strokeColor, lineWidth: 2)) + .overlay( + Circle().stroke( + strokeColor, + lineWidth: strokeLineWidth + ) + ) } else { ZStack { avatarSurface .frame(width: Space.xxxLarge.rawValue, height: Space.xxxLarge.rawValue) - .overlay(Circle().stroke(strokeColor, lineWidth: 2)) + .overlay( + Circle().stroke( + strokeColor, + lineWidth: strokeLineWidth + ) + ) } } } diff --git a/Sources/OversizeUI/Controls/Avatar/AvatarModifiers.swift b/Sources/OversizeUI/Controls/Avatar/AvatarModifiers.swift index 0e1db62..da840d0 100644 --- a/Sources/OversizeUI/Controls/Avatar/AvatarModifiers.swift +++ b/Sources/OversizeUI/Controls/Avatar/AvatarModifiers.swift @@ -27,9 +27,10 @@ public extension Avatar { /// Sets a stroke for the Avatar /// - Parameter strokeColor: Color for Avatar stroke /// - Returns: The modified view with stroke. - func avatarStroke(_ strokeColor: Color = .surfacePrimary) -> Avatar { + func avatarStroke(_ strokeColor: Color = .surfacePrimary, lineWidth: CGFloat = 2) -> Avatar { var control = self control.strokeColor = strokeColor + control.strokeLineWidth = lineWidth return control } } diff --git a/Sources/OversizeUI/Controls/Button/FieldButtonStyle.swift b/Sources/OversizeUI/Controls/Button/FieldButtonStyle.swift index 5121cbc..1a79818 100644 --- a/Sources/OversizeUI/Controls/Button/FieldButtonStyle.swift +++ b/Sources/OversizeUI/Controls/Button/FieldButtonStyle.swift @@ -7,7 +7,7 @@ import SwiftUI public struct FieldButtonStyle: ButtonStyle { @Environment(\.theme) private var theme: ThemeSettings - @Environment(\.fieldPosition) private var fieldPosition: FieldPosition + @Environment(\.fieldPosition) private var fieldPosition: VerticalAlignment? public init() {} @@ -24,16 +24,6 @@ public struct FieldButtonStyle: ButtonStyle { @ViewBuilder private func fieldBackground(isPressed: Bool) -> some View { switch fieldPosition { - case .default: - RoundedRectangle(cornerRadius: Radius.medium, style: .continuous) - .fill(isPressed ? Color.surfaceTertiary : Color.surfaceSecondary) - .overlay( - RoundedRectangle(cornerRadius: Radius.medium, - style: .continuous) - .stroke(theme.borderTextFields - ? Color.border - : Color.surfaceSecondary, lineWidth: CGFloat(theme.borderSize)) - ) case .top, .bottom, .center: #if os(iOS) RoundedRectangleCorner(radius: Radius.medium, corners: backgroundShapeCorners) @@ -55,6 +45,17 @@ public struct FieldButtonStyle: ButtonStyle { : Color.surfaceSecondary, lineWidth: CGFloat(theme.borderSize)) ) #endif + + default: + RoundedRectangle(cornerRadius: Radius.medium, style: .continuous) + .fill(isPressed ? Color.surfaceTertiary : Color.surfaceSecondary) + .overlay( + RoundedRectangle(cornerRadius: Radius.medium, + style: .continuous) + .stroke(theme.borderTextFields + ? Color.border + : Color.surfaceSecondary, lineWidth: CGFloat(theme.borderSize)) + ) } } diff --git a/Sources/OversizeUI/Controls/IconPicker/IconPicker.swift b/Sources/OversizeUI/Controls/IconPicker/IconPicker.swift index dd1ca6d..c5314e9 100644 --- a/Sources/OversizeUI/Controls/IconPicker/IconPicker.swift +++ b/Sources/OversizeUI/Controls/IconPicker/IconPicker.swift @@ -5,9 +5,7 @@ import SwiftUI -@available(macOS, unavailable) -@available(watchOS, unavailable) -@available(tvOS, unavailable) +#if os(iOS) public struct IconPicker: View { @Environment(\.theme) private var theme: ThemeSettings @Environment(\.horizontalSizeClass) var horizontalSizeClass @@ -109,3 +107,4 @@ public struct IconPicker: View { } } } +#endif diff --git a/Sources/OversizeUI/Controls/PageControl/PageIndexView.swift b/Sources/OversizeUI/Controls/PageControl/PageIndexView.swift index 72d48c3..5fc08ef 100644 --- a/Sources/OversizeUI/Controls/PageControl/PageIndexView.swift +++ b/Sources/OversizeUI/Controls/PageControl/PageIndexView.swift @@ -19,7 +19,11 @@ public struct PageIndexView: View { ForEach(0 ..< maxIndex, id: \.self) { index in Capsule() .fill(index == self.index ? Color.accent : Color.surfaceTertiary) + #if os(iOS) .frame(width: index == self.index ? 28 : 8, height: 8) + #else + .frame(width: index == self.index ? 24 : 6, height: 6) + #endif .animation(.default, value: index) } } diff --git a/Sources/OversizeUI/Controls/PageView/Page.swift b/Sources/OversizeUI/Controls/PageView/Page.swift index 9709c53..b176af8 100644 --- a/Sources/OversizeUI/Controls/PageView/Page.swift +++ b/Sources/OversizeUI/Controls/PageView/Page.swift @@ -1109,7 +1109,7 @@ struct SeartchTextFieldButtonStyle: ButtonStyle { private extension View { @ViewBuilder func prefersNavigationBarHidden() -> some View { - #if os(watchOS) + #if os(watchOS) || os(macOS) self #else if #available(iOS 16.0, macOS 13.0, tvOS 16.0, *) { diff --git a/Sources/OversizeUI/Controls/PriceField/PriceField.swift b/Sources/OversizeUI/Controls/PriceField/PriceField.swift index 8495391..4f19577 100644 --- a/Sources/OversizeUI/Controls/PriceField/PriceField.swift +++ b/Sources/OversizeUI/Controls/PriceField/PriceField.swift @@ -9,7 +9,7 @@ import SwiftUI import UIKit #endif -@available(macOS 13, iOS 16, tvOS 16, watchOS 9, *) +@available(macOS 14, iOS 16, tvOS 16, watchOS 9, *) public struct PriceField: View { private var formatter: NumberFormatter { let formatter = NumberFormatter() diff --git a/Sources/OversizeUI/Controls/Select/MultiSelect.swift b/Sources/OversizeUI/Controls/Select/MultiSelect.swift index e9ae58f..8588495 100644 --- a/Sources/OversizeUI/Controls/Select/MultiSelect.swift +++ b/Sources/OversizeUI/Controls/Select/MultiSelect.swift @@ -6,6 +6,7 @@ import SwiftUI // swiftlint:disable all +@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *) public struct MultiSelect: View where Content: View, @@ -143,6 +144,7 @@ public struct MultiSelect: View where Content: View, @@ -138,6 +139,7 @@ public struct Select TextBox { diff --git a/Sources/OversizeUI/Controls/TextEditor/TextEditorPlaceholderViewModifier.swift b/Sources/OversizeUI/Controls/TextEditor/TextEditorPlaceholderViewModifier.swift index 8a6f9f0..92bbc53 100644 --- a/Sources/OversizeUI/Controls/TextEditor/TextEditorPlaceholderViewModifier.swift +++ b/Sources/OversizeUI/Controls/TextEditor/TextEditorPlaceholderViewModifier.swift @@ -31,14 +31,12 @@ public struct TextEditorPlaceholderViewModifier: ViewModifier { } content - .padding(.horizontal, .xSmall) - .padding(.top, topInputPadding) - .padding(.bottom, 10) + .padding(padding) .headline(.medium) .onSurfaceHighEmphasisForegroundColor() .background { ZStack { - RoundedRectangle(cornerRadius: .medium, style: .continuous) + RoundedRectangle(cornerRadius: fieldRadius, style: .continuous) .fill(isFocused ? Color.surfacePrimary : Color.surfaceSecondary) overlay } @@ -53,12 +51,66 @@ public struct TextEditorPlaceholderViewModifier: ViewModifier { } } - var topInputPadding: CGFloat { + private var fieldRadius: Radius { + #if os(macOS) + return .xSmall + #else + return .medium + #endif + } + + var padding: EdgeInsets { + switch fieldPlaceholderPosition { + case .default, .adjacent: + #if os(macOS) + return .init( + top: 10, + leading: Space.xSmall.rawValue, + bottom: 10, + trailing: Space.xSmall.rawValue + ) + #else + return .init( + top: 10, + leading: Space.xSmall.rawValue, + bottom: 10, + trailing: Space.xSmall.rawValue + ) + #endif + case .overInput: + #if os(macOS) + return .init( + top: text.isEmpty ? 13 : 22, + leading: Space.xxSmall.rawValue, + bottom: 10, + trailing: Space.xxSmall.rawValue + ) + #else + return .init( + top: text.isEmpty ? 8 : 22, + leading: Space.xSmall.rawValue, + bottom: 10, + trailing: Space.xSmall.rawValue + ) + + #endif + } + } + + var labelPadding: EdgeInsets { switch fieldPlaceholderPosition { case .default, .adjacent: - 10 + #if os(macOS) + return .init(Space.xSmall) + #else + return .init(Space.xSmall) + #endif case .overInput: - text.isEmpty ? 8 : 22 + #if os(macOS) + return .init(horizontal: Space.xSmall, vertical: Space.xSmall) + #else + return .init(Space.xxSmall) + #endif } } @@ -71,7 +123,7 @@ public struct TextEditorPlaceholderViewModifier: ViewModifier { .subheadline() .onSurfaceDisabledForegroundColor() .opacity(0.7) - .padding(.small) + .padding(labelPadding) } case .adjacent: EmptyView() @@ -81,14 +133,14 @@ public struct TextEditorPlaceholderViewModifier: ViewModifier { .fontWeight(text.isEmpty ? .medium : .semibold) .onSurfaceDisabledForegroundColor() .opacity(0.7) - .padding(.small) + .padding(labelPadding) .offset(y: text.isEmpty ? 0 : -6) } } @ViewBuilder var overlay: some View { - RoundedRectangle(cornerRadius: Radius.medium, style: .continuous) + RoundedRectangle(cornerRadius: fieldRadius, style: .continuous) .stroke(overlayBorderColor, lineWidth: isFocused ? 2 : CGFloat(theme.borderSize)) } @@ -123,10 +175,12 @@ struct TextEditor_preview: PreviewProvider { TextEditor(text: .constant("")) .textEditorPlaceholder("Complaint", text: .constant("")) .fieldLabelPosition(.overInput) + .fieldPosition(.top) TextEditor(text: .constant("Text")) .textEditorPlaceholder("Complaint", text: .constant("Text")) .fieldLabelPosition(.overInput) + .fieldPosition(.bottom) Spacer() } diff --git a/Sources/OversizeUI/Controls/TextField/FieldHelperViewModifier.swift b/Sources/OversizeUI/Controls/TextField/FieldHelperViewModifier.swift index fa1edce..ce2e97e 100644 --- a/Sources/OversizeUI/Controls/TextField/FieldHelperViewModifier.swift +++ b/Sources/OversizeUI/Controls/TextField/FieldHelperViewModifier.swift @@ -23,13 +23,13 @@ public struct FieldHelperViewModifier: ViewModifier { } public func body(content: Content) -> some View { - VStack(alignment: .leading, spacing: platform == .mac ? .xxxSmall : .xSmall) { + VStack(alignment: .leading, spacing: platform == .macOS ? .xxxSmall : .xSmall) { content if helperText.isEmpty == false, helperStyle != .none { Text(helperText) .subheadline(.medium) .foregroundColor(helperForegroundColor) - .offset(x: platform == .mac ? 4 : 0) + .offset(x: platform == .macOS ? 4 : 0) } } .animation(.easeIn(duration: 0.15), value: helperStyle) diff --git a/Sources/OversizeUI/Controls/TextField/LabeledTextFieldStyle.swift b/Sources/OversizeUI/Controls/TextField/LabeledTextFieldStyle.swift index a88d016..3407d6e 100644 --- a/Sources/OversizeUI/Controls/TextField/LabeledTextFieldStyle.swift +++ b/Sources/OversizeUI/Controls/TextField/LabeledTextFieldStyle.swift @@ -6,10 +6,11 @@ import SwiftUI // swiftlint:disable identifier_name +@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *) public struct LabeledTextFieldStyle: TextFieldStyle { @Environment(\.theme) private var theme: ThemeSettings @Environment(\.fieldLabelPosition) private var fieldPlaceholderPosition: FieldLabelPosition - @Environment(\.fieldPosition) private var fieldPosition: FieldPosition + @Environment(\.fieldPosition) private var fieldPosition: VerticalAlignment? @Environment(\.platform) private var platform: Platform @FocusState private var isFocused: Bool @Binding private var text: String @@ -21,13 +22,13 @@ public struct LabeledTextFieldStyle: TextFieldStyle { } public func _body(configuration: TextField) -> some View { - VStack(alignment: .leading, spacing: platform == .mac ? .xxxSmall : .xSmall) { + VStack(alignment: .leading, spacing: platform == .macOS ? .xxxSmall : .xSmall) { if fieldPlaceholderPosition == .adjacent { Text(placeholder) .subheadline(.medium) - .foregroundColor(platform == .mac ? .onSurfaceMediumEmphasis : .onSurfaceHighEmphasis) + .foregroundColor(platform == .macOS ? .onSurfaceMediumEmphasis : .onSurfaceHighEmphasis) .frame(maxWidth: .infinity, alignment: .leading) - .offset(x: platform == .mac ? 4 : 0) + .offset(x: platform == .macOS ? 4 : 0) } ZStack(alignment: .leading) { labelTextView @@ -62,7 +63,7 @@ public struct LabeledTextFieldStyle: TextFieldStyle { #endif case .overInput: #if os(macOS) - return .init(horizontal: .xxSmall, vertical: .xSmall) + return .init(.xSmall) #else return .init( top: Space.xxxSmall.rawValue + Space.small.rawValue, @@ -83,27 +84,28 @@ public struct LabeledTextFieldStyle: TextFieldStyle { @ViewBuilder private var fieldBackground: some View { switch fieldPosition { - case .default: + case .top, .bottom, .center: #if canImport(UIKit) - RoundedRectangle( - cornerRadius: fieldRadius, - style: .continuous + RoundedRectangleCorner( + radius: fieldRadius, + corners: backgroundShapeCorners ) .fill(isFocused ? Color.surfacePrimary : Color.surfaceSecondary) #else if fieldPlaceholderPosition != .adjacent { - RoundedRectangle( - cornerRadius: fieldRadius, - style: .continuous + RoundedRectangleCorner( + radius: fieldRadius, + corners: backgroundShapeCorners ) .fill(isFocused ? Color.surfacePrimary : Color.surfaceSecondary) } #endif - case .top, .bottom, .center: + + default: #if canImport(UIKit) - RoundedRectangleCorner( - radius: fieldRadius, - corners: backgroundShapeCorners + RoundedRectangle( + cornerRadius: fieldRadius, + style: .continuous ) .fill(isFocused ? Color.surfacePrimary : Color.surfaceSecondary) #else @@ -118,7 +120,7 @@ public struct LabeledTextFieldStyle: TextFieldStyle { } } - var fieldRadius: Radius { + private var fieldRadius: Radius { #if os(macOS) return .xSmall #else @@ -141,13 +143,28 @@ public struct LabeledTextFieldStyle: TextFieldStyle { } #endif + #if canImport(AppKit) + private var backgroundShapeCorners: RectCorner { + switch fieldPosition { + case .top: + [.topLeft, .topRight] + case .bottom: + [.bottomLeft, .bottomRight] + case .center: + [] + default: + [.allCorners] + } + } + #endif + private var fieldOffset: CGFloat { switch fieldPlaceholderPosition { case .default, .adjacent: .zero case .overInput: #if os(macOS) - text.isEmpty ? 0 : 8 + text.isEmpty && !isFocused ? -2 : text.isEmpty ? 0 : isFocused ? 9 : 7 #else text.isEmpty ? 0 : 10 #endif @@ -157,23 +174,6 @@ public struct LabeledTextFieldStyle: TextFieldStyle { @ViewBuilder private var overlay: some View { switch fieldPosition { - case .default: - #if canImport(UIKit) - RoundedRectangle( - cornerRadius: fieldRadius, - style: .continuous - ) - .stroke(overlayBorderColor, lineWidth: isFocused ? 2 : CGFloat(theme.borderSize)) - #else - if fieldPlaceholderPosition != .adjacent { - RoundedRectangle( - cornerRadius: fieldRadius, - style: .continuous - ) - .stroke(overlayBorderColor, lineWidth: isFocused ? 2 : CGFloat(theme.borderSize)) - } - #endif - case .top, .bottom, .center: #if canImport(UIKit) RoundedRectangleCorner(radius: fieldRadius, corners: backgroundShapeCorners) @@ -181,6 +181,22 @@ public struct LabeledTextFieldStyle: TextFieldStyle { overlayBorderColor, lineWidth: isFocused ? 2 : CGFloat(theme.borderSize) ) + #elseif canImport(AppKit) + if fieldPlaceholderPosition != .adjacent { + RoundedRectangleCorner(radius: fieldRadius, corners: backgroundShapeCorners) + .stroke( + overlayBorderColor, + lineWidth: isFocused ? 2 : CGFloat(theme.borderSize) + ) + } + #endif + default: + #if canImport(UIKit) + RoundedRectangle( + cornerRadius: fieldRadius, + style: .continuous + ) + .stroke(overlayBorderColor, lineWidth: isFocused ? 2 : CGFloat(theme.borderSize)) #else if fieldPlaceholderPosition != .adjacent { RoundedRectangle( @@ -237,6 +253,7 @@ public struct LabeledTextFieldStyle: TextFieldStyle { } } +@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *) public extension TextFieldStyle where Self == LabeledTextFieldStyle { static var `default`: LabeledTextFieldStyle { LabeledTextFieldStyle(placeholder: "", text: .constant("")) @@ -247,6 +264,7 @@ public extension TextFieldStyle where Self == LabeledTextFieldStyle { } } +@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *) struct LabeledTextFieldStyle_Previews: PreviewProvider { static var previews: some View { VStack(spacing: 32) { diff --git a/Sources/OversizeUI/Core/Appearance/ThemeSettings.swift b/Sources/OversizeUI/Core/Appearance/ThemeSettings.swift index 4d12550..f7031be 100644 --- a/Sources/OversizeUI/Core/Appearance/ThemeSettings.swift +++ b/Sources/OversizeUI/Core/Appearance/ThemeSettings.swift @@ -38,8 +38,14 @@ public class ThemeSettings: ObservableObject { @AppStorage(ThemeSettingsNames.borderApp) public var borderApp: Bool = false @AppStorage(ThemeSettingsNames.borderButtons) public var borderButtons: Bool = false + #if os(macOS) + @AppStorage(ThemeSettingsNames.borderTextFields) public var borderTextFields: Bool = true + @AppStorage(ThemeSettingsNames.borderSurface) public var borderSurface: Bool = true + #else @AppStorage(ThemeSettingsNames.borderSurface) public var borderSurface: Bool = false @AppStorage(ThemeSettingsNames.borderTextFields) public var borderTextFields: Bool = false + #endif + @AppStorage(ThemeSettingsNames.borderControls) public var borderControls: Bool = false @AppStorage(ThemeSettingsNames.borderSize) public var borderSize: Double = 0.5 diff --git a/Sources/OversizeUI/Core/EnvironmentKeys/FieldPositionEnvironment.swift b/Sources/OversizeUI/Core/EnvironmentKeys/FieldPositionEnvironment.swift index 5ea8649..9011d73 100644 --- a/Sources/OversizeUI/Core/EnvironmentKeys/FieldPositionEnvironment.swift +++ b/Sources/OversizeUI/Core/EnvironmentKeys/FieldPositionEnvironment.swift @@ -5,23 +5,19 @@ import SwiftUI -public enum FieldPosition { - case `default`, top, bottom, center -} - private struct FieldPositionKey: EnvironmentKey { - public static var defaultValue: FieldPosition = .default + public static var defaultValue: VerticalAlignment? = nil } public extension EnvironmentValues { - var fieldPosition: FieldPosition { + var fieldPosition: VerticalAlignment? { get { self[FieldPositionKey.self] } set { self[FieldPositionKey.self] = newValue } } } public extension View { - func fieldPosition(_ position: FieldPosition) -> some View { + func fieldPosition(_ position: VerticalAlignment?) -> some View { environment(\.fieldPosition, position) } } diff --git a/Sources/OversizeUI/Core/EnvironmentKeys/Platform.swift b/Sources/OversizeUI/Core/EnvironmentKeys/Platform.swift index 853b23b..2122915 100644 --- a/Sources/OversizeUI/Core/EnvironmentKeys/Platform.swift +++ b/Sources/OversizeUI/Core/EnvironmentKeys/Platform.swift @@ -9,15 +9,15 @@ import UIKit #endif public enum Platform { - case iPhone, iPad, mac, tv, watch, vision, carPlay, other + case iPhone, iPadOS, macOS, tvOS, watchOS, visionOS, carPlay, other } private struct PlatformKey: EnvironmentKey { static let defaultValue: Platform = { #if os(macOS) || targetEnvironment(macCatalyst) - return .mac + return .macOS #elseif os(watchOS) - return .watch + return .watchOS #elseif os(visionOS) return .vision #elseif canImport(UIKit) @@ -25,15 +25,15 @@ private struct PlatformKey: EnvironmentKey { case .phone: return .iPhone case .pad: - return .iPad + return .iPadOS case .tv: - return .tv + return .tvOS case .carPlay: return .carPlay case .mac: - return .mac + return .macOS case .vision: - return .vision + return .visionOS case .unspecified: return .other @unknown default: diff --git a/Sources/OversizeUI/Core/Typography.swift b/Sources/OversizeUI/Core/Typography.swift index 12a9631..b779820 100644 --- a/Sources/OversizeUI/Core/Typography.swift +++ b/Sources/OversizeUI/Core/Typography.swift @@ -38,35 +38,71 @@ public struct Typography: ViewModifier { public func body(content: Content) -> some View { content - .font(.system(fontStyle, design: fontDesign).weight(fontWeight).leading(.tight)) - .frame(minHeight: lineHeight) + .font( + .system(fontStyle, design: fontDesign) + .weight(fontWeight) + .leading(.tight) + ) .lineSpacing(lineHeight * 0.2) + .frame(minHeight: lineHeight) } private var lineHeight: CGFloat { switch fontStyle { case .largeTitle: + #if os(macOS) + return 40 + #else return 44 + #endif case .title: + #if os(macOS) + return 32 + #else return 36 + #endif case .title2: + #if os(macOS) + return 24 + #else return 28 + #endif case .title3: + #if os(macOS) + return 20 + #else return 24 + #endif case .headline: + #if os(macOS) + return 20 + #else return 24 + #endif case .subheadline: + #if os(macOS) + return 16 + #else return 20 + #endif case .body: + #if os(macOS) + return 20 + #else return 24 + #endif case .callout: + #if os(macOS) + return 16 + #else return 20 + #endif case .footnote: return 16 case .caption: return 16 case .caption2: - return 12 + return 16 @unknown default: return 16 } diff --git a/Sources/OversizeUI/Deprecated/PageView.swift b/Sources/OversizeUI/Deprecated/PageView.swift index 2004381..d3ccc6a 100644 --- a/Sources/OversizeUI/Deprecated/PageView.swift +++ b/Sources/OversizeUI/Deprecated/PageView.swift @@ -5,6 +5,7 @@ import SwiftUI +@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *) public struct PageView: View where Content: View, LeadingBar: View, TrailingBar: View, TopToolbar: View, TitleLabel: View { @Environment(\.screenSize) var screenSize @@ -271,6 +272,7 @@ public struct PageView } } +@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *) public extension PageView { enum PageViewBottomType { case shadow, gradient, none @@ -281,6 +283,7 @@ public extension PageView { } } +@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *) public extension PageView where LeadingBar == EmptyView, TitleLabel == EmptyView { init(_ title: String? = nil, onOffsetChanged: @escaping (CGFloat) -> Void = { _ in }, @@ -296,6 +299,7 @@ public extension PageView where LeadingBar == EmptyView, TitleLabel == EmptyView } } +@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *) public extension PageView where TrailingBar == EmptyView, TitleLabel == EmptyView { init(_ title: String? = nil, onOffsetChanged: @escaping (CGFloat) -> Void = { _ in }, @@ -311,6 +315,7 @@ public extension PageView where TrailingBar == EmptyView, TitleLabel == EmptyVie } } +@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *) public extension PageView where TrailingBar == EmptyView, LeadingBar == EmptyView, TitleLabel == EmptyView { init(_ title: String? = nil, onOffsetChanged: @escaping (CGFloat) -> Void = { _ in }, @@ -327,6 +332,7 @@ public extension PageView where TrailingBar == EmptyView, LeadingBar == EmptyVie } } +@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *) public extension PageView where TrailingBar == EmptyView, LeadingBar == EmptyView, TopToolbar == EmptyView, TitleLabel == EmptyView { init(_ title: String? = nil, onOffsetChanged: @escaping (CGFloat) -> Void = { _ in }, @@ -344,6 +350,7 @@ public extension PageView where TrailingBar == EmptyView, LeadingBar == EmptyVie } } +@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *) public extension PageView where LeadingBar == EmptyView, TopToolbar == EmptyView, TitleLabel == EmptyView { init(_ title: String? = nil, onOffsetChanged: @escaping (CGFloat) -> Void = { _ in }, @@ -360,6 +367,7 @@ public extension PageView where LeadingBar == EmptyView, TopToolbar == EmptyView } } +@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *) public extension PageView where TrailingBar == EmptyView, TopToolbar == EmptyView, TitleLabel == EmptyView { init(_ title: String? = nil, onOffsetChanged: @escaping (CGFloat) -> Void = { _ in }, @@ -376,6 +384,7 @@ public extension PageView where TrailingBar == EmptyView, TopToolbar == EmptyVie } } +@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *) public extension PageView where TopToolbar == EmptyView, TitleLabel == EmptyView { init(_ title: String? = nil, onOffsetChanged: @escaping (CGFloat) -> Void = { _ in }, @@ -391,6 +400,7 @@ public extension PageView where TopToolbar == EmptyView, TitleLabel == EmptyView } } +@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *) public extension PageView where TrailingBar == EmptyView, LeadingBar == EmptyView, TopToolbar == EmptyView { init(_ title: String? = nil, onOffsetChanged: @escaping (CGFloat) -> Void = { _ in }, @@ -407,6 +417,7 @@ public extension PageView where TrailingBar == EmptyView, LeadingBar == EmptyVie } } +@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *) public extension PageView where TrailingBar == EmptyView, TopToolbar == EmptyView { init(_ title: String? = nil, onOffsetChanged: @escaping (CGFloat) -> Void = { _ in }, @@ -422,6 +433,7 @@ public extension PageView where TrailingBar == EmptyView, TopToolbar == EmptyVie } } +@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *) public extension PageView where LeadingBar == EmptyView, TopToolbar == EmptyView { init(_ title: String? = nil, onOffsetChanged: @escaping (CGFloat) -> Void = { _ in }, @@ -437,6 +449,7 @@ public extension PageView where LeadingBar == EmptyView, TopToolbar == EmptyView } } +@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *) public extension PageView where TrailingBar == EmptyView { init(_ title: String? = nil, onOffsetChanged: @escaping (CGFloat) -> Void = { _ in }, @@ -451,6 +464,7 @@ public extension PageView where TrailingBar == EmptyView { } } +@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *) public extension PageView where LeadingBar == EmptyView { init(_ title: String? = nil, onOffsetChanged: @escaping (CGFloat) -> Void = { _ in }, @@ -465,6 +479,7 @@ public extension PageView where LeadingBar == EmptyView { } } +@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *) public extension PageView where TopToolbar == EmptyView { init(_ title: String? = nil, onOffsetChanged: @escaping (CGFloat) -> Void = { _ in }, @@ -479,6 +494,7 @@ public extension PageView where TopToolbar == EmptyView { } } +@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *) public extension PageView where TitleLabel == EmptyView { init(_ title: String? = nil, onOffsetChanged: @escaping (CGFloat) -> Void = { _ in }, diff --git a/Sources/OversizeUI/Extensions/View/View+CornerRadius.swift b/Sources/OversizeUI/Extensions/View/View+CornerRadius.swift index c3a79c7..366b083 100644 --- a/Sources/OversizeUI/Extensions/View/View+CornerRadius.swift +++ b/Sources/OversizeUI/Extensions/View/View+CornerRadius.swift @@ -3,14 +3,22 @@ // View+CornerRadius.swift, created on 11.09.2021 // -#if os(iOS) import SwiftUI +#if canImport(UIKit) +public extension View { + func cornerRadius(_ radius: CGFloat, corners: UIRectCorner) -> some View { + clipShape(RoundedRectangleCorner(radius: radius, corners: corners)) + } +} +#endif + +#if canImport(AppKit) public extension View { - @available(macOS, unavailable) @available(watchOS, unavailable) @available(tvOS, unavailable) - func cornerRadius(_ radius: CGFloat, corners: UIRectCorner) -> some View { + @available(macOS 14, *) + func cornerRadius(_ radius: CGFloat, corners: RectCorner) -> some View { clipShape(RoundedRectangleCorner(radius: radius, corners: corners)) } } diff --git a/Sources/OversizeUI/Shapes/RoundedRectangleCorner.swift b/Sources/OversizeUI/Shapes/RoundedRectangleCorner.swift index 4de13c5..c41437c 100644 --- a/Sources/OversizeUI/Shapes/RoundedRectangleCorner.swift +++ b/Sources/OversizeUI/Shapes/RoundedRectangleCorner.swift @@ -1,16 +1,22 @@ -// -// Copyright © 2021 Alexander Romanov -// RoundedRectangleCorner.swift, created on 11.09.2021 -// +import SwiftUI #if canImport(UIKit) -import SwiftUI +import UIKit +#elseif canImport(AppKit) +import AppKit +#endif +@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *) public struct RoundedRectangleCorner: Shape { private var radius: CGFloat = .infinity + #if canImport(UIKit) private var corners: UIRectCorner = .allCorners + #else + private var corners: RectCorner = .allCorners + #endif + #if canImport(UIKit) public init(radius: CGFloat, corners: UIRectCorner) { self.radius = radius self.corners = corners @@ -20,11 +26,79 @@ public struct RoundedRectangleCorner: Shape { self.radius = radius.rawValue self.corners = corners } + #else + public init(radius: CGFloat, corners: RectCorner) { + self.radius = radius + self.corners = corners + } + + public init(radius: Radius, corners: RectCorner) { + self.radius = radius.rawValue + self.corners = corners + } + #endif public func path(in rect: CGRect) -> Path { + #if canImport(UIKit) let path = UIBezierPath(roundedRect: rect, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius)) return Path(path.cgPath) + #else + let path = NSBezierPath() + + let topLeftRadius = corners.contains(.topLeft) ? radius : 0 + let topRightRadius = corners.contains(.topRight) ? radius : 0 + let bottomLeftRadius = corners.contains(.bottomLeft) ? radius : 0 + let bottomRightRadius = corners.contains(.bottomRight) ? radius : 0 + + path.move(to: CGPoint(x: rect.minX + topLeftRadius, y: rect.minY)) + + path.line(to: CGPoint(x: rect.maxX - topRightRadius, y: rect.minY)) + if topRightRadius > 0 { + path.curve(to: CGPoint(x: rect.maxX, y: rect.minY + topRightRadius), + controlPoint1: CGPoint(x: rect.maxX - topRightRadius / 2, y: rect.minY), + controlPoint2: CGPoint(x: rect.maxX, y: rect.minY + topRightRadius / 2)) + } + + path.line(to: CGPoint(x: rect.maxX, y: rect.maxY - bottomRightRadius)) + if bottomRightRadius > 0 { + path.curve(to: CGPoint(x: rect.maxX - bottomRightRadius, y: rect.maxY), + controlPoint1: CGPoint(x: rect.maxX, y: rect.maxY - bottomRightRadius / 2), + controlPoint2: CGPoint(x: rect.maxX - bottomRightRadius / 2, y: rect.maxY)) + } + + path.line(to: CGPoint(x: rect.minX + bottomLeftRadius, y: rect.maxY)) + if bottomLeftRadius > 0 { + path.curve(to: CGPoint(x: rect.minX, y: rect.maxY - bottomLeftRadius), + controlPoint1: CGPoint(x: rect.minX + bottomLeftRadius / 2, y: rect.maxY), + controlPoint2: CGPoint(x: rect.minX, y: rect.maxY - bottomLeftRadius / 2)) + } + + path.line(to: CGPoint(x: rect.minX, y: rect.minY + topLeftRadius)) + if topLeftRadius > 0 { + path.curve(to: CGPoint(x: rect.minX + topLeftRadius, y: rect.minY), + controlPoint1: CGPoint(x: rect.minX, y: rect.minY + topLeftRadius / 2), + controlPoint2: CGPoint(x: rect.minX + topLeftRadius / 2, y: rect.minY)) + } + + path.close() + return Path(path.cgPath) + #endif + } +} + +#if !canImport(UIKit) +public struct RectCorner: OptionSet, Sendable { + public let rawValue: Int + + public static let topLeft = RectCorner(rawValue: 1 << 0) + public static let topRight = RectCorner(rawValue: 1 << 1) + public static let bottomLeft = RectCorner(rawValue: 1 << 2) + public static let bottomRight = RectCorner(rawValue: 1 << 3) + public static let allCorners: RectCorner = [.topLeft, .topRight, .bottomLeft, .bottomRight] + + public init(rawValue: Int) { + self.rawValue = rawValue } } #endif From 13962f073b2122bea252b2306fcfd1463c31758a Mon Sep 17 00:00:00 2001 From: Alexandr Romanov Date: Thu, 26 Sep 2024 21:37:54 +0300 Subject: [PATCH 14/30] Add Platform and minor bug fixes --- .../OversizeUI/Core/EnvironmentKeys/Platform.swift | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Sources/OversizeUI/Core/EnvironmentKeys/Platform.swift b/Sources/OversizeUI/Core/EnvironmentKeys/Platform.swift index 853b23b..6405bd7 100644 --- a/Sources/OversizeUI/Core/EnvironmentKeys/Platform.swift +++ b/Sources/OversizeUI/Core/EnvironmentKeys/Platform.swift @@ -14,13 +14,7 @@ public enum Platform { private struct PlatformKey: EnvironmentKey { static let defaultValue: Platform = { - #if os(macOS) || targetEnvironment(macCatalyst) - return .mac - #elseif os(watchOS) - return .watch - #elseif os(visionOS) - return .vision - #elseif canImport(UIKit) + #if canImport(UIKit) switch UIDevice.current.userInterfaceIdiom { case .phone: return .iPhone @@ -39,6 +33,12 @@ private struct PlatformKey: EnvironmentKey { @unknown default: return .other } + #elseif os(watchOS) + return .watch + #elseif os(visionOS) + return .vision + #elseif os(macOS) || targetEnvironment(macCatalyst) + return .mac #else return .other #endif From 09bb0102e635234cf9bc53589139368059a55973 Mon Sep 17 00:00:00 2001 From: Alexandr Romanov Date: Thu, 26 Sep 2024 22:09:42 +0300 Subject: [PATCH 15/30] Fix platform --- .../OversizeUI/Core/EnvironmentKeys/Platform.swift | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Sources/OversizeUI/Core/EnvironmentKeys/Platform.swift b/Sources/OversizeUI/Core/EnvironmentKeys/Platform.swift index 6405bd7..853b23b 100644 --- a/Sources/OversizeUI/Core/EnvironmentKeys/Platform.swift +++ b/Sources/OversizeUI/Core/EnvironmentKeys/Platform.swift @@ -14,7 +14,13 @@ public enum Platform { private struct PlatformKey: EnvironmentKey { static let defaultValue: Platform = { - #if canImport(UIKit) + #if os(macOS) || targetEnvironment(macCatalyst) + return .mac + #elseif os(watchOS) + return .watch + #elseif os(visionOS) + return .vision + #elseif canImport(UIKit) switch UIDevice.current.userInterfaceIdiom { case .phone: return .iPhone @@ -33,12 +39,6 @@ private struct PlatformKey: EnvironmentKey { @unknown default: return .other } - #elseif os(watchOS) - return .watch - #elseif os(visionOS) - return .vision - #elseif os(macOS) || targetEnvironment(macCatalyst) - return .mac #else return .other #endif From 68cf2b8c585331b237803b10e8bc5adc40f4f919 Mon Sep 17 00:00:00 2001 From: Alexandr Romanov Date: Thu, 26 Sep 2024 23:47:31 +0300 Subject: [PATCH 16/30] Update ci.yml --- .github/workflows/ci.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ddb0340..25b0c9e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -84,11 +84,6 @@ jobs: name: Bump version if: github.ref == 'refs/heads/main' needs: - - build-swiftpm - - build-iOS-example - - build-macOS-example - - build-tvOS-example - - build-watchOS-example - + - build-app uses: oversizedev/GithubWorkflows/.github/workflows/bump.yml@main secrets: inherit From bf97a4c893f74e183205c49bb1fe6d6253996d1e Mon Sep 17 00:00:00 2001 From: Alexandr Romanov Date: Thu, 26 Sep 2024 23:55:33 +0300 Subject: [PATCH 17/30] Revert changes --- .github/workflows/ci.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 25b0c9e..ddb0340 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -84,6 +84,11 @@ jobs: name: Bump version if: github.ref == 'refs/heads/main' needs: - - build-app + - build-swiftpm + - build-iOS-example + - build-macOS-example + - build-tvOS-example + - build-watchOS-example + uses: oversizedev/GithubWorkflows/.github/workflows/bump.yml@main secrets: inherit From 48fd61f429df07f6368e9283431db480e13dc6cb Mon Sep 17 00:00:00 2001 From: Alexandr Romanov Date: Sun, 6 Oct 2024 11:46:38 +0400 Subject: [PATCH 18/30] Add RoundedRectangleCorner for macOS, update filed position and etc --- .../OversizeUI/Controls/Avatar/Avatar.swift | 31 ++++++- .../Controls/Avatar/AvatarModifiers.swift | 3 +- .../Controls/Button/FieldButtonStyle.swift | 23 ++--- .../Controls/IconPicker/IconPicker.swift | 5 +- .../Controls/PageControl/PageIndexView.swift | 4 + .../OversizeUI/Controls/PageView/Page.swift | 2 +- .../Controls/PriceField/PriceField.swift | 2 +- .../Controls/Select/MultiSelect.swift | 5 ++ .../OversizeUI/Controls/Select/Select.swift | 5 ++ .../OversizeUI/Controls/TextBox/TextBox.swift | 45 ++++++---- .../TextEditorPlaceholderViewModifier.swift | 74 +++++++++++++--- .../TextField/FieldHelperViewModifier.swift | 4 +- .../TextField/LabeledTextFieldStyle.swift | 88 +++++++++++-------- .../Core/Appearance/ThemeSettings.swift | 6 ++ .../FieldPositionEnvironment.swift | 10 +-- .../Core/EnvironmentKeys/Platform.swift | 14 +-- Sources/OversizeUI/Core/Typography.swift | 42 ++++++++- Sources/OversizeUI/Deprecated/PageView.swift | 16 ++++ .../Extensions/View/View+CornerRadius.swift | 14 ++- .../Shapes/RoundedRectangleCorner.swift | 84 ++++++++++++++++-- 20 files changed, 365 insertions(+), 112 deletions(-) diff --git a/Sources/OversizeUI/Controls/Avatar/Avatar.swift b/Sources/OversizeUI/Controls/Avatar/Avatar.swift index 9c1d2fb..80449be 100644 --- a/Sources/OversizeUI/Controls/Avatar/Avatar.swift +++ b/Sources/OversizeUI/Controls/Avatar/Avatar.swift @@ -41,6 +41,9 @@ public struct Avatar: View { /// Sets a stroke color for the Avatar. var strokeColor: Color = .clear + /// Sets a stroke width for the Avatar. + var strokeLineWidth: CGFloat = 2 + /// Sets a custom background color for the Avatar. var background: AvatarBackgroundType = .color(.surfaceSecondary) @@ -82,13 +85,23 @@ public struct Avatar: View { .scaledToFill() .frame(width: avatarSize, height: avatarSize) .clipShape(Circle()) - .overlay(Circle().stroke(strokeColor, lineWidth: 2)) + .overlay( + Circle().stroke( + strokeColor, + lineWidth: strokeLineWidth + ) + ) } else { ZStack { avatarSurface .frame(width: avatarSize, height: avatarSize) - .overlay(Circle().stroke(strokeColor, lineWidth: 2)) + .overlay( + Circle().stroke( + strokeColor, + lineWidth: strokeLineWidth + ) + ) avatarLabel } @@ -106,13 +119,23 @@ public struct Avatar: View { .scaledToFill() .frame(width: Space.xxxLarge.rawValue, height: Space.xxxLarge.rawValue) .clipShape(Circle()) - .overlay(Circle().stroke(strokeColor, lineWidth: 2)) + .overlay( + Circle().stroke( + strokeColor, + lineWidth: strokeLineWidth + ) + ) } else { ZStack { avatarSurface .frame(width: Space.xxxLarge.rawValue, height: Space.xxxLarge.rawValue) - .overlay(Circle().stroke(strokeColor, lineWidth: 2)) + .overlay( + Circle().stroke( + strokeColor, + lineWidth: strokeLineWidth + ) + ) } } } diff --git a/Sources/OversizeUI/Controls/Avatar/AvatarModifiers.swift b/Sources/OversizeUI/Controls/Avatar/AvatarModifiers.swift index 0e1db62..da840d0 100644 --- a/Sources/OversizeUI/Controls/Avatar/AvatarModifiers.swift +++ b/Sources/OversizeUI/Controls/Avatar/AvatarModifiers.swift @@ -27,9 +27,10 @@ public extension Avatar { /// Sets a stroke for the Avatar /// - Parameter strokeColor: Color for Avatar stroke /// - Returns: The modified view with stroke. - func avatarStroke(_ strokeColor: Color = .surfacePrimary) -> Avatar { + func avatarStroke(_ strokeColor: Color = .surfacePrimary, lineWidth: CGFloat = 2) -> Avatar { var control = self control.strokeColor = strokeColor + control.strokeLineWidth = lineWidth return control } } diff --git a/Sources/OversizeUI/Controls/Button/FieldButtonStyle.swift b/Sources/OversizeUI/Controls/Button/FieldButtonStyle.swift index 5121cbc..1a79818 100644 --- a/Sources/OversizeUI/Controls/Button/FieldButtonStyle.swift +++ b/Sources/OversizeUI/Controls/Button/FieldButtonStyle.swift @@ -7,7 +7,7 @@ import SwiftUI public struct FieldButtonStyle: ButtonStyle { @Environment(\.theme) private var theme: ThemeSettings - @Environment(\.fieldPosition) private var fieldPosition: FieldPosition + @Environment(\.fieldPosition) private var fieldPosition: VerticalAlignment? public init() {} @@ -24,16 +24,6 @@ public struct FieldButtonStyle: ButtonStyle { @ViewBuilder private func fieldBackground(isPressed: Bool) -> some View { switch fieldPosition { - case .default: - RoundedRectangle(cornerRadius: Radius.medium, style: .continuous) - .fill(isPressed ? Color.surfaceTertiary : Color.surfaceSecondary) - .overlay( - RoundedRectangle(cornerRadius: Radius.medium, - style: .continuous) - .stroke(theme.borderTextFields - ? Color.border - : Color.surfaceSecondary, lineWidth: CGFloat(theme.borderSize)) - ) case .top, .bottom, .center: #if os(iOS) RoundedRectangleCorner(radius: Radius.medium, corners: backgroundShapeCorners) @@ -55,6 +45,17 @@ public struct FieldButtonStyle: ButtonStyle { : Color.surfaceSecondary, lineWidth: CGFloat(theme.borderSize)) ) #endif + + default: + RoundedRectangle(cornerRadius: Radius.medium, style: .continuous) + .fill(isPressed ? Color.surfaceTertiary : Color.surfaceSecondary) + .overlay( + RoundedRectangle(cornerRadius: Radius.medium, + style: .continuous) + .stroke(theme.borderTextFields + ? Color.border + : Color.surfaceSecondary, lineWidth: CGFloat(theme.borderSize)) + ) } } diff --git a/Sources/OversizeUI/Controls/IconPicker/IconPicker.swift b/Sources/OversizeUI/Controls/IconPicker/IconPicker.swift index dd1ca6d..c5314e9 100644 --- a/Sources/OversizeUI/Controls/IconPicker/IconPicker.swift +++ b/Sources/OversizeUI/Controls/IconPicker/IconPicker.swift @@ -5,9 +5,7 @@ import SwiftUI -@available(macOS, unavailable) -@available(watchOS, unavailable) -@available(tvOS, unavailable) +#if os(iOS) public struct IconPicker: View { @Environment(\.theme) private var theme: ThemeSettings @Environment(\.horizontalSizeClass) var horizontalSizeClass @@ -109,3 +107,4 @@ public struct IconPicker: View { } } } +#endif diff --git a/Sources/OversizeUI/Controls/PageControl/PageIndexView.swift b/Sources/OversizeUI/Controls/PageControl/PageIndexView.swift index 72d48c3..5fc08ef 100644 --- a/Sources/OversizeUI/Controls/PageControl/PageIndexView.swift +++ b/Sources/OversizeUI/Controls/PageControl/PageIndexView.swift @@ -19,7 +19,11 @@ public struct PageIndexView: View { ForEach(0 ..< maxIndex, id: \.self) { index in Capsule() .fill(index == self.index ? Color.accent : Color.surfaceTertiary) + #if os(iOS) .frame(width: index == self.index ? 28 : 8, height: 8) + #else + .frame(width: index == self.index ? 24 : 6, height: 6) + #endif .animation(.default, value: index) } } diff --git a/Sources/OversizeUI/Controls/PageView/Page.swift b/Sources/OversizeUI/Controls/PageView/Page.swift index 9709c53..b176af8 100644 --- a/Sources/OversizeUI/Controls/PageView/Page.swift +++ b/Sources/OversizeUI/Controls/PageView/Page.swift @@ -1109,7 +1109,7 @@ struct SeartchTextFieldButtonStyle: ButtonStyle { private extension View { @ViewBuilder func prefersNavigationBarHidden() -> some View { - #if os(watchOS) + #if os(watchOS) || os(macOS) self #else if #available(iOS 16.0, macOS 13.0, tvOS 16.0, *) { diff --git a/Sources/OversizeUI/Controls/PriceField/PriceField.swift b/Sources/OversizeUI/Controls/PriceField/PriceField.swift index 8495391..4f19577 100644 --- a/Sources/OversizeUI/Controls/PriceField/PriceField.swift +++ b/Sources/OversizeUI/Controls/PriceField/PriceField.swift @@ -9,7 +9,7 @@ import SwiftUI import UIKit #endif -@available(macOS 13, iOS 16, tvOS 16, watchOS 9, *) +@available(macOS 14, iOS 16, tvOS 16, watchOS 9, *) public struct PriceField: View { private var formatter: NumberFormatter { let formatter = NumberFormatter() diff --git a/Sources/OversizeUI/Controls/Select/MultiSelect.swift b/Sources/OversizeUI/Controls/Select/MultiSelect.swift index e9ae58f..8588495 100644 --- a/Sources/OversizeUI/Controls/Select/MultiSelect.swift +++ b/Sources/OversizeUI/Controls/Select/MultiSelect.swift @@ -6,6 +6,7 @@ import SwiftUI // swiftlint:disable all +@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *) public struct MultiSelect: View where Content: View, @@ -143,6 +144,7 @@ public struct MultiSelect: View where Content: View, @@ -138,6 +139,7 @@ public struct Select TextBox { diff --git a/Sources/OversizeUI/Controls/TextEditor/TextEditorPlaceholderViewModifier.swift b/Sources/OversizeUI/Controls/TextEditor/TextEditorPlaceholderViewModifier.swift index 8a6f9f0..92bbc53 100644 --- a/Sources/OversizeUI/Controls/TextEditor/TextEditorPlaceholderViewModifier.swift +++ b/Sources/OversizeUI/Controls/TextEditor/TextEditorPlaceholderViewModifier.swift @@ -31,14 +31,12 @@ public struct TextEditorPlaceholderViewModifier: ViewModifier { } content - .padding(.horizontal, .xSmall) - .padding(.top, topInputPadding) - .padding(.bottom, 10) + .padding(padding) .headline(.medium) .onSurfaceHighEmphasisForegroundColor() .background { ZStack { - RoundedRectangle(cornerRadius: .medium, style: .continuous) + RoundedRectangle(cornerRadius: fieldRadius, style: .continuous) .fill(isFocused ? Color.surfacePrimary : Color.surfaceSecondary) overlay } @@ -53,12 +51,66 @@ public struct TextEditorPlaceholderViewModifier: ViewModifier { } } - var topInputPadding: CGFloat { + private var fieldRadius: Radius { + #if os(macOS) + return .xSmall + #else + return .medium + #endif + } + + var padding: EdgeInsets { + switch fieldPlaceholderPosition { + case .default, .adjacent: + #if os(macOS) + return .init( + top: 10, + leading: Space.xSmall.rawValue, + bottom: 10, + trailing: Space.xSmall.rawValue + ) + #else + return .init( + top: 10, + leading: Space.xSmall.rawValue, + bottom: 10, + trailing: Space.xSmall.rawValue + ) + #endif + case .overInput: + #if os(macOS) + return .init( + top: text.isEmpty ? 13 : 22, + leading: Space.xxSmall.rawValue, + bottom: 10, + trailing: Space.xxSmall.rawValue + ) + #else + return .init( + top: text.isEmpty ? 8 : 22, + leading: Space.xSmall.rawValue, + bottom: 10, + trailing: Space.xSmall.rawValue + ) + + #endif + } + } + + var labelPadding: EdgeInsets { switch fieldPlaceholderPosition { case .default, .adjacent: - 10 + #if os(macOS) + return .init(Space.xSmall) + #else + return .init(Space.xSmall) + #endif case .overInput: - text.isEmpty ? 8 : 22 + #if os(macOS) + return .init(horizontal: Space.xSmall, vertical: Space.xSmall) + #else + return .init(Space.xxSmall) + #endif } } @@ -71,7 +123,7 @@ public struct TextEditorPlaceholderViewModifier: ViewModifier { .subheadline() .onSurfaceDisabledForegroundColor() .opacity(0.7) - .padding(.small) + .padding(labelPadding) } case .adjacent: EmptyView() @@ -81,14 +133,14 @@ public struct TextEditorPlaceholderViewModifier: ViewModifier { .fontWeight(text.isEmpty ? .medium : .semibold) .onSurfaceDisabledForegroundColor() .opacity(0.7) - .padding(.small) + .padding(labelPadding) .offset(y: text.isEmpty ? 0 : -6) } } @ViewBuilder var overlay: some View { - RoundedRectangle(cornerRadius: Radius.medium, style: .continuous) + RoundedRectangle(cornerRadius: fieldRadius, style: .continuous) .stroke(overlayBorderColor, lineWidth: isFocused ? 2 : CGFloat(theme.borderSize)) } @@ -123,10 +175,12 @@ struct TextEditor_preview: PreviewProvider { TextEditor(text: .constant("")) .textEditorPlaceholder("Complaint", text: .constant("")) .fieldLabelPosition(.overInput) + .fieldPosition(.top) TextEditor(text: .constant("Text")) .textEditorPlaceholder("Complaint", text: .constant("Text")) .fieldLabelPosition(.overInput) + .fieldPosition(.bottom) Spacer() } diff --git a/Sources/OversizeUI/Controls/TextField/FieldHelperViewModifier.swift b/Sources/OversizeUI/Controls/TextField/FieldHelperViewModifier.swift index fa1edce..ce2e97e 100644 --- a/Sources/OversizeUI/Controls/TextField/FieldHelperViewModifier.swift +++ b/Sources/OversizeUI/Controls/TextField/FieldHelperViewModifier.swift @@ -23,13 +23,13 @@ public struct FieldHelperViewModifier: ViewModifier { } public func body(content: Content) -> some View { - VStack(alignment: .leading, spacing: platform == .mac ? .xxxSmall : .xSmall) { + VStack(alignment: .leading, spacing: platform == .macOS ? .xxxSmall : .xSmall) { content if helperText.isEmpty == false, helperStyle != .none { Text(helperText) .subheadline(.medium) .foregroundColor(helperForegroundColor) - .offset(x: platform == .mac ? 4 : 0) + .offset(x: platform == .macOS ? 4 : 0) } } .animation(.easeIn(duration: 0.15), value: helperStyle) diff --git a/Sources/OversizeUI/Controls/TextField/LabeledTextFieldStyle.swift b/Sources/OversizeUI/Controls/TextField/LabeledTextFieldStyle.swift index a88d016..3407d6e 100644 --- a/Sources/OversizeUI/Controls/TextField/LabeledTextFieldStyle.swift +++ b/Sources/OversizeUI/Controls/TextField/LabeledTextFieldStyle.swift @@ -6,10 +6,11 @@ import SwiftUI // swiftlint:disable identifier_name +@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *) public struct LabeledTextFieldStyle: TextFieldStyle { @Environment(\.theme) private var theme: ThemeSettings @Environment(\.fieldLabelPosition) private var fieldPlaceholderPosition: FieldLabelPosition - @Environment(\.fieldPosition) private var fieldPosition: FieldPosition + @Environment(\.fieldPosition) private var fieldPosition: VerticalAlignment? @Environment(\.platform) private var platform: Platform @FocusState private var isFocused: Bool @Binding private var text: String @@ -21,13 +22,13 @@ public struct LabeledTextFieldStyle: TextFieldStyle { } public func _body(configuration: TextField) -> some View { - VStack(alignment: .leading, spacing: platform == .mac ? .xxxSmall : .xSmall) { + VStack(alignment: .leading, spacing: platform == .macOS ? .xxxSmall : .xSmall) { if fieldPlaceholderPosition == .adjacent { Text(placeholder) .subheadline(.medium) - .foregroundColor(platform == .mac ? .onSurfaceMediumEmphasis : .onSurfaceHighEmphasis) + .foregroundColor(platform == .macOS ? .onSurfaceMediumEmphasis : .onSurfaceHighEmphasis) .frame(maxWidth: .infinity, alignment: .leading) - .offset(x: platform == .mac ? 4 : 0) + .offset(x: platform == .macOS ? 4 : 0) } ZStack(alignment: .leading) { labelTextView @@ -62,7 +63,7 @@ public struct LabeledTextFieldStyle: TextFieldStyle { #endif case .overInput: #if os(macOS) - return .init(horizontal: .xxSmall, vertical: .xSmall) + return .init(.xSmall) #else return .init( top: Space.xxxSmall.rawValue + Space.small.rawValue, @@ -83,27 +84,28 @@ public struct LabeledTextFieldStyle: TextFieldStyle { @ViewBuilder private var fieldBackground: some View { switch fieldPosition { - case .default: + case .top, .bottom, .center: #if canImport(UIKit) - RoundedRectangle( - cornerRadius: fieldRadius, - style: .continuous + RoundedRectangleCorner( + radius: fieldRadius, + corners: backgroundShapeCorners ) .fill(isFocused ? Color.surfacePrimary : Color.surfaceSecondary) #else if fieldPlaceholderPosition != .adjacent { - RoundedRectangle( - cornerRadius: fieldRadius, - style: .continuous + RoundedRectangleCorner( + radius: fieldRadius, + corners: backgroundShapeCorners ) .fill(isFocused ? Color.surfacePrimary : Color.surfaceSecondary) } #endif - case .top, .bottom, .center: + + default: #if canImport(UIKit) - RoundedRectangleCorner( - radius: fieldRadius, - corners: backgroundShapeCorners + RoundedRectangle( + cornerRadius: fieldRadius, + style: .continuous ) .fill(isFocused ? Color.surfacePrimary : Color.surfaceSecondary) #else @@ -118,7 +120,7 @@ public struct LabeledTextFieldStyle: TextFieldStyle { } } - var fieldRadius: Radius { + private var fieldRadius: Radius { #if os(macOS) return .xSmall #else @@ -141,13 +143,28 @@ public struct LabeledTextFieldStyle: TextFieldStyle { } #endif + #if canImport(AppKit) + private var backgroundShapeCorners: RectCorner { + switch fieldPosition { + case .top: + [.topLeft, .topRight] + case .bottom: + [.bottomLeft, .bottomRight] + case .center: + [] + default: + [.allCorners] + } + } + #endif + private var fieldOffset: CGFloat { switch fieldPlaceholderPosition { case .default, .adjacent: .zero case .overInput: #if os(macOS) - text.isEmpty ? 0 : 8 + text.isEmpty && !isFocused ? -2 : text.isEmpty ? 0 : isFocused ? 9 : 7 #else text.isEmpty ? 0 : 10 #endif @@ -157,23 +174,6 @@ public struct LabeledTextFieldStyle: TextFieldStyle { @ViewBuilder private var overlay: some View { switch fieldPosition { - case .default: - #if canImport(UIKit) - RoundedRectangle( - cornerRadius: fieldRadius, - style: .continuous - ) - .stroke(overlayBorderColor, lineWidth: isFocused ? 2 : CGFloat(theme.borderSize)) - #else - if fieldPlaceholderPosition != .adjacent { - RoundedRectangle( - cornerRadius: fieldRadius, - style: .continuous - ) - .stroke(overlayBorderColor, lineWidth: isFocused ? 2 : CGFloat(theme.borderSize)) - } - #endif - case .top, .bottom, .center: #if canImport(UIKit) RoundedRectangleCorner(radius: fieldRadius, corners: backgroundShapeCorners) @@ -181,6 +181,22 @@ public struct LabeledTextFieldStyle: TextFieldStyle { overlayBorderColor, lineWidth: isFocused ? 2 : CGFloat(theme.borderSize) ) + #elseif canImport(AppKit) + if fieldPlaceholderPosition != .adjacent { + RoundedRectangleCorner(radius: fieldRadius, corners: backgroundShapeCorners) + .stroke( + overlayBorderColor, + lineWidth: isFocused ? 2 : CGFloat(theme.borderSize) + ) + } + #endif + default: + #if canImport(UIKit) + RoundedRectangle( + cornerRadius: fieldRadius, + style: .continuous + ) + .stroke(overlayBorderColor, lineWidth: isFocused ? 2 : CGFloat(theme.borderSize)) #else if fieldPlaceholderPosition != .adjacent { RoundedRectangle( @@ -237,6 +253,7 @@ public struct LabeledTextFieldStyle: TextFieldStyle { } } +@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *) public extension TextFieldStyle where Self == LabeledTextFieldStyle { static var `default`: LabeledTextFieldStyle { LabeledTextFieldStyle(placeholder: "", text: .constant("")) @@ -247,6 +264,7 @@ public extension TextFieldStyle where Self == LabeledTextFieldStyle { } } +@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *) struct LabeledTextFieldStyle_Previews: PreviewProvider { static var previews: some View { VStack(spacing: 32) { diff --git a/Sources/OversizeUI/Core/Appearance/ThemeSettings.swift b/Sources/OversizeUI/Core/Appearance/ThemeSettings.swift index 4d12550..f7031be 100644 --- a/Sources/OversizeUI/Core/Appearance/ThemeSettings.swift +++ b/Sources/OversizeUI/Core/Appearance/ThemeSettings.swift @@ -38,8 +38,14 @@ public class ThemeSettings: ObservableObject { @AppStorage(ThemeSettingsNames.borderApp) public var borderApp: Bool = false @AppStorage(ThemeSettingsNames.borderButtons) public var borderButtons: Bool = false + #if os(macOS) + @AppStorage(ThemeSettingsNames.borderTextFields) public var borderTextFields: Bool = true + @AppStorage(ThemeSettingsNames.borderSurface) public var borderSurface: Bool = true + #else @AppStorage(ThemeSettingsNames.borderSurface) public var borderSurface: Bool = false @AppStorage(ThemeSettingsNames.borderTextFields) public var borderTextFields: Bool = false + #endif + @AppStorage(ThemeSettingsNames.borderControls) public var borderControls: Bool = false @AppStorage(ThemeSettingsNames.borderSize) public var borderSize: Double = 0.5 diff --git a/Sources/OversizeUI/Core/EnvironmentKeys/FieldPositionEnvironment.swift b/Sources/OversizeUI/Core/EnvironmentKeys/FieldPositionEnvironment.swift index 5ea8649..9011d73 100644 --- a/Sources/OversizeUI/Core/EnvironmentKeys/FieldPositionEnvironment.swift +++ b/Sources/OversizeUI/Core/EnvironmentKeys/FieldPositionEnvironment.swift @@ -5,23 +5,19 @@ import SwiftUI -public enum FieldPosition { - case `default`, top, bottom, center -} - private struct FieldPositionKey: EnvironmentKey { - public static var defaultValue: FieldPosition = .default + public static var defaultValue: VerticalAlignment? = nil } public extension EnvironmentValues { - var fieldPosition: FieldPosition { + var fieldPosition: VerticalAlignment? { get { self[FieldPositionKey.self] } set { self[FieldPositionKey.self] = newValue } } } public extension View { - func fieldPosition(_ position: FieldPosition) -> some View { + func fieldPosition(_ position: VerticalAlignment?) -> some View { environment(\.fieldPosition, position) } } diff --git a/Sources/OversizeUI/Core/EnvironmentKeys/Platform.swift b/Sources/OversizeUI/Core/EnvironmentKeys/Platform.swift index 853b23b..2122915 100644 --- a/Sources/OversizeUI/Core/EnvironmentKeys/Platform.swift +++ b/Sources/OversizeUI/Core/EnvironmentKeys/Platform.swift @@ -9,15 +9,15 @@ import UIKit #endif public enum Platform { - case iPhone, iPad, mac, tv, watch, vision, carPlay, other + case iPhone, iPadOS, macOS, tvOS, watchOS, visionOS, carPlay, other } private struct PlatformKey: EnvironmentKey { static let defaultValue: Platform = { #if os(macOS) || targetEnvironment(macCatalyst) - return .mac + return .macOS #elseif os(watchOS) - return .watch + return .watchOS #elseif os(visionOS) return .vision #elseif canImport(UIKit) @@ -25,15 +25,15 @@ private struct PlatformKey: EnvironmentKey { case .phone: return .iPhone case .pad: - return .iPad + return .iPadOS case .tv: - return .tv + return .tvOS case .carPlay: return .carPlay case .mac: - return .mac + return .macOS case .vision: - return .vision + return .visionOS case .unspecified: return .other @unknown default: diff --git a/Sources/OversizeUI/Core/Typography.swift b/Sources/OversizeUI/Core/Typography.swift index 12a9631..b779820 100644 --- a/Sources/OversizeUI/Core/Typography.swift +++ b/Sources/OversizeUI/Core/Typography.swift @@ -38,35 +38,71 @@ public struct Typography: ViewModifier { public func body(content: Content) -> some View { content - .font(.system(fontStyle, design: fontDesign).weight(fontWeight).leading(.tight)) - .frame(minHeight: lineHeight) + .font( + .system(fontStyle, design: fontDesign) + .weight(fontWeight) + .leading(.tight) + ) .lineSpacing(lineHeight * 0.2) + .frame(minHeight: lineHeight) } private var lineHeight: CGFloat { switch fontStyle { case .largeTitle: + #if os(macOS) + return 40 + #else return 44 + #endif case .title: + #if os(macOS) + return 32 + #else return 36 + #endif case .title2: + #if os(macOS) + return 24 + #else return 28 + #endif case .title3: + #if os(macOS) + return 20 + #else return 24 + #endif case .headline: + #if os(macOS) + return 20 + #else return 24 + #endif case .subheadline: + #if os(macOS) + return 16 + #else return 20 + #endif case .body: + #if os(macOS) + return 20 + #else return 24 + #endif case .callout: + #if os(macOS) + return 16 + #else return 20 + #endif case .footnote: return 16 case .caption: return 16 case .caption2: - return 12 + return 16 @unknown default: return 16 } diff --git a/Sources/OversizeUI/Deprecated/PageView.swift b/Sources/OversizeUI/Deprecated/PageView.swift index 2004381..d3ccc6a 100644 --- a/Sources/OversizeUI/Deprecated/PageView.swift +++ b/Sources/OversizeUI/Deprecated/PageView.swift @@ -5,6 +5,7 @@ import SwiftUI +@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *) public struct PageView: View where Content: View, LeadingBar: View, TrailingBar: View, TopToolbar: View, TitleLabel: View { @Environment(\.screenSize) var screenSize @@ -271,6 +272,7 @@ public struct PageView } } +@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *) public extension PageView { enum PageViewBottomType { case shadow, gradient, none @@ -281,6 +283,7 @@ public extension PageView { } } +@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *) public extension PageView where LeadingBar == EmptyView, TitleLabel == EmptyView { init(_ title: String? = nil, onOffsetChanged: @escaping (CGFloat) -> Void = { _ in }, @@ -296,6 +299,7 @@ public extension PageView where LeadingBar == EmptyView, TitleLabel == EmptyView } } +@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *) public extension PageView where TrailingBar == EmptyView, TitleLabel == EmptyView { init(_ title: String? = nil, onOffsetChanged: @escaping (CGFloat) -> Void = { _ in }, @@ -311,6 +315,7 @@ public extension PageView where TrailingBar == EmptyView, TitleLabel == EmptyVie } } +@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *) public extension PageView where TrailingBar == EmptyView, LeadingBar == EmptyView, TitleLabel == EmptyView { init(_ title: String? = nil, onOffsetChanged: @escaping (CGFloat) -> Void = { _ in }, @@ -327,6 +332,7 @@ public extension PageView where TrailingBar == EmptyView, LeadingBar == EmptyVie } } +@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *) public extension PageView where TrailingBar == EmptyView, LeadingBar == EmptyView, TopToolbar == EmptyView, TitleLabel == EmptyView { init(_ title: String? = nil, onOffsetChanged: @escaping (CGFloat) -> Void = { _ in }, @@ -344,6 +350,7 @@ public extension PageView where TrailingBar == EmptyView, LeadingBar == EmptyVie } } +@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *) public extension PageView where LeadingBar == EmptyView, TopToolbar == EmptyView, TitleLabel == EmptyView { init(_ title: String? = nil, onOffsetChanged: @escaping (CGFloat) -> Void = { _ in }, @@ -360,6 +367,7 @@ public extension PageView where LeadingBar == EmptyView, TopToolbar == EmptyView } } +@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *) public extension PageView where TrailingBar == EmptyView, TopToolbar == EmptyView, TitleLabel == EmptyView { init(_ title: String? = nil, onOffsetChanged: @escaping (CGFloat) -> Void = { _ in }, @@ -376,6 +384,7 @@ public extension PageView where TrailingBar == EmptyView, TopToolbar == EmptyVie } } +@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *) public extension PageView where TopToolbar == EmptyView, TitleLabel == EmptyView { init(_ title: String? = nil, onOffsetChanged: @escaping (CGFloat) -> Void = { _ in }, @@ -391,6 +400,7 @@ public extension PageView where TopToolbar == EmptyView, TitleLabel == EmptyView } } +@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *) public extension PageView where TrailingBar == EmptyView, LeadingBar == EmptyView, TopToolbar == EmptyView { init(_ title: String? = nil, onOffsetChanged: @escaping (CGFloat) -> Void = { _ in }, @@ -407,6 +417,7 @@ public extension PageView where TrailingBar == EmptyView, LeadingBar == EmptyVie } } +@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *) public extension PageView where TrailingBar == EmptyView, TopToolbar == EmptyView { init(_ title: String? = nil, onOffsetChanged: @escaping (CGFloat) -> Void = { _ in }, @@ -422,6 +433,7 @@ public extension PageView where TrailingBar == EmptyView, TopToolbar == EmptyVie } } +@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *) public extension PageView where LeadingBar == EmptyView, TopToolbar == EmptyView { init(_ title: String? = nil, onOffsetChanged: @escaping (CGFloat) -> Void = { _ in }, @@ -437,6 +449,7 @@ public extension PageView where LeadingBar == EmptyView, TopToolbar == EmptyView } } +@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *) public extension PageView where TrailingBar == EmptyView { init(_ title: String? = nil, onOffsetChanged: @escaping (CGFloat) -> Void = { _ in }, @@ -451,6 +464,7 @@ public extension PageView where TrailingBar == EmptyView { } } +@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *) public extension PageView where LeadingBar == EmptyView { init(_ title: String? = nil, onOffsetChanged: @escaping (CGFloat) -> Void = { _ in }, @@ -465,6 +479,7 @@ public extension PageView where LeadingBar == EmptyView { } } +@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *) public extension PageView where TopToolbar == EmptyView { init(_ title: String? = nil, onOffsetChanged: @escaping (CGFloat) -> Void = { _ in }, @@ -479,6 +494,7 @@ public extension PageView where TopToolbar == EmptyView { } } +@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *) public extension PageView where TitleLabel == EmptyView { init(_ title: String? = nil, onOffsetChanged: @escaping (CGFloat) -> Void = { _ in }, diff --git a/Sources/OversizeUI/Extensions/View/View+CornerRadius.swift b/Sources/OversizeUI/Extensions/View/View+CornerRadius.swift index c3a79c7..366b083 100644 --- a/Sources/OversizeUI/Extensions/View/View+CornerRadius.swift +++ b/Sources/OversizeUI/Extensions/View/View+CornerRadius.swift @@ -3,14 +3,22 @@ // View+CornerRadius.swift, created on 11.09.2021 // -#if os(iOS) import SwiftUI +#if canImport(UIKit) +public extension View { + func cornerRadius(_ radius: CGFloat, corners: UIRectCorner) -> some View { + clipShape(RoundedRectangleCorner(radius: radius, corners: corners)) + } +} +#endif + +#if canImport(AppKit) public extension View { - @available(macOS, unavailable) @available(watchOS, unavailable) @available(tvOS, unavailable) - func cornerRadius(_ radius: CGFloat, corners: UIRectCorner) -> some View { + @available(macOS 14, *) + func cornerRadius(_ radius: CGFloat, corners: RectCorner) -> some View { clipShape(RoundedRectangleCorner(radius: radius, corners: corners)) } } diff --git a/Sources/OversizeUI/Shapes/RoundedRectangleCorner.swift b/Sources/OversizeUI/Shapes/RoundedRectangleCorner.swift index 4de13c5..c41437c 100644 --- a/Sources/OversizeUI/Shapes/RoundedRectangleCorner.swift +++ b/Sources/OversizeUI/Shapes/RoundedRectangleCorner.swift @@ -1,16 +1,22 @@ -// -// Copyright © 2021 Alexander Romanov -// RoundedRectangleCorner.swift, created on 11.09.2021 -// +import SwiftUI #if canImport(UIKit) -import SwiftUI +import UIKit +#elseif canImport(AppKit) +import AppKit +#endif +@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *) public struct RoundedRectangleCorner: Shape { private var radius: CGFloat = .infinity + #if canImport(UIKit) private var corners: UIRectCorner = .allCorners + #else + private var corners: RectCorner = .allCorners + #endif + #if canImport(UIKit) public init(radius: CGFloat, corners: UIRectCorner) { self.radius = radius self.corners = corners @@ -20,11 +26,79 @@ public struct RoundedRectangleCorner: Shape { self.radius = radius.rawValue self.corners = corners } + #else + public init(radius: CGFloat, corners: RectCorner) { + self.radius = radius + self.corners = corners + } + + public init(radius: Radius, corners: RectCorner) { + self.radius = radius.rawValue + self.corners = corners + } + #endif public func path(in rect: CGRect) -> Path { + #if canImport(UIKit) let path = UIBezierPath(roundedRect: rect, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius)) return Path(path.cgPath) + #else + let path = NSBezierPath() + + let topLeftRadius = corners.contains(.topLeft) ? radius : 0 + let topRightRadius = corners.contains(.topRight) ? radius : 0 + let bottomLeftRadius = corners.contains(.bottomLeft) ? radius : 0 + let bottomRightRadius = corners.contains(.bottomRight) ? radius : 0 + + path.move(to: CGPoint(x: rect.minX + topLeftRadius, y: rect.minY)) + + path.line(to: CGPoint(x: rect.maxX - topRightRadius, y: rect.minY)) + if topRightRadius > 0 { + path.curve(to: CGPoint(x: rect.maxX, y: rect.minY + topRightRadius), + controlPoint1: CGPoint(x: rect.maxX - topRightRadius / 2, y: rect.minY), + controlPoint2: CGPoint(x: rect.maxX, y: rect.minY + topRightRadius / 2)) + } + + path.line(to: CGPoint(x: rect.maxX, y: rect.maxY - bottomRightRadius)) + if bottomRightRadius > 0 { + path.curve(to: CGPoint(x: rect.maxX - bottomRightRadius, y: rect.maxY), + controlPoint1: CGPoint(x: rect.maxX, y: rect.maxY - bottomRightRadius / 2), + controlPoint2: CGPoint(x: rect.maxX - bottomRightRadius / 2, y: rect.maxY)) + } + + path.line(to: CGPoint(x: rect.minX + bottomLeftRadius, y: rect.maxY)) + if bottomLeftRadius > 0 { + path.curve(to: CGPoint(x: rect.minX, y: rect.maxY - bottomLeftRadius), + controlPoint1: CGPoint(x: rect.minX + bottomLeftRadius / 2, y: rect.maxY), + controlPoint2: CGPoint(x: rect.minX, y: rect.maxY - bottomLeftRadius / 2)) + } + + path.line(to: CGPoint(x: rect.minX, y: rect.minY + topLeftRadius)) + if topLeftRadius > 0 { + path.curve(to: CGPoint(x: rect.minX + topLeftRadius, y: rect.minY), + controlPoint1: CGPoint(x: rect.minX, y: rect.minY + topLeftRadius / 2), + controlPoint2: CGPoint(x: rect.minX + topLeftRadius / 2, y: rect.minY)) + } + + path.close() + return Path(path.cgPath) + #endif + } +} + +#if !canImport(UIKit) +public struct RectCorner: OptionSet, Sendable { + public let rawValue: Int + + public static let topLeft = RectCorner(rawValue: 1 << 0) + public static let topRight = RectCorner(rawValue: 1 << 1) + public static let bottomLeft = RectCorner(rawValue: 1 << 2) + public static let bottomRight = RectCorner(rawValue: 1 << 3) + public static let allCorners: RectCorner = [.topLeft, .topRight, .bottomLeft, .bottomRight] + + public init(rawValue: Int) { + self.rawValue = rawValue } } #endif From cb908392fb26b654a815d7c56c0915ffc373d752 Mon Sep 17 00:00:00 2001 From: Alexandr Romanov Date: Sun, 6 Oct 2024 11:57:25 +0400 Subject: [PATCH 19/30] Fix watchOS field --- .../OversizeUI/Controls/TextField/LabeledTextFieldStyle.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/OversizeUI/Controls/TextField/LabeledTextFieldStyle.swift b/Sources/OversizeUI/Controls/TextField/LabeledTextFieldStyle.swift index 3407d6e..0e41744 100644 --- a/Sources/OversizeUI/Controls/TextField/LabeledTextFieldStyle.swift +++ b/Sources/OversizeUI/Controls/TextField/LabeledTextFieldStyle.swift @@ -131,14 +131,14 @@ public struct LabeledTextFieldStyle: TextFieldStyle { #if canImport(UIKit) private var backgroundShapeCorners: UIRectCorner { switch fieldPosition { - case .default: - [.allCorners] case .top: [.topLeft, .topRight] case .bottom: [.bottomLeft, .bottomRight] case .center: [] + default: + [.allCorners] } } #endif From 510992719c3f8f387b75d3a36709da413834b498 Mon Sep 17 00:00:00 2001 From: Alexandr Romanov Date: Sun, 6 Oct 2024 12:01:23 +0400 Subject: [PATCH 20/30] Fix iOS build --- Sources/OversizeUI/Controls/Button/FieldButtonStyle.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/OversizeUI/Controls/Button/FieldButtonStyle.swift b/Sources/OversizeUI/Controls/Button/FieldButtonStyle.swift index 1a79818..2af80b3 100644 --- a/Sources/OversizeUI/Controls/Button/FieldButtonStyle.swift +++ b/Sources/OversizeUI/Controls/Button/FieldButtonStyle.swift @@ -65,14 +65,14 @@ public struct FieldButtonStyle: ButtonStyle { @available(tvOS, unavailable) private var backgroundShapeCorners: UIRectCorner { switch fieldPosition { - case .default: - [.allCorners] case .top: [.topLeft, .topRight] case .bottom: [.bottomLeft, .bottomRight] case .center: [] + default: + [.allCorners] } } #endif From 246ff31d819d5cd4ffcda06a4e0c184927b1886d Mon Sep 17 00:00:00 2001 From: Alexandr Romanov Date: Sun, 6 Oct 2024 16:08:06 +0400 Subject: [PATCH 21/30] Fix example --- Example/Example.xcodeproj/project.pbxproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Example/Example.xcodeproj/project.pbxproj b/Example/Example.xcodeproj/project.pbxproj index d445862..cf218d3 100644 --- a/Example/Example.xcodeproj/project.pbxproj +++ b/Example/Example.xcodeproj/project.pbxproj @@ -1246,7 +1246,7 @@ "$(inherited)", "@executable_path/../Frameworks", ); - MACOSX_DEPLOYMENT_TARGET = 13.0; + MACOSX_DEPLOYMENT_TARGET = 14.0; PRODUCT_BUNDLE_IDENTIFIER = romanov.cc.Example; PRODUCT_NAME = Example; SDKROOT = macosx; @@ -1271,7 +1271,7 @@ "$(inherited)", "@executable_path/../Frameworks", ); - MACOSX_DEPLOYMENT_TARGET = 13.0; + MACOSX_DEPLOYMENT_TARGET = 14.0; PRODUCT_BUNDLE_IDENTIFIER = romanov.cc.Example; PRODUCT_NAME = Example; SDKROOT = macosx; From 8af2ddb0a023aa14a645adcb35b660d4db4e1e44 Mon Sep 17 00:00:00 2001 From: Alexandr Romanov Date: Tue, 15 Oct 2024 21:37:26 +0400 Subject: [PATCH 22/30] Adopt Swift 6 --- Package.swift | 2 +- .../Controls/Checkbox/Checkbox.swift | 24 ++- .../ColorSelector/ColorSelectorStyle.swift | 6 +- .../Styles/AnyColorSelectorStyle.swift | 2 +- .../Controls/GridSelect/GridSelectStyle.swift | 12 +- Sources/OversizeUI/Controls/Radio/Radio.swift | 22 +- .../Controls/Radio/RadioPicker.swift | 22 +- .../Controls/SectionView/SectionView.swift | 12 +- .../SegmentedControlStyle.swift | 154 ++++++++------ .../OversizeUI/Controls/Switch/Switch.swift | 24 ++- .../TextField/LabeledTextFieldStyle.swift | 30 --- .../Core/Appearance/Appearance.swift | 4 +- .../OversizeUI/Core/Appearance/Theme.swift | 2 +- .../Core/Appearance/ThemeSettings.swift | 32 +-- Sources/OversizeUI/Core/Colors.swift | 126 +++++------ Sources/OversizeUI/Core/EdgeSpaceInsets.swift | 2 +- Sources/OversizeUI/Core/Elevation.swift | 2 +- .../EnvironmentKeys/AccentEnvironment.swift | 2 +- .../EnvironmentKeys/BorderedEnvironment.swift | 2 +- .../ControlBorderShapeEnvironment.swift | 4 +- .../ControlPaddingEnvironment.swift | 4 +- .../ElevationEnvironment.swift | 2 +- .../FieldLabelPositionEnvironment.swift | 4 +- .../FieldPositionEnvironment.swift | 2 +- .../IconStyleEnvironment.swift | 4 +- .../EnvironmentKeys/LoadingEnvironment.swift | 2 +- .../MultiSelectStyleEnvironment.swift | 4 +- .../Core/EnvironmentKeys/Platform.swift | 54 +++-- .../EnvironmentKeys/PortraitEnvironment.swift | 2 +- .../EnvironmentKeys/PremiumEnvironment.swift | 2 +- .../EnvironmentKeys/RadiusEnvironment.swift | 2 +- .../ScreenSizeEnvironment.swift | 2 +- .../SectionViewStyleEnvironment.swift | 2 +- .../SelectPickerStyleEnvironment.swift | 4 +- .../SurfaceElevationEnvironment.swift | 2 +- .../SurfaceRadiusEnvironment.swift | 2 +- .../EnvironmentKeys/ThemeEnvironment.swift | 2 +- Sources/OversizeUI/Core/Palette.swift | 6 +- .../ScrollOffsetPreferenceKey.swift | 2 +- .../PreferenceKeys/SizePreferenceKey.swift | 2 +- Sources/OversizeUI/Core/Radius.swift | 2 +- Sources/OversizeUI/Core/Space.swift | 2 +- Sources/OversizeUI/Core/Typography.swift | 200 +++++++----------- Sources/OversizeUI/Core/Validation.swift | 2 +- .../ViewModifier/HalfSheet/HalfSheet.swift | 4 +- Sources/OversizeUI/Deprecated/Icon.swift | 10 +- .../Deprecated/TextFieldDeprecated.swift | 173 --------------- .../OversizeUI/Deprecated/ViewOffsetKey.swift | 2 +- .../Extensions/Padding/Padding.swift | 12 +- .../Extensions/Spacing/Spacing.swift | 16 +- .../OversizeUI/Extensions/View/View+If.swift | 2 +- .../Shapes/RoundedRectangleCorner.swift | 2 +- 52 files changed, 410 insertions(+), 609 deletions(-) delete mode 100644 Sources/OversizeUI/Deprecated/TextFieldDeprecated.swift diff --git a/Package.swift b/Package.swift index 9c6c4ca..96be672 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version: 5.9 +// swift-tools-version: 6.0 // The swift-tools-version declares the minimum version of Swift required to build this package. // swiftlint:disable all diff --git a/Sources/OversizeUI/Controls/Checkbox/Checkbox.swift b/Sources/OversizeUI/Controls/Checkbox/Checkbox.swift index 1683531..e72a2d8 100644 --- a/Sources/OversizeUI/Controls/Checkbox/Checkbox.swift +++ b/Sources/OversizeUI/Controls/Checkbox/Checkbox.swift @@ -5,7 +5,7 @@ import SwiftUI -public enum CheckboxAlignment { +public enum CheckboxAlignment: Sendable { case leading, trailing } @@ -115,16 +115,18 @@ public extension Checkbox where Label == EmptyView { } } -struct Checkbox_LibraryContent: LibraryContentProvider { - var views: [LibraryItem] { - LibraryItem( - Checkbox(isOn: .constant(false), label: { - Text("Text") - }), - title: "Checkbox", category: .control - ) - } -} +/* + struct Checkbox_LibraryContent: LibraryContentProvider { + var views: [LibraryItem] { + LibraryItem( + Checkbox(isOn: .constant(false), label: { + Text("Text") + }), + title: "Checkbox", category: .control + ) + } + } + */ struct Checkbox_preview: PreviewProvider { static var previews: some View { diff --git a/Sources/OversizeUI/Controls/ColorSelector/ColorSelectorStyle.swift b/Sources/OversizeUI/Controls/ColorSelector/ColorSelectorStyle.swift index 03f792a..42ae91a 100644 --- a/Sources/OversizeUI/Controls/ColorSelector/ColorSelectorStyle.swift +++ b/Sources/OversizeUI/Controls/ColorSelector/ColorSelectorStyle.swift @@ -5,14 +5,14 @@ import SwiftUI -public protocol ColorSelectorStyle { +public protocol ColorSelectorStyle: Sendable { associatedtype Body: View typealias Configuration = ColorSelectorConfiguration func makeBody(configuration: Self.Configuration) -> Self.Body } -public struct ColorSelectorConfiguration { +public struct ColorSelectorConfiguration: Sendable { public struct Label: View { public init(content: some View) { body = AnyView(content) @@ -31,7 +31,7 @@ public struct DefaultColorSelectorStyle: ColorSelectorStyle { } struct ColorSelectorStyleStyleKey: EnvironmentKey { - public static var defaultValue = AnyColorSelectorStyle(style: DefaultColorSelectorStyle()) + public static let defaultValue = AnyColorSelectorStyle(style: DefaultColorSelectorStyle()) } public extension EnvironmentValues { diff --git a/Sources/OversizeUI/Controls/ColorSelector/Styles/AnyColorSelectorStyle.swift b/Sources/OversizeUI/Controls/ColorSelector/Styles/AnyColorSelectorStyle.swift index 2ce0164..e99bffd 100644 --- a/Sources/OversizeUI/Controls/ColorSelector/Styles/AnyColorSelectorStyle.swift +++ b/Sources/OversizeUI/Controls/ColorSelector/Styles/AnyColorSelectorStyle.swift @@ -6,7 +6,7 @@ import SwiftUI public struct AnyColorSelectorStyle: ColorSelectorStyle { - private var _makeBody: (Configuration) -> AnyView + private var _makeBody: @Sendable (Configuration) -> AnyView public init(style: some ColorSelectorStyle) { _makeBody = { configuration in diff --git a/Sources/OversizeUI/Controls/GridSelect/GridSelectStyle.swift b/Sources/OversizeUI/Controls/GridSelect/GridSelectStyle.swift index 0023816..d097c13 100644 --- a/Sources/OversizeUI/Controls/GridSelect/GridSelectStyle.swift +++ b/Sources/OversizeUI/Controls/GridSelect/GridSelectStyle.swift @@ -57,24 +57,24 @@ public struct SelectionOnlyGridSelectStyle: GridSelectStyle { // MARK: - Support -public enum GridSelectSeletionIconStyle { +public enum GridSelectSeletionIconStyle: Sendable { case none case checkbox(alignment: Alignment = .bottomTrailing) case radio(alignment: Alignment = .bottomTrailing) } -public enum GridSelectSeletionStyle { +public enum GridSelectSeletionStyle: Sendable { case shadowSurface case graySurface case accentSurface } -public enum GridSelectUnseletionStyle { +public enum GridSelectUnseletionStyle: Sendable { case clean case surface } -public protocol GridSelectStyle { +public protocol GridSelectStyle: Sendable { associatedtype Body: View typealias Configuration = GridSelectConfiguration @@ -103,7 +103,7 @@ public struct AnyGridSelectStyle: GridSelectStyle { public var unseletionStyle: GridSelectUnseletionStyle public var icon: GridSelectSeletionIconStyle - private var _makeBody: (Configuration) -> AnyView + private var _makeBody: @Sendable (Configuration) -> AnyView public init( seletionStyle: GridSelectSeletionStyle, @@ -125,7 +125,7 @@ public struct AnyGridSelectStyle: GridSelectStyle { } struct GridSelectStyleKey: EnvironmentKey { - public static var defaultValue = AnyGridSelectStyle(seletionStyle: .accentSurface, + public static let defaultValue = AnyGridSelectStyle(seletionStyle: .accentSurface, unseletionStyle: .surface, icon: .none, style: IslandGridSelectStyle()) diff --git a/Sources/OversizeUI/Controls/Radio/Radio.swift b/Sources/OversizeUI/Controls/Radio/Radio.swift index 4bc8a4f..caf8b8d 100644 --- a/Sources/OversizeUI/Controls/Radio/Radio.swift +++ b/Sources/OversizeUI/Controls/Radio/Radio.swift @@ -121,16 +121,18 @@ public extension Radio where Label == EmptyView { } } -struct Radio_LibraryContent: LibraryContentProvider { - var views: [LibraryItem] { - LibraryItem( - Radio(isOn: false, alignment: .leading, label: { - Text("Text") - }), - title: "Chip", category: .control - ) - } -} +/* + struct Radio_LibraryContent: LibraryContentProvider { + var views: [LibraryItem] { + LibraryItem( + Radio(isOn: false, alignment: .leading, label: { + Text("Text") + }), + title: "Chip", category: .control + ) + } + } + */ struct Radio_preview: PreviewProvider { struct RadioPreview: View { diff --git a/Sources/OversizeUI/Controls/Radio/RadioPicker.swift b/Sources/OversizeUI/Controls/Radio/RadioPicker.swift index 0663843..d05b5d2 100644 --- a/Sources/OversizeUI/Controls/Radio/RadioPicker.swift +++ b/Sources/OversizeUI/Controls/Radio/RadioPicker.swift @@ -54,16 +54,18 @@ public struct RadioPicker: View where Content: View } } -struct RadioPicker_LibraryContent: LibraryContentProvider { - var views: [LibraryItem] { - LibraryItem( - RadioPicker(["One", "Two"], selection: .constant("One")) { item in - Text(item) - }, - title: "Radio Picker", category: .control - ) - } -} +/* + struct RadioPicker_LibraryContent: LibraryContentProvider { + var views: [LibraryItem] { + LibraryItem( + RadioPicker(["One", "Two"], selection: .constant("One")) { item in + Text(item) + }, + title: "Radio Picker", category: .control + ) + } + } + */ struct RadioPicker_previw: PreviewProvider { struct RadioPickerPreview: View { diff --git a/Sources/OversizeUI/Controls/SectionView/SectionView.swift b/Sources/OversizeUI/Controls/SectionView/SectionView.swift index 9822275..b1fb071 100644 --- a/Sources/OversizeUI/Controls/SectionView/SectionView.swift +++ b/Sources/OversizeUI/Controls/SectionView/SectionView.swift @@ -5,20 +5,20 @@ import SwiftUI -public enum SectionViewTitlePosition { +public enum SectionViewTitlePosition: Sendable { case inside, outside } -public enum SectionViewTitleButtonPosition { +public enum SectionViewTitleButtonPosition: Sendable { case leading, trailing } -public enum SectionViewTitleButton { - case arrow(_ action: () -> Void) - case title(_ title: String, _ action: () -> Void) +public enum SectionViewTitleButton: Sendable { + case arrow(_ action: @Sendable () -> Void) + case title(_ title: String, _ action: @Sendable () -> Void) } -public enum SectionViewStyle { +public enum SectionViewStyle: Sendable { case `default`, smallIndent, edgeToEdge } diff --git a/Sources/OversizeUI/Controls/SegmentedControl/SegmentedControlStyle.swift b/Sources/OversizeUI/Controls/SegmentedControl/SegmentedControlStyle.swift index 29286b9..7d634db 100644 --- a/Sources/OversizeUI/Controls/SegmentedControl/SegmentedControlStyle.swift +++ b/Sources/OversizeUI/Controls/SegmentedControl/SegmentedControlStyle.swift @@ -7,7 +7,7 @@ import SwiftUI // MARK: - Styles -public enum SegmentedControlStyleType { +public enum SegmentedControlStyleType: Sendable { case `default` case island(selected: SegmentedControlSeletionStyle = .shadowSurface) case islandLeading(selected: SegmentedControlSeletionStyle = .shadowSurface) @@ -17,13 +17,13 @@ public enum SegmentedControlStyleType { case onlySelectionScroll(selected: SegmentedControlSeletionStyle = .shadowSurface) } -public enum SegmentedControlSeletionStyle { +public enum SegmentedControlSeletionStyle: Sendable { case shadowSurface case graySurface case accentSurface } -public enum SegmentedControlUnseletionStyle { +public enum SegmentedControlUnseletionStyle: Sendable { case clean case surface } @@ -35,66 +35,94 @@ public extension View { case .default: let style: RectangleSegmentedControlStyle = .init() - return environment(\.segmentedControlStyle, - AnySegmentedControlStyle(isEquallySpacing: style.isEquallySpacing, - isShowBackground: style.isShowBackground, - seletionStyle: style.seletionStyle, - unseletionStyle: style.unseletionStyle, - style: style)) + return environment( + \.segmentedControlStyle, + AnySegmentedControlStyle( + isEquallySpacing: style.isEquallySpacing, + isShowBackground: style.isShowBackground, + seletionStyle: style.seletionStyle, + unseletionStyle: style.unseletionStyle, + style: style + ) + ) case let .island(selected: selected): let style: IslandSegmentedControlStyle = .init() - return environment(\.segmentedControlStyle, - AnySegmentedControlStyle(isEquallySpacing: true, - isShowBackground: false, - seletionStyle: selected, - unseletionStyle: .surface, - style: style)) + return environment( + \.segmentedControlStyle, + AnySegmentedControlStyle( + isEquallySpacing: true, + isShowBackground: false, + seletionStyle: selected, + unseletionStyle: .surface, + style: style + ) + ) case let .islandScroll(selected: selected): let style: ScrollSegmentedControlStyle = .init() - return environment(\.segmentedControlStyle, - AnySegmentedControlStyle(isEquallySpacing: false, - isShowBackground: false, - seletionStyle: selected, - unseletionStyle: .surface, - style: style)) + return environment( + \.segmentedControlStyle, + AnySegmentedControlStyle( + isEquallySpacing: false, + isShowBackground: false, + seletionStyle: selected, + unseletionStyle: .surface, + style: style + ) + ) case let .onlySelection(selected: selected): let style: SelectionOnlySegmentedControlStyle = .init() - return environment(\.segmentedControlStyle, - AnySegmentedControlStyle(isEquallySpacing: true, - isShowBackground: false, - seletionStyle: selected, - unseletionStyle: .clean, - style: style)) + return environment( + \.segmentedControlStyle, + AnySegmentedControlStyle( + isEquallySpacing: true, + isShowBackground: false, + seletionStyle: selected, + unseletionStyle: .clean, + style: style + ) + ) case let .onlySelectionLeading(selected: selected): let style: SelectionOnlySegmentedControlStyle = .init() - return environment(\.segmentedControlStyle, - AnySegmentedControlStyle(isEquallySpacing: false, - isShowBackground: false, - seletionStyle: selected, - unseletionStyle: .clean, - style: style)) + return environment( + \.segmentedControlStyle, + AnySegmentedControlStyle( + isEquallySpacing: false, + isShowBackground: false, + seletionStyle: selected, + unseletionStyle: .clean, + style: style + ) + ) case let .onlySelectionScroll(selected: selected): let style: ScrollSegmentedControlStyle = .init() - return environment(\.segmentedControlStyle, - AnySegmentedControlStyle(isEquallySpacing: false, - isShowBackground: false, - seletionStyle: selected, - unseletionStyle: .clean, - style: style)) + return environment( + \.segmentedControlStyle, + AnySegmentedControlStyle( + isEquallySpacing: false, + isShowBackground: false, + seletionStyle: selected, + unseletionStyle: .clean, + style: style + ) + ) case let .islandLeading(selected: selected): let style: IslandSegmentedControlStyle = .init() - return environment(\.segmentedControlStyle, - AnySegmentedControlStyle(isEquallySpacing: false, - isShowBackground: false, - seletionStyle: selected, - unseletionStyle: .surface, - style: style)) + return environment( + \.segmentedControlStyle, + AnySegmentedControlStyle( + isEquallySpacing: false, + isShowBackground: false, + seletionStyle: selected, + unseletionStyle: .surface, + style: style + ) + ) } } } @@ -187,7 +215,7 @@ public struct IslandSegmentedControlStyle: SegmentedControlStyle { // MARK: - Support -public protocol SegmentedControlStyle { +public protocol SegmentedControlStyle: Sendable { associatedtype Body: View typealias Configuration = SegmentedControlConfiguration @@ -199,7 +227,7 @@ public protocol SegmentedControlStyle { func makeBody(configuration: Self.Configuration) -> Self.Body } -public struct SegmentedControlConfiguration { +public struct SegmentedControlConfiguration: Sendable { public struct Label: View { public init(content: some View) { body = AnyView(content) @@ -211,7 +239,7 @@ public struct SegmentedControlConfiguration { public let label: SegmentedControlConfiguration.Label } -public struct AnySegmentedControlStyle: SegmentedControlStyle { +public struct AnySegmentedControlStyle: SegmentedControlStyle, Sendable { public var isEquallySpacing: Bool public var isShowBackground: Bool @@ -220,7 +248,7 @@ public struct AnySegmentedControlStyle: SegmentedControlStyle { public var unseletionStyle: SegmentedControlUnseletionStyle - private var _makeBody: (Configuration) -> AnyView + private var _makeBody: @Sendable (Configuration) -> AnyView public init(isEquallySpacing: Bool, isShowBackground: Bool, @@ -243,11 +271,13 @@ public struct AnySegmentedControlStyle: SegmentedControlStyle { } public struct SegmentedControlKey: EnvironmentKey { - public static var defaultValue = AnySegmentedControlStyle(isEquallySpacing: true, - isShowBackground: true, - seletionStyle: .shadowSurface, - unseletionStyle: .clean, - style: RectangleSegmentedControlStyle()) + public static let defaultValue = AnySegmentedControlStyle( + isEquallySpacing: true, + isShowBackground: true, + seletionStyle: .shadowSurface, + unseletionStyle: .clean, + style: RectangleSegmentedControlStyle() + ) } public extension EnvironmentValues { @@ -259,11 +289,15 @@ public extension EnvironmentValues { public extension View { func segmentedControlStyle(_ style: some SegmentedControlStyle) -> some View { - environment(\.segmentedControlStyle, - AnySegmentedControlStyle(isEquallySpacing: style.isEquallySpacing, - isShowBackground: style.isShowBackground, - seletionStyle: style.seletionStyle, - unseletionStyle: style.unseletionStyle, - style: style)) + environment( + \.segmentedControlStyle, + AnySegmentedControlStyle( + isEquallySpacing: style.isEquallySpacing, + isShowBackground: style.isShowBackground, + seletionStyle: style.seletionStyle, + unseletionStyle: style.unseletionStyle, + style: style + ) + ) } } diff --git a/Sources/OversizeUI/Controls/Switch/Switch.swift b/Sources/OversizeUI/Controls/Switch/Switch.swift index dac048d..da141b3 100644 --- a/Sources/OversizeUI/Controls/Switch/Switch.swift +++ b/Sources/OversizeUI/Controls/Switch/Switch.swift @@ -110,17 +110,19 @@ public extension Switch where Label == EmptyView { } } -@available(iOS 14.0, *) -struct Switch_LibraryContent: LibraryContentProvider { - var views: [LibraryItem] { - LibraryItem( - Switch(isOn: .constant(false)) { - Text("Text") - }, - title: "Checkbox", category: .control - ) - } -} +/* + @available(iOS 14.0, *) + struct Switch_LibraryContent: LibraryContentProvider { + var views: [LibraryItem] { + LibraryItem( + Switch(isOn: .constant(false)) { + Text("Text") + }, + title: "Checkbox", category: .control + ) + } + } + */ struct Switch_preview: PreviewProvider { static var previews: some View { diff --git a/Sources/OversizeUI/Controls/TextField/LabeledTextFieldStyle.swift b/Sources/OversizeUI/Controls/TextField/LabeledTextFieldStyle.swift index 0e41744..0190799 100644 --- a/Sources/OversizeUI/Controls/TextField/LabeledTextFieldStyle.swift +++ b/Sources/OversizeUI/Controls/TextField/LabeledTextFieldStyle.swift @@ -263,33 +263,3 @@ public extension TextFieldStyle where Self == LabeledTextFieldStyle { LabeledTextFieldStyle(placeholder: placeholder, text: text) } } - -@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *) -struct LabeledTextFieldStyle_Previews: PreviewProvider { - static var previews: some View { - VStack(spacing: 32) { - TextField("Text", text: .constant("Placeholder")) - .textFieldStyle(.default) - - TextField("Text", text: .constant("Placeholder")) - .textFieldStyle(OverPlaceholderTextFieldStyle(placeholder: "Label")) - - TextField("Text", text: .constant("Placeholder")) - .textFieldStyle(InsidePlaceholderTextFieldStyle(placeholder: "Label")) - - TextField("Text", text: .constant("Placeholder")) - .textFieldStyle(DefaultPlaceholderTextFieldStyle()) - .fieldHelper(.constant("Help"), style: .constant(.helperText)) - - TextField("Text", text: .constant("Placeholder")) - .textFieldStyle(OverPlaceholderTextFieldStyle(placeholder: "Label")) - .fieldHelper(.constant("Ok"), style: .constant(.sussesText)) - - TextField("Text", text: .constant("Placeholder")) - .textFieldStyle(InsidePlaceholderTextFieldStyle(placeholder: "Label")) - .fieldHelper(.constant("Error"), style: .constant(.errorText)) - - }.padding() - .previewLayout(.sizeThatFits) - } -} diff --git a/Sources/OversizeUI/Core/Appearance/Appearance.swift b/Sources/OversizeUI/Core/Appearance/Appearance.swift index 7eff3b9..10eaed3 100644 --- a/Sources/OversizeUI/Core/Appearance/Appearance.swift +++ b/Sources/OversizeUI/Core/Appearance/Appearance.swift @@ -5,7 +5,7 @@ import SwiftUI -public enum Appearance: Int { +public enum Appearance: Int, Sendable { case system case light case dark @@ -43,5 +43,5 @@ public enum Appearance: Int { } } - public static var allCases: [Appearance] = [.system, .light, .dark] + public static let allCases: [Appearance] = [.system, .light, .dark] } diff --git a/Sources/OversizeUI/Core/Appearance/Theme.swift b/Sources/OversizeUI/Core/Appearance/Theme.swift index 7f58413..96cc35a 100644 --- a/Sources/OversizeUI/Core/Appearance/Theme.swift +++ b/Sources/OversizeUI/Core/Appearance/Theme.swift @@ -6,7 +6,7 @@ import SwiftUI // swiftlint:disable identifier_name -public struct Theme: Identifiable { +public struct Theme: Identifiable, Sendable { public let id: Int public let name: String public let accentColor: Color diff --git a/Sources/OversizeUI/Core/Appearance/ThemeSettings.swift b/Sources/OversizeUI/Core/Appearance/ThemeSettings.swift index f7031be..d710d9d 100644 --- a/Sources/OversizeUI/Core/Appearance/ThemeSettings.swift +++ b/Sources/OversizeUI/Core/Appearance/ThemeSettings.swift @@ -5,24 +5,24 @@ import SwiftUI -public enum ThemeSettingsNames { - public static var appearance = "Settings.Appearance" - public static var accentColor = "Settings.AccentColor" - public static var fontTitle = "Settings.FontTitle" - public static var fontParagraph = "Settings.FontParagraph" - public static var fontButton = "Settings.FontButton" - public static var fontOverline = "Settings.FontOverline" - public static var borderApp = "Settings.BorderApp" - public static var borderButtons = "Settings.BorderButtons" - public static var borderSurface = "Settings.BorderSurface" - public static var borderTextFields = "Settings.BorderTextFields" - public static var borderControls = "Settings.BorderControls" - public static var borderSize = "Settings.BorderSize" - public static var theme = "Settings.Theme" - public static var radius = "Settings.Radius" +public enum ThemeSettingsNames: Sendable { + public static let appearance = "Settings.Appearance" + public static let accentColor = "Settings.AccentColor" + public static let fontTitle = "Settings.FontTitle" + public static let fontParagraph = "Settings.FontParagraph" + public static let fontButton = "Settings.FontButton" + public static let fontOverline = "Settings.FontOverline" + public static let borderApp = "Settings.BorderApp" + public static let borderButtons = "Settings.BorderButtons" + public static let borderSurface = "Settings.BorderSurface" + public static let borderTextFields = "Settings.BorderTextFields" + public static let borderControls = "Settings.BorderControls" + public static let borderSize = "Settings.BorderSize" + public static let theme = "Settings.Theme" + public static let radius = "Settings.Radius" } -public class ThemeSettings: ObservableObject { +public class ThemeSettings: ObservableObject, @unchecked Sendable { public init() {} @AppStorage(ThemeSettingsNames.appearance) public var appearance: Appearance = .system diff --git a/Sources/OversizeUI/Core/Colors.swift b/Sources/OversizeUI/Core/Colors.swift index 3a275b5..6dd7271 100644 --- a/Sources/OversizeUI/Core/Colors.swift +++ b/Sources/OversizeUI/Core/Colors.swift @@ -126,87 +126,87 @@ public extension Color { // MARK: - Foreground Color Extension public extension View { - func onPrimaryHighEmphasisForegroundColor() -> some View { + nonisolated func onPrimaryHighEmphasisForegroundColor() -> some View { foregroundColor(Color.onPrimaryHighEmphasis) } - func onPrimaryMediumEmphasisForegroundColor() -> some View { + nonisolated func onPrimaryMediumEmphasisForegroundColor() -> some View { foregroundColor(Color.onPrimaryMediumEmphasis) } - func onPrimaryDisabledForegroundColor() -> some View { + nonisolated func onPrimaryDisabledForegroundColor() -> some View { foregroundColor(Color.onPrimaryDisabled) } - func backgroundPrimaryForegroundColor() -> some View { + nonisolated func backgroundPrimaryForegroundColor() -> some View { foregroundColor(Color.backgroundPrimary) } - func backgroundSecondaryForegroundColor() -> some View { + nonisolated func backgroundSecondaryForegroundColor() -> some View { foregroundColor(Color.backgroundSecondary) } - func backgroundTertiaryForegroundColor() -> some View { + nonisolated func backgroundTertiaryForegroundColor() -> some View { foregroundColor(Color.backgroundTertiary) } - func onBackgroundHighEmphasisForegroundColor() -> some View { + nonisolated func onBackgroundHighEmphasisForegroundColor() -> some View { foregroundColor(Color.onBackgroundHighEmphasis) } - func onBackgroundMediumEmphasisForegroundColor() -> some View { + nonisolated func onBackgroundMediumEmphasisForegroundColor() -> some View { foregroundColor(Color.onBackgroundMediumEmphasis) } - func onBackgroundDisabledForegroundColor() -> some View { + nonisolated func onBackgroundDisabledForegroundColor() -> some View { foregroundColor(Color.onBackgroundDisabled) } - func surfacePrimaryForegroundColor() -> some View { + nonisolated func surfacePrimaryForegroundColor() -> some View { foregroundColor(Color.surfacePrimary) } - func surfaceSecondaryForegroundColor() -> some View { + nonisolated func surfaceSecondaryForegroundColor() -> some View { foregroundColor(Color.surfaceSecondary) } - func surfaceTertiaryForegroundColor() -> some View { + nonisolated func surfaceTertiaryForegroundColor() -> some View { foregroundColor(Color.surfaceTertiary) } - func onSurfaceHighEmphasisForegroundColor() -> some View { + nonisolated func onSurfaceHighEmphasisForegroundColor() -> some View { foregroundColor(Color.onSurfaceHighEmphasis) } - func onSurfaceMediumEmphasisForegroundColor() -> some View { + nonisolated func onSurfaceMediumEmphasisForegroundColor() -> some View { foregroundColor(Color.onSurfaceMediumEmphasis) } - func onSurfaceDisabledForegroundColor() -> some View { + nonisolated func onSurfaceDisabledForegroundColor() -> some View { foregroundColor(Color.onSurfaceDisabled) } - func accentForegroundColor() -> some View { + nonisolated func accentForegroundColor() -> some View { foregroundColor(Color.accentColor) } - func errorForegroundColor() -> some View { + nonisolated func errorForegroundColor() -> some View { foregroundColor(Color.error) } - func successForegroundColor() -> some View { + nonisolated func successForegroundColor() -> some View { foregroundColor(Color.success) } - func warningForegroundColor() -> some View { + nonisolated func warningForegroundColor() -> some View { foregroundColor(Color.warning) } - func linkForegroundColor() -> some View { + nonisolated func linkForegroundColor() -> some View { foregroundColor(Color.link) } - func borderForegroundColor() -> some View { + nonisolated func borderForegroundColor() -> some View { foregroundColor(Color.border) } } @@ -214,194 +214,194 @@ public extension View { // MARK: - Fill Color Extension public extension Shape { - func fillOnPrimaryHighEmphasis() -> some View { + nonisolated func fillOnPrimaryHighEmphasis() -> some View { fill(Color.onPrimaryHighEmphasis) } - func fillOnPrimaryMediumEmphasis() -> some View { + nonisolated func fillOnPrimaryMediumEmphasis() -> some View { fill(Color.onPrimaryMediumEmphasis) } - func fillOnPrimaryDisabled() -> some View { + nonisolated func fillOnPrimaryDisabled() -> some View { fill(Color.onPrimaryDisabled) } - func fillAccent() -> some View { + nonisolated func fillAccent() -> some View { fill(Color.accentColor) } - func fillBackgroundPrimary() -> some View { + nonisolated func fillBackgroundPrimary() -> some View { fill(Color.backgroundPrimary) } - func fillBackgroundSecondary() -> some View { + nonisolated func fillBackgroundSecondary() -> some View { fill(Color.backgroundSecondary) } - func fillBackgroundTertiary() -> some View { + nonisolated func fillBackgroundTertiary() -> some View { fill(Color.backgroundTertiary) } - func fillOnBackgroundHighEmphasis() -> some View { + nonisolated func fillOnBackgroundHighEmphasis() -> some View { fill(Color.onBackgroundHighEmphasis) } - func fillOnBackgroundMediumEmphasis() -> some View { + nonisolated func fillOnBackgroundMediumEmphasis() -> some View { fill(Color.onBackgroundMediumEmphasis) } - func fillOnBackgroundDisabled() -> some View { + nonisolated func fillOnBackgroundDisabled() -> some View { fill(Color.onBackgroundDisabled) } - func fillSurfacePrimary() -> some View { + nonisolated func fillSurfacePrimary() -> some View { fill(Color.surfacePrimary) } - func fillSurfaceSecondary() -> some View { + nonisolated func fillSurfaceSecondary() -> some View { fill(Color.surfaceSecondary) } - func fillSurfaceTertiary() -> some View { + nonisolated func fillSurfaceTertiary() -> some View { fill(Color.surfaceTertiary) } - func fillOnSurfaceHighEmphasis() -> some View { + nonisolated func fillOnSurfaceHighEmphasis() -> some View { fill(Color.onSurfaceHighEmphasis) } - func fillOnSurfaceMediumEmphasis() -> some View { + nonisolated func fillOnSurfaceMediumEmphasis() -> some View { fill(Color.onSurfaceMediumEmphasis) } - func fillOnSurfaceDisabled() -> some View { + nonisolated func fillOnSurfaceDisabled() -> some View { fill(Color.onSurfaceDisabled) } - func fillError() -> some View { + nonisolated func fillError() -> some View { fill(Color.error) } - func fillSuccess() -> some View { + nonisolated func fillSuccess() -> some View { fill(Color.success) } - func fillWarning() -> some View { + nonisolated func fillWarning() -> some View { fill(Color.warning) } - func fillLink() -> some View { + nonisolated func fillLink() -> some View { fill(Color.link) } - func fillBorder() -> some View { + nonisolated func fillBorder() -> some View { fill(Color.border) } } public extension View { @available(*, deprecated, renamed: "onPrimaryHighEmphasisForegroundColor") - func foregroundOnPrimaryHighEmphasis() -> some View { + nonisolated func foregroundOnPrimaryHighEmphasis() -> some View { foregroundColor(Color.onPrimaryHighEmphasis) } @available(*, deprecated, renamed: "onPrimaryMediumEmphasisForegroundColor") - func foregroundOnPrimaryMediumEmphasis() -> some View { + nonisolated func foregroundOnPrimaryMediumEmphasis() -> some View { foregroundColor(Color.onPrimaryMediumEmphasis) } @available(*, deprecated, renamed: "onPrimaryDisabledForegroundColor") - func foregroundOnPrimaryDisabled() -> some View { + nonisolated func foregroundOnPrimaryDisabled() -> some View { foregroundColor(Color.onPrimaryDisabled) } @available(*, deprecated, renamed: "accentForegroundColor") - func foregroundAccent() -> some View { + nonisolated func foregroundAccent() -> some View { foregroundColor(Color.accentColor) } @available(*, deprecated, renamed: "backgroundPrimaryForegroundColor") - func foregroundBackgroundPrimary() -> some View { + nonisolated func foregroundBackgroundPrimary() -> some View { foregroundColor(Color.backgroundPrimary) } @available(*, deprecated, renamed: "backgroundSecondaryForegroundColor") - func foregroundBackgroundSecondary() -> some View { + nonisolated func foregroundBackgroundSecondary() -> some View { foregroundColor(Color.backgroundSecondary) } @available(*, deprecated, renamed: "backgroundTertiaryForegroundColor") - func foregroundBackgroundTertiary() -> some View { + nonisolated func foregroundBackgroundTertiary() -> some View { foregroundColor(Color.backgroundTertiary) } @available(*, deprecated, renamed: "onBackgroundHighEmphasisForegroundColor") - func foregroundOnBackgroundHighEmphasis() -> some View { + nonisolated func foregroundOnBackgroundHighEmphasis() -> some View { foregroundColor(Color.onBackgroundHighEmphasis) } @available(*, deprecated, renamed: "onBackgroundMediumEmphasisForegroundColor") - func foregroundOnBackgroundMediumEmphasis() -> some View { + nonisolated func foregroundOnBackgroundMediumEmphasis() -> some View { foregroundColor(Color.onBackgroundMediumEmphasis) } @available(*, deprecated, renamed: "onBackgroundDisabledForegroundColor") - func foregroundOnBackgroundDisabled() -> some View { + nonisolated func foregroundOnBackgroundDisabled() -> some View { foregroundColor(Color.onBackgroundDisabled) } @available(*, deprecated, renamed: "surfacePrimaryForegroundColor") - func foregroundSurfacePrimary() -> some View { + nonisolated func foregroundSurfacePrimary() -> some View { foregroundColor(Color.surfacePrimary) } @available(*, deprecated, renamed: "surfaceSecondaryForegroundColor") - func foregroundSurfaceSecondary() -> some View { + nonisolated func foregroundSurfaceSecondary() -> some View { foregroundColor(Color.surfaceSecondary) } @available(*, deprecated, renamed: "aurfaceTertiaryForegroundColor") - func foregroundSurfaceTertiary() -> some View { + nonisolated func foregroundSurfaceTertiary() -> some View { foregroundColor(Color.surfaceTertiary) } @available(*, deprecated, renamed: "onSurfaceHighEmphasisForegroundColor") - func foregroundOnSurfaceHighEmphasis() -> some View { + nonisolated func foregroundOnSurfaceHighEmphasis() -> some View { foregroundColor(Color.onSurfaceHighEmphasis) } @available(*, deprecated, renamed: "onSurfaceMediumEmphasisForegroundColor") - func foregroundOnSurfaceMediumEmphasis() -> some View { + nonisolated func foregroundOnSurfaceMediumEmphasis() -> some View { foregroundColor(Color.onSurfaceMediumEmphasis) } @available(*, deprecated, renamed: "onSurfaceDisabledForegroundColor") - func foregroundOnSurfaceDisabled() -> some View { + nonisolated func foregroundOnSurfaceDisabled() -> some View { foregroundColor(Color.onSurfaceDisabled) } @available(*, deprecated, renamed: "errorForegroundColor") - func foregroundError() -> some View { + nonisolated func foregroundError() -> some View { foregroundColor(Color.error) } @available(*, deprecated, renamed: "successForegroundColor") - func foregroundSuccess() -> some View { + nonisolated func foregroundSuccess() -> some View { foregroundColor(Color.success) } @available(*, deprecated, renamed: "warningForegroundColor") - func foregroundWarning() -> some View { + nonisolated func foregroundWarning() -> some View { foregroundColor(Color.warning) } @available(*, deprecated, renamed: "linkForegroundColor") - func foregroundLink() -> some View { + nonisolated func foregroundLink() -> some View { foregroundColor(Color.link) } @available(*, deprecated, renamed: "borderForegroundColor") - func foregroundBorder() -> some View { + nonisolated func foregroundBorder() -> some View { foregroundColor(Color.border) } } diff --git a/Sources/OversizeUI/Core/EdgeSpaceInsets.swift b/Sources/OversizeUI/Core/EdgeSpaceInsets.swift index f3fcf0b..9426e18 100644 --- a/Sources/OversizeUI/Core/EdgeSpaceInsets.swift +++ b/Sources/OversizeUI/Core/EdgeSpaceInsets.swift @@ -5,7 +5,7 @@ import Foundation -public struct EdgeSpaceInsets { +public struct EdgeSpaceInsets: Sendable { public let top: Space public let leading: Space public let bottom: Space diff --git a/Sources/OversizeUI/Core/Elevation.swift b/Sources/OversizeUI/Core/Elevation.swift index 108eeb4..57db644 100644 --- a/Sources/OversizeUI/Core/Elevation.swift +++ b/Sources/OversizeUI/Core/Elevation.swift @@ -6,7 +6,7 @@ import SwiftUI // swiftlint:disable identifier_name -public enum Elevation: Int, CaseIterable { +public enum Elevation: Int, CaseIterable, Sendable { case z0 case z1 case z2 diff --git a/Sources/OversizeUI/Core/EnvironmentKeys/AccentEnvironment.swift b/Sources/OversizeUI/Core/EnvironmentKeys/AccentEnvironment.swift index 2b3c744..dce7fa4 100644 --- a/Sources/OversizeUI/Core/EnvironmentKeys/AccentEnvironment.swift +++ b/Sources/OversizeUI/Core/EnvironmentKeys/AccentEnvironment.swift @@ -6,7 +6,7 @@ import SwiftUI private struct AccentStateKey: EnvironmentKey { - public static var defaultValue: Bool = false + public static let defaultValue: Bool = false } public extension EnvironmentValues { diff --git a/Sources/OversizeUI/Core/EnvironmentKeys/BorderedEnvironment.swift b/Sources/OversizeUI/Core/EnvironmentKeys/BorderedEnvironment.swift index 5fb0c13..74b6747 100644 --- a/Sources/OversizeUI/Core/EnvironmentKeys/BorderedEnvironment.swift +++ b/Sources/OversizeUI/Core/EnvironmentKeys/BorderedEnvironment.swift @@ -6,7 +6,7 @@ import SwiftUI private struct BorderedStateKey: EnvironmentKey { - public static var defaultValue: Bool = false + public static let defaultValue: Bool = false } public extension EnvironmentValues { diff --git a/Sources/OversizeUI/Core/EnvironmentKeys/ControlBorderShapeEnvironment.swift b/Sources/OversizeUI/Core/EnvironmentKeys/ControlBorderShapeEnvironment.swift index e57e1f7..f8c25b6 100644 --- a/Sources/OversizeUI/Core/EnvironmentKeys/ControlBorderShapeEnvironment.swift +++ b/Sources/OversizeUI/Core/EnvironmentKeys/ControlBorderShapeEnvironment.swift @@ -5,13 +5,13 @@ import SwiftUI -public enum ControlBorderShape { +public enum ControlBorderShape: Sendable { case capsule case roundedRectangle(radius: Radius = .medium) } private struct ControlBorderShapeKey: EnvironmentKey { - public static var defaultValue: ControlBorderShape = .roundedRectangle(radius: .medium) + public static let defaultValue: ControlBorderShape = .roundedRectangle(radius: .medium) } public extension EnvironmentValues { diff --git a/Sources/OversizeUI/Core/EnvironmentKeys/ControlPaddingEnvironment.swift b/Sources/OversizeUI/Core/EnvironmentKeys/ControlPaddingEnvironment.swift index e40107d..5310897 100644 --- a/Sources/OversizeUI/Core/EnvironmentKeys/ControlPaddingEnvironment.swift +++ b/Sources/OversizeUI/Core/EnvironmentKeys/ControlPaddingEnvironment.swift @@ -5,7 +5,7 @@ import SwiftUI -public struct ControlMargin { +public struct ControlMargin: Sendable { public var top: Space = .medium public var leading: Space = .medium public var bottom: Space = .medium @@ -88,7 +88,7 @@ public struct ControlMargin { } private struct ControlMarginKey: EnvironmentKey { - public static var defaultValue: ControlMargin = .init(.medium) + public static let defaultValue: ControlMargin = .init(.medium) } public extension EnvironmentValues { diff --git a/Sources/OversizeUI/Core/EnvironmentKeys/ElevationEnvironment.swift b/Sources/OversizeUI/Core/EnvironmentKeys/ElevationEnvironment.swift index fd65f22..02c2c1d 100644 --- a/Sources/OversizeUI/Core/EnvironmentKeys/ElevationEnvironment.swift +++ b/Sources/OversizeUI/Core/EnvironmentKeys/ElevationEnvironment.swift @@ -6,7 +6,7 @@ import SwiftUI private struct ElevationStateKey: EnvironmentKey { - public static var defaultValue: Elevation = .z0 + public static let defaultValue: Elevation = .z0 } public extension EnvironmentValues { diff --git a/Sources/OversizeUI/Core/EnvironmentKeys/FieldLabelPositionEnvironment.swift b/Sources/OversizeUI/Core/EnvironmentKeys/FieldLabelPositionEnvironment.swift index f937246..e7a198b 100644 --- a/Sources/OversizeUI/Core/EnvironmentKeys/FieldLabelPositionEnvironment.swift +++ b/Sources/OversizeUI/Core/EnvironmentKeys/FieldLabelPositionEnvironment.swift @@ -5,12 +5,12 @@ import SwiftUI -public enum FieldLabelPosition { +public enum FieldLabelPosition: Sendable { case `default`, adjacent, overInput } private struct FieldLabelPositionKey: EnvironmentKey { - public static var defaultValue: FieldLabelPosition = .default + public static let defaultValue: FieldLabelPosition = .default } public extension EnvironmentValues { diff --git a/Sources/OversizeUI/Core/EnvironmentKeys/FieldPositionEnvironment.swift b/Sources/OversizeUI/Core/EnvironmentKeys/FieldPositionEnvironment.swift index 9011d73..6f38a90 100644 --- a/Sources/OversizeUI/Core/EnvironmentKeys/FieldPositionEnvironment.swift +++ b/Sources/OversizeUI/Core/EnvironmentKeys/FieldPositionEnvironment.swift @@ -6,7 +6,7 @@ import SwiftUI private struct FieldPositionKey: EnvironmentKey { - public static var defaultValue: VerticalAlignment? = nil + public static let defaultValue: VerticalAlignment? = nil } public extension EnvironmentValues { diff --git a/Sources/OversizeUI/Core/EnvironmentKeys/IconStyleEnvironment.swift b/Sources/OversizeUI/Core/EnvironmentKeys/IconStyleEnvironment.swift index 36445e9..3b867fc 100644 --- a/Sources/OversizeUI/Core/EnvironmentKeys/IconStyleEnvironment.swift +++ b/Sources/OversizeUI/Core/EnvironmentKeys/IconStyleEnvironment.swift @@ -5,12 +5,12 @@ import SwiftUI -public enum IconStyle { +public enum IconStyle: Sendable { case line, fill, twoTone } private struct IconStyleKey: EnvironmentKey { - public static var defaultValue: IconStyle = .line + public static let defaultValue: IconStyle = .line } public extension EnvironmentValues { diff --git a/Sources/OversizeUI/Core/EnvironmentKeys/LoadingEnvironment.swift b/Sources/OversizeUI/Core/EnvironmentKeys/LoadingEnvironment.swift index 9d6663b..192685d 100644 --- a/Sources/OversizeUI/Core/EnvironmentKeys/LoadingEnvironment.swift +++ b/Sources/OversizeUI/Core/EnvironmentKeys/LoadingEnvironment.swift @@ -6,7 +6,7 @@ import SwiftUI private struct LoadingStateKey: EnvironmentKey { - public static var defaultValue: Bool = false + public static let defaultValue: Bool = false } public extension EnvironmentValues { diff --git a/Sources/OversizeUI/Core/EnvironmentKeys/MultiSelectStyleEnvironment.swift b/Sources/OversizeUI/Core/EnvironmentKeys/MultiSelectStyleEnvironment.swift index 72e17fa..af58cbc 100644 --- a/Sources/OversizeUI/Core/EnvironmentKeys/MultiSelectStyleEnvironment.swift +++ b/Sources/OversizeUI/Core/EnvironmentKeys/MultiSelectStyleEnvironment.swift @@ -5,12 +5,12 @@ import SwiftUI -public enum MultiSelectStyle { +public enum MultiSelectStyle: Sendable { case `default`, section } private struct MultiSelectStyleKey: EnvironmentKey { - public static var defaultValue: MultiSelectStyle = .default + public static let defaultValue: MultiSelectStyle = .default } public extension EnvironmentValues { diff --git a/Sources/OversizeUI/Core/EnvironmentKeys/Platform.swift b/Sources/OversizeUI/Core/EnvironmentKeys/Platform.swift index 2122915..51c7852 100644 --- a/Sources/OversizeUI/Core/EnvironmentKeys/Platform.swift +++ b/Sources/OversizeUI/Core/EnvironmentKeys/Platform.swift @@ -8,7 +8,7 @@ import SwiftUI import UIKit #endif -public enum Platform { +public enum Platform: Sendable { case iPhone, iPadOS, macOS, tvOS, watchOS, visionOS, carPlay, other } @@ -21,23 +21,25 @@ private struct PlatformKey: EnvironmentKey { #elseif os(visionOS) return .vision #elseif canImport(UIKit) - switch UIDevice.current.userInterfaceIdiom { - case .phone: - return .iPhone - case .pad: - return .iPadOS - case .tv: - return .tvOS - case .carPlay: - return .carPlay - case .mac: - return .macOS - case .vision: - return .visionOS - case .unspecified: - return .other - @unknown default: - return .other + MainActor.assumeIsolated { + switch UIDevice.current.userInterfaceIdiom { + case .phone: + return .iPhone + case .pad: + return .iPadOS + case .tv: + return .tvOS + case .carPlay: + return .carPlay + case .mac: + return .macOS + case .vision: + return .visionOS + case .unspecified: + return .other + @unknown default: + return .other + } } #else return .other @@ -45,6 +47,22 @@ private struct PlatformKey: EnvironmentKey { }() } +// private struct PlatformKey: EnvironmentKey { +// +// #if os(macOS) || targetEnvironment(macCatalyst) +// static let defaultValue: Platform = .macOS +// #elseif os(watchOS) +// static let defaultValue: Platform = .watchOS +// #elseif os(visionOS) +// static let defaultValue: Platform = .vision +// #elseif os(iOS) +// static let defaultValue: Platform = .iPhone +// #else +// static let defaultValue: Platform = .other +// #endif +// +// } + public extension EnvironmentValues { var platform: Platform { get { self[PlatformKey.self] } diff --git a/Sources/OversizeUI/Core/EnvironmentKeys/PortraitEnvironment.swift b/Sources/OversizeUI/Core/EnvironmentKeys/PortraitEnvironment.swift index 5ae6981..caf3f8d 100644 --- a/Sources/OversizeUI/Core/EnvironmentKeys/PortraitEnvironment.swift +++ b/Sources/OversizeUI/Core/EnvironmentKeys/PortraitEnvironment.swift @@ -6,7 +6,7 @@ import SwiftUI private struct PortraitStateKey: EnvironmentKey { - public static var defaultValue: Bool = false + public static let defaultValue: Bool = false } public extension EnvironmentValues { diff --git a/Sources/OversizeUI/Core/EnvironmentKeys/PremiumEnvironment.swift b/Sources/OversizeUI/Core/EnvironmentKeys/PremiumEnvironment.swift index 5e8e041..d89f80a 100644 --- a/Sources/OversizeUI/Core/EnvironmentKeys/PremiumEnvironment.swift +++ b/Sources/OversizeUI/Core/EnvironmentKeys/PremiumEnvironment.swift @@ -6,7 +6,7 @@ import SwiftUI private struct PremiumStateKey: EnvironmentKey { - public static var defaultValue: Bool = false + public static let defaultValue: Bool = false } public extension EnvironmentValues { diff --git a/Sources/OversizeUI/Core/EnvironmentKeys/RadiusEnvironment.swift b/Sources/OversizeUI/Core/EnvironmentKeys/RadiusEnvironment.swift index ba6ba34..37f1541 100644 --- a/Sources/OversizeUI/Core/EnvironmentKeys/RadiusEnvironment.swift +++ b/Sources/OversizeUI/Core/EnvironmentKeys/RadiusEnvironment.swift @@ -6,7 +6,7 @@ import SwiftUI private struct ControlRadiusKey: EnvironmentKey { - public static var defaultValue: Radius = .medium + public static let defaultValue: Radius = .medium } public extension EnvironmentValues { diff --git a/Sources/OversizeUI/Core/EnvironmentKeys/ScreenSizeEnvironment.swift b/Sources/OversizeUI/Core/EnvironmentKeys/ScreenSizeEnvironment.swift index 64430d1..cc86468 100644 --- a/Sources/OversizeUI/Core/EnvironmentKeys/ScreenSizeEnvironment.swift +++ b/Sources/OversizeUI/Core/EnvironmentKeys/ScreenSizeEnvironment.swift @@ -5,7 +5,7 @@ import SwiftUI -public struct ScreenSize { +public struct ScreenSize: Sendable { public let safeAreaWidth: CGFloat public let safeAreaHeight: CGFloat public let safeAreaTop: CGFloat diff --git a/Sources/OversizeUI/Core/EnvironmentKeys/SectionViewStyleEnvironment.swift b/Sources/OversizeUI/Core/EnvironmentKeys/SectionViewStyleEnvironment.swift index b17dfd1..fd3bb93 100644 --- a/Sources/OversizeUI/Core/EnvironmentKeys/SectionViewStyleEnvironment.swift +++ b/Sources/OversizeUI/Core/EnvironmentKeys/SectionViewStyleEnvironment.swift @@ -6,7 +6,7 @@ import SwiftUI private struct SectionViewStyleKey: EnvironmentKey { - public static var defaultValue: SectionViewStyle = .default + public static let defaultValue: SectionViewStyle = .default } public extension EnvironmentValues { diff --git a/Sources/OversizeUI/Core/EnvironmentKeys/SelectPickerStyleEnvironment.swift b/Sources/OversizeUI/Core/EnvironmentKeys/SelectPickerStyleEnvironment.swift index 464cebc..422b5f1 100644 --- a/Sources/OversizeUI/Core/EnvironmentKeys/SelectPickerStyleEnvironment.swift +++ b/Sources/OversizeUI/Core/EnvironmentKeys/SelectPickerStyleEnvironment.swift @@ -5,7 +5,7 @@ import SwiftUI -public enum SelectStyle { +public enum SelectStyle: Sendable { case `default` case section @available(macOS, unavailable) @@ -13,7 +13,7 @@ public enum SelectStyle { } private struct SelectStyleKey: EnvironmentKey { - public static var defaultValue: SelectStyle = .default + public static let defaultValue: SelectStyle = .default } public extension EnvironmentValues { diff --git a/Sources/OversizeUI/Core/EnvironmentKeys/SurfaceElevationEnvironment.swift b/Sources/OversizeUI/Core/EnvironmentKeys/SurfaceElevationEnvironment.swift index 1dae333..24b0810 100644 --- a/Sources/OversizeUI/Core/EnvironmentKeys/SurfaceElevationEnvironment.swift +++ b/Sources/OversizeUI/Core/EnvironmentKeys/SurfaceElevationEnvironment.swift @@ -6,7 +6,7 @@ import SwiftUI private struct SurfaceElevationStateKey: EnvironmentKey { - public static var defaultValue: Elevation = .z0 + public static let defaultValue: Elevation = .z0 } public extension EnvironmentValues { diff --git a/Sources/OversizeUI/Core/EnvironmentKeys/SurfaceRadiusEnvironment.swift b/Sources/OversizeUI/Core/EnvironmentKeys/SurfaceRadiusEnvironment.swift index a34a9af..75c6634 100644 --- a/Sources/OversizeUI/Core/EnvironmentKeys/SurfaceRadiusEnvironment.swift +++ b/Sources/OversizeUI/Core/EnvironmentKeys/SurfaceRadiusEnvironment.swift @@ -6,7 +6,7 @@ import SwiftUI private struct SurfaceRadiusKey: EnvironmentKey { - public static var defaultValue: Radius = .medium + public static let defaultValue: Radius = .medium } public extension EnvironmentValues { diff --git a/Sources/OversizeUI/Core/EnvironmentKeys/ThemeEnvironment.swift b/Sources/OversizeUI/Core/EnvironmentKeys/ThemeEnvironment.swift index 6c11667..f242edf 100644 --- a/Sources/OversizeUI/Core/EnvironmentKeys/ThemeEnvironment.swift +++ b/Sources/OversizeUI/Core/EnvironmentKeys/ThemeEnvironment.swift @@ -6,7 +6,7 @@ import SwiftUI private struct ThemeStateKey: EnvironmentKey { - public static var defaultValue = ThemeSettings() + public static let defaultValue = ThemeSettings() } public extension EnvironmentValues { diff --git a/Sources/OversizeUI/Core/Palette.swift b/Sources/OversizeUI/Core/Palette.swift index 93a5cb9..3f65e28 100644 --- a/Sources/OversizeUI/Core/Palette.swift +++ b/Sources/OversizeUI/Core/Palette.swift @@ -5,7 +5,7 @@ import SwiftUI -public enum Palette: String { +public enum Palette: String, Sendable { case red case orange case yellow @@ -39,8 +39,8 @@ public enum Palette: String { } } - public static var base: [Palette] = [.red, .orange, .yellow, .green, .blue, .pink, .gray, .black] - public static var baseColors: [Color] = base.compactMap { color in + public static let base: [Palette] = [.red, .orange, .yellow, .green, .blue, .pink, .gray, .black] + public static let baseColors: [Color] = base.compactMap { color in color.color } } diff --git a/Sources/OversizeUI/Core/PreferenceKeys/ScrollOffsetPreferenceKey.swift b/Sources/OversizeUI/Core/PreferenceKeys/ScrollOffsetPreferenceKey.swift index 612c37c..c2d296a 100644 --- a/Sources/OversizeUI/Core/PreferenceKeys/ScrollOffsetPreferenceKey.swift +++ b/Sources/OversizeUI/Core/PreferenceKeys/ScrollOffsetPreferenceKey.swift @@ -6,6 +6,6 @@ import SwiftUI public struct ScrollOffsetPreferenceKey: PreferenceKey { - public static var defaultValue: CGPoint = .zero + public static let defaultValue: CGPoint = .zero public static func reduce(value _: inout CGPoint, nextValue _: () -> CGPoint) {} } diff --git a/Sources/OversizeUI/Core/PreferenceKeys/SizePreferenceKey.swift b/Sources/OversizeUI/Core/PreferenceKeys/SizePreferenceKey.swift index b74d21d..05517b9 100644 --- a/Sources/OversizeUI/Core/PreferenceKeys/SizePreferenceKey.swift +++ b/Sources/OversizeUI/Core/PreferenceKeys/SizePreferenceKey.swift @@ -6,6 +6,6 @@ import SwiftUI public struct SizePreferenceKey: PreferenceKey { - public static var defaultValue: CGSize = .zero + public static let defaultValue: CGSize = .zero public static func reduce(value _: inout CGSize, nextValue _: () -> CGSize) {} } diff --git a/Sources/OversizeUI/Core/Radius.swift b/Sources/OversizeUI/Core/Radius.swift index 51d37e3..df7ea16 100644 --- a/Sources/OversizeUI/Core/Radius.swift +++ b/Sources/OversizeUI/Core/Radius.swift @@ -5,7 +5,7 @@ import SwiftUI -public enum Radius { +public enum Radius: Sendable { private var theme: ThemeSettings { ThemeSettings() } diff --git a/Sources/OversizeUI/Core/Space.swift b/Sources/OversizeUI/Core/Space.swift index 4704e29..550f79a 100644 --- a/Sources/OversizeUI/Core/Space.swift +++ b/Sources/OversizeUI/Core/Space.swift @@ -5,7 +5,7 @@ import SwiftUI -public enum Space: CGFloat { +public enum Space: CGFloat, Sendable { /// 0 case zero = 0 diff --git a/Sources/OversizeUI/Core/Typography.swift b/Sources/OversizeUI/Core/Typography.swift index b779820..2d3dc1f 100644 --- a/Sources/OversizeUI/Core/Typography.swift +++ b/Sources/OversizeUI/Core/Typography.swift @@ -1,11 +1,6 @@ -// -// Copyright © 2021 Alexander Romanov -// Typography.swift, created on 07.06.2020 -// - import SwiftUI -public enum FontDesignType: String, CaseIterable { +public enum FontDesignType: String, CaseIterable, Sendable { case `default`, serif, round, mono public var system: Font.Design { @@ -24,13 +19,12 @@ public enum FontDesignType: String, CaseIterable { public struct Typography: ViewModifier { @Environment(\.theme) private var theme: ThemeSettings - @Environment(\.isLoading) var isLoading private let fontStyle: Font.TextStyle private let isBold: Bool? private let weight: Font.Weight? - public init(fontStyle: Font.TextStyle, isBold: Bool? = nil, weight: Font.Weight? = nil) { + public nonisolated init(fontStyle: Font.TextStyle, isBold: Bool? = nil, weight: Font.Weight? = nil) { self.fontStyle = fontStyle self.isBold = isBold self.weight = weight @@ -49,62 +43,13 @@ public struct Typography: ViewModifier { private var lineHeight: CGFloat { switch fontStyle { - case .largeTitle: - #if os(macOS) - return 40 - #else - return 44 - #endif - case .title: - #if os(macOS) - return 32 - #else - return 36 - #endif - case .title2: - #if os(macOS) - return 24 - #else - return 28 - #endif - case .title3: - #if os(macOS) - return 20 - #else - return 24 - #endif - case .headline: - #if os(macOS) - return 20 - #else - return 24 - #endif - case .subheadline: - #if os(macOS) - return 16 - #else - return 20 - #endif - case .body: - #if os(macOS) - return 20 - #else - return 24 - #endif - case .callout: - #if os(macOS) - return 16 - #else - return 20 - #endif - case .footnote: - return 16 - case .caption: - return 16 - case .caption2: - return 16 - @unknown default: - return 16 + case .largeTitle: return 44 + case .title: return 36 + case .title2: return 28 + case .title3, .headline: return 24 + case .subheadline, .body: return 20 + case .callout, .footnote, .caption, .caption2: return 16 + @unknown default: return 16 } } @@ -123,119 +68,116 @@ public struct Typography: ViewModifier { private var fontWeight: Font.Weight { if let weight { - weight - } else { - switch fontStyle { - case .largeTitle, .title: - isBold ?? true ? .bold : .regular - case .headline: - isBold ?? true ? .bold : .semibold - default: - isBold ?? false ? .bold : .regular - } + return weight + } + switch fontStyle { + case .largeTitle, .title: + return (isBold ?? true) ? .bold : .regular + case .headline: + return (isBold ?? true) ? .bold : .semibold + default: + return (isBold ?? false) ? .bold : .regular } } } public extension View { - func largeTitle(_ bold: Bool = true) -> some View { + // Large Title + nonisolated func largeTitle(_ bold: Bool = true) -> some View { modifier(Typography(fontStyle: .largeTitle, isBold: bold)) } - func title(_ bold: Bool = true) -> some View { - modifier(Typography(fontStyle: .title, isBold: bold)) - } - - func title2(_ bold: Bool = true) -> some View { - modifier(Typography(fontStyle: .title2, isBold: bold)) - } - - func title3(_ bold: Bool = true) -> some View { - modifier(Typography(fontStyle: .title3, isBold: bold)) + nonisolated func largeTitle(_ weight: Font.Weight) -> some View { + modifier(Typography(fontStyle: .largeTitle, weight: weight)) } - func headline(_ bold: Bool = true) -> some View { - modifier(Typography(fontStyle: .headline, isBold: bold)) + // Title + nonisolated func title(_ bold: Bool = true) -> some View { + modifier(Typography(fontStyle: .title, isBold: bold)) } - func subheadline(_ bold: Bool = false) -> some View { - modifier(Typography(fontStyle: .subheadline, isBold: bold)) + nonisolated func title(_ weight: Font.Weight) -> some View { + modifier(Typography(fontStyle: .title, weight: weight)) } - func body(_ bold: Bool = false) -> some View { - modifier(Typography(fontStyle: .body, isBold: bold)) + // Title 2 + nonisolated func title2(_ bold: Bool = true) -> some View { + modifier(Typography(fontStyle: .title2, isBold: bold)) } - func callout(_ bold: Bool = false) -> some View { - modifier(Typography(fontStyle: .callout, isBold: bold)) + nonisolated func title2(_ weight: Font.Weight) -> some View { + modifier(Typography(fontStyle: .title2, weight: weight)) } - func footnote(_ bold: Bool = false) -> some View { - modifier(Typography(fontStyle: .footnote, isBold: bold)) + // Title 3 + nonisolated func title3(_ bold: Bool = true) -> some View { + modifier(Typography(fontStyle: .title3, isBold: bold)) } - func caption(_ bold: Bool = false) -> some View { - modifier(Typography(fontStyle: .caption, isBold: bold)) + nonisolated func title3(_ weight: Font.Weight) -> some View { + modifier(Typography(fontStyle: .title3, weight: weight)) } - func caption2(_ bold: Bool = false) -> some View { - modifier(Typography(fontStyle: .caption2, isBold: bold)) + // Headline + nonisolated func headline(_ bold: Bool = true) -> some View { + modifier(Typography(fontStyle: .headline, isBold: bold)) } - func largeTitle(_ weight: Font.Weight) -> some View { - modifier(Typography(fontStyle: .largeTitle, weight: weight)) + nonisolated func headline(_ weight: Font.Weight) -> some View { + modifier(Typography(fontStyle: .headline, weight: weight)) } - func title(_ weight: Font.Weight) -> some View { - modifier(Typography(fontStyle: .title, weight: weight)) + // Subheadline + nonisolated func subheadline(_ bold: Bool = false) -> some View { + modifier(Typography(fontStyle: .subheadline, isBold: bold)) } - func title2(_ weight: Font.Weight) -> some View { - modifier(Typography(fontStyle: .title2, weight: weight)) + nonisolated func subheadline(_ weight: Font.Weight) -> some View { + modifier(Typography(fontStyle: .subheadline, weight: weight)) } - func title3(_ weight: Font.Weight) -> some View { - modifier(Typography(fontStyle: .title3, weight: weight)) + // Body + nonisolated func body(_ bold: Bool = false) -> some View { + modifier(Typography(fontStyle: .body, isBold: bold)) } - func headline(_ weight: Font.Weight) -> some View { - modifier(Typography(fontStyle: .headline, weight: weight)) + nonisolated func body(_ weight: Font.Weight) -> some View { + modifier(Typography(fontStyle: .body, weight: weight)) } - func subheadline(_ weight: Font.Weight) -> some View { - modifier(Typography(fontStyle: .subheadline, weight: weight)) + // Callout + nonisolated func callout(_ bold: Bool = false) -> some View { + modifier(Typography(fontStyle: .callout, isBold: bold)) } - func body(_ weight: Font.Weight) -> some View { - modifier(Typography(fontStyle: .body, weight: weight)) + nonisolated func callout(_ weight: Font.Weight) -> some View { + modifier(Typography(fontStyle: .callout, weight: weight)) } - func callout(_ weight: Font.Weight) -> some View { - modifier(Typography(fontStyle: .callout, weight: weight)) + // Footnote + nonisolated func footnote(_ bold: Bool = false) -> some View { + modifier(Typography(fontStyle: .footnote, isBold: bold)) } - func footnote(_ weight: Font.Weight) -> some View { + nonisolated func footnote(_ weight: Font.Weight) -> some View { modifier(Typography(fontStyle: .footnote, weight: weight)) } - func caption(_ weight: Font.Weight) -> some View { - modifier(Typography(fontStyle: .caption, weight: weight)) + // Caption + nonisolated func caption(_ bold: Bool = false) -> some View { + modifier(Typography(fontStyle: .caption, isBold: bold)) } - func caption2(_ weight: Font.Weight) -> some View { - modifier(Typography(fontStyle: .caption2, weight: weight)) + nonisolated func caption(_ weight: Font.Weight) -> some View { + modifier(Typography(fontStyle: .caption, weight: weight)) } -} -public extension View { - @available(*, deprecated, message: "Use native modificator", renamed: "font") - func fontStyle(_ style: Font.TextStyle) -> some View { - modifier(Typography(fontStyle: style)) + // Caption 2 + nonisolated func caption2(_ bold: Bool = false) -> some View { + modifier(Typography(fontStyle: .caption2, isBold: bold)) } - @available(*, deprecated, message: "Use native color modificator", renamed: "font") - func fontStyle(_ style: Font.TextStyle, color: Color) -> some View { - modifier(Typography(fontStyle: style)) - .foregroundColor(color) + nonisolated func caption2(_ weight: Font.Weight) -> some View { + modifier(Typography(fontStyle: .caption2, weight: weight)) } } diff --git a/Sources/OversizeUI/Core/Validation.swift b/Sources/OversizeUI/Core/Validation.swift index 93ca1ad..617d812 100644 --- a/Sources/OversizeUI/Core/Validation.swift +++ b/Sources/OversizeUI/Core/Validation.swift @@ -5,7 +5,7 @@ import Foundation -public enum Validation { +public enum Validation: Sendable { case success case failure(message: String) diff --git a/Sources/OversizeUI/Core/ViewModifier/HalfSheet/HalfSheet.swift b/Sources/OversizeUI/Core/ViewModifier/HalfSheet/HalfSheet.swift index 991661a..4c44e26 100644 --- a/Sources/OversizeUI/Core/ViewModifier/HalfSheet/HalfSheet.swift +++ b/Sources/OversizeUI/Core/ViewModifier/HalfSheet/HalfSheet.swift @@ -8,13 +8,14 @@ import SwiftUI import UIKit #endif -public enum Detents: Hashable { +public enum Detents: Hashable, Sendable { case large case medium case height(CGFloat) #if os(iOS) @available(iOS 15, *) + @MainActor public var uiViewDetents: UISheetPresentationController.Detent { switch self { case .large: @@ -44,6 +45,7 @@ public enum Detents: Hashable { #if os(iOS) public struct SheetModifier: ViewModifier { public let detents: [Detents] + public func body(content: Content) -> some View { SheetView(detents: detents) { content diff --git a/Sources/OversizeUI/Deprecated/Icon.swift b/Sources/OversizeUI/Deprecated/Icon.swift index e51cfec..6e150fe 100644 --- a/Sources/OversizeUI/Deprecated/Icon.swift +++ b/Sources/OversizeUI/Deprecated/Icon.swift @@ -30,12 +30,12 @@ public enum IconSizes: CaseIterable { } public struct IconDeprecated: View { - private enum Constants { + private enum Constants: Sendable { /// Size - static var small: CGFloat = Space.small.rawValue - static var medium: CGFloat = Space.medium.rawValue - static var large: CGFloat = Space.large.rawValue - static var xLarge: CGFloat = Space.xLarge.rawValue + static let small: CGFloat = Space.small.rawValue + static let medium: CGFloat = Space.medium.rawValue + static let large: CGFloat = Space.large.rawValue + static let xLarge: CGFloat = Space.xLarge.rawValue } let name: IconsNames? diff --git a/Sources/OversizeUI/Deprecated/TextFieldDeprecated.swift b/Sources/OversizeUI/Deprecated/TextFieldDeprecated.swift deleted file mode 100644 index 464b5b6..0000000 --- a/Sources/OversizeUI/Deprecated/TextFieldDeprecated.swift +++ /dev/null @@ -1,173 +0,0 @@ -// -// -// Copyright © 2023 Aleksandr Romanov -// File.swift, created on 07.03.2023 -// - -import SwiftUI - -public struct DefaultPlaceholderTextFieldStyle: TextFieldStyle { - @Environment(\.theme) private var theme: ThemeSettings - - private let isFocused: Bool - - public init(focused: Bool = false) { - isFocused = focused - } - - public func _body(configuration: TextField<_Label>) -> some View { - VStack(alignment: .leading) { - configuration - .headline() - .foregroundColor(.onSurfaceHighEmphasis) - } - .padding() - .background( - RoundedRectangle( - cornerRadius: Radius.medium, - style: .continuous - ) - .fill(isFocused ? Color.surfacePrimary : Color.surfaceSecondary) - .overlay(overlay) - ) - } - - @ViewBuilder - var overlay: some View { - RoundedRectangle(cornerRadius: Radius.medium, - style: .continuous) - .stroke(overlayBorderColor, lineWidth: isFocused ? 2 : CGFloat(theme.borderSize)) - } - - var overlayBorderColor: Color { - if isFocused { - Color.accentColor - } else if theme.borderTextFields { - Color.border - } else { - Color.clear - } - } -} - -// swiftlint:disable identifier_name -public struct OverPlaceholderTextFieldStyle: TextFieldStyle { - @Environment(\.theme) private var theme: ThemeSettings - - public let placeholder: String - private let isFocused: Bool - - public init(placeholder: String, focused: Bool = false) { - self.placeholder = placeholder - isFocused = focused - } - - public func _body(configuration: TextField<_Label>) -> some View { - VStack(alignment: .leading) { - HStack { - Text(placeholder) - .subheadline(.semibold) - .foregroundColor(.onSurfaceHighEmphasis) - Spacer() - } - - VStack(alignment: .leading) { - configuration - .headline() - .foregroundColor(.onSurfaceHighEmphasis) - } - .padding() - .background( - RoundedRectangle(cornerRadius: Radius.medium, - style: .continuous) - .fill(isFocused ? Color.surfacePrimary : Color.surfaceSecondary) - .overlay(overlay) - ) - } - } - - @ViewBuilder - var overlay: some View { - RoundedRectangle(cornerRadius: Radius.medium, - style: .continuous) - .stroke(overlayBorderColor, lineWidth: isFocused ? 2 : CGFloat(theme.borderSize)) - } - - var overlayBorderColor: Color { - if isFocused { - Color.accentColor - } else if theme.borderTextFields { - Color.border - } else { - Color.clear - } - } -} - -// swiftlint:disable identifier_name -public struct InsidePlaceholderTextFieldStyle: TextFieldStyle { - @Environment(\.theme) private var theme: ThemeSettings - - public let placeholder: String - private let isFocused: Bool - - public init(placeholder: String, focused: Bool = false) { - self.placeholder = placeholder - isFocused = focused - } - - public func _body(configuration: TextField<_Label>) -> some View { - VStack(alignment: .leading, spacing: .zero) { - VStack(alignment: .leading) { - HStack { - Text(placeholder) - .subheadline(.semibold) - .foregroundColor(.onSurfaceMediumEmphasis) - Spacer() - } - - configuration - .headline() - .foregroundColor(.onSurfaceHighEmphasis) - } - .padding() - .background( - RoundedRectangle(cornerRadius: Radius.medium, - style: .continuous) - .fill(isFocused ? Color.surfacePrimary : Color.surfaceSecondary) - .overlay(overlay) - ) - } - } - - @ViewBuilder - var overlay: some View { - RoundedRectangle(cornerRadius: Radius.medium, - style: .continuous) - .stroke(overlayBorderColor, lineWidth: isFocused ? 2 : CGFloat(theme.borderSize)) - } - - var overlayBorderColor: Color { - if isFocused { - Color.accentColor - } else if theme.borderTextFields { - Color.border - } else { - Color.clear - } - } -} - -public extension TextFieldStyle where Self == DefaultPlaceholderTextFieldStyle { - @available(*, deprecated, message: "Use native @FocusState") - static func `default`(focused: Bool) -> DefaultPlaceholderTextFieldStyle { - DefaultPlaceholderTextFieldStyle(focused: focused) - } -} - -public extension TextFieldStyle where Self == InsidePlaceholderTextFieldStyle { - @available(*, deprecated, message: "Use .fieldLabelPosition(.overInput)") - static func placeholderInside(_ placeholder: String, focused: Bool = false) -> InsidePlaceholderTextFieldStyle { - InsidePlaceholderTextFieldStyle(placeholder: placeholder, focused: focused) - } -} diff --git a/Sources/OversizeUI/Deprecated/ViewOffsetKey.swift b/Sources/OversizeUI/Deprecated/ViewOffsetKey.swift index 276f75a..d46c314 100644 --- a/Sources/OversizeUI/Deprecated/ViewOffsetKey.swift +++ b/Sources/OversizeUI/Deprecated/ViewOffsetKey.swift @@ -6,7 +6,7 @@ import SwiftUI public struct ViewOffsetKey: PreferenceKey { - public static var defaultValue = CGFloat.zero + public static let defaultValue = CGFloat.zero public static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) { value += nextValue() } diff --git a/Sources/OversizeUI/Extensions/Padding/Padding.swift b/Sources/OversizeUI/Extensions/Padding/Padding.swift index 752152d..8efd8ad 100644 --- a/Sources/OversizeUI/Extensions/Padding/Padding.swift +++ b/Sources/OversizeUI/Extensions/Padding/Padding.swift @@ -8,7 +8,7 @@ import SwiftUI public struct PaddingModifier: ViewModifier { private let edges: Edge.Set private let length: Space - public init(edges: Edge.Set, length: Space) { + public nonisolated init(edges: Edge.Set, length: Space) { self.edges = edges self.length = length } @@ -20,7 +20,7 @@ public struct PaddingModifier: ViewModifier { public struct PaddingEdgeInsetsModifier: ViewModifier { private let insets: EdgeSpaceInsets - public init(insets: EdgeSpaceInsets) { + public nonisolated init(insets: EdgeSpaceInsets) { self.insets = insets } @@ -55,22 +55,22 @@ public struct ContentPaddingModifier: ViewModifier { public extension View { @_disfavoredOverload - func padding(_ edges: Edge.Set, _ length: Space) -> some View { + nonisolated func padding(_ edges: Edge.Set, _ length: Space) -> some View { modifier(PaddingModifier(edges: edges, length: length)) } @_disfavoredOverload - func padding(_ length: Space) -> some View { + nonisolated func padding(_ length: Space) -> some View { modifier(PaddingModifier(edges: Edge.Set.all, length: length)) } - func padding(_ insets: EdgeSpaceInsets) -> some View { + nonisolated func padding(_ insets: EdgeSpaceInsets) -> some View { modifier(PaddingEdgeInsetsModifier(insets: insets)) } } public extension View { - func paddingContent(_ edges: Edge.Set = .all) -> some View { + nonisolated func paddingContent(_ edges: Edge.Set = .all) -> some View { modifier(ContentPaddingModifier(edges: edges)) } } diff --git a/Sources/OversizeUI/Extensions/Spacing/Spacing.swift b/Sources/OversizeUI/Extensions/Spacing/Spacing.swift index ea583fd..5653638 100644 --- a/Sources/OversizeUI/Extensions/Spacing/Spacing.swift +++ b/Sources/OversizeUI/Extensions/Spacing/Spacing.swift @@ -7,49 +7,49 @@ import SwiftUI // swiftlint:disable line_length public extension HStack { - @inlinable init(alignment: VerticalAlignment = .center, spacing: Space, @ViewBuilder content: () -> Content) { + @inlinable nonisolated init(alignment: VerticalAlignment = .center, spacing: Space, @ViewBuilder content: () -> Content) { self = .init(alignment: alignment, spacing: spacing.rawValue, content: content) } } public extension VStack { - @inlinable init(alignment: HorizontalAlignment = .center, spacing: Space, @ViewBuilder content: () -> Content) { + @inlinable nonisolated init(alignment: HorizontalAlignment = .center, spacing: Space, @ViewBuilder content: () -> Content) { self = .init(alignment: alignment, spacing: spacing.rawValue, content: content) } } public extension LazyHStack { - @inlinable init(alignment: VerticalAlignment = .center, spacing: Space, @ViewBuilder content: () -> Content) { + @inlinable nonisolated init(alignment: VerticalAlignment = .center, spacing: Space, @ViewBuilder content: () -> Content) { self = .init(alignment: alignment, spacing: spacing.rawValue, content: content) } } public extension LazyVStack { - @inlinable init(alignment: HorizontalAlignment = .center, spacing: Space, @ViewBuilder content: () -> Content) { + @inlinable nonisolated init(alignment: HorizontalAlignment = .center, spacing: Space, @ViewBuilder content: () -> Content) { self = .init(alignment: alignment, spacing: spacing.rawValue, content: content) } } public extension LazyVGrid { - @inlinable init(columns: [GridItem], alignment: HorizontalAlignment = .center, spacing: Space, pinnedViews: PinnedScrollableViews = .init(), @ViewBuilder content: () -> Content) { + @inlinable nonisolated init(columns: [GridItem], alignment: HorizontalAlignment = .center, spacing: Space, pinnedViews: PinnedScrollableViews = .init(), @ViewBuilder content: () -> Content) { self = .init(columns: columns, alignment: alignment, spacing: spacing.rawValue, pinnedViews: pinnedViews, content: content) } } public extension Spacer { - @inlinable init(minLength: Space) { + @MainActor @inlinable @preconcurrency init(minLength: Space) { self = .init(minLength: minLength.rawValue) } } public extension GridItem { - @inlinable init(_ size: GridItem.Size = .flexible(), spacing: Space, alignment: Alignment? = nil) { + @inlinable nonisolated init(_ size: GridItem.Size = .flexible(), spacing: Space, alignment: Alignment? = nil) { self = .init(size, spacing: spacing.rawValue, alignment: alignment) } } public extension RoundedRectangle { - @inlinable init(cornerRadius: Radius, style: RoundedCornerStyle = .circular) { + @inlinable nonisolated init(cornerRadius: Radius, style: RoundedCornerStyle = .circular) { self = .init(cornerRadius: cornerRadius.rawValue, style: style) } } diff --git a/Sources/OversizeUI/Extensions/View/View+If.swift b/Sources/OversizeUI/Extensions/View/View+If.swift index ba9d399..624ccc6 100644 --- a/Sources/OversizeUI/Extensions/View/View+If.swift +++ b/Sources/OversizeUI/Extensions/View/View+If.swift @@ -7,7 +7,7 @@ import SwiftUI public extension View { @ViewBuilder - func `if`(_ condition: Bool, _ modifications: (Self) -> some View) -> some View { + nonisolated func `if`(_ condition: Bool, _ modifications: (Self) -> some View) -> some View { if condition { modifications(self) } else { diff --git a/Sources/OversizeUI/Shapes/RoundedRectangleCorner.swift b/Sources/OversizeUI/Shapes/RoundedRectangleCorner.swift index c41437c..3ec5799 100644 --- a/Sources/OversizeUI/Shapes/RoundedRectangleCorner.swift +++ b/Sources/OversizeUI/Shapes/RoundedRectangleCorner.swift @@ -66,7 +66,7 @@ public struct RoundedRectangleCorner: Shape { controlPoint1: CGPoint(x: rect.maxX, y: rect.maxY - bottomRightRadius / 2), controlPoint2: CGPoint(x: rect.maxX - bottomRightRadius / 2, y: rect.maxY)) } - + path.line(to: CGPoint(x: rect.minX + bottomLeftRadius, y: rect.maxY)) if bottomLeftRadius > 0 { path.curve(to: CGPoint(x: rect.minX, y: rect.maxY - bottomLeftRadius), From 97220d1dd5d0097c50dd4394b90b7bc585c33ace Mon Sep 17 00:00:00 2001 From: Alexandr Romanov Date: Sun, 3 Nov 2024 12:42:23 +0300 Subject: [PATCH 23/30] Update MacOS styles --- Sources/OversizeUI/Controls/HUD/HUD.swift | 101 +++++++++++++---- .../OversizeUI/Controls/PageView/Page.swift | 4 +- .../Support/SegmentedControl+Extensions.swift | 4 +- .../Controls/Stacks/LeadingVStack.swift | 102 ++++++++++++++++++ .../OversizeUI/Controls/Surface/Surface.swift | 33 +++++- .../OversizeUI/Controls/Toast/Snackbar.swift | 1 - .../Controls/URLField/URLField.swift | 10 +- .../Core/Appearance/ThemeSettings.swift | 8 +- Sources/OversizeUI/Core/Typography.swift | 16 +++ .../OversizeUI/Deprecated/ButtonLegacy.swift | 9 +- .../Extensions/View/View+Cursor.swift | 20 ++++ 11 files changed, 273 insertions(+), 35 deletions(-) create mode 100644 Sources/OversizeUI/Controls/Stacks/LeadingVStack.swift create mode 100644 Sources/OversizeUI/Extensions/View/View+Cursor.swift diff --git a/Sources/OversizeUI/Controls/HUD/HUD.swift b/Sources/OversizeUI/Controls/HUD/HUD.swift index eff6dc4..ad1248c 100644 --- a/Sources/OversizeUI/Controls/HUD/HUD.swift +++ b/Sources/OversizeUI/Controls/HUD/HUD.swift @@ -14,8 +14,12 @@ public struct HUD: View where Title: View, Icon: View { private let isAutoHide: Bool @Binding private var isPresented: Bool + #if os(macOS) + @State private var offset: CGFloat = 200 + #else + @State private var offset: CGFloat = -200 + #endif - @State private var bottomOffset: CGFloat = 0 @State private var opacity: CGFloat = 0 // MARK: Initializers @@ -41,7 +45,12 @@ public struct HUD: View where Title: View, Icon: View { if let text { Text(text) .body(.medium) - .foregroundColor(.onSurfaceHighEmphasis) + #if os(macOS) + .foregroundColor(Color.onPrimaryHighEmphasis) + #else + .foregroundColor(Color.onSurfaceHighEmphasis) + + #endif } else if let title { title @@ -50,26 +59,41 @@ public struct HUD: View where Title: View, Icon: View { .padding(.leading, icon == nil ? .medium : .small) .padding(.trailing, .medium) .padding(.vertical, .xSmall) - .background( - Capsule() - .foregroundColor(Color.surfacePrimary) - .shadowElevaton(.z2) - ) - .padding(.small) - .opacity(opacity) - .offset(y: bottomOffset) - .onChange(of: isPresented, perform: { present in - if present { - presentAnimated() - } else { - dismissAnimated() + #if os(macOS) + .background( + RoundedRectangle(cornerRadius: .small, style: .continuous) + .foregroundColor(Color.onBackgroundHighEmphasis) + .shadowElevaton(.z2) + ) + #else + .background( + Capsule() + .foregroundColor(Color.surfacePrimary) + .shadowElevaton(.z2) + ) + #endif + .padding(.small) + .opacity(opacity) + .offset(y: offset) + .onChange(of: isPresented) { present in + if present { + if offset == 0 { + dismissAnimated() + DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { + presentAnimated() + } + } else { + presentAnimated() + } + } else { + dismissAnimated() + } } - }) } private func presentAnimated() { withAnimation { - bottomOffset = 0 + offset = 0 opacity = 1 } if isAutoHide { @@ -83,7 +107,11 @@ public struct HUD: View where Title: View, Icon: View { private func dismissAnimated() { withAnimation { - bottomOffset = -200 + #if os(macOS) + offset = 200 + #else + offset = -200 + #endif opacity = 0 } } @@ -132,6 +160,42 @@ public extension HUD where Icon == EmptyView { } } +#if os(macOS) +@MainActor +public extension View { + func hud(_ text: String, autoHide: Bool = true, isPresented: Binding) -> some View { + overlay(alignment: .bottomTrailing) { + HUD(text, autoHide: autoHide, isPresented: isPresented) + } + } + + func hud(_ text: String, isPresented: Binding, @ViewBuilder icon: () -> some View) -> some View { + overlay(alignment: .bottomTrailing) { + HUD(text, isPresented: isPresented, icon: icon) + } + } + + func hud(isPresented: Binding, @ViewBuilder title: () -> some View) -> some View { + overlay(alignment: .bottomTrailing) { + HUD(isPresented: isPresented, title: title) + } + } + + func hud(isPresented: Binding, @ViewBuilder title: () -> some View, @ViewBuilder icon: () -> some View) -> some View { + overlay(alignment: .bottomTrailing) { + HUD(isPresented: isPresented, title: title, icon: icon) + } + } + + func hudLoader(_ text: String = "Loading", isPresented: Binding) -> some View { + overlay(alignment: .bottomTrailing) { + HUD(text, autoHide: false, isPresented: isPresented) { + ProgressView() + } + } + } +} +#else public extension View { func hud(_ text: String, isPresented: Binding) -> some View { overlay(alignment: .top) { @@ -165,3 +229,4 @@ public extension View { } } } +#endif diff --git a/Sources/OversizeUI/Controls/PageView/Page.swift b/Sources/OversizeUI/Controls/PageView/Page.swift index b176af8..f5025e5 100644 --- a/Sources/OversizeUI/Controls/PageView/Page.swift +++ b/Sources/OversizeUI/Controls/PageView/Page.swift @@ -4,6 +4,8 @@ import SwiftUI public struct Page: View where Content: View, Header: View, LeadingBar: View, TrailingBar: View, TopToolbar: View, TitleLabel: View { + @Environment(\.platform) var platform + public typealias ScrollAction = (_ offset: CGPoint, _ headerVisibleRatio: CGFloat) -> Void private let title: String? @@ -103,7 +105,7 @@ public struct Page CGFloat) -> some View + computeValue: @Sendable @escaping (ViewDimensions) -> CGFloat) -> some View { if isActive { alignmentGuide(alignment, computeValue: computeValue) @@ -33,7 +33,7 @@ extension View { @ViewBuilder @inlinable func alignmentGuide(_ alignment: VerticalAlignment, isActive: Bool, - computeValue: @escaping (ViewDimensions) -> CGFloat) -> some View + computeValue: @Sendable @escaping (ViewDimensions) -> CGFloat) -> some View { if isActive { alignmentGuide(alignment, computeValue: computeValue) diff --git a/Sources/OversizeUI/Controls/Stacks/LeadingVStack.swift b/Sources/OversizeUI/Controls/Stacks/LeadingVStack.swift new file mode 100644 index 0000000..f2a9293 --- /dev/null +++ b/Sources/OversizeUI/Controls/Stacks/LeadingVStack.swift @@ -0,0 +1,102 @@ +// +// Copyright © 2024 Alexander Romanov +// LeadingVStack.swift, created on 28.10.2024 +// + +import SwiftUI + +public struct LeadingVStack: View { + private let spacing: Space + private let content: Content + + public init(spacing: Space = .zero, @ViewBuilder content: () -> Content) { + self.spacing = spacing + self.content = content() + } + + public var body: some View { + VStack(alignment: .leading, spacing: spacing.rawValue) { + content + } + } +} + +public struct TrailingVStack: View { + private let spacing: Space + private let content: Content + + public init(spacing: Space = .zero, @ViewBuilder content: () -> Content) { + self.spacing = spacing + self.content = content() + } + + public var body: some View { + VStack(alignment: .trailing, spacing: spacing.rawValue) { + content + } + } +} + +public struct CenterVStack: View { + private let spacing: Space + private let content: Content + + public init(spacing: Space = .zero, @ViewBuilder content: () -> Content) { + self.spacing = spacing + self.content = content() + } + + public var body: some View { + VStack(alignment: .center, spacing: spacing.rawValue) { + content + } + } +} + +public struct LeadingLazyVStack: View { + private let spacing: Space + private let content: Content + + public init(spacing: Space = .zero, @ViewBuilder content: () -> Content) { + self.spacing = spacing + self.content = content() + } + + public var body: some View { + LazyVStack(alignment: .leading, spacing: spacing.rawValue) { + content + } + } +} + +public struct TrailingLazyVStack: View { + private let spacing: Space + private let content: Content + + public init(spacing: Space = .zero, @ViewBuilder content: () -> Content) { + self.spacing = spacing + self.content = content() + } + + public var body: some View { + LazyVStack(alignment: .trailing, spacing: spacing.rawValue) { + content + } + } +} + +public struct CenterLazyVStack: View { + private let spacing: Space + private let content: Content + + public init(spacing: Space = .zero, @ViewBuilder content: () -> Content) { + self.spacing = spacing + self.content = content() + } + + public var body: some View { + LazyVStack(alignment: .center, spacing: spacing.rawValue) { + content + } + } +} diff --git a/Sources/OversizeUI/Controls/Surface/Surface.swift b/Sources/OversizeUI/Controls/Surface/Surface.swift index cd13ba9..9fade58 100644 --- a/Sources/OversizeUI/Controls/Surface/Surface.swift +++ b/Sources/OversizeUI/Controls/Surface/Surface.swift @@ -36,6 +36,8 @@ public struct Surface: View { private let forceContentInsets: EdgeSpaceInsets? private var isSurfaceClipped: Bool = false + @State var isHover = false + public init( action: (() -> Void)? = nil, @ViewBuilder label: () -> Label @@ -58,8 +60,12 @@ public struct Surface: View { action?() } label: { surface + .contentShape(Rectangle()) } .buttonStyle(SurfaceButtonStyle()) + .onHover { hover in + isHover = hover + } } private var surface: some View { @@ -68,14 +74,33 @@ public struct Surface: View { .padding(.bottom, forceContentInsets?.bottom ?? contentInsets.bottom) .padding(.leading, forceContentInsets?.leading ?? contentInsets.leading) .padding(.trailing, forceContentInsets?.trailing ?? contentInsets.trailing) - .background( + .background { + #if os(macOS) + ZStack { + RoundedRectangle( + cornerRadius: surfaceRadius, + style: .continuous + ) + .fill(surfaceBackgroundColor) + .shadowElevaton(elevation) + + if isHover { + RoundedRectangle( + cornerRadius: surfaceRadius, + style: .continuous + ) + .fill(Color.onSurfaceDisabled.opacity(0.04)) + } + } + #else RoundedRectangle( cornerRadius: surfaceRadius, style: .continuous ) .fill(surfaceBackgroundColor) .shadowElevaton(elevation) - ) + #endif + } .overlay( RoundedRectangle( cornerRadius: surfaceRadius, @@ -171,7 +196,11 @@ public struct SurfaceButtonStyle: ButtonStyle { public func makeBody(configuration: Self.Configuration) -> some View { configuration.label + #if os(macOS) + .scaleEffect(configuration.isPressed ? 0.98 : 1) + #else .scaleEffect(configuration.isPressed ? 0.96 : 1) + #endif } } diff --git a/Sources/OversizeUI/Controls/Toast/Snackbar.swift b/Sources/OversizeUI/Controls/Toast/Snackbar.swift index ffa46d4..3e04082 100644 --- a/Sources/OversizeUI/Controls/Toast/Snackbar.swift +++ b/Sources/OversizeUI/Controls/Toast/Snackbar.swift @@ -55,7 +55,6 @@ public struct Snackbar: View where Label: View, Actions: View { } } } - .padding(.leading, .medium) .padding(.trailing, .xSmall) .padding(.vertical, .xSmall) diff --git a/Sources/OversizeUI/Controls/URLField/URLField.swift b/Sources/OversizeUI/Controls/URLField/URLField.swift index 341c6de..491b50f 100644 --- a/Sources/OversizeUI/Controls/URLField/URLField.swift +++ b/Sources/OversizeUI/Controls/URLField/URLField.swift @@ -20,6 +20,7 @@ public struct URLField: View { public init(_ title: String = "URL", url: Binding) { self.title = title _url = url + _urlString = .init(initialValue: url.wrappedValue?.absoluteString ?? "") } public var body: some View { @@ -38,7 +39,7 @@ public struct URLField: View { if state { textFieldHelper = .none - } else if let url = URL(string: urlString), NSWorkspace.shared.urlForApplication(toOpen: url) != nil { + } else if let url = URL(string: urlString) { // , NSWorkspace.shared.urlForApplication(toOpen: url) != nil { textFieldHelper = .none self.url = url } else { @@ -56,7 +57,7 @@ public struct URLField: View { textFieldHelper = .errorText } #else - if let url = URL(string: urlString), NSWorkspace.shared.urlForApplication(toOpen: url) != nil { + if let url = URL(string: urlString) { // , NSWorkspace.shared.urlForApplication(toOpen: url) != nil { textFieldHelper = .none self.url = url } else { @@ -71,6 +72,11 @@ public struct URLField: View { .textContentType(.URL) .autocorrectionDisabled() .fieldHelper(.constant("Invalid URL"), style: $textFieldHelper) + .onChange(of: url) { newValue in + if let newValue, newValue.absoluteString != urlString { + urlString = newValue.absoluteString + } + } } } #endif diff --git a/Sources/OversizeUI/Core/Appearance/ThemeSettings.swift b/Sources/OversizeUI/Core/Appearance/ThemeSettings.swift index d710d9d..2003066 100644 --- a/Sources/OversizeUI/Core/Appearance/ThemeSettings.swift +++ b/Sources/OversizeUI/Core/Appearance/ThemeSettings.swift @@ -39,19 +39,19 @@ public class ThemeSettings: ObservableObject, @unchecked Sendable { @AppStorage(ThemeSettingsNames.borderApp) public var borderApp: Bool = false @AppStorage(ThemeSettingsNames.borderButtons) public var borderButtons: Bool = false #if os(macOS) + @AppStorage(ThemeSettingsNames.borderSize) public var borderSize: Double = 1 @AppStorage(ThemeSettingsNames.borderTextFields) public var borderTextFields: Bool = true @AppStorage(ThemeSettingsNames.borderSurface) public var borderSurface: Bool = true + @AppStorage(ThemeSettingsNames.radius) public var radius: Double = 4 #else @AppStorage(ThemeSettingsNames.borderSurface) public var borderSurface: Bool = false @AppStorage(ThemeSettingsNames.borderTextFields) public var borderTextFields: Bool = false + @AppStorage(ThemeSettingsNames.borderSize) public var borderSize: Double = 0.5 + @AppStorage(ThemeSettingsNames.radius) public var radius: Double = 8 #endif @AppStorage(ThemeSettingsNames.borderControls) public var borderControls: Bool = false - @AppStorage(ThemeSettingsNames.borderSize) public var borderSize: Double = 0.5 - - @AppStorage(ThemeSettingsNames.radius) public var radius: Double = 8 - @AppStorage(ThemeSettingsNames.theme) public var theme: Int = 0 public let themes: [Theme] = [ diff --git a/Sources/OversizeUI/Core/Typography.swift b/Sources/OversizeUI/Core/Typography.swift index 2d3dc1f..1310577 100644 --- a/Sources/OversizeUI/Core/Typography.swift +++ b/Sources/OversizeUI/Core/Typography.swift @@ -41,6 +41,20 @@ public struct Typography: ViewModifier { .frame(minHeight: lineHeight) } + #if os(macOS) + private var lineHeight: CGFloat { + switch fontStyle { + case .largeTitle: return 32 + case .title: return 28 + case .title2: return 24 + case .title3: return 20 + case .headline: return 16 + case .subheadline: return 20 + case .body, .callout, .footnote, .caption, .caption2: return 16 + @unknown default: return 16 + } + } + #else private var lineHeight: CGFloat { switch fontStyle { case .largeTitle: return 44 @@ -53,6 +67,8 @@ public struct Typography: ViewModifier { } } + #endif + private var fontDesign: Font.Design { switch fontStyle { case .largeTitle, .title, .title2, .title3, .headline, .subheadline: diff --git a/Sources/OversizeUI/Deprecated/ButtonLegacy.swift b/Sources/OversizeUI/Deprecated/ButtonLegacy.swift index de2ee23..5e1cf5b 100644 --- a/Sources/OversizeUI/Deprecated/ButtonLegacy.swift +++ b/Sources/OversizeUI/Deprecated/ButtonLegacy.swift @@ -277,23 +277,22 @@ public struct ButtonStyleExtended: ButtonStyle { public extension Button { /// Changes the appearance of the button - - @available(*, deprecated, message: "Use native buttonStyle", renamed: "buttonStyle") + @MainActor @available(*, deprecated, message: "Use native buttonStyle", renamed: "buttonStyle") func style(_ style: LegacyButtonType) -> some View { buttonStyle(ButtonStyleExtended(style: style)) } - @available(*, deprecated, message: "Use native buttonStyle", renamed: "buttonStyle") + @MainActor @available(*, deprecated, message: "Use native buttonStyle", renamed: "buttonStyle") func style(_ style: LegacyButtonType, size: ButtonSize) -> some View { buttonStyle(ButtonStyleExtended(style: style, size: size)) } - @available(*, deprecated, message: "Use native buttonStyle", renamed: "buttonStyle") + @MainActor @available(*, deprecated, message: "Use native buttonStyle", renamed: "buttonStyle") func style(_ style: LegacyButtonType, size: ButtonSize, shadow: Bool) -> some View { buttonStyle(ButtonStyleExtended(style: style, size: size, shadow: shadow)) } - @available(*, deprecated, message: "Use native buttonStyle", renamed: "buttonStyle") + @MainActor @available(*, deprecated, message: "Use native buttonStyle", renamed: "buttonStyle") func style(_ style: LegacyButtonType, size: ButtonSize, rounded: ButtonRounded, width: ButtonWidth = .standart, shadow: Bool) -> some View { buttonStyle(ButtonStyleExtended(style: style, size: size, rounded: rounded, width: width, shadow: shadow)) } diff --git a/Sources/OversizeUI/Extensions/View/View+Cursor.swift b/Sources/OversizeUI/Extensions/View/View+Cursor.swift new file mode 100644 index 0000000..fe624f3 --- /dev/null +++ b/Sources/OversizeUI/Extensions/View/View+Cursor.swift @@ -0,0 +1,20 @@ +// +// Copyright © 2024 Alexander Romanov +// View+Cursor.swift, created on 23.10.2024 +// + +import SwiftUI + +#if os(macOS) +public extension View { + func cursor(_ cursor: NSCursor) -> some View { + onHover { inside in + if inside { + cursor.push() + } else { + NSCursor.pop() + } + } + } +} +#endif From c364a566c78cfde80772601e66fc0027a4ff260f Mon Sep 17 00:00:00 2001 From: Alexandr Romanov Date: Sun, 3 Nov 2024 12:52:27 +0300 Subject: [PATCH 24/30] Fix tvOS build --- Sources/OversizeUI/Controls/Surface/Surface.swift | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Sources/OversizeUI/Controls/Surface/Surface.swift b/Sources/OversizeUI/Controls/Surface/Surface.swift index 9fade58..3e4b68f 100644 --- a/Sources/OversizeUI/Controls/Surface/Surface.swift +++ b/Sources/OversizeUI/Controls/Surface/Surface.swift @@ -63,9 +63,11 @@ public struct Surface: View { .contentShape(Rectangle()) } .buttonStyle(SurfaceButtonStyle()) - .onHover { hover in - isHover = hover - } + #if os(macOS) + .onHover { hover in + isHover = hover + } + #endif } private var surface: some View { From a6028de86fa156f11e4d3de90061d8c101ca8d33 Mon Sep 17 00:00:00 2001 From: Alexandr Romanov Date: Sun, 3 Nov 2024 13:06:15 +0300 Subject: [PATCH 25/30] Up CI versions --- .github/workflows/ci.yml | 16 ++++++++-------- Example/Shared/ExampleApp.swift | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ddb0340..cfe0d21 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,9 +17,9 @@ jobs: strategy: matrix: destination: - - platform=iOS Simulator,name=iPhone 16,OS=18.0 - - platform=watchOS Simulator,name=Apple Watch SE (40mm) (2nd generation),OS=11.0 - - platform=tvOS Simulator,name=Apple TV 4K (3rd generation) (at 1080p),OS=18.0 + - platform=iOS Simulator,name=iPhone 16,OS=18.1 + - platform=watchOS Simulator,name=Apple Watch SE (40mm) (2nd generation),OS=11.1 + - platform=tvOS Simulator,name=Apple TV 4K (3rd generation) (at 1080p),OS=18.1 - platform=macOS,arch=arm64 with: package: OversizeUI @@ -33,8 +33,8 @@ jobs: strategy: matrix: destination: - - platform=iOS Simulator,name=iPhone 16 Pro,OS=18.0 - - platform=iOS Simulator,name=iPad (10th generation),OS=18.0 + - platform=iOS Simulator,name=iPhone 16 Pro,OS=18.1 + - platform=iOS Simulator,name=iPad (10th generation),OS=18.1 with: path: Example/Example scheme: Example (iOS) @@ -58,8 +58,8 @@ jobs: strategy: matrix: destination: - - platform=tvOS Simulator,name=Apple TV 4K (3rd generation) (at 1080p),OS=18.0 - - platform=tvOS Simulator,name=Apple TV 4K (3rd generation),OS=18.0 + - platform=tvOS Simulator,name=Apple TV 4K (3rd generation) (at 1080p),OS=18.1 + - platform=tvOS Simulator,name=Apple TV 4K (3rd generation),OS=18.1 with: path: Example/Example scheme: Example (tvOS) @@ -73,7 +73,7 @@ jobs: strategy: matrix: destination: - - platform=watchOS Simulator,name=Apple Watch SE (40mm) (2nd generation),OS=11.0 + - platform=watchOS Simulator,name=Apple Watch SE (40mm) (2nd generation),OS=11.1 with: path: Example/Example scheme: Example (watchOS) diff --git a/Example/Shared/ExampleApp.swift b/Example/Shared/ExampleApp.swift index 837d742..2400a74 100644 --- a/Example/Shared/ExampleApp.swift +++ b/Example/Shared/ExampleApp.swift @@ -40,7 +40,7 @@ struct ExampleApp: App { } #if os(iOS) -extension UINavigationController: UIGestureRecognizerDelegate { +extension UINavigationController: @retroactive UIGestureRecognizerDelegate { override open func viewDidLoad() { super.viewDidLoad() interactivePopGestureRecognizer?.delegate = self From 924c5fb83987b90873883abafd14db31d873382d Mon Sep 17 00:00:00 2001 From: Alexandr Romanov Date: Sun, 3 Nov 2024 13:12:11 +0300 Subject: [PATCH 26/30] Fix fontStyle --- Sources/OversizeUI/Core/Typography.swift | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Sources/OversizeUI/Core/Typography.swift b/Sources/OversizeUI/Core/Typography.swift index 1310577..65254ab 100644 --- a/Sources/OversizeUI/Core/Typography.swift +++ b/Sources/OversizeUI/Core/Typography.swift @@ -51,7 +51,7 @@ public struct Typography: ViewModifier { case .headline: return 16 case .subheadline: return 20 case .body, .callout, .footnote, .caption, .caption2: return 16 - @unknown default: return 16 + default: return 16 } } #else @@ -63,10 +63,9 @@ public struct Typography: ViewModifier { case .title3, .headline: return 24 case .subheadline, .body: return 20 case .callout, .footnote, .caption, .caption2: return 16 - @unknown default: return 16 + default: return 16 } } - #endif private var fontDesign: Font.Design { @@ -77,7 +76,7 @@ public struct Typography: ViewModifier { return theme.fontParagraph.system case .caption, .caption2, .footnote, .callout: return theme.fontOverline.system - @unknown default: + default: return .default } } From 4e825fadcb51f81cc444f7df26b9a71997874095 Mon Sep 17 00:00:00 2001 From: Alexandr Romanov Date: Sat, 9 Nov 2024 20:40:36 +0300 Subject: [PATCH 27/30] Add HUD autoHide and format --- Sources/OversizeUI/Controls/HUD/HUD.swift | 4 +- .../OversizeUI/Controls/Surface/Surface.swift | 2 +- Sources/OversizeUI/Core/Typography.swift | 38 +++++++++---------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/Sources/OversizeUI/Controls/HUD/HUD.swift b/Sources/OversizeUI/Controls/HUD/HUD.swift index ad1248c..c085fab 100644 --- a/Sources/OversizeUI/Controls/HUD/HUD.swift +++ b/Sources/OversizeUI/Controls/HUD/HUD.swift @@ -197,9 +197,9 @@ public extension View { } #else public extension View { - func hud(_ text: String, isPresented: Binding) -> some View { + func hud(_ text: String, autoHide: Bool = true, isPresented: Binding) -> some View { overlay(alignment: .top) { - HUD(text, isPresented: isPresented) + HUD(text, autoHide: autoHide, isPresented: isPresented) } } diff --git a/Sources/OversizeUI/Controls/Surface/Surface.swift b/Sources/OversizeUI/Controls/Surface/Surface.swift index 3e4b68f..52ccd2d 100644 --- a/Sources/OversizeUI/Controls/Surface/Surface.swift +++ b/Sources/OversizeUI/Controls/Surface/Surface.swift @@ -199,7 +199,7 @@ public struct SurfaceButtonStyle: ButtonStyle { public func makeBody(configuration: Self.Configuration) -> some View { configuration.label #if os(macOS) - .scaleEffect(configuration.isPressed ? 0.98 : 1) + .scaleEffect(configuration.isPressed ? 0.99 : 1) #else .scaleEffect(configuration.isPressed ? 0.96 : 1) #endif diff --git a/Sources/OversizeUI/Core/Typography.swift b/Sources/OversizeUI/Core/Typography.swift index 65254ab..427aa77 100644 --- a/Sources/OversizeUI/Core/Typography.swift +++ b/Sources/OversizeUI/Core/Typography.swift @@ -44,26 +44,26 @@ public struct Typography: ViewModifier { #if os(macOS) private var lineHeight: CGFloat { switch fontStyle { - case .largeTitle: return 32 - case .title: return 28 - case .title2: return 24 - case .title3: return 20 - case .headline: return 16 - case .subheadline: return 20 - case .body, .callout, .footnote, .caption, .caption2: return 16 - default: return 16 + case .largeTitle: 32 + case .title: 28 + case .title2: 24 + case .title3: 20 + case .headline: 16 + case .subheadline: 20 + case .body, .callout, .footnote, .caption, .caption2: 16 + default: 16 } } #else private var lineHeight: CGFloat { switch fontStyle { - case .largeTitle: return 44 - case .title: return 36 - case .title2: return 28 - case .title3, .headline: return 24 - case .subheadline, .body: return 20 - case .callout, .footnote, .caption, .caption2: return 16 - default: return 16 + case .largeTitle: 44 + case .title: 36 + case .title2: 28 + case .title3, .headline: 24 + case .subheadline, .body: 20 + case .callout, .footnote, .caption, .caption2: 16 + default: 16 } } #endif @@ -71,13 +71,13 @@ public struct Typography: ViewModifier { private var fontDesign: Font.Design { switch fontStyle { case .largeTitle, .title, .title2, .title3, .headline, .subheadline: - return theme.fontTitle.system + theme.fontTitle.system case .body: - return theme.fontParagraph.system + theme.fontParagraph.system case .caption, .caption2, .footnote, .callout: - return theme.fontOverline.system + theme.fontOverline.system default: - return .default + .default } } From a334c18aee5700a40cecd0dedad74b220c2207fe Mon Sep 17 00:00:00 2001 From: Alexandr Romanov Date: Sat, 9 Nov 2024 21:57:47 +0300 Subject: [PATCH 28/30] Renamed colors --- .../OversizeUI/Controls/Avatar/Avatar.swift | 2 +- .../Controls/Button/BarButton.swift | 8 +- .../OversizeUI/Controls/Button/Button.swift | 14 +- .../Controls/Checkbox/Checkbox.swift | 8 +- .../Controls/GridSelect/GridSelect.swift | 4 +- Sources/OversizeUI/Controls/HUD/HUD.swift | 4 +- .../Controls/Label/MenuLabelStyle.swift | 6 +- .../Controls/Label/RowLabelStyle.swift | 6 +- .../Controls/Loader/LoaderOverlayView.swift | 4 +- .../Controls/Menu/BarButtonMenuStyle.swift | 4 +- .../Controls/Notice/NoticeView.swift | 4 +- .../OversizeUI/Controls/PageView/Page.swift | 16 +- .../Controls/Premium/PremiumLabel.swift | 6 +- Sources/OversizeUI/Controls/Radio/Radio.swift | 6 +- Sources/OversizeUI/Controls/Row/Row.swift | 8 +- .../OversizeUI/Controls/Row/RowButton.swift | 2 +- .../OversizeUI/Controls/Row/RowTitle.swift | 6 +- .../Controls/SectionView/SectionView.swift | 6 +- .../SegmentedControl/SegmentedControl.swift | 6 +- .../Support/SegmentedControlPreview.swift | 2 +- .../Controls/Select/MultiSelect.swift | 4 +- .../OversizeUI/Controls/Select/Select.swift | 6 +- .../Controls/Select/SelectPicker.swift | 2 +- .../OversizeUI/Controls/Surface/Surface.swift | 6 +- .../OversizeUI/Controls/Switch/Switch.swift | 6 +- .../OversizeUI/Controls/TextBox/TextBox.swift | 4 +- .../TextEditorPlaceholderViewModifier.swift | 8 +- .../TextField/FieldHelperViewModifier.swift | 2 +- .../TextField/FieldTitleViewModifier.swift | 2 +- .../TextField/LabeledTextFieldStyle.swift | 8 +- .../TextField/TextFieldExtended.swift | 6 +- .../OversizeUI/Controls/Toast/Snackbar.swift | 2 +- .../Controls/Toogle/CheckboxStyle.swift | 6 +- .../Controls/Toogle/RadioStyle.swift | 4 +- Sources/OversizeUI/Core/Colors.swift | 178 +++++++++--------- .../OversizeUI/Deprecated/ButtonLegacy.swift | 10 +- .../OversizeUI/Deprecated/HUDDeprecated.swift | 6 +- Sources/OversizeUI/Deprecated/Icon.swift | 6 +- Sources/OversizeUI/Deprecated/PageView.swift | 4 +- .../OversizeUI/Deprecated/RowDeprecated.swift | 8 +- .../OversizeUI/Deprecated/RowLeading.swift | 4 +- .../OversizeUI/Deprecated/RowTrailing.swift | 12 +- .../Extensions/Image/Image+Extensions.swift | 4 +- 43 files changed, 210 insertions(+), 210 deletions(-) diff --git a/Sources/OversizeUI/Controls/Avatar/Avatar.swift b/Sources/OversizeUI/Controls/Avatar/Avatar.swift index 80449be..f8f3400 100644 --- a/Sources/OversizeUI/Controls/Avatar/Avatar.swift +++ b/Sources/OversizeUI/Controls/Avatar/Avatar.swift @@ -48,7 +48,7 @@ public struct Avatar: View { var background: AvatarBackgroundType = .color(.surfaceSecondary) /// Sets a custom text and image color for the Avatar. - var onBackgroundColor: Color = .onSurfaceMediumEmphasis + var onBackgroundColor: Color = .onSurfaceSecondary /// Creates and initializes a Avatar /// - Parameters: diff --git a/Sources/OversizeUI/Controls/Button/BarButton.swift b/Sources/OversizeUI/Controls/Button/BarButton.swift index 488a089..542974d 100644 --- a/Sources/OversizeUI/Controls/Button/BarButton.swift +++ b/Sources/OversizeUI/Controls/Button/BarButton.swift @@ -133,17 +133,17 @@ public struct BarButton: View { case let .primary(text, _): Text(text) case .closeAction: - IconDeprecated(.xMini, color: .onSurfaceMediumEmphasis) + IconDeprecated(.xMini, color: .onSurfaceSecondary) case .backAction: - IconDeprecated(.arrowLeft, color: .onSurfaceMediumEmphasis) + IconDeprecated(.arrowLeft, color: .onSurfaceSecondary) case let .disabled(text): Text(text) case let .image(image, _): image .renderingMode(.template) - .onSurfaceHighEmphasisForegroundColor() + .onSurfacePrimaryForeground() case let .icon(icon, _): - IconDeprecated(icon, color: .onSurfaceMediumEmphasis) + IconDeprecated(icon, color: .onSurfaceSecondary) } } } diff --git a/Sources/OversizeUI/Controls/Button/Button.swift b/Sources/OversizeUI/Controls/Button/Button.swift index a8c64f6..0e4a645 100644 --- a/Sources/OversizeUI/Controls/Button/Button.swift +++ b/Sources/OversizeUI/Controls/Button/Button.swift @@ -56,7 +56,7 @@ public struct OversizeButtonStyle: ButtonStyle { .opacity(backgroundOpacity)) .overlay { Capsule() - .strokeBorder(Color.onSurfaceHighEmphasis.opacity(0.15), lineWidth: 2) + .strokeBorder(Color.onSurfacePrimary.opacity(0.15), lineWidth: 2) .opacity(isBordered || theme.borderButtons ? 1 : 0) } @@ -66,7 +66,7 @@ public struct OversizeButtonStyle: ButtonStyle { .opacity(backgroundOpacity)) .overlay { RoundedRectangle(cornerRadius: radius != .medium ? radius.rawValue : theme.radius, style: .continuous) - .strokeBorder(Color.onSurfaceHighEmphasis.opacity(0.15), lineWidth: 2) + .strokeBorder(Color.onSurfacePrimary.opacity(0.15), lineWidth: 2) .opacity(isBordered || theme.borderButtons ? 1 : 0) } } @@ -100,10 +100,10 @@ public struct OversizeButtonStyle: ButtonStyle { switch type { case .primary: switch role { - case .some(.destructive), .some(.cancel): Color.onPrimaryHighEmphasis + case .some(.destructive), .some(.cancel): Color.onPrimary default: if isAccent { - Color.onPrimaryHighEmphasis + Color.onPrimary } else { Color.backgroundPrimary } @@ -116,18 +116,18 @@ public struct OversizeButtonStyle: ButtonStyle { if isAccent { Color.accent } else { - Color.onSurfaceHighEmphasis + Color.onSurfacePrimary } } case .tertiary: switch role { case .some(.destructive): Color.error - case .some(.cancel): Color.onSurfaceHighEmphasis + case .some(.cancel): Color.onSurfacePrimary default: if isAccent { Color.accent } else { - Color.onSurfaceHighEmphasis + Color.onSurfacePrimary } } } diff --git a/Sources/OversizeUI/Controls/Checkbox/Checkbox.swift b/Sources/OversizeUI/Controls/Checkbox/Checkbox.swift index e72a2d8..2a77b9d 100644 --- a/Sources/OversizeUI/Controls/Checkbox/Checkbox.swift +++ b/Sources/OversizeUI/Controls/Checkbox/Checkbox.swift @@ -77,7 +77,7 @@ public struct Checkbox: View { private func checkboxImage(isEnabled: Bool, isOn: Bool) -> some View { ZStack { RoundedRectangle(cornerRadius: Radius.small, style: .continuous) - .strokeBorder(Color.onSurfaceDisabled.opacity(isEnabled ? 1 : 0.5), lineWidth: 2.5) + .strokeBorder(Color.onSurfaceTertiary.opacity(isEnabled ? 1 : 0.5), lineWidth: 2.5) .frame(width: 24, height: 24) .opacity(isOn ? 0 : 1) @@ -87,16 +87,16 @@ public struct Checkbox: View { Image(systemName: "checkmark") .font(.caption.weight(.black)) - .foregroundColor(.onPrimaryHighEmphasis.opacity(isEnabled ? 1 : 0.5)) + .foregroundColor(.onPrimary.opacity(isEnabled ? 1 : 0.5)) .opacity(isOn ? 1 : 0) } } private var foregroundColor: Color { if isEnabled { - Color.onSurfaceHighEmphasis + Color.onSurfacePrimary } else { - Color.onSurfaceDisabled + Color.onSurfaceTertiary } } } diff --git a/Sources/OversizeUI/Controls/GridSelect/GridSelect.swift b/Sources/OversizeUI/Controls/GridSelect/GridSelect.swift index 966af35..44a0d86 100644 --- a/Sources/OversizeUI/Controls/GridSelect/GridSelect.swift +++ b/Sources/OversizeUI/Controls/GridSelect/GridSelect.swift @@ -122,7 +122,7 @@ public struct GridSelect: View RoundedRectangle(cornerRadius: radius, style: .continuous) - .strokeBorder(Color.onSurfaceMediumEmphasis, lineWidth: 2) + .strokeBorder(Color.onSurfaceSecondary, lineWidth: 2) case .accentSurface: RoundedRectangle(cornerRadius: radius.rawValue, style: .continuous) @@ -163,7 +163,7 @@ public struct GridSelect: View Circle() .foregroundColor(Color.surfacePrimary) .shadowElevaton(.z2) - IconDeprecated(.checkMini, color: .onSurfaceHighEmphasis) + IconDeprecated(.checkMini, color: .onSurfacePrimary) }.frame(width: Space.large.rawValue, height: Space.large.rawValue) .padding(.small) } diff --git a/Sources/OversizeUI/Controls/HUD/HUD.swift b/Sources/OversizeUI/Controls/HUD/HUD.swift index c085fab..6366a2d 100644 --- a/Sources/OversizeUI/Controls/HUD/HUD.swift +++ b/Sources/OversizeUI/Controls/HUD/HUD.swift @@ -46,7 +46,7 @@ public struct HUD: View where Title: View, Icon: View { Text(text) .body(.medium) #if os(macOS) - .foregroundColor(Color.onPrimaryHighEmphasis) + .foregroundColor(Color.onPrimary) #else .foregroundColor(Color.onSurfaceHighEmphasis) @@ -62,7 +62,7 @@ public struct HUD: View where Title: View, Icon: View { #if os(macOS) .background( RoundedRectangle(cornerRadius: .small, style: .continuous) - .foregroundColor(Color.onBackgroundHighEmphasis) + .foregroundColor(Color.onBackgroundPrimary) .shadowElevaton(.z2) ) #else diff --git a/Sources/OversizeUI/Controls/Label/MenuLabelStyle.swift b/Sources/OversizeUI/Controls/Label/MenuLabelStyle.swift index 123b34b..1d10c74 100644 --- a/Sources/OversizeUI/Controls/Label/MenuLabelStyle.swift +++ b/Sources/OversizeUI/Controls/Label/MenuLabelStyle.swift @@ -19,17 +19,17 @@ public struct MenuLabelStyle: LabelStyle { HStack(spacing: .xSmall) { configuration.icon .headline() - .foregroundColor(.onSurfaceHighEmphasis) + .foregroundColor(.onSurfacePrimary) VStack(alignment: textAlignment, spacing: .xxxSmall) { configuration.title .headline(.semibold) - .foregroundColor(.onSurfaceHighEmphasis) + .foregroundColor(.onSurfacePrimary) if let subtitle, !subtitle.isEmpty { Text(subtitle) .subheadline() - .foregroundColor(.onSurfaceMediumEmphasis) + .foregroundColor(.onSurfaceSecondary) } } } diff --git a/Sources/OversizeUI/Controls/Label/RowLabelStyle.swift b/Sources/OversizeUI/Controls/Label/RowLabelStyle.swift index 03d808f..7f43f24 100644 --- a/Sources/OversizeUI/Controls/Label/RowLabelStyle.swift +++ b/Sources/OversizeUI/Controls/Label/RowLabelStyle.swift @@ -19,17 +19,17 @@ public struct RowLabelStyle: LabelStyle { HStack(spacing: .xSmall) { configuration.icon .headline() - .foregroundColor(.onSurfaceHighEmphasis) + .foregroundColor(.onSurfacePrimary) VStack(alignment: textAlignment, spacing: .xxxSmall) { configuration.title .headline(.semibold) - .foregroundColor(.onSurfaceHighEmphasis) + .foregroundColor(.onSurfacePrimary) if let subtitle, !subtitle.isEmpty { Text(subtitle) .subheadline() - .foregroundColor(.onSurfaceMediumEmphasis) + .foregroundColor(.onSurfaceSecondary) } } } diff --git a/Sources/OversizeUI/Controls/Loader/LoaderOverlayView.swift b/Sources/OversizeUI/Controls/Loader/LoaderOverlayView.swift index 2d09d66..155bc71 100644 --- a/Sources/OversizeUI/Controls/Loader/LoaderOverlayView.swift +++ b/Sources/OversizeUI/Controls/Loader/LoaderOverlayView.swift @@ -59,7 +59,7 @@ public struct LoaderOverlayView: View { if showText { Text(text.isEmpty ? "Loading" : text) .headline(.semibold) - .onSurfaceDisabledForegroundColor() + .onSurfaceTertiaryForeground() .offset(y: 8) } } @@ -74,7 +74,7 @@ public struct LoaderOverlayView: View { if showText { Text(text.isEmpty ? "Loading" : text) .headline(.semibold) - .onSurfaceDisabledForegroundColor() + .onSurfaceTertiaryForeground() .offset(y: 8) } } diff --git a/Sources/OversizeUI/Controls/Menu/BarButtonMenuStyle.swift b/Sources/OversizeUI/Controls/Menu/BarButtonMenuStyle.swift index d755346..1b6a4fe 100644 --- a/Sources/OversizeUI/Controls/Menu/BarButtonMenuStyle.swift +++ b/Sources/OversizeUI/Controls/Menu/BarButtonMenuStyle.swift @@ -17,7 +17,7 @@ public struct BarButtonMenuStyle: MenuStyle { public func makeBody(configuration: Configuration) -> some View { Menu(configuration) .body(true) - .foregroundColor(Color.onPrimaryHighEmphasis) + .foregroundColor(Color.onPrimary) .padding(.xxSmall) .background(background) .shadowElevaton(.z2) @@ -28,7 +28,7 @@ public struct BarButtonMenuStyle: MenuStyle { .fill(Color.surfacePrimary) .overlay { Capsule() - .strokeBorder(Color.onSurfaceHighEmphasis.opacity(0.15), lineWidth: 2) + .strokeBorder(Color.onSurfacePrimary.opacity(0.15), lineWidth: 2) .opacity(isBordered || theme.borderButtons ? 1 : 0) } } diff --git a/Sources/OversizeUI/Controls/Notice/NoticeView.swift b/Sources/OversizeUI/Controls/Notice/NoticeView.swift index 77bd0cb..18a2523 100644 --- a/Sources/OversizeUI/Controls/Notice/NoticeView.swift +++ b/Sources/OversizeUI/Controls/Notice/NoticeView.swift @@ -52,7 +52,7 @@ public struct NoticeView: View where A: View { Text(title) .headline(.semibold) - .onSurfaceHighEmphasisForegroundColor() + .onSurfacePrimaryForeground() .multilineTextAlignment(.leading) .padding(.trailing, closeAction != nil ? .medium : .zero) } @@ -60,7 +60,7 @@ public struct NoticeView: View where A: View { subtitle.map { text in Text(text) .body(.medium) - .onSurfaceMediumEmphasisForegroundColor() + .onSurfaceSecondaryForeground() .multilineTextAlignment(.leading) } diff --git a/Sources/OversizeUI/Controls/PageView/Page.swift b/Sources/OversizeUI/Controls/PageView/Page.swift index f5025e5..c86258d 100644 --- a/Sources/OversizeUI/Controls/PageView/Page.swift +++ b/Sources/OversizeUI/Controls/PageView/Page.swift @@ -273,7 +273,7 @@ public struct Page 20 ? opacity : 0)) + .foregroundColor(Color.onSurfaceTertiary.opacity(height > 20 ? opacity : 0)) configuration.label .frame(maxWidth: .infinity, alignment: .leading) - .foregroundColor(Color.onSurfaceDisabled.opacity(height > 20 ? opacity : 0)) + .foregroundColor(Color.onSurfaceTertiary.opacity(height > 20 ? opacity : 0)) } .callout(.semibold) @@ -1102,7 +1102,7 @@ struct SeartchTextFieldButtonStyle: ButtonStyle { cornerRadius: .medium, style: .continuous ) - .fill(Color.onSurfaceHighEmphasis.opacity(0.07)) + .fill(Color.onSurfacePrimary.opacity(0.07)) ) .submitLabel(.search) } diff --git a/Sources/OversizeUI/Controls/Premium/PremiumLabel.swift b/Sources/OversizeUI/Controls/Premium/PremiumLabel.swift index bb5a27f..1cde093 100644 --- a/Sources/OversizeUI/Controls/Premium/PremiumLabel.swift +++ b/Sources/OversizeUI/Controls/Premium/PremiumLabel.swift @@ -33,11 +33,11 @@ public struct PremiumLabel: View { if let image { image .renderingMode(.template) - .foregroundColor(isMonohrom ? Color(red: 0.718, green: 0.325, blue: 0.459) : .onPrimaryHighEmphasis) + .foregroundColor(isMonohrom ? Color(red: 0.718, green: 0.325, blue: 0.459) : .onPrimary) } Text(text) .font(.system(size: fontSize, weight: .heavy)) - .foregroundColor(isMonohrom ? Color(red: 0.718, green: 0.325, blue: 0.459) : .onPrimaryHighEmphasis) + .foregroundColor(isMonohrom ? Color(red: 0.718, green: 0.325, blue: 0.459) : .onPrimary) } .padding(.leading, leadingPadding) .padding(.trailing, trailingPadding) @@ -47,7 +47,7 @@ public struct PremiumLabel: View { Group { if isMonohrom { RoundedRectangle(cornerRadius: radius, style: .continuous) - .fill(Color.onPrimaryHighEmphasis) + .fill(Color.onPrimary) } else { RoundedRectangle(cornerRadius: radius, style: .continuous) .fill(LinearGradient(gradient: Gradient(colors: [ diff --git a/Sources/OversizeUI/Controls/Radio/Radio.swift b/Sources/OversizeUI/Controls/Radio/Radio.swift index caf8b8d..ccd7f4a 100644 --- a/Sources/OversizeUI/Controls/Radio/Radio.swift +++ b/Sources/OversizeUI/Controls/Radio/Radio.swift @@ -82,7 +82,7 @@ public struct Radio: View { private func radioImage(isEnabled: Bool, isOn: Bool) -> some View { ZStack { Circle() - .stroke(Color.onSurfaceDisabled.opacity(isEnabled ? 1 : 0.5), lineWidth: 4) + .stroke(Color.onSurfaceTertiary.opacity(isEnabled ? 1 : 0.5), lineWidth: 4) .frame(width: 24, height: 24) .cornerRadius(12) .opacity(isOn ? 0 : 1) @@ -100,9 +100,9 @@ public struct Radio: View { private var foregroundColor: Color { if isEnabled { - Color.onSurfaceHighEmphasis + Color.onSurfacePrimary } else { - Color.onSurfaceDisabled + Color.onSurfaceTertiary } } } diff --git a/Sources/OversizeUI/Controls/Row/Row.swift b/Sources/OversizeUI/Controls/Row/Row.swift index 95f0e65..9656ae8 100644 --- a/Sources/OversizeUI/Controls/Row/Row.swift +++ b/Sources/OversizeUI/Controls/Row/Row.swift @@ -132,7 +132,7 @@ public struct Row: View where LeadingLabel: View, T if isShowArrowIcon { Image.Base.chevronRight - .icon(.onSurfaceDisabled) + .icon(.onSurfaceTertiary) } } } @@ -160,7 +160,7 @@ public struct Row: View where LeadingLabel: View, T сlearAction?() } label: { ZStack { - IconDeprecated(.xMini, color: .onSurfaceDisabled) + IconDeprecated(.xMini, color: .onSurfaceTertiary) .background( RoundedRectangle(cornerRadius: .small, style: .continuous) .fillSurfaceSecondary() @@ -183,7 +183,7 @@ public struct Row: View where LeadingLabel: View, T if let textColor { textColor } else { - Color.onSurfaceHighEmphasis + Color.onSurfacePrimary } } @@ -191,7 +191,7 @@ public struct Row: View where LeadingLabel: View, T if let textColor { textColor } else { - Color.onSurfaceMediumEmphasis + Color.onSurfaceSecondary } } diff --git a/Sources/OversizeUI/Controls/Row/RowButton.swift b/Sources/OversizeUI/Controls/Row/RowButton.swift index 14cec4f..df27aef 100644 --- a/Sources/OversizeUI/Controls/Row/RowButton.swift +++ b/Sources/OversizeUI/Controls/Row/RowButton.swift @@ -68,6 +68,6 @@ public struct RowButton: View { ? Color.link : style == .delete ? Color.error - : Color.onSurfaceHighEmphasis + : Color.onSurfacePrimary } } diff --git a/Sources/OversizeUI/Controls/Row/RowTitle.swift b/Sources/OversizeUI/Controls/Row/RowTitle.swift index b5d641d..fd40d25 100644 --- a/Sources/OversizeUI/Controls/Row/RowTitle.swift +++ b/Sources/OversizeUI/Controls/Row/RowTitle.swift @@ -44,14 +44,14 @@ public struct RowTitle: View { } label: { Text(title) .font(.title2.bold()) - .foregroundColor(.onSurfaceHighEmphasis) + .foregroundColor(.onSurfacePrimary) } .buttonStyle(.scale) } } else { Text(title) .font(.title2.bold()) - .foregroundColor(.onSurfaceHighEmphasis) + .foregroundColor(.onSurfacePrimary) } } @@ -63,7 +63,7 @@ public struct RowTitle: View { action() } label: { IconDeprecated(.chevronRight) - .iconColor(.onSurfaceMediumEmphasis) + .iconColor(.onSurfaceSecondary) .offset(y: titleButtonPosition == .leading ? 1.5 : 0) } .buttonStyle(.scale) diff --git a/Sources/OversizeUI/Controls/SectionView/SectionView.swift b/Sources/OversizeUI/Controls/SectionView/SectionView.swift index b1fb071..fe86bbf 100644 --- a/Sources/OversizeUI/Controls/SectionView/SectionView.swift +++ b/Sources/OversizeUI/Controls/SectionView/SectionView.swift @@ -106,9 +106,9 @@ public struct SectionView: View { private var titleColor: Color { switch titlePosition { case .inside: - .onSurfaceHighEmphasis + .onSurfacePrimary case .outside: - .onBackgroundHighEmphasis + .onBackgroundPrimary } } @@ -141,7 +141,7 @@ public struct SectionView: View { action() } label: { IconDeprecated(.chevronRight) - .iconColor(.onSurfaceMediumEmphasis) + .iconColor(.onSurfaceSecondary) .offset(y: titleButtonPosition == .leading ? 1.5 : 0) } .buttonStyle(.scale) diff --git a/Sources/OversizeUI/Controls/SegmentedControl/SegmentedControl.swift b/Sources/OversizeUI/Controls/SegmentedControl/SegmentedControl.swift index ae428a1..6c32c51 100644 --- a/Sources/OversizeUI/Controls/SegmentedControl/SegmentedControl.swift +++ b/Sources/OversizeUI/Controls/SegmentedControl/SegmentedControl.swift @@ -105,7 +105,7 @@ public struct SegmentedPickerSelector: V content(data[index], selectedIndex == index) .body(.semibold) - .foregroundColor(style.seletionStyle == .accentSurface && selectedIndex == index ? Color.onPrimaryHighEmphasis : Color.onSurfaceHighEmphasis) + .foregroundColor(style.seletionStyle == .accentSurface && selectedIndex == index ? Color.onPrimary : Color.onSurfacePrimary) .multilineTextAlignment(.center) .contentShape(Rectangle()) .frame( @@ -173,7 +173,7 @@ public struct SegmentedPickerSelector: V }, label: { content(data[index], selectedIndex == index) .body(.semibold) - .foregroundColor(style.seletionStyle == .accentSurface && selectedIndex == index ? Color.onPrimaryHighEmphasis : Color.onSurfaceHighEmphasis) + .foregroundColor(style.seletionStyle == .accentSurface && selectedIndex == index ? Color.onPrimary : Color.onSurfacePrimary) .multilineTextAlignment(.center) .padding(.leading, controlPadding.leading) .padding(.trailing, controlPadding.trailing) @@ -244,7 +244,7 @@ public struct SegmentedPickerSelector: V ? controlRadius.rawValue - 4 : controlRadius.rawValue, style: .continuous) - .strokeBorder(Color.onSurfaceMediumEmphasis, lineWidth: 2) + .strokeBorder(Color.onSurfaceSecondary, lineWidth: 2) } case .accentSurface: RoundedRectangle( diff --git a/Sources/OversizeUI/Controls/SegmentedControl/Support/SegmentedControlPreview.swift b/Sources/OversizeUI/Controls/SegmentedControl/Support/SegmentedControlPreview.swift index fbff8d0..2e65ac9 100644 --- a/Sources/OversizeUI/Controls/SegmentedControl/Support/SegmentedControlPreview.swift +++ b/Sources/OversizeUI/Controls/SegmentedControl/Support/SegmentedControlPreview.swift @@ -71,7 +71,7 @@ struct SegmentedControlPreview: View { Text(item) Text("Subtitle") .subheadline() - .onSurfaceMediumEmphasisForegroundColor() + .onSurfaceSecondaryForeground() } } .segmentedControlStyle(SelectionOnlySegmentedControlStyle()) diff --git a/Sources/OversizeUI/Controls/Select/MultiSelect.swift b/Sources/OversizeUI/Controls/Select/MultiSelect.swift index 8588495..a63fd76 100644 --- a/Sources/OversizeUI/Controls/Select/MultiSelect.swift +++ b/Sources/OversizeUI/Controls/Select/MultiSelect.swift @@ -63,7 +63,7 @@ public struct MultiSelect: View { cornerRadius: surfaceRadius, style: .continuous ) - .fill(Color.onSurfaceDisabled.opacity(0.04)) + .fill(Color.onSurfaceTertiary.opacity(0.04)) } } #else @@ -291,7 +291,7 @@ struct Surface_Previews: PreviewProvider { Surface { Text("Text") .title3() - .onSurfaceHighEmphasisForegroundColor() + .onSurfacePrimaryForeground() } .surfaceStyle(.secondary) .previewLayout(.fixed(width: 414, height: 200)) @@ -299,7 +299,7 @@ struct Surface_Previews: PreviewProvider { Surface { Text("Text") .title3() - .onSurfaceHighEmphasisForegroundColor() + .onSurfacePrimaryForeground() } .surfaceStyle(.primary) .surfaceBorderColor(.surfaceSecondary) diff --git a/Sources/OversizeUI/Controls/Switch/Switch.swift b/Sources/OversizeUI/Controls/Switch/Switch.swift index da141b3..6bf280f 100644 --- a/Sources/OversizeUI/Controls/Switch/Switch.swift +++ b/Sources/OversizeUI/Controls/Switch/Switch.swift @@ -72,7 +72,7 @@ public struct Switch: View { if let subtitle, !subtitle.isEmpty { Text(subtitle) .subheadline() - .foregroundColor(.onSurfaceMediumEmphasis) + .foregroundColor(.onSurfaceSecondary) } } .padding(contentInset) @@ -88,9 +88,9 @@ public struct Switch: View { private var foregroundColor: Color { if isEnabled { - Color.onSurfaceHighEmphasis + Color.onSurfacePrimary } else { - Color.onSurfaceDisabled + Color.onSurfaceTertiary } } } diff --git a/Sources/OversizeUI/Controls/TextBox/TextBox.swift b/Sources/OversizeUI/Controls/TextBox/TextBox.swift index c975a18..9c9cb26 100644 --- a/Sources/OversizeUI/Controls/TextBox/TextBox.swift +++ b/Sources/OversizeUI/Controls/TextBox/TextBox.swift @@ -33,12 +33,12 @@ public struct TextBox: View { VStack(alignment: textStackAlignment, spacing: textSpacing) { Text(title) .font(titleFont) - .onSurfaceHighEmphasisForegroundColor() + .onSurfacePrimaryForeground() subtitle.map { Text($0) .font(subtitleFont) - .onSurfaceMediumEmphasisForegroundColor() + .onSurfaceSecondaryForeground() } } .multilineTextAlignment(multilineTextAlignment) diff --git a/Sources/OversizeUI/Controls/TextEditor/TextEditorPlaceholderViewModifier.swift b/Sources/OversizeUI/Controls/TextEditor/TextEditorPlaceholderViewModifier.swift index 92bbc53..36df967 100644 --- a/Sources/OversizeUI/Controls/TextEditor/TextEditorPlaceholderViewModifier.swift +++ b/Sources/OversizeUI/Controls/TextEditor/TextEditorPlaceholderViewModifier.swift @@ -25,7 +25,7 @@ public struct TextEditorPlaceholderViewModifier: ViewModifier { HStack { Text(placeholder) .subheadline(.medium) - .foregroundColor(.onSurfaceHighEmphasis) + .foregroundColor(.onSurfacePrimary) Spacer() } } @@ -33,7 +33,7 @@ public struct TextEditorPlaceholderViewModifier: ViewModifier { content .padding(padding) .headline(.medium) - .onSurfaceHighEmphasisForegroundColor() + .onSurfacePrimaryForeground() .background { ZStack { RoundedRectangle(cornerRadius: fieldRadius, style: .continuous) @@ -121,7 +121,7 @@ public struct TextEditorPlaceholderViewModifier: ViewModifier { if text.isEmpty { Text(placeholder) .subheadline() - .onSurfaceDisabledForegroundColor() + .onSurfaceTertiaryForeground() .opacity(0.7) .padding(labelPadding) } @@ -131,7 +131,7 @@ public struct TextEditorPlaceholderViewModifier: ViewModifier { Text(placeholder) .font(text.isEmpty ? .headline : .subheadline) .fontWeight(text.isEmpty ? .medium : .semibold) - .onSurfaceDisabledForegroundColor() + .onSurfaceTertiaryForeground() .opacity(0.7) .padding(labelPadding) .offset(y: text.isEmpty ? 0 : -6) diff --git a/Sources/OversizeUI/Controls/TextField/FieldHelperViewModifier.swift b/Sources/OversizeUI/Controls/TextField/FieldHelperViewModifier.swift index ce2e97e..25d640f 100644 --- a/Sources/OversizeUI/Controls/TextField/FieldHelperViewModifier.swift +++ b/Sources/OversizeUI/Controls/TextField/FieldHelperViewModifier.swift @@ -38,7 +38,7 @@ public struct FieldHelperViewModifier: ViewModifier { private var helperForegroundColor: Color { switch helperStyle { case .helperText: - Color.onSurfaceMediumEmphasis + Color.onSurfaceSecondary case .errorText: Color.error case .sussesText: diff --git a/Sources/OversizeUI/Controls/TextField/FieldTitleViewModifier.swift b/Sources/OversizeUI/Controls/TextField/FieldTitleViewModifier.swift index 123fe08..f9323fd 100644 --- a/Sources/OversizeUI/Controls/TextField/FieldTitleViewModifier.swift +++ b/Sources/OversizeUI/Controls/TextField/FieldTitleViewModifier.swift @@ -16,7 +16,7 @@ public struct FieldTitleViewModifier: ViewModifier { VStack(alignment: .leading, spacing: .xSmall) { Text(title) .subheadline(.medium) - .onSurfaceHighEmphasisForegroundColor() + .onSurfacePrimaryForeground() content } diff --git a/Sources/OversizeUI/Controls/TextField/LabeledTextFieldStyle.swift b/Sources/OversizeUI/Controls/TextField/LabeledTextFieldStyle.swift index 0190799..09444cf 100644 --- a/Sources/OversizeUI/Controls/TextField/LabeledTextFieldStyle.swift +++ b/Sources/OversizeUI/Controls/TextField/LabeledTextFieldStyle.swift @@ -26,7 +26,7 @@ public struct LabeledTextFieldStyle: TextFieldStyle { if fieldPlaceholderPosition == .adjacent { Text(placeholder) .subheadline(.medium) - .foregroundColor(platform == .macOS ? .onSurfaceMediumEmphasis : .onSurfaceHighEmphasis) + .foregroundColor(platform == .macOS ? .onSurfaceSecondary : .onSurfacePrimary) .frame(maxWidth: .infinity, alignment: .leading) .offset(x: platform == .macOS ? 4 : 0) } @@ -34,7 +34,7 @@ public struct LabeledTextFieldStyle: TextFieldStyle { labelTextView configuration .headline(.medium) - .foregroundColor(.onSurfaceHighEmphasis) + .foregroundColor(.onSurfacePrimary) .padding(padding) .offset(y: fieldOffset) .focused($isFocused) @@ -216,7 +216,7 @@ public struct LabeledTextFieldStyle: TextFieldStyle { if isFocused { Text(placeholder) .subheadline() - .onSurfaceDisabledForegroundColor() + .onSurfaceTertiaryForeground() .opacity(0.7) #if os(macOS) .padding(.xSmall) @@ -230,7 +230,7 @@ public struct LabeledTextFieldStyle: TextFieldStyle { Text(placeholder) .font(text.isEmpty ? .headline : .subheadline) .fontWeight(text.isEmpty ? .medium : .semibold) - .onSurfaceDisabledForegroundColor() + .onSurfaceTertiaryForeground() #if os(macOS) .padding(.xSmall) .offset(y: text.isEmpty ? 0 : -10) diff --git a/Sources/OversizeUI/Controls/TextField/TextFieldExtended.swift b/Sources/OversizeUI/Controls/TextField/TextFieldExtended.swift index 152b1e3..e28dc21 100644 --- a/Sources/OversizeUI/Controls/TextField/TextFieldExtended.swift +++ b/Sources/OversizeUI/Controls/TextField/TextFieldExtended.swift @@ -62,7 +62,7 @@ public struct TextFieldExtended: View { HStack { Text(placeholder) .subheadline() - .foregroundColor(.onSurfaceHighEmphasis) + .foregroundColor(.onSurfacePrimary) Spacer() } .padding(.bottom, Space.xxSmall) @@ -81,7 +81,7 @@ public struct TextFieldExtended: View { self.focused = focused }) .headline() - .foregroundColor(.onSurfaceHighEmphasis) + .foregroundColor(.onSurfacePrimary) } if trallingImage != .none { @@ -116,7 +116,7 @@ public struct TextFieldExtended: View { if helperStyle == .helperText { Text(helperText) .subheadline() - .foregroundColor(.onSurfaceMediumEmphasis) + .foregroundColor(.onSurfaceSecondary) } else if helperStyle == .errorText { Text(helperText) .subheadline() diff --git a/Sources/OversizeUI/Controls/Toast/Snackbar.swift b/Sources/OversizeUI/Controls/Toast/Snackbar.swift index 3e04082..d4df23c 100644 --- a/Sources/OversizeUI/Controls/Toast/Snackbar.swift +++ b/Sources/OversizeUI/Controls/Toast/Snackbar.swift @@ -36,7 +36,7 @@ public struct Snackbar: View where Label: View, Actions: View { if let text { Text(text) .body(.medium) - .foregroundColor(.onPrimaryHighEmphasis) + .foregroundColor(.onPrimary) } else if let label { label diff --git a/Sources/OversizeUI/Controls/Toogle/CheckboxStyle.swift b/Sources/OversizeUI/Controls/Toogle/CheckboxStyle.swift index 5b02752..03c8041 100644 --- a/Sources/OversizeUI/Controls/Toogle/CheckboxStyle.swift +++ b/Sources/OversizeUI/Controls/Toogle/CheckboxStyle.swift @@ -12,13 +12,13 @@ public struct CheckboxStyle: ToggleStyle { HStack { configuration.label .headline(.semibold) - .foregroundColor(.onSurfaceHighEmphasis) + .foregroundColor(.onSurfacePrimary) Spacer() ZStack { RoundedRectangle(cornerRadius: Radius.small, style: .continuous) - .strokeBorder(Color.onSurfaceDisabled, lineWidth: 2.5) + .strokeBorder(Color.onSurfaceTertiary, lineWidth: 2.5) .frame(width: 24, height: 24) .opacity(configuration.isOn ? 0 : 1) @@ -28,7 +28,7 @@ public struct CheckboxStyle: ToggleStyle { Image(systemName: "checkmark") .font(.caption.weight(.black)) - .foregroundColor(.onPrimaryHighEmphasis) + .foregroundColor(.onPrimary) .opacity(configuration.isOn ? 1 : 0) } } diff --git a/Sources/OversizeUI/Controls/Toogle/RadioStyle.swift b/Sources/OversizeUI/Controls/Toogle/RadioStyle.swift index 8d570d5..e602bb6 100644 --- a/Sources/OversizeUI/Controls/Toogle/RadioStyle.swift +++ b/Sources/OversizeUI/Controls/Toogle/RadioStyle.swift @@ -12,13 +12,13 @@ public struct RadioStyle: ToggleStyle { HStack { configuration.label .headline(.semibold) - .foregroundColor(.onSurfaceHighEmphasis) + .foregroundColor(.onSurfacePrimary) Spacer() ZStack { Circle() - .stroke(Color.onSurfaceDisabled, lineWidth: 4) + .stroke(Color.onSurfaceTertiary, lineWidth: 4) .frame(width: 24, height: 24) .cornerRadius(12) .opacity(configuration.isOn ? 0 : 1) diff --git a/Sources/OversizeUI/Core/Colors.swift b/Sources/OversizeUI/Core/Colors.swift index 6dd7271..86e24c5 100644 --- a/Sources/OversizeUI/Core/Colors.swift +++ b/Sources/OversizeUI/Core/Colors.swift @@ -15,17 +15,17 @@ public extension Color { // MARK: - On Primary /// On Primary High Emphasis - static var onPrimaryHighEmphasis: Color { + static var onPrimary: Color { Color("OnPrimaryHighEmphasis", bundle: .module) } /// On Primary Medium Emphasis - static var onPrimaryMediumEmphasis: Color { + static var onPrimarySecondary: Color { Color("OnPrimaryMediumEmphasis", bundle: .module) } /// On Primary Disabled - static var onPrimaryDisabled: Color { + static var onPrimaryTertiary: Color { Color("OnPrimaryDisabled", bundle: .module) } @@ -49,17 +49,17 @@ public extension Color { // MARK: - On Background /// On Background High Emphasis - static var onBackgroundHighEmphasis: Color { + static var onBackgroundPrimary: Color { Color("OnBackgroundHighEmphasis", bundle: .module) } /// On BackgroundMedium Emphasis - static var onBackgroundMediumEmphasis: Color { + static var onBackgroundSecondary: Color { Color("OnBackgroundMediumEmphasis", bundle: .module) } /// On Background Disabled - static var onBackgroundDisabled: Color { + static var onBackgroundTertiary: Color { Color("OnBackgroundDisabled", bundle: .module) } @@ -81,17 +81,17 @@ public extension Color { } /// On Surface High Emphasis - static var onSurfaceHighEmphasis: Color { + static var onSurfacePrimary: Color { Color("OnSurfaceHighEmphasis", bundle: .module) } /// On Surface Medium Emphasis - static var onSurfaceMediumEmphasis: Color { + static var onSurfaceSecondary: Color { Color("OnSurfaceMediumEmphasis", bundle: .module) } /// On Surface Disabled - static var onSurfaceDisabled: Color { + static var onSurfaceTertiary: Color { Color("OnSurfaceDisabled", bundle: .module) } @@ -126,87 +126,87 @@ public extension Color { // MARK: - Foreground Color Extension public extension View { - nonisolated func onPrimaryHighEmphasisForegroundColor() -> some View { - foregroundColor(Color.onPrimaryHighEmphasis) + nonisolated func onPrimaryForeground() -> some View { + foregroundColor(Color.onPrimary) } - nonisolated func onPrimaryMediumEmphasisForegroundColor() -> some View { - foregroundColor(Color.onPrimaryMediumEmphasis) + nonisolated func onPrimarySecondaryForeground() -> some View { + foregroundColor(Color.onPrimarySecondary) } - nonisolated func onPrimaryDisabledForegroundColor() -> some View { - foregroundColor(Color.onPrimaryDisabled) + nonisolated func onPrimaryTertiaryForeground() -> some View { + foregroundColor(Color.onPrimaryTertiary) } - nonisolated func backgroundPrimaryForegroundColor() -> some View { + nonisolated func backgroundPrimary() -> some View { foregroundColor(Color.backgroundPrimary) } - nonisolated func backgroundSecondaryForegroundColor() -> some View { + nonisolated func backgroundSecondaryForeground() -> some View { foregroundColor(Color.backgroundSecondary) } - nonisolated func backgroundTertiaryForegroundColor() -> some View { + nonisolated func backgroundTertiaryForeground() -> some View { foregroundColor(Color.backgroundTertiary) } - nonisolated func onBackgroundHighEmphasisForegroundColor() -> some View { - foregroundColor(Color.onBackgroundHighEmphasis) + nonisolated func onBackgroundPrimaryForeground() -> some View { + foregroundColor(Color.onBackgroundPrimary) } - nonisolated func onBackgroundMediumEmphasisForegroundColor() -> some View { - foregroundColor(Color.onBackgroundMediumEmphasis) + nonisolated func onBackgroundSecondaryForeground() -> some View { + foregroundColor(Color.onBackgroundSecondary) } - nonisolated func onBackgroundDisabledForegroundColor() -> some View { - foregroundColor(Color.onBackgroundDisabled) + nonisolated func onBackgroundTertiaryForeground() -> some View { + foregroundColor(Color.onBackgroundTertiary) } - nonisolated func surfacePrimaryForegroundColor() -> some View { + nonisolated func surfacePrimaryForeground() -> some View { foregroundColor(Color.surfacePrimary) } - nonisolated func surfaceSecondaryForegroundColor() -> some View { + nonisolated func surfaceSecondaryForeground() -> some View { foregroundColor(Color.surfaceSecondary) } - nonisolated func surfaceTertiaryForegroundColor() -> some View { + nonisolated func surfaceTertiaryForeground() -> some View { foregroundColor(Color.surfaceTertiary) } - nonisolated func onSurfaceHighEmphasisForegroundColor() -> some View { - foregroundColor(Color.onSurfaceHighEmphasis) + nonisolated func onSurfacePrimaryForeground() -> some View { + foregroundColor(Color.onSurfacePrimary) } - nonisolated func onSurfaceMediumEmphasisForegroundColor() -> some View { - foregroundColor(Color.onSurfaceMediumEmphasis) + nonisolated func onSurfaceSecondaryForeground() -> some View { + foregroundColor(Color.onSurfaceSecondary) } - nonisolated func onSurfaceDisabledForegroundColor() -> some View { - foregroundColor(Color.onSurfaceDisabled) + nonisolated func onSurfaceTertiaryForeground() -> some View { + foregroundColor(Color.onSurfaceTertiary) } - nonisolated func accentForegroundColor() -> some View { + nonisolated func accentForeground() -> some View { foregroundColor(Color.accentColor) } - nonisolated func errorForegroundColor() -> some View { + nonisolated func errorForeground() -> some View { foregroundColor(Color.error) } - nonisolated func successForegroundColor() -> some View { + nonisolated func successForeground() -> some View { foregroundColor(Color.success) } - nonisolated func warningForegroundColor() -> some View { + nonisolated func warningForeground() -> some View { foregroundColor(Color.warning) } - nonisolated func linkForegroundColor() -> some View { + nonisolated func linkForeground() -> some View { foregroundColor(Color.link) } - nonisolated func borderForegroundColor() -> some View { + nonisolated func borderForeground() -> some View { foregroundColor(Color.border) } } @@ -214,16 +214,16 @@ public extension View { // MARK: - Fill Color Extension public extension Shape { - nonisolated func fillOnPrimaryHighEmphasis() -> some View { - fill(Color.onPrimaryHighEmphasis) + nonisolated func fillOnPrimary() -> some View { + fill(Color.onPrimary) } - nonisolated func fillOnPrimaryMediumEmphasis() -> some View { - fill(Color.onPrimaryMediumEmphasis) + nonisolated func fillOnPrimarySecondary() -> some View { + fill(Color.onPrimarySecondary) } - nonisolated func fillOnPrimaryDisabled() -> some View { - fill(Color.onPrimaryDisabled) + nonisolated func fillOnPrimaryTertiary() -> some View { + fill(Color.onPrimaryTertiary) } nonisolated func fillAccent() -> some View { @@ -242,16 +242,16 @@ public extension Shape { fill(Color.backgroundTertiary) } - nonisolated func fillOnBackgroundHighEmphasis() -> some View { - fill(Color.onBackgroundHighEmphasis) + nonisolated func fillOnBackgroundPrimary() -> some View { + fill(Color.onBackgroundPrimary) } - nonisolated func fillOnBackgroundMediumEmphasis() -> some View { - fill(Color.onBackgroundMediumEmphasis) + nonisolated func fillOnBackgroundSecondary() -> some View { + fill(Color.onBackgroundSecondary) } - nonisolated func fillOnBackgroundDisabled() -> some View { - fill(Color.onBackgroundDisabled) + nonisolated func fillOnBackgroundTertiary() -> some View { + fill(Color.onBackgroundTertiary) } nonisolated func fillSurfacePrimary() -> some View { @@ -266,16 +266,16 @@ public extension Shape { fill(Color.surfaceTertiary) } - nonisolated func fillOnSurfaceHighEmphasis() -> some View { - fill(Color.onSurfaceHighEmphasis) + nonisolated func fillOnSurfacePrimary() -> some View { + fill(Color.onSurfacePrimary) } - nonisolated func fillOnSurfaceMediumEmphasis() -> some View { - fill(Color.onSurfaceMediumEmphasis) + nonisolated func fillOnSurfaceSecondary() -> some View { + fill(Color.onSurfaceSecondary) } - nonisolated func fillOnSurfaceDisabled() -> some View { - fill(Color.onSurfaceDisabled) + nonisolated func fillOnSurfaceTertiary() -> some View { + fill(Color.onSurfaceTertiary) } nonisolated func fillError() -> some View { @@ -300,62 +300,62 @@ public extension Shape { } public extension View { - @available(*, deprecated, renamed: "onPrimaryHighEmphasisForegroundColor") + @available(*, deprecated, renamed: "onPrimaryForeground") nonisolated func foregroundOnPrimaryHighEmphasis() -> some View { - foregroundColor(Color.onPrimaryHighEmphasis) + foregroundColor(Color.onPrimary) } - @available(*, deprecated, renamed: "onPrimaryMediumEmphasisForegroundColor") + @available(*, deprecated, renamed: "onPrimarySecondaryForeground") nonisolated func foregroundOnPrimaryMediumEmphasis() -> some View { - foregroundColor(Color.onPrimaryMediumEmphasis) + foregroundColor(Color.onPrimarySecondary) } - @available(*, deprecated, renamed: "onPrimaryDisabledForegroundColor") + @available(*, deprecated, renamed: "onPrimaryTertiaryForeground") nonisolated func foregroundOnPrimaryDisabled() -> some View { - foregroundColor(Color.onPrimaryDisabled) + foregroundColor(Color.onPrimaryTertiary) } - @available(*, deprecated, renamed: "accentForegroundColor") + @available(*, deprecated, renamed: "accentForeground") nonisolated func foregroundAccent() -> some View { foregroundColor(Color.accentColor) } - @available(*, deprecated, renamed: "backgroundPrimaryForegroundColor") + @available(*, deprecated, renamed: "backgroundPrimary") nonisolated func foregroundBackgroundPrimary() -> some View { foregroundColor(Color.backgroundPrimary) } - @available(*, deprecated, renamed: "backgroundSecondaryForegroundColor") + @available(*, deprecated, renamed: "backgroundSecondaryForeground") nonisolated func foregroundBackgroundSecondary() -> some View { foregroundColor(Color.backgroundSecondary) } - @available(*, deprecated, renamed: "backgroundTertiaryForegroundColor") + @available(*, deprecated, renamed: "backgroundTertiaryForeground") nonisolated func foregroundBackgroundTertiary() -> some View { foregroundColor(Color.backgroundTertiary) } - @available(*, deprecated, renamed: "onBackgroundHighEmphasisForegroundColor") + @available(*, deprecated, renamed: "onBackgroundPrimaryForeground") nonisolated func foregroundOnBackgroundHighEmphasis() -> some View { - foregroundColor(Color.onBackgroundHighEmphasis) + foregroundColor(Color.onBackgroundPrimary) } - @available(*, deprecated, renamed: "onBackgroundMediumEmphasisForegroundColor") + @available(*, deprecated, renamed: "onBackgroundSecondaryForeground") nonisolated func foregroundOnBackgroundMediumEmphasis() -> some View { - foregroundColor(Color.onBackgroundMediumEmphasis) + foregroundColor(Color.onBackgroundSecondary) } - @available(*, deprecated, renamed: "onBackgroundDisabledForegroundColor") + @available(*, deprecated, renamed: "onBackgroundTertiaryForeground") nonisolated func foregroundOnBackgroundDisabled() -> some View { - foregroundColor(Color.onBackgroundDisabled) + foregroundColor(Color.onBackgroundTertiary) } - @available(*, deprecated, renamed: "surfacePrimaryForegroundColor") + @available(*, deprecated, renamed: "surfacePrimaryForeground") nonisolated func foregroundSurfacePrimary() -> some View { foregroundColor(Color.surfacePrimary) } - @available(*, deprecated, renamed: "surfaceSecondaryForegroundColor") + @available(*, deprecated, renamed: "surfaceSecondaryForeground") nonisolated func foregroundSurfaceSecondary() -> some View { foregroundColor(Color.surfaceSecondary) } @@ -367,40 +367,40 @@ public extension View { @available(*, deprecated, renamed: "onSurfaceHighEmphasisForegroundColor") nonisolated func foregroundOnSurfaceHighEmphasis() -> some View { - foregroundColor(Color.onSurfaceHighEmphasis) + foregroundColor(Color.onSurfacePrimary) } - @available(*, deprecated, renamed: "onSurfaceMediumEmphasisForegroundColor") + @available(*, deprecated, renamed: "onSurfaceSecondaryForeground") nonisolated func foregroundOnSurfaceMediumEmphasis() -> some View { - foregroundColor(Color.onSurfaceMediumEmphasis) + foregroundColor(Color.onSurfaceSecondary) } - @available(*, deprecated, renamed: "onSurfaceDisabledForegroundColor") + @available(*, deprecated, renamed: "onSurfaceTertiaryForeground") nonisolated func foregroundOnSurfaceDisabled() -> some View { - foregroundColor(Color.onSurfaceDisabled) + foregroundColor(Color.onSurfaceTertiary) } - @available(*, deprecated, renamed: "errorForegroundColor") + @available(*, deprecated, renamed: "errorForeground") nonisolated func foregroundError() -> some View { foregroundColor(Color.error) } - @available(*, deprecated, renamed: "successForegroundColor") + @available(*, deprecated, renamed: "successForeground") nonisolated func foregroundSuccess() -> some View { foregroundColor(Color.success) } - @available(*, deprecated, renamed: "warningForegroundColor") + @available(*, deprecated, renamed: "warningForeground") nonisolated func foregroundWarning() -> some View { foregroundColor(Color.warning) } - @available(*, deprecated, renamed: "linkForegroundColor") + @available(*, deprecated, renamed: "linkForeground") nonisolated func foregroundLink() -> some View { foregroundColor(Color.link) } - @available(*, deprecated, renamed: "borderForegroundColor") + @available(*, deprecated, renamed: "borderForeground") nonisolated func foregroundBorder() -> some View { foregroundColor(Color.border) } @@ -410,16 +410,16 @@ struct Color_Previews: PreviewProvider { static var previews: some View { VStack(alignment: .leading, spacing: 10) { Text("Accent") - .foregroundColor(Color.onPrimaryMediumEmphasis) + .foregroundColor(Color.onPrimarySecondary) .padding() HStack { Rectangle().size(CGSize(width: 50, height: 50)) - .foregroundColor(Color.onPrimaryHighEmphasis) + .foregroundColor(Color.onPrimary) Rectangle().size(CGSize(width: 50, height: 50)) - .foregroundColor(Color.onPrimaryMediumEmphasis) + .foregroundColor(Color.onPrimarySecondary) Rectangle().size(CGSize(width: 50, height: 50)) - .foregroundColor(Color.onPrimaryDisabled) + .foregroundColor(Color.onPrimaryTertiary) Rectangle().size(CGSize(width: 50, height: 50)) } .padding(.horizontal) diff --git a/Sources/OversizeUI/Deprecated/ButtonLegacy.swift b/Sources/OversizeUI/Deprecated/ButtonLegacy.swift index 5e1cf5b..c4b97c0 100644 --- a/Sources/OversizeUI/Deprecated/ButtonLegacy.swift +++ b/Sources/OversizeUI/Deprecated/ButtonLegacy.swift @@ -86,7 +86,7 @@ public struct ButtonStyleExtended: ButtonStyle { configuration.label .body(true) .padding(.horizontal, Space.small) - .foregroundColor(isEnabled ? .onPrimaryHighEmphasis : .onPrimaryDisabled) + .foregroundColor(isEnabled ? .onPrimary : .onPrimaryTertiary) .frame(maxWidth: width == .full ? .infinity : width == .standart ? nil : size == .large ? Constants.heightL : Constants.heightM, minHeight: size == .large ? ButtonStyleExtended.Constants.heightL : ButtonStyleExtended.Constants.heightM) .background( @@ -123,7 +123,7 @@ public struct ButtonStyleExtended: ButtonStyle { configuration.label .body(true) .padding(.horizontal, Space.small) - .foregroundColor(isEnabled ? Color.backgroundPrimary : .onPrimaryDisabled) + .foregroundColor(isEnabled ? Color.backgroundPrimary : .onPrimaryTertiary) .frame(maxWidth: width == .full ? .infinity : width == .standart ? nil : size == .large ? Constants.heightL : Constants.heightM, minHeight: size == .large ? ButtonStyleExtended.Constants.heightL : ButtonStyleExtended.Constants.heightM) .background( @@ -159,7 +159,7 @@ public struct ButtonStyleExtended: ButtonStyle { configuration.label .body(true) .padding(.horizontal, Space.small) - .foregroundColor(isEnabled ? .onSurfaceHighEmphasis : .onSurfaceDisabled) + .foregroundColor(isEnabled ? .onSurfacePrimary : .onSurfaceTertiary) .frame(maxWidth: width == .full ? .infinity : width == .standart ? nil : size == .large ? Constants.heightL : Constants.heightM, minHeight: size == .large ? ButtonStyleExtended.Constants.heightL : ButtonStyleExtended.Constants.heightM) .background( @@ -195,7 +195,7 @@ public struct ButtonStyleExtended: ButtonStyle { configuration.label .body(true) .padding(.horizontal, Space.small) - .foregroundColor(isEnabled ? .onBackgroundHighEmphasis : .onBackgroundDisabled) + .foregroundColor(isEnabled ? .onBackgroundPrimary : .onBackgroundTertiary) .frame(maxWidth: width == .full ? .infinity : width == .standart ? nil : size == .large ? Constants.heightL : Constants.heightM, minHeight: size == .large ? ButtonStyleExtended.Constants.heightL : ButtonStyleExtended.Constants.heightM) .background( @@ -228,7 +228,7 @@ public struct ButtonStyleExtended: ButtonStyle { configuration.label .body(true) .padding(.horizontal, Space.small) - .foregroundColor(isEnabled ? .onSurfaceHighEmphasis : .onSurfaceDisabled) + .foregroundColor(isEnabled ? .onSurfacePrimary : .onSurfaceTertiary) .frame(maxWidth: width == .full ? .infinity : width == .standart ? nil : size == .large ? Constants.heightL : Constants.heightM, minHeight: size == .large ? ButtonStyleExtended.Constants.heightL : ButtonStyleExtended.Constants.heightM) .opacity(configuration.isPressed ? 0.9 : 1) diff --git a/Sources/OversizeUI/Deprecated/HUDDeprecated.swift b/Sources/OversizeUI/Deprecated/HUDDeprecated.swift index 28defe4..c6aab44 100644 --- a/Sources/OversizeUI/Deprecated/HUDDeprecated.swift +++ b/Sources/OversizeUI/Deprecated/HUDDeprecated.swift @@ -212,12 +212,12 @@ public struct HUDContent: View { case .hud: HStack { // if let icon = hudState.icon { -// IconDeprecated(icon, color: .onSurfaceHighEmphasis) +// IconDeprecated(icon, color: .onSurfacePrimary) // } Text(title) .body() - .onSurfaceHighEmphasisForegroundColor() + .onSurfacePrimaryForeground() } case .alert: VStack(spacing: .large) { @@ -227,7 +227,7 @@ public struct HUDContent: View { Text(title) .title3() - .onSurfaceHighEmphasisForegroundColor() + .onSurfacePrimaryForeground() } .frame(minWidth: 225) } diff --git a/Sources/OversizeUI/Deprecated/Icon.swift b/Sources/OversizeUI/Deprecated/Icon.swift index 6e150fe..6eb0e89 100644 --- a/Sources/OversizeUI/Deprecated/Icon.swift +++ b/Sources/OversizeUI/Deprecated/Icon.swift @@ -46,18 +46,18 @@ public struct IconDeprecated: View { public init(_ image: Image) { self.image = image size = .medium - color = Color.onBackgroundHighEmphasis + color = Color.onBackgroundPrimary name = nil } public init(_ name: IconsNames = .menu) { self.name = name size = .medium - color = Color.onBackgroundHighEmphasis + color = Color.onBackgroundPrimary image = nil } - public init(_ name: IconsNames = .menu, size: IconSizes = .medium, color: Color = .onBackgroundHighEmphasis) { + public init(_ name: IconsNames = .menu, size: IconSizes = .medium, color: Color = .onBackgroundPrimary) { self.name = name self.color = color self.size = size diff --git a/Sources/OversizeUI/Deprecated/PageView.swift b/Sources/OversizeUI/Deprecated/PageView.swift index d3ccc6a..1b9a899 100644 --- a/Sources/OversizeUI/Deprecated/PageView.swift +++ b/Sources/OversizeUI/Deprecated/PageView.swift @@ -126,7 +126,7 @@ public struct PageView case .none: EmptyView() case .icon: - IconDeprecated(.xMini, color: .onSurfaceMediumEmphasis) + IconDeprecated(.xMini, color: .onSurfaceSecondary) .background { Circle() .fill(Color.backgroundTertiary) @@ -135,7 +135,7 @@ public struct PageView case let .label(text): Text(text) .subheadline(.bold) - .foregroundColor(.onSurfaceHighEmphasis) + .foregroundColor(.onSurfacePrimary) .padding(.horizontal, .xSmall) .background { RoundedRectangle(cornerRadius: .small, style: .continuous) diff --git a/Sources/OversizeUI/Deprecated/RowDeprecated.swift b/Sources/OversizeUI/Deprecated/RowDeprecated.swift index a6bbcf2..564ecb0 100644 --- a/Sources/OversizeUI/Deprecated/RowDeprecated.swift +++ b/Sources/OversizeUI/Deprecated/RowDeprecated.swift @@ -108,7 +108,7 @@ public struct RowDeprecated: View { } if isShowArrowIcon { - IconDeprecated(.chevronRight, color: .onSurfaceDisabled) + IconDeprecated(.chevronRight, color: .onSurfaceTertiary) } } } @@ -124,11 +124,11 @@ public struct RowDeprecated: View { VStack(alignment: textAlignment, spacing: .xxxSmall) { Text(title) .headline(.semibold) - .foregroundColor(.onSurfaceHighEmphasis) + .foregroundColor(.onSurfacePrimary) if let subtitle, !subtitle.isEmpty { Text(subtitle) .subheadline() - .foregroundColor(.onSurfaceMediumEmphasis) + .foregroundColor(.onSurfaceSecondary) } } .multilineTextAlignment(multilineTextAlignment) @@ -141,7 +141,7 @@ public struct RowDeprecated: View { сlearAction?() } label: { ZStack { - IconDeprecated(.xMini, color: .onSurfaceDisabled) + IconDeprecated(.xMini, color: .onSurfaceTertiary) .background( RoundedRectangle(cornerRadius: .small, style: .continuous) .fillSurfaceSecondary() diff --git a/Sources/OversizeUI/Deprecated/RowLeading.swift b/Sources/OversizeUI/Deprecated/RowLeading.swift index c932d82..1fc1433 100644 --- a/Sources/OversizeUI/Deprecated/RowLeading.swift +++ b/Sources/OversizeUI/Deprecated/RowLeading.swift @@ -8,7 +8,7 @@ import SwiftUI public enum RowLeadingType { case icon(_ name: IconsNames) case iconOnSurface(_ name: IconsNames) - case image(_ image: Image, color: Color? = .onSurfaceHighEmphasis) + case image(_ image: Image, color: Color? = .onSurfacePrimary) case imageOnSurface(_ image: Image, color: Color? = nil) case systemImage(_ imageName: String) case avatar(_ avatar: Avatar) @@ -65,7 +65,7 @@ struct RowLeading: View { case let .systemImage(systemImage): Image(systemName: systemImage) - .foregroundColor(Color.onBackgroundHighEmphasis) + .foregroundColor(Color.onBackgroundPrimary) .font(.system(size: 24)) .frame(width: 24, height: 24, alignment: .center) diff --git a/Sources/OversizeUI/Deprecated/RowTrailing.swift b/Sources/OversizeUI/Deprecated/RowTrailing.swift index 8d1becf..dfc60dc 100644 --- a/Sources/OversizeUI/Deprecated/RowTrailing.swift +++ b/Sources/OversizeUI/Deprecated/RowTrailing.swift @@ -46,7 +46,7 @@ struct RowTrailing: View { case let .radio(isOn: isOn): ZStack { Circle() - .stroke(Color.onSurfaceDisabled, lineWidth: 4) + .stroke(Color.onSurfaceTertiary, lineWidth: 4) .frame(width: 24, height: 24) .cornerRadius(12) .opacity(isOn.wrappedValue ? 0 : 1) @@ -64,7 +64,7 @@ struct RowTrailing: View { case let .checkbox(isOn: isOn): ZStack { RoundedRectangle(cornerRadius: Radius.small, style: .continuous) - .strokeBorder(Color.onSurfaceDisabled, lineWidth: 2.5) + .strokeBorder(Color.onSurfaceTertiary, lineWidth: 2.5) .frame(width: 24, height: 24) .opacity(isOn.wrappedValue ? 0 : 1) @@ -74,7 +74,7 @@ struct RowTrailing: View { Image(systemName: "checkmark") .font(.caption.weight(.black)) - .foregroundColor(.onPrimaryHighEmphasis) + .foregroundColor(.onPrimary) .opacity(isOn.wrappedValue ? 1 : 0) } @@ -84,13 +84,13 @@ struct RowTrailing: View { .labelsHidden() Button(action: action ?? {}, label: { - IconDeprecated(.chevronRight, color: .onSurfaceDisabled) + IconDeprecated(.chevronRight, color: .onSurfaceTertiary) }) } .disabled(isPremiumOption && premiumStatus == false) case .arrowIcon: - IconDeprecated(.chevronRight, color: .onSurfaceDisabled) + IconDeprecated(.chevronRight, color: .onSurfaceTertiary) case let .timePicker(date: date): #if os(watchOS) @@ -102,7 +102,7 @@ struct RowTrailing: View { case let .text(text): Text(text) .subheadline() - .foregroundColor(.onSurfaceMediumEmphasis) + .foregroundColor(.onSurfaceSecondary) case let .button(text, action: action): #if os(tvOS) diff --git a/Sources/OversizeUI/Extensions/Image/Image+Extensions.swift b/Sources/OversizeUI/Extensions/Image/Image+Extensions.swift index f89ef12..524c3b9 100644 --- a/Sources/OversizeUI/Extensions/Image/Image+Extensions.swift +++ b/Sources/OversizeUI/Extensions/Image/Image+Extensions.swift @@ -14,7 +14,7 @@ public extension Image { } public extension Image { - func icon(_ color: Color = Color.onSurfaceHighEmphasis) -> some View { + func icon(_ color: Color = Color.onSurfacePrimary) -> some View { renderingMode(.template) #if os(macOS) .resizable() @@ -28,7 +28,7 @@ public extension Image { } public extension Image { - func icon(_ color: Color = Color.onSurfaceHighEmphasis, size: IconSizes) -> some View { + func icon(_ color: Color = Color.onSurfacePrimary, size: IconSizes) -> some View { renderingMode(.template) .resizable() .frame( From d14b9e97586b6e74ddb9efe800fec9718b77102c Mon Sep 17 00:00:00 2001 From: Alexandr Romanov Date: Sat, 9 Nov 2024 22:25:30 +0300 Subject: [PATCH 29/30] Delete deprecated HUD and Row --- .../Controls/DateField/DateField.swift | 4 +- Sources/OversizeUI/Controls/HUD/HUD.swift | 2 +- .../Controls/IconPicker/IconPicker.swift | 4 +- .../Controls/Notice/NoticeView.swift | 2 +- Sources/OversizeUI/Controls/Row/Row.swift | 40 +-- .../OversizeUI/Controls/Surface/Surface.swift | 2 +- Sources/OversizeUI/Deprecated/BlurView.swift | 35 -- .../OversizeUI/Deprecated/ButtonLegacy.swift | 299 ------------------ .../OversizeUI/Deprecated/HUDDeprecated.swift | 236 -------------- .../OversizeUI/Deprecated/RowDeprecated.swift | 270 ---------------- .../OversizeUI/Deprecated/RowLeading.swift | 76 ----- .../OversizeUI/Deprecated/RowTrailing.swift | 119 ------- .../View+NavigationView.swift | 0 .../Deprecated/View+ScrollViewOffset.swift | 18 -- .../OversizeUI/Deprecated/ViewOffsetKey.swift | 13 - .../Extensions/View/View+Navigationable.swift | 20 -- 16 files changed, 27 insertions(+), 1113 deletions(-) delete mode 100644 Sources/OversizeUI/Deprecated/BlurView.swift delete mode 100644 Sources/OversizeUI/Deprecated/ButtonLegacy.swift delete mode 100644 Sources/OversizeUI/Deprecated/HUDDeprecated.swift delete mode 100644 Sources/OversizeUI/Deprecated/RowDeprecated.swift delete mode 100644 Sources/OversizeUI/Deprecated/RowLeading.swift delete mode 100644 Sources/OversizeUI/Deprecated/RowTrailing.swift rename Sources/OversizeUI/{Extensions/View => Deprecated}/View+NavigationView.swift (100%) delete mode 100644 Sources/OversizeUI/Deprecated/View+ScrollViewOffset.swift delete mode 100644 Sources/OversizeUI/Deprecated/ViewOffsetKey.swift delete mode 100644 Sources/OversizeUI/Extensions/View/View+Navigationable.swift diff --git a/Sources/OversizeUI/Controls/DateField/DateField.swift b/Sources/OversizeUI/Controls/DateField/DateField.swift index 0e6092e..2033480 100644 --- a/Sources/OversizeUI/Controls/DateField/DateField.swift +++ b/Sources/OversizeUI/Controls/DateField/DateField.swift @@ -46,7 +46,7 @@ public struct DateField: View { HStack { Text(label) .subheadline(.medium) - .foregroundColor(.onSurfaceHighEmphasis) + .foregroundColor(.onSurfacePrimary) Spacer() } } @@ -58,7 +58,7 @@ public struct DateField: View { Text(label) .font(.subheadline) .fontWeight(.semibold) - .onSurfaceDisabledForegroundColor() + .onSurfaceTertiaryForeground() } HStack { diff --git a/Sources/OversizeUI/Controls/HUD/HUD.swift b/Sources/OversizeUI/Controls/HUD/HUD.swift index 6366a2d..81e9b21 100644 --- a/Sources/OversizeUI/Controls/HUD/HUD.swift +++ b/Sources/OversizeUI/Controls/HUD/HUD.swift @@ -48,7 +48,7 @@ public struct HUD: View where Title: View, Icon: View { #if os(macOS) .foregroundColor(Color.onPrimary) #else - .foregroundColor(Color.onSurfaceHighEmphasis) + .foregroundColor(Color.onSurfacePrimary) #endif diff --git a/Sources/OversizeUI/Controls/IconPicker/IconPicker.swift b/Sources/OversizeUI/Controls/IconPicker/IconPicker.swift index c5314e9..ba5562d 100644 --- a/Sources/OversizeUI/Controls/IconPicker/IconPicker.swift +++ b/Sources/OversizeUI/Controls/IconPicker/IconPicker.swift @@ -45,13 +45,13 @@ public struct IconPicker: View { } label: { HStack(spacing: .xxSmall) { Text(label) - .onSurfaceHighEmphasisForegroundColor() + .onSurfacePrimaryForeground() Spacer() if let image = selection { image } - IconDeprecated(.chevronDown, color: .onSurfaceHighEmphasis) + IconDeprecated(.chevronDown, color: .onSurfacePrimary) } } .buttonStyle(.field) diff --git a/Sources/OversizeUI/Controls/Notice/NoticeView.swift b/Sources/OversizeUI/Controls/Notice/NoticeView.swift index 18a2523..71ecae7 100644 --- a/Sources/OversizeUI/Controls/Notice/NoticeView.swift +++ b/Sources/OversizeUI/Controls/Notice/NoticeView.swift @@ -83,7 +83,7 @@ public struct NoticeView: View where A: View { Button { closeAction?() } label: { - IconDeprecated(.xMini, color: .onSurfaceHighEmphasis) + IconDeprecated(.xMini, color: .onSurfacePrimary) } .buttonStyle(subtitle != nil ? .tertiary(infinityWidth: false) : .quaternary(infinityWidth: false)) .controlBorderShape(.capsule) diff --git a/Sources/OversizeUI/Controls/Row/Row.swift b/Sources/OversizeUI/Controls/Row/Row.swift index 9656ae8..74ae464 100644 --- a/Sources/OversizeUI/Controls/Row/Row.swift +++ b/Sources/OversizeUI/Controls/Row/Row.swift @@ -26,8 +26,8 @@ public struct Row: View where LeadingLabel: View, T private let leadingLabel: LeadingLabel? private let trailingLabel: TrailingLabel? - private var leadingType: RowLeadingType? - private var trallingType: RowTrailingType? +// private var leadingType: RowLeadingType? +// private var trallingType: RowTrailingType? private let action: (() -> Void)? @@ -66,16 +66,16 @@ public struct Row: View where LeadingLabel: View, T @available(*, deprecated, message: "Use leading: {} and tralling: {}") public init(_ title: String, subtitle: String? = nil, - leadingType: RowLeadingType? = nil, - trallingType: RowTrailingType? = nil, +// leadingType: RowLeadingType? = nil, +// trallingType: RowTrailingType? = nil, paddingHorizontal _: Space = .medium, paddingVertical _: Space = .small, action: (() -> Void)? = nil) { self.title = title self.subtitle = subtitle - self.leadingType = leadingType - self.trallingType = trallingType +// self.leadingType = leadingType +// self.trallingType = trallingType self.action = action leadingLabel = nil trailingLabel = nil @@ -246,20 +246,20 @@ public extension Row { control.textColor = color return control } - - @available(*, deprecated, message: "Use leading: {} and tralling: {}") - func rowLeading(_ leading: RowLeadingType?) -> Row { - var control = self - control.leadingType = leading - return control - } - - @available(*, deprecated, message: "Use leading: {} and tralling: {}") - func rowTrailing(_ trailing: RowTrailingType?) -> Row { - var control = self - control.trallingType = trailing - return control - } +// +// @available(*, deprecated, message: "Use leading: {} and tralling: {}") +// func rowLeading(_ leading: RowLeadingType?) -> Row { +// var control = self +// control.leadingType = leading +// return control +// } +// +// @available(*, deprecated, message: "Use leading: {} and tralling: {}") +// func rowTrailing(_ trailing: RowTrailingType?) -> Row { +// var control = self +// control.trallingType = trailing +// return control +// } } public extension View { diff --git a/Sources/OversizeUI/Controls/Surface/Surface.swift b/Sources/OversizeUI/Controls/Surface/Surface.swift index c598465..3b4982e 100644 --- a/Sources/OversizeUI/Controls/Surface/Surface.swift +++ b/Sources/OversizeUI/Controls/Surface/Surface.swift @@ -283,7 +283,7 @@ struct Surface_Previews: PreviewProvider { static var previews: some View { VStack { Surface { - RowDeprecated("Title") {} + Row("Title") {} } .surfaceStyle(.primary) .previewLayout(.fixed(width: 414, height: 300)) diff --git a/Sources/OversizeUI/Deprecated/BlurView.swift b/Sources/OversizeUI/Deprecated/BlurView.swift deleted file mode 100644 index 7eec056..0000000 --- a/Sources/OversizeUI/Deprecated/BlurView.swift +++ /dev/null @@ -1,35 +0,0 @@ -// -// Copyright © 2021 Alexander Romanov -// BlurView.swift, created on 11.09.2021 -// - -import Foundation -import SwiftUI - -// swiftlint:disable all -#if os(iOS) -public struct BlurView: UIViewRepresentable { - public init(_ style: UIBlurEffect.Style = .light) { - self.style = style - } - - public let style: UIBlurEffect.Style - - public func makeUIView(context _: UIViewRepresentableContext) -> UIView { - let view: UIView = .init(frame: .zero) - view.backgroundColor = .clear - let blurEffect: UIBlurEffect = .init(style: style) - let blurView: UIVisualEffectView = .init(effect: blurEffect) - blurView.translatesAutoresizingMaskIntoConstraints = false - view.insertSubview(blurView, at: 0) - NSLayoutConstraint.activate([ - blurView.heightAnchor.constraint(equalTo: view.heightAnchor), - blurView.widthAnchor.constraint(equalTo: view.widthAnchor), - ]) - return view - } - - public func updateUIView(_: UIView, - context _: UIViewRepresentableContext) {} -} -#endif diff --git a/Sources/OversizeUI/Deprecated/ButtonLegacy.swift b/Sources/OversizeUI/Deprecated/ButtonLegacy.swift deleted file mode 100644 index c4b97c0..0000000 --- a/Sources/OversizeUI/Deprecated/ButtonLegacy.swift +++ /dev/null @@ -1,299 +0,0 @@ -// -// Copyright © 2021 Alexander Romanov -// ButtonLegacy.swift, created on 11.09.2021 -// - -import SwiftUI - -public enum LegacyButtonType: Int, CaseIterable { - case accent - case primary - case secondary - case gray - case text - case link - case deleteLink -} - -public enum ButtonSize { - case large - case medium -} - -public enum ButtonRounded { - case full - case medium - case small - case none -} - -public enum ButtonWidth { - case full - case round - case standart -} - -// swiftlint:disable all -public struct ButtonStyleExtended: ButtonStyle { - @Environment(\.theme) private var theme: ThemeSettings - - var style: LegacyButtonType - var size: ButtonSize = .large - var rounded: ButtonRounded = .medium - var width: ButtonWidth = .full - var shadow: Bool = true - - private enum Constants { - /// Size - static var heightL: CGFloat { Space.xLarge.rawValue + Space.xxSmall.rawValue } - static var heightM: CGFloat { Space.large.rawValue + Space.xxSmall.rawValue } - - /// Radius - static var radiusM: CGFloat { Radius.medium.rawValue } - static var radiusS: CGFloat { Radius.small.rawValue } - } - - @ViewBuilder - public func makeBody(configuration: ButtonStyle.Configuration) -> some View { - switch style { - case .primary: - PrimaryButton(size: size, rounded: rounded, width: width, shadow: shadow, isBordered: theme.borderButtons, borderLineWidth: CGFloat(theme.borderSize), configuration: configuration) - case .secondary: - SecondaryButton(size: size, rounded: rounded, width: width, shadow: shadow, isBordered: theme.borderButtons, borderLineWidth: CGFloat(theme.borderSize), configuration: configuration) - case .gray: - GrayButton(size: size, rounded: rounded, width: width, shadow: shadow, isBordered: theme.borderButtons, borderLineWidth: CGFloat(theme.borderSize), configuration: configuration) - case .text: - TextButton(size: size, rounded: rounded, width: width, configuration: configuration) - case .link: - LinkButton(size: size, rounded: rounded, width: width, shadow: shadow, configuration: configuration) - case .deleteLink: - DeleteButton(size: size, rounded: rounded, width: width, shadow: shadow, configuration: configuration) - case .accent: - AccentButton(size: size, rounded: rounded, width: width, shadow: shadow, configuration: configuration, isBordered: theme.borderButtons, borderLineWidth: CGFloat(theme.borderSize)) - } - } - - struct AccentButton: View { - var size: ButtonSize - var rounded: ButtonRounded - var width: ButtonWidth - var shadow: Bool - let configuration: ButtonStyle.Configuration - var isBordered: Bool - var borderLineWidth: CGFloat - @Environment(\.isEnabled) private var isEnabled: Bool - var body: some View { - configuration.label - .body(true) - .padding(.horizontal, Space.small) - .foregroundColor(isEnabled ? .onPrimary : .onPrimaryTertiary) - .frame(maxWidth: width == .full ? .infinity : width == .standart ? nil : size == .large ? Constants.heightL : Constants.heightM, - minHeight: size == .large ? ButtonStyleExtended.Constants.heightL : ButtonStyleExtended.Constants.heightM) - .background( - RoundedRectangle(cornerRadius: rounded == .none ? 0 : rounded == .medium ? ButtonStyleExtended.Constants.radiusM : rounded == .small ? ButtonStyleExtended.Constants.radiusS : - size == .large ? ButtonStyleExtended.Constants.heightL / 2 : ButtonStyleExtended.Constants.heightM / 2, - style: .continuous) - .fill(isEnabled ? Color.accent : Color.accent.opacity(0.9)) - .overlay( - RoundedRectangle(cornerRadius: rounded == .none ? 0 : rounded == .medium ? ButtonStyleExtended.Constants.radiusM : rounded == .small ? ButtonStyleExtended.Constants.radiusS : - size == .large ? ButtonStyleExtended.Constants.heightL / 2 : ButtonStyleExtended.Constants.heightM / 2, - style: .continuous) - .stroke(isBordered - ? Color.border - : isEnabled ? Color.accent : Color.accent.opacity(0.9), lineWidth: 1) - ) - ) - .opacity(configuration.isPressed ? 0.9 : 1) - .scaleEffect(configuration.isPressed ? 0.95 : 1) - // .animation(.spring()) - .shadowElevaton(shadow ? .z2 : .z0, color: Color.accent) - } - } - - struct PrimaryButton: View { - var size: ButtonSize - var rounded: ButtonRounded - var width: ButtonWidth - var shadow: Bool - var isBordered: Bool - var borderLineWidth: CGFloat - let configuration: ButtonStyle.Configuration - @Environment(\.isEnabled) private var isEnabled: Bool - var body: some View { - configuration.label - .body(true) - .padding(.horizontal, Space.small) - .foregroundColor(isEnabled ? Color.backgroundPrimary : .onPrimaryTertiary) - .frame(maxWidth: width == .full ? .infinity : width == .standart ? nil : size == .large ? Constants.heightL : Constants.heightM, - minHeight: size == .large ? ButtonStyleExtended.Constants.heightL : ButtonStyleExtended.Constants.heightM) - .background( - RoundedRectangle(cornerRadius: rounded == .none ? 0 : rounded == .medium ? ButtonStyleExtended.Constants.radiusM : rounded == .small ? ButtonStyleExtended.Constants.radiusS : - size == .large ? ButtonStyleExtended.Constants.heightL / 2 : ButtonStyleExtended.Constants.heightM / 2, - style: .continuous) - .fill(isEnabled ? Color.primary : Color.primary.opacity(0.9)) - .overlay( - RoundedRectangle(cornerRadius: rounded == .none ? 0 : rounded == .medium ? ButtonStyleExtended.Constants.radiusM : rounded == .small ? ButtonStyleExtended.Constants.radiusS : - size == .large ? ButtonStyleExtended.Constants.heightL / 2 : ButtonStyleExtended.Constants.heightM / 2, - style: .continuous) - .stroke(isBordered - ? Color.border - : isEnabled ? Color.primary : Color.primary.opacity(0.9), lineWidth: 1) - ) - ) - .opacity(configuration.isPressed ? 0.9 : 1) - .scaleEffect(configuration.isPressed ? 0.95 : 1) - .shadowElevaton(shadow ? .z2 : .z0, color: Color.primary) - } - } - - struct SecondaryButton: View { - var size: ButtonSize - var rounded: ButtonRounded - var width: ButtonWidth - var shadow: Bool - var isBordered: Bool - var borderLineWidth: CGFloat - let configuration: ButtonStyle.Configuration - @Environment(\.isEnabled) private var isEnabled: Bool - var body: some View { - configuration.label - .body(true) - .padding(.horizontal, Space.small) - .foregroundColor(isEnabled ? .onSurfacePrimary : .onSurfaceTertiary) - .frame(maxWidth: width == .full ? .infinity : width == .standart ? nil : size == .large ? Constants.heightL : Constants.heightM, - minHeight: size == .large ? ButtonStyleExtended.Constants.heightL : ButtonStyleExtended.Constants.heightM) - .background( - RoundedRectangle(cornerRadius: rounded == .none ? 0 : rounded == .medium ? ButtonStyleExtended.Constants.radiusM : rounded == .small ? ButtonStyleExtended.Constants.radiusS : - size == .large ? ButtonStyleExtended.Constants.heightL / 2 : ButtonStyleExtended.Constants.heightM / 2, - style: .continuous) - .fill(isEnabled ? Color.surfacePrimary : Color.surfaceSecondary.opacity(0.9)) - .overlay( - RoundedRectangle(cornerRadius: rounded == .none ? 0 : rounded == .medium ? ButtonStyleExtended.Constants.radiusM : rounded == .small ? ButtonStyleExtended.Constants.radiusS : - size == .large ? ButtonStyleExtended.Constants.heightL / 2 : ButtonStyleExtended.Constants.heightM / 2, - style: .continuous) - .stroke(isBordered - ? Color.border - : isEnabled ? Color.surfacePrimary : Color.surfaceSecondary.opacity(0.9), lineWidth: 1) - ) - ) - .opacity(configuration.isPressed ? 0.9 : 1) - .scaleEffect(configuration.isPressed ? 0.95 : 1) - .shadowElevaton(shadow ? .z2 : .z0) - } - } - - struct GrayButton: View { - var size: ButtonSize - var rounded: ButtonRounded - var width: ButtonWidth - var shadow: Bool - var isBordered: Bool - var borderLineWidth: CGFloat - let configuration: ButtonStyle.Configuration - @Environment(\.isEnabled) private var isEnabled: Bool - var body: some View { - configuration.label - .body(true) - .padding(.horizontal, Space.small) - .foregroundColor(isEnabled ? .onBackgroundPrimary : .onBackgroundTertiary) - .frame(maxWidth: width == .full ? .infinity : width == .standart ? nil : size == .large ? Constants.heightL : Constants.heightM, - minHeight: size == .large ? ButtonStyleExtended.Constants.heightL : ButtonStyleExtended.Constants.heightM) - .background( - RoundedRectangle(cornerRadius: rounded == .none ? 0 : rounded == .medium ? ButtonStyleExtended.Constants.radiusM : rounded == .small ? ButtonStyleExtended.Constants.radiusS : - size == .large ? ButtonStyleExtended.Constants.heightL / 2 : ButtonStyleExtended.Constants.heightM / 2, - style: .continuous) - .fill(isEnabled ? Color.surfaceSecondary : Color.surfaceSecondary.opacity(0.9)) - .overlay( - RoundedRectangle(cornerRadius: rounded == .none ? 0 : rounded == .medium ? ButtonStyleExtended.Constants.radiusM : rounded == .small ? ButtonStyleExtended.Constants.radiusS : - size == .large ? ButtonStyleExtended.Constants.heightL / 2 : ButtonStyleExtended.Constants.heightM / 2, - style: .continuous) - .stroke(isBordered - ? Color.border - : isEnabled ? Color.surfaceSecondary : Color.surfaceSecondary.opacity(0.9), lineWidth: 1) - ) - ) - .opacity(configuration.isPressed ? 0.9 : 1) - .scaleEffect(configuration.isPressed ? 0.95 : 1) - .shadowElevaton(shadow ? .z2 : .z0) - } - } - - struct TextButton: View { - var size: ButtonSize - var rounded: ButtonRounded - var width: ButtonWidth - let configuration: ButtonStyle.Configuration - @Environment(\.isEnabled) private var isEnabled: Bool - var body: some View { - configuration.label - .body(true) - .padding(.horizontal, Space.small) - .foregroundColor(isEnabled ? .onSurfacePrimary : .onSurfaceTertiary) - .frame(maxWidth: width == .full ? .infinity : width == .standart ? nil : size == .large ? Constants.heightL : Constants.heightM, - minHeight: size == .large ? ButtonStyleExtended.Constants.heightL : ButtonStyleExtended.Constants.heightM) - .opacity(configuration.isPressed ? 0.9 : 1) - .scaleEffect(configuration.isPressed ? 0.95 : 1) - } - } - - struct LinkButton: View { - var size: ButtonSize - var rounded: ButtonRounded - var width: ButtonWidth - var shadow: Bool - let configuration: ButtonStyle.Configuration - @Environment(\.isEnabled) private var isEnabled: Bool - var body: some View { - configuration.label - .body(true) - .padding(.horizontal, Space.small) - .foregroundColor(isEnabled ? .accent : Color.accent.opacity(0.7)) - .frame(maxWidth: width == .full ? .infinity : width == .standart ? nil : size == .large ? Constants.heightL : Constants.heightM, - minHeight: size == .large ? ButtonStyleExtended.Constants.heightL : ButtonStyleExtended.Constants.heightM) - .opacity(configuration.isPressed ? 0.9 : 1) - .scaleEffect(configuration.isPressed ? 0.95 : 1) - } - } - - struct DeleteButton: View { - var size: ButtonSize - var rounded: ButtonRounded - var width: ButtonWidth - var shadow: Bool - let configuration: ButtonStyle.Configuration - @Environment(\.isEnabled) private var isEnabled: Bool - var body: some View { - configuration.label - .body(true) - .padding(.horizontal, Space.small) - .foregroundColor(isEnabled ? .error : Color.error.opacity(0.7)) - .frame(maxWidth: width == .full ? .infinity : width == .standart ? nil : size == .large ? Constants.heightL : Constants.heightM, - minHeight: size == .large ? ButtonStyleExtended.Constants.heightL : ButtonStyleExtended.Constants.heightM) - .opacity(configuration.isPressed ? 0.9 : 1) - .scaleEffect(configuration.isPressed ? 0.95 : 1) - } - } -} - -public extension Button { - /// Changes the appearance of the button - @MainActor @available(*, deprecated, message: "Use native buttonStyle", renamed: "buttonStyle") - func style(_ style: LegacyButtonType) -> some View { - buttonStyle(ButtonStyleExtended(style: style)) - } - - @MainActor @available(*, deprecated, message: "Use native buttonStyle", renamed: "buttonStyle") - func style(_ style: LegacyButtonType, size: ButtonSize) -> some View { - buttonStyle(ButtonStyleExtended(style: style, size: size)) - } - - @MainActor @available(*, deprecated, message: "Use native buttonStyle", renamed: "buttonStyle") - func style(_ style: LegacyButtonType, size: ButtonSize, shadow: Bool) -> some View { - buttonStyle(ButtonStyleExtended(style: style, size: size, shadow: shadow)) - } - - @MainActor @available(*, deprecated, message: "Use native buttonStyle", renamed: "buttonStyle") - func style(_ style: LegacyButtonType, size: ButtonSize, rounded: ButtonRounded, width: ButtonWidth = .standart, shadow: Bool) -> some View { - buttonStyle(ButtonStyleExtended(style: style, size: size, rounded: rounded, width: width, shadow: shadow)) - } -} diff --git a/Sources/OversizeUI/Deprecated/HUDDeprecated.swift b/Sources/OversizeUI/Deprecated/HUDDeprecated.swift deleted file mode 100644 index c6aab44..0000000 --- a/Sources/OversizeUI/Deprecated/HUDDeprecated.swift +++ /dev/null @@ -1,236 +0,0 @@ -// -// Copyright © 2021 Alexander Romanov -// HUD.swift, created on 26.04.2021 -// - -import SwiftUI - -public enum HUDType { - case hud, alert -} - -public class HUDDeprecated: ObservableObject { - @Published public var isPresented: Bool = false - public var title: String - public var icon: IconsNames? - public var image: Image? - @Published public var type: HUDType = .hud - - public init(title: String = "") { - self.title = title - type = .hud - } - - public init(title: String = "", icon: IconsNames) { - self.title = title - self.icon = icon - type = .hud - } - - public init(title: String = "", image: Image) { - self.title = title - self.image = image - type = .alert - } - - public func show(title: String) { - self.title = title - type = .hud - withAnimation { - isPresented = true - } - } - - public func show(title: String, icon: IconsNames, type: HUDType = .hud) { - self.title = title - self.icon = icon - self.type = type - withAnimation { - isPresented = true - } - } - - public func show(title: String, image: Image, type: HUDType = .hud) { - self.title = title - self.image = image - self.type = type - withAnimation { - isPresented = true - } - } -} - -public extension View { - func hudDeprecated(isPresented: Binding, - type: Binding, - @ViewBuilder content: () -> some View) -> some View - { - ZStack(alignment: type.wrappedValue == .hud ? .top : .center) { - self - // .blur(radius: type.wrappedValue == .alert && isPresented.wrappedValue ? 10 : 0) - - if isPresented.wrappedValue { - HUDSurfaceView(type: type, content: content) - .transition( - type.wrappedValue == .hud - ? AnyTransition.move(edge: .top).combined(with: .opacity) - : AnyTransition.opacity.animation(.default) - ) - .onAppear { - DispatchQueue.main.asyncAfter(deadline: .now() + 3) { - withAnimation { - isPresented.wrappedValue = false - } - } - } - .zIndex(1) - } - } - } -} - -public struct HUDSurfaceView: View { - public let content: Content - @Binding public var type: HUDType - - public init(type: Binding, @ViewBuilder content: () -> Content) { - _type = type - self.content = content() - } - - public var body: some View { - #if os(iOS) - if #available(iOS 15.0, *) { - content - .padding(.top, topPadding) - .padding(.horizontal, horizontalPadding) - .padding(.bottom, bottomPadding) - .background(backgroundMaterial(type: type), - in: backgroundShape(type: type)) - .shadowElevaton(type == .hud ? .z2 : .z0) - } else { - content - .padding(.top, topPadding) - .padding(.horizontal, horizontalPadding) - .padding(.bottom, bottomPadding) - .background(background(type: type)) - } - #else - content - .padding(.top, topPadding) - .padding(.horizontal, horizontalPadding) - .padding(.bottom, bottomPadding) - .background(background(type: type)) - #endif - } - - #if os(iOS) - @available(iOS 15.0, *) - private func backgroundMaterial(type: HUDType) -> Material { - switch type { - case .hud: - .regular - case .alert: - .ultraThinMaterial - } - } - #endif - - private func backgroundShape(type: HUDType) -> AnyShape { - switch type { - case .hud: - AnyShape(Capsule()) - - case .alert: - AnyShape(RoundedRectangle(cornerRadius: Radius.medium, style: .continuous)) - } - } - - @ViewBuilder - private func background(type: HUDType) -> some View { - switch type { - case .hud: - Capsule() - .foregroundColor(Color.surfacePrimary) - .shadowElevaton(.z2) - case .alert: - RoundedRectangle(cornerRadius: 20, style: .continuous) - .foregroundColor(Color.surfacePrimary) - .shadowElevaton(.z4) - } - } - - var horizontalPadding: Space { - switch type { - case .hud: - .medium - case .alert: - .medium - } - } - - var topPadding: Space { - switch type { - case .hud: - .small - case .alert: - .xLarge - } - } - - var bottomPadding: Space { - switch type { - case .hud: - .small - case .alert: - .xLarge - } - } -} - -public struct HUDContent: View { - public var title: String - // public var icon: Icons? - public var image: Image? - public var type: HUDType - - public init(title: String, image: Image?, type: HUDType = .hud) { - self.title = title - self.image = image - self.type = type - } - - public var body: some View { - // Text(title) - // background(background(type: type)) - background - } - - private var background: some View { - Group { - switch type { - case .hud: - HStack { -// if let icon = hudState.icon { -// IconDeprecated(icon, color: .onSurfacePrimary) -// } - - Text(title) - .body() - .onSurfacePrimaryForeground() - } - case .alert: - VStack(spacing: .large) { - if let image { - image - } - - Text(title) - .title3() - .onSurfacePrimaryForeground() - } - .frame(minWidth: 225) - } - } - } -} diff --git a/Sources/OversizeUI/Deprecated/RowDeprecated.swift b/Sources/OversizeUI/Deprecated/RowDeprecated.swift deleted file mode 100644 index 564ecb0..0000000 --- a/Sources/OversizeUI/Deprecated/RowDeprecated.swift +++ /dev/null @@ -1,270 +0,0 @@ -// -// Copyright © 2021 Alexander Romanov -// RowDeprecated.swift, created on 11.09.2021 -// - -import SwiftUI - -public struct RowDeprecated: View { - @Environment(\.elevation) private var elevation: Elevation - @Environment(\.controlRadius) var controlRadius: Radius - @Environment(\.rowContentMargins) var controlPadding: EdgeSpaceInsets - @Environment(\.multilineTextAlignment) var multilineTextAlignment - @Environment(\.isPremium) var premiumStatus - @Environment(\.isAccent) var isAccent - @Environment(\.isLoading) var isLoading - - private let title: String - private let subtitle: String? - - private var leadingType: RowLeadingType? - private var trallingType: RowTrailingType? - - private let action: (() -> Void)? - - private var isPremiumOption: Bool = false - private var isShowArrowIcon: Bool = false - - private var iconBackgroundColor: Color? - - private var сlearButtonStyle: RowClearIconStyle = .default - private var сlearAction: (() -> Void)? - - private var isShowSubtitle: Bool { - (subtitle?.isEmpty) != nil - } - - public init(_ title: String, - subtitle: String? = nil, - action: (() -> Void)? = nil) - { - self.title = title - self.subtitle = subtitle - self.action = action - } - - @available(*, deprecated, message: "Use leading: {} and tralling: {}") - public init(_ title: String, - subtitle: String? = nil, - leadingType: RowLeadingType? = nil, - trallingType: RowTrailingType? = nil, - paddingHorizontal _: Space = .medium, - paddingVertical _: Space = .small, - action: (() -> Void)? = nil) - { - self.title = title - self.subtitle = subtitle - self.leadingType = leadingType - self.trallingType = trallingType - self.action = action - } - - public var body: some View { - if action != nil { - Button { - if isPremiumOption == false || (isPremiumOption && premiumStatus) { - action?() - } - } label: { - content(multilineTextAlignment) - } - .buttonStyle(.row) - } else { - content(multilineTextAlignment) - } - } - - @ViewBuilder - private func content(_ textAlignment: TextAlignment) -> some View { - VStack(alignment: .leading) { - HStack(spacing: .zero) { - if let leadingType { - RowLeading(leadingType, isShowSubtitle: isShowSubtitle, iconBackgroundColor: iconBackgroundColor) - .padding(.trailing, .small) - } - - if textAlignment == .trailing || textAlignment == .center { - Spacer() - } - - text - - premiumLabel - - if textAlignment == .leading || textAlignment == .center { - Spacer() - } - - if isLoading { - ProgressView() - .padding(.trailing, .xSmall) - } - - сlearButton - - if let trallingType { - RowTrailing(trallingType, isPremiumOption: isPremiumOption) - .padding(.leading, .xxSmall) - } - - if isShowArrowIcon { - IconDeprecated(.chevronRight, color: .onSurfaceTertiary) - } - } - } - .padding( - EdgeInsets(top: controlPadding.top, - leading: controlPadding.leading, - bottom: controlPadding.bottom, - trailing: controlPadding.trailing) - ) - } - - private var text: some View { - VStack(alignment: textAlignment, spacing: .xxxSmall) { - Text(title) - .headline(.semibold) - .foregroundColor(.onSurfacePrimary) - if let subtitle, !subtitle.isEmpty { - Text(subtitle) - .subheadline() - .foregroundColor(.onSurfaceSecondary) - } - } - .multilineTextAlignment(multilineTextAlignment) - } - - @ViewBuilder - private var сlearButton: some View { - if сlearAction != nil { - Button { - сlearAction?() - } label: { - ZStack { - IconDeprecated(.xMini, color: .onSurfaceTertiary) - .background( - RoundedRectangle(cornerRadius: .small, style: .continuous) - .fillSurfaceSecondary() - .opacity(сlearButtonStyle == .onSurface ? 1 : 0) - ) - } - } - } - } - - @ViewBuilder - private var premiumLabel: some View { - if isPremiumOption, premiumStatus == false { - PremiumLabel(text: "Pro", size: .small) - .padding(.leading, .small) - } - } - - private var textAlignment: HorizontalAlignment { - switch multilineTextAlignment { - case .leading: - .leading - case .center: - .center - case .trailing: - .trailing - } - } -} - -// MARK: - Modificators - -public extension RowDeprecated { - func premium(_ premium: Bool = true) -> RowDeprecated { - var control = self - control.isPremiumOption = premium - return control - } - - func rowArrow(_ showArrowIcon: Bool = true) -> RowDeprecated { - var control = self - control.isShowArrowIcon = showArrowIcon - return control - } - - func rowIconBackgroundColor(_ color: Color?) -> RowDeprecated { - var control = self - control.iconBackgroundColor = color - return control - } - - func rowClearButton(style: RowClearIconStyle = .default, action: (() -> Void)?) -> RowDeprecated { - var control = self - control.сlearButtonStyle = style - control.сlearAction = action - return control - } - - @available(*, deprecated, message: "Use leading: {} and tralling: {}") - func rowLeading(_ leading: RowLeadingType?) -> RowDeprecated { - var control = self - control.leadingType = leading - return control - } - - @available(*, deprecated, message: "Use leading: {} and tralling: {}") - func rowTrailing(_ trailing: RowTrailingType?) -> RowDeprecated { - var control = self - control.trallingType = trailing - return control - } -} - -// public extension View { -// func rowOnSurface(_ elevation: Elevation = .z4, backgroundColor: Color? = nil) -> some View { -// Surface { -// self.rowContentInset(.zero) -// } -// .surfaceBackgroundColor(backgroundColor) -// .elevation(elevation) -// } -// } - -// MARK: - Preview - -// swiftlint:disable all -struct ListRowDeprecated_Previews: PreviewProvider { - static var previews: some View { - VStack(spacing: .medium) { - Row("Title") - - Row("Title", subtitle: "Subtitle") - - Row("Title", subtitle: "Subtitle") { - IconDeprecated(.calendar) - } - - Radio(isOn: true, label: { - Row("Title", subtitle: "Subtitle") { - IconDeprecated(.calendar) - } - }) - - Checkbox(isOn: .constant(true), label: { - Row("Title", subtitle: "Subtitle") { - IconDeprecated(.calendar) - } - .rowOnSurface() - }) - -// Row("Title", subtitle: "Subtitle") -// .rowLeading(.avatar(AvatarView(firstName: "Name"))) -// .rowTrailing(.text("Text")) - -// Row("Title") -// .rowTrailing(.toggleWithArrowButton(isOn: .constant(true), action: nil)) -// -// Row("Title", subtitle: "Subtitle") -// .rowTrailing(.button("Button", action: {})) - - Row("Title", subtitle: "Red") - .premium() - } - .previewLayout(.fixed(width: 375, height: 70)) - } -} diff --git a/Sources/OversizeUI/Deprecated/RowLeading.swift b/Sources/OversizeUI/Deprecated/RowLeading.swift deleted file mode 100644 index 1fc1433..0000000 --- a/Sources/OversizeUI/Deprecated/RowLeading.swift +++ /dev/null @@ -1,76 +0,0 @@ -// -// Copyright © 2021 Alexander Romanov -// RowLeading.swift, created on 23.12.2022 -// - -import SwiftUI - -public enum RowLeadingType { - case icon(_ name: IconsNames) - case iconOnSurface(_ name: IconsNames) - case image(_ image: Image, color: Color? = .onSurfacePrimary) - case imageOnSurface(_ image: Image, color: Color? = nil) - case systemImage(_ imageName: String) - case avatar(_ avatar: Avatar) - - @available(*, deprecated, message: "Use leading: {}") - case view(_ view: AnyView) -} - -struct RowLeading: View { - private let type: RowLeadingType - private let isShowSubtitle: Bool - private let iconBackgroundColor: Color? - - init(_ type: RowLeadingType, isShowSubtitle: Bool = false, iconBackgroundColor: Color? = nil) { - self.type = type - self.isShowSubtitle = isShowSubtitle - self.iconBackgroundColor = iconBackgroundColor - } - - var body: some View { - switch type { - case let .icon(icon): - IconDeprecated(icon) - - case let .image(image, color): - image - .renderingMode(color != nil ? .template : .original) - .resizable() - .scaledToFill() - .foregroundColor(color) - .frame(width: isShowSubtitle ? 48 : 24, height: isShowSubtitle ? 48 : 24) - .cornerRadius(isShowSubtitle ? 4 : 2) - - case let .avatar(avatar): - avatar - - case let .iconOnSurface(icon): - Surface { - IconDeprecated(icon) - } - .surfaceStyle(.secondary) - .surfaceBackgroundColor(iconBackgroundColor) - .surfaceContentMargins(.xxSmall) - - case let .imageOnSurface(image, color): - Surface { - image - .renderingMode(.template) - .foregroundColor(color) - } - .surfaceStyle(.secondary) - .surfaceBackgroundColor(iconBackgroundColor) - .surfaceContentMargins(.xxSmall) - - case let .systemImage(systemImage): - Image(systemName: systemImage) - .foregroundColor(Color.onBackgroundPrimary) - .font(.system(size: 24)) - .frame(width: 24, height: 24, alignment: .center) - - case let .view(view): - view - } - } -} diff --git a/Sources/OversizeUI/Deprecated/RowTrailing.swift b/Sources/OversizeUI/Deprecated/RowTrailing.swift deleted file mode 100644 index dfc60dc..0000000 --- a/Sources/OversizeUI/Deprecated/RowTrailing.swift +++ /dev/null @@ -1,119 +0,0 @@ -// -// Copyright © 2021 Alexander Romanov -// RowTrailing.swift, created on 23.12.2022 -// - -import SwiftUI - -import SwiftUI - -public enum RowTrailingType { - @available(*, deprecated, message: "Use Radio") - case radio(isOn: Binding) - @available(*, deprecated, message: "Use Checkbox") - case checkbox(isOn: Binding) - @available(*, deprecated, message: "Use Toogle") - case toggle(isOn: Binding) - @available(*, deprecated, message: "Use Toogle") - case toggleWithArrowButton(isOn: Binding, action: (() -> Void)? = nil) - @available(watchOS, unavailable) - case timePicker(date: Binding) - case arrowIcon - case text(_ text: String) - @available(tvOS, unavailable) - case button(_ text: String, action: () -> Void) -} - -struct RowTrailing: View { - @Environment(\.isPremium) var premiumStatus - - private let type: RowTrailingType - private let isPremiumOption: Bool - - init(_ type: RowTrailingType, isPremiumOption: Bool = false) { - self.type = type - self.isPremiumOption = isPremiumOption - } - - // swiftlint:disable function_body_length - var body: some View { - switch type { - case let .toggle(isOn): - Toggle(isOn: isOn) {} - .labelsHidden() - .disabled(isPremiumOption && premiumStatus == false) - - case let .radio(isOn: isOn): - ZStack { - Circle() - .stroke(Color.onSurfaceTertiary, lineWidth: 4) - .frame(width: 24, height: 24) - .cornerRadius(12) - .opacity(isOn.wrappedValue ? 0 : 1) - - Circle().fill(Color.accent) - .frame(width: 24, height: 24) - .cornerRadius(12) - .opacity(isOn.wrappedValue ? 1 : 0) - - Circle().fill(Color.white).frame(width: 8, height: 8) - .cornerRadius(4) - .opacity(isOn.wrappedValue ? 1 : 0) - } - - case let .checkbox(isOn: isOn): - ZStack { - RoundedRectangle(cornerRadius: Radius.small, style: .continuous) - .strokeBorder(Color.onSurfaceTertiary, lineWidth: 2.5) - .frame(width: 24, height: 24) - .opacity(isOn.wrappedValue ? 0 : 1) - - RoundedRectangle(cornerRadius: Radius.small, style: .continuous).fill(Color.accent) - .frame(width: 24, height: 24) - .opacity(isOn.wrappedValue ? 1 : 0) - - Image(systemName: "checkmark") - .font(.caption.weight(.black)) - .foregroundColor(.onPrimary) - .opacity(isOn.wrappedValue ? 1 : 0) - } - - case let .toggleWithArrowButton(isOn: isOn, action: action): - HStack { - Toggle(isOn: isOn) {} - .labelsHidden() - - Button(action: action ?? {}, label: { - IconDeprecated(.chevronRight, color: .onSurfaceTertiary) - }) - } - .disabled(isPremiumOption && premiumStatus == false) - - case .arrowIcon: - IconDeprecated(.chevronRight, color: .onSurfaceTertiary) - - case let .timePicker(date: date): - #if os(watchOS) - EmptyView() - #elseif os(iOS) - DatePicker("", selection: date, displayedComponents: .hourAndMinute) - .labelsHidden() - #endif - case let .text(text): - Text(text) - .subheadline() - .foregroundColor(.onSurfaceSecondary) - - case let .button(text, action: action): - #if os(tvOS) - EmptyView() - #else - Button(text, action: action) - .buttonStyle(.tertiary) - .controlBorderShape(.capsule) - .controlSize(.small) - .disabled(isPremiumOption && premiumStatus == false) - #endif - } - } -} diff --git a/Sources/OversizeUI/Extensions/View/View+NavigationView.swift b/Sources/OversizeUI/Deprecated/View+NavigationView.swift similarity index 100% rename from Sources/OversizeUI/Extensions/View/View+NavigationView.swift rename to Sources/OversizeUI/Deprecated/View+NavigationView.swift diff --git a/Sources/OversizeUI/Deprecated/View+ScrollViewOffset.swift b/Sources/OversizeUI/Deprecated/View+ScrollViewOffset.swift deleted file mode 100644 index 95dcaff..0000000 --- a/Sources/OversizeUI/Deprecated/View+ScrollViewOffset.swift +++ /dev/null @@ -1,18 +0,0 @@ -// -// Copyright © 2021 Alexander Romanov -// View+ScrollViewOffset.swift, created on 22.03.2022 -// - -import SwiftUI - -public extension View { - func scrollOffset(name: String = "", onChange: @escaping (CGFloat) -> Void) -> some View { - overlay( - GeometryReader { - Color.clear - .preference(key: ViewOffsetKey.self, - value: -$0.frame(in: name == "" ? .global : .named(name)).origin.y) - }) - .onPreferenceChange(ViewOffsetKey.self, perform: onChange) - } -} diff --git a/Sources/OversizeUI/Deprecated/ViewOffsetKey.swift b/Sources/OversizeUI/Deprecated/ViewOffsetKey.swift deleted file mode 100644 index d46c314..0000000 --- a/Sources/OversizeUI/Deprecated/ViewOffsetKey.swift +++ /dev/null @@ -1,13 +0,0 @@ -// -// Copyright © 2021 Alexander Romanov -// ViewOffsetKey.swift, created on 22.03.2022 -// - -import SwiftUI - -public struct ViewOffsetKey: PreferenceKey { - public static let defaultValue = CGFloat.zero - public static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) { - value += nextValue() - } -} diff --git a/Sources/OversizeUI/Extensions/View/View+Navigationable.swift b/Sources/OversizeUI/Extensions/View/View+Navigationable.swift deleted file mode 100644 index 3af643c..0000000 --- a/Sources/OversizeUI/Extensions/View/View+Navigationable.swift +++ /dev/null @@ -1,20 +0,0 @@ -// -// Copyright © 2021 Alexander Romanov -// View+Navigationable.swift, created on 14.04.2022 -// - -import SwiftUI - -public extension View { - @available(macOS, unavailable) - @available(watchOS, unavailable) - @available(tvOS, unavailable) - func navigationable(_ navigationBarHidden: Bool = true) -> some View { - NavigationView { - self - #if os(iOS) - .navigationBarHidden(navigationBarHidden) - #endif - } - } -} From 703fff756f6790d84c8e8669c865fef6b03e8230 Mon Sep 17 00:00:00 2001 From: Alexandr Romanov Date: Sat, 9 Nov 2024 23:40:58 +0300 Subject: [PATCH 30/30] Fix examples #major --- Example/Example WatchKit App/Info.plist | 6 +- Example/Example.xcodeproj/project.pbxproj | 208 ++++-------------- .../xcschemes/Example (iOS).xcscheme | 2 +- .../xcschemes/Example (macOS).xcscheme | 2 +- Example/Shared/ComponentsList.swift | 1 - .../DemoPages/SegmentedControlDemo.swift | 2 +- Example/Shared/DemoPages/SurfaceDemo.swift | 2 +- .../Controls/Avatar/AvatarPreview.swift | 2 +- .../OversizeUI/Controls/PageView/Page.swift | 56 ++--- Sources/OversizeUI/Controls/Row/Row.swift | 37 ---- .../ScrollViewWithStickyHeader.swift | 8 +- .../Controls/URLField/URLField.swift | 4 +- .../Core/EnvironmentKeys/Platform.swift | 16 -- 13 files changed, 92 insertions(+), 254 deletions(-) diff --git a/Example/Example WatchKit App/Info.plist b/Example/Example WatchKit App/Info.plist index 32e1d08..03a76ab 100644 --- a/Example/Example WatchKit App/Info.plist +++ b/Example/Example WatchKit App/Info.plist @@ -20,12 +20,16 @@ 1.0 CFBundleVersion 1 + CLKComplicationPrincipalClass + $(PRODUCT_MODULE_NAME).ComplicationController UISupportedInterfaceOrientations UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown - WKWatchKitApp + WKApplication + + WKWatchOnly diff --git a/Example/Example.xcodeproj/project.pbxproj b/Example/Example.xcodeproj/project.pbxproj index cf218d3..bb6f3ce 100644 --- a/Example/Example.xcodeproj/project.pbxproj +++ b/Example/Example.xcodeproj/project.pbxproj @@ -9,7 +9,6 @@ /* Begin PBXBuildFile section */ 1101694E26E41DE10035CB67 /* Example (watchOS).app in Embed Watch Content */ = {isa = PBXBuildFile; fileRef = 1101694D26E41DE10035CB67 /* Example (watchOS).app */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; 1101695326E41DE30035CB67 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1101695226E41DE30035CB67 /* Assets.xcassets */; }; - 1101695A26E41DE40035CB67 /* Example WatchKit Extension.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 1101695926E41DE40035CB67 /* Example WatchKit Extension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; 1101696326E41DE40035CB67 /* NotificationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1101696226E41DE40035CB67 /* NotificationController.swift */; }; 1101696526E41DE40035CB67 /* NotificationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1101696426E41DE40035CB67 /* NotificationView.swift */; }; 1101696726E41DE40035CB67 /* ComplicationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1101696626E41DE40035CB67 /* ComplicationController.swift */; }; @@ -91,26 +90,19 @@ remoteGlobalIDString = 1101694C26E41DE10035CB67; remoteInfo = "Example WatchKit App"; }; - 1101695B26E41DE40035CB67 /* PBXContainerItemProxy */ = { + 1101697F26E41DE50035CB67 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 84D9F9DC26BDE4EA00B2FCA2 /* Project object */; proxyType = 1; - remoteGlobalIDString = 1101695826E41DE40035CB67; - remoteInfo = "Example WatchKit Extension"; + remoteGlobalIDString = 1101694C26E41DE10035CB67; + remoteInfo = "Example WatchKit App"; }; - 1101697426E41DE50035CB67 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 84D9F9DC26BDE4EA00B2FCA2 /* Project object */; - proxyType = 1; - remoteGlobalIDString = 1101695826E41DE40035CB67; - remoteInfo = "Example WatchKit Extension"; - }; - 1101697F26E41DE50035CB67 /* PBXContainerItemProxy */ = { + 848111842CDFFFDE004D65FE /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 84D9F9DC26BDE4EA00B2FCA2 /* Project object */; proxyType = 1; remoteGlobalIDString = 1101694C26E41DE10035CB67; - remoteInfo = "Example WatchKit App"; + remoteInfo = "Example (watchOS)"; }; /* End PBXContainerItemProxy section */ @@ -126,17 +118,6 @@ name = "Embed Watch Content"; runOnlyForDeploymentPostprocessing = 0; }; - 1101698A26E41DE50035CB67 /* Embed App Extensions */ = { - isa = PBXCopyFilesBuildPhase; - buildActionMask = 2147483647; - dstPath = ""; - dstSubfolderSpec = 13; - files = ( - 1101695A26E41DE40035CB67 /* Example WatchKit Extension.appex in Embed App Extensions */, - ); - name = "Embed App Extensions"; - runOnlyForDeploymentPostprocessing = 0; - }; /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ @@ -144,7 +125,6 @@ 1101694D26E41DE10035CB67 /* Example (watchOS).app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Example (watchOS).app"; sourceTree = BUILT_PRODUCTS_DIR; }; 1101695226E41DE30035CB67 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 1101695426E41DE30035CB67 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 1101695926E41DE40035CB67 /* Example WatchKit Extension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = "Example WatchKit Extension.appex"; sourceTree = BUILT_PRODUCTS_DIR; }; 1101696226E41DE40035CB67 /* NotificationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationController.swift; sourceTree = ""; }; 1101696426E41DE40035CB67 /* NotificationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationView.swift; sourceTree = ""; }; 1101696626E41DE40035CB67 /* ComplicationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ComplicationController.swift; sourceTree = ""; }; @@ -369,7 +349,6 @@ 84D9F9F026BDE4EB00B2FCA2 /* Example.app */, 1101694A26E41DE10035CB67 /* Example.app */, 1101694D26E41DE10035CB67 /* Example (watchOS).app */, - 1101695926E41DE40035CB67 /* Example WatchKit Extension.appex */, 1101697326E41DE40035CB67 /* ExampleTests.xctest */, 1101697E26E41DE50035CB67 /* ExampleUITests.xctest */, 1101699E26E423260035CB67 /* Example (tvOS).app */, @@ -419,37 +398,17 @@ buildConfigurationList = 1101699226E41DE50035CB67 /* Build configuration list for PBXNativeTarget "Example (watchOS)" */; buildPhases = ( 1101694B26E41DE10035CB67 /* Resources */, - 1101698A26E41DE50035CB67 /* Embed App Extensions */, + 1101695526E41DE40035CB67 /* Sources */, + 1101695626E41DE40035CB67 /* Frameworks */, ); buildRules = ( ); dependencies = ( - 1101695C26E41DE40035CB67 /* PBXTargetDependency */, ); name = "Example (watchOS)"; productName = "Example WatchKit App"; productReference = 1101694D26E41DE10035CB67 /* Example (watchOS).app */; - productType = "com.apple.product-type.application.watchapp2"; - }; - 1101695826E41DE40035CB67 /* Example WatchKit Extension */ = { - isa = PBXNativeTarget; - buildConfigurationList = 1101699126E41DE50035CB67 /* Build configuration list for PBXNativeTarget "Example WatchKit Extension" */; - buildPhases = ( - 1101695526E41DE40035CB67 /* Sources */, - 1101695626E41DE40035CB67 /* Frameworks */, - 1101695726E41DE40035CB67 /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = "Example WatchKit Extension"; - packageProductDependencies = ( - 114C9CCA26ECC74A00520E04 /* OversizeUI */, - ); - productName = "Example WatchKit Extension"; - productReference = 1101695926E41DE40035CB67 /* Example WatchKit Extension.appex */; - productType = "com.apple.product-type.watchkit2-extension"; + productType = "com.apple.product-type.application"; }; 1101697226E41DE40035CB67 /* ExampleTests */ = { isa = PBXNativeTarget; @@ -462,7 +421,7 @@ buildRules = ( ); dependencies = ( - 1101697526E41DE50035CB67 /* PBXTargetDependency */, + 848111852CDFFFDE004D65FE /* PBXTargetDependency */, ); name = ExampleTests; productName = ExampleTests; @@ -553,8 +512,9 @@ 84D9F9DC26BDE4EA00B2FCA2 /* Project object */ = { isa = PBXProject; attributes = { + BuildIndependentTargetsInParallel = YES; LastSwiftUpdateCheck = 1250; - LastUpgradeCheck = 1330; + LastUpgradeCheck = 1610; TargetAttributes = { 1101694926E41DE10035CB67 = { CreatedOnToolsVersion = 12.5.1; @@ -563,12 +523,9 @@ CreatedOnToolsVersion = 12.5.1; LastSwiftMigration = 1250; }; - 1101695826E41DE40035CB67 = { - CreatedOnToolsVersion = 12.5.1; - }; 1101697226E41DE40035CB67 = { CreatedOnToolsVersion = 12.5.1; - TestTargetID = 1101695826E41DE40035CB67; + TestTargetID = 1101694C26E41DE10035CB67; }; 1101697D26E41DE50035CB67 = { CreatedOnToolsVersion = 12.5.1; @@ -602,7 +559,6 @@ 84D9F9EF26BDE4EB00B2FCA2 /* Example (macOS) */, 1101694926E41DE10035CB67 /* Example */, 1101694C26E41DE10035CB67 /* Example (watchOS) */, - 1101695826E41DE40035CB67 /* Example WatchKit Extension */, 1101697226E41DE40035CB67 /* ExampleTests */, 1101697D26E41DE50035CB67 /* ExampleUITests */, 1101699D26E423260035CB67 /* Example (tvOS) */, @@ -619,19 +575,12 @@ runOnlyForDeploymentPostprocessing = 0; }; 1101694B26E41DE10035CB67 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 1101695326E41DE30035CB67 /* Assets.xcassets in Resources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 1101695726E41DE40035CB67 /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( 1101696C26E41DE40035CB67 /* Preview Assets.xcassets in Resources */, 1101696926E41DE40035CB67 /* Assets.xcassets in Resources */, + 1101695326E41DE30035CB67 /* Assets.xcassets in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -788,21 +737,16 @@ target = 1101694C26E41DE10035CB67 /* Example (watchOS) */; targetProxy = 1101694F26E41DE10035CB67 /* PBXContainerItemProxy */; }; - 1101695C26E41DE40035CB67 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = 1101695826E41DE40035CB67 /* Example WatchKit Extension */; - targetProxy = 1101695B26E41DE40035CB67 /* PBXContainerItemProxy */; - }; - 1101697526E41DE50035CB67 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = 1101695826E41DE40035CB67 /* Example WatchKit Extension */; - targetProxy = 1101697426E41DE50035CB67 /* PBXContainerItemProxy */; - }; 1101698026E41DE50035CB67 /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = 1101694C26E41DE10035CB67 /* Example (watchOS) */; targetProxy = 1101697F26E41DE50035CB67 /* PBXContainerItemProxy */; }; + 848111852CDFFFDE004D65FE /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 1101694C26E41DE10035CB67 /* Example (watchOS) */; + targetProxy = 848111842CDFFFDE004D65FE /* PBXContainerItemProxy */; + }; /* End PBXTargetDependency section */ /* Begin XCBuildConfiguration section */ @@ -817,7 +761,7 @@ PRODUCT_BUNDLE_IDENTIFIER = romanov.cc.Example; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; }; name = Debug; }; @@ -832,7 +776,7 @@ PRODUCT_BUNDLE_IDENTIFIER = romanov.cc.Example; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; VALIDATE_PRODUCT = YES; }; name = Release; @@ -840,25 +784,23 @@ 1101698826E41DE50035CB67 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_COMPLICATION_NAME = Complication; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CLANG_ENABLE_MODULES = YES; CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = ER582ZK85C; - IBSC_MODULE = Example_WatchKit_Extension; INFOPLIST_FILE = "Example WatchKit App/Info.plist"; LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - "@loader_path/../Frameworks", + "@executable_path/Frameworks", + "@executable_path/../../Frameworks", ); PRODUCT_BUNDLE_IDENTIFIER = romanov.cc.Example.watchkitapp; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = watchos; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; TARGETED_DEVICE_FAMILY = 4; WATCHOS_DEPLOYMENT_TARGET = 9.0; }; @@ -867,73 +809,22 @@ 1101698926E41DE50035CB67 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_COMPLICATION_NAME = Complication; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CLANG_ENABLE_MODULES = YES; CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = ER582ZK85C; - IBSC_MODULE = Example_WatchKit_Extension; INFOPLIST_FILE = "Example WatchKit App/Info.plist"; LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - "@loader_path/../Frameworks", - ); - PRODUCT_BUNDLE_IDENTIFIER = romanov.cc.Example.watchkitapp; - PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = watchos; - SKIP_INSTALL = YES; - SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = 4; - VALIDATE_PRODUCT = YES; - WATCHOS_DEPLOYMENT_TARGET = 9.0; - }; - name = Release; - }; - 1101698B26E41DE50035CB67 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ASSETCATALOG_COMPILER_COMPLICATION_NAME = Complication; - CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_ASSET_PATHS = "\"Example WatchKit Extension/Preview Content\""; - DEVELOPMENT_TEAM = ER582ZK85C; - ENABLE_PREVIEWS = YES; - INFOPLIST_FILE = "Example WatchKit Extension/Info.plist"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@executable_path/../../Frameworks", - ); - PRODUCT_BUNDLE_IDENTIFIER = romanov.cc.Example.watchkitapp.watchkitextension; - PRODUCT_NAME = "${TARGET_NAME}"; - SDKROOT = watchos; - SKIP_INSTALL = YES; - SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = 4; - WATCHOS_DEPLOYMENT_TARGET = 9.0; - }; - name = Debug; - }; - 1101698C26E41DE50035CB67 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ASSETCATALOG_COMPILER_COMPLICATION_NAME = Complication; - CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_ASSET_PATHS = "\"Example WatchKit Extension/Preview Content\""; - DEVELOPMENT_TEAM = ER582ZK85C; - ENABLE_PREVIEWS = YES; - INFOPLIST_FILE = "Example WatchKit Extension/Info.plist"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", "@executable_path/Frameworks", "@executable_path/../../Frameworks", ); - PRODUCT_BUNDLE_IDENTIFIER = romanov.cc.Example.watchkitapp.watchkitextension; - PRODUCT_NAME = "${TARGET_NAME}"; + PRODUCT_BUNDLE_IDENTIFIER = romanov.cc.Example.watchkitapp; + PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = watchos; SKIP_INSTALL = YES; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; TARGETED_DEVICE_FAMILY = 4; VALIDATE_PRODUCT = YES; WATCHOS_DEPLOYMENT_TARGET = 9.0; @@ -943,7 +834,6 @@ 1101698D26E41DE50035CB67 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; BUNDLE_LOADER = "$(TEST_HOST)"; CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = ER582ZK85C; @@ -956,9 +846,9 @@ PRODUCT_BUNDLE_IDENTIFIER = romanov.cc.ExampleTests; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = watchos; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; TARGETED_DEVICE_FAMILY = 4; - TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Example WatchKit Extension.appex/Example WatchKit Extension"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Example (watchOS).app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Example (watchOS)"; WATCHOS_DEPLOYMENT_TARGET = 9.0; }; name = Debug; @@ -966,7 +856,6 @@ 1101698E26E41DE50035CB67 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; BUNDLE_LOADER = "$(TEST_HOST)"; CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = ER582ZK85C; @@ -979,9 +868,9 @@ PRODUCT_BUNDLE_IDENTIFIER = romanov.cc.ExampleTests; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = watchos; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; TARGETED_DEVICE_FAMILY = 4; - TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Example WatchKit Extension.appex/Example WatchKit Extension"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Example (watchOS).app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Example (watchOS)"; VALIDATE_PRODUCT = YES; WATCHOS_DEPLOYMENT_TARGET = 9.0; }; @@ -1001,7 +890,7 @@ PRODUCT_BUNDLE_IDENTIFIER = romanov.cc.ExampleUITests; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = watchos; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; TARGETED_DEVICE_FAMILY = 4; TEST_TARGET_NAME = "Example WatchKit App"; WATCHOS_DEPLOYMENT_TARGET = 9.0; @@ -1022,7 +911,7 @@ PRODUCT_BUNDLE_IDENTIFIER = romanov.cc.ExampleUITests; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = watchos; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; TARGETED_DEVICE_FAMILY = 4; TEST_TARGET_NAME = "Example WatchKit App"; VALIDATE_PRODUCT = YES; @@ -1045,7 +934,7 @@ PRODUCT_BUNDLE_IDENTIFIER = romanov.cc.ExampletvOS; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = appletvos; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; TARGETED_DEVICE_FAMILY = 3; TVOS_DEPLOYMENT_TARGET = 15.0; }; @@ -1066,7 +955,7 @@ PRODUCT_BUNDLE_IDENTIFIER = romanov.cc.ExampletvOS; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = appletvos; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; TARGETED_DEVICE_FAMILY = 3; TVOS_DEPLOYMENT_TARGET = 15.0; VALIDATE_PRODUCT = YES; @@ -1077,6 +966,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; @@ -1107,9 +997,11 @@ CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; + DEAD_CODE_STRIPPING = YES; DEBUG_INFORMATION_FORMAT = dwarf; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; + ENABLE_USER_SCRIPT_SANDBOXING = YES; GCC_C_LANGUAGE_STANDARD = gnu11; GCC_DYNAMIC_NO_PIC = NO; GCC_NO_COMMON_BLOCKS = YES; @@ -1136,6 +1028,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; @@ -1166,9 +1059,11 @@ CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; + DEAD_CODE_STRIPPING = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_USER_SCRIPT_SANDBOXING = YES; GCC_C_LANGUAGE_STANDARD = gnu11; GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; @@ -1201,7 +1096,7 @@ PRODUCT_BUNDLE_IDENTIFIER = romanov.cc.Example; PRODUCT_NAME = Example; SDKROOT = iphoneos; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -1223,7 +1118,7 @@ PRODUCT_BUNDLE_IDENTIFIER = romanov.cc.Example; PRODUCT_NAME = Example; SDKROOT = iphoneos; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; }; @@ -1238,6 +1133,7 @@ CODE_SIGN_IDENTITY = "-"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; + DEAD_CODE_STRIPPING = YES; DEVELOPMENT_TEAM = ER582ZK85C; ENABLE_HARDENED_RUNTIME = YES; ENABLE_PREVIEWS = YES; @@ -1250,7 +1146,7 @@ PRODUCT_BUNDLE_IDENTIFIER = romanov.cc.Example; PRODUCT_NAME = Example; SDKROOT = macosx; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; }; name = Debug; }; @@ -1263,6 +1159,7 @@ CODE_SIGN_IDENTITY = "-"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; + DEAD_CODE_STRIPPING = YES; DEVELOPMENT_TEAM = ER582ZK85C; ENABLE_HARDENED_RUNTIME = YES; ENABLE_PREVIEWS = YES; @@ -1275,22 +1172,13 @@ PRODUCT_BUNDLE_IDENTIFIER = romanov.cc.Example; PRODUCT_NAME = Example; SDKROOT = macosx; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; }; name = Release; }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ - 1101699126E41DE50035CB67 /* Build configuration list for PBXNativeTarget "Example WatchKit Extension" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 1101698B26E41DE50035CB67 /* Debug */, - 1101698C26E41DE50035CB67 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; 1101699226E41DE50035CB67 /* Build configuration list for PBXNativeTarget "Example (watchOS)" */ = { isa = XCConfigurationList; buildConfigurations = ( diff --git a/Example/Example.xcodeproj/xcshareddata/xcschemes/Example (iOS).xcscheme b/Example/Example.xcodeproj/xcshareddata/xcschemes/Example (iOS).xcscheme index 4a05217..28cd8ba 100644 --- a/Example/Example.xcodeproj/xcshareddata/xcschemes/Example (iOS).xcscheme +++ b/Example/Example.xcodeproj/xcshareddata/xcschemes/Example (iOS).xcscheme @@ -1,6 +1,6 @@ : View where LeadingLabel: View, T private let leadingLabel: LeadingLabel? private let trailingLabel: TrailingLabel? -// private var leadingType: RowLeadingType? -// private var trallingType: RowTrailingType? - private let action: (() -> Void)? private var isPremiumOption = false @@ -63,26 +60,6 @@ public struct Row: View where LeadingLabel: View, T leadingRadius = nil } - @available(*, deprecated, message: "Use leading: {} and tralling: {}") - public init(_ title: String, - subtitle: String? = nil, -// leadingType: RowLeadingType? = nil, -// trallingType: RowTrailingType? = nil, - paddingHorizontal _: Space = .medium, - paddingVertical _: Space = .small, - action: (() -> Void)? = nil) - { - self.title = title - self.subtitle = subtitle -// self.leadingType = leadingType -// self.trallingType = trallingType - self.action = action - leadingLabel = nil - trailingLabel = nil - leadingSize = nil - leadingRadius = nil - } - public var body: some View { if action != nil { Button { @@ -246,20 +223,6 @@ public extension Row { control.textColor = color return control } -// -// @available(*, deprecated, message: "Use leading: {} and tralling: {}") -// func rowLeading(_ leading: RowLeadingType?) -> Row { -// var control = self -// control.leadingType = leading -// return control -// } -// -// @available(*, deprecated, message: "Use leading: {} and tralling: {}") -// func rowTrailing(_ trailing: RowTrailingType?) -> Row { -// var control = self -// control.trallingType = trailing -// return control -// } } public extension View { diff --git a/Sources/OversizeUI/Controls/ScrollView/ScrollViewWithStickyHeader.swift b/Sources/OversizeUI/Controls/ScrollView/ScrollViewWithStickyHeader.swift index d66930a..415d37a 100644 --- a/Sources/OversizeUI/Controls/ScrollView/ScrollViewWithStickyHeader.swift +++ b/Sources/OversizeUI/Controls/ScrollView/ScrollViewWithStickyHeader.swift @@ -1,7 +1,7 @@ -//// -//// Copyright © 2023 Alexander Romanov -//// File.swift, created on 26.11.2023 -//// +// +// Copyright © 2023 Alexander Romanov +// ScrollViewHeader.swift, created on 26.11.2023 +// // import SwiftUI diff --git a/Sources/OversizeUI/Controls/URLField/URLField.swift b/Sources/OversizeUI/Controls/URLField/URLField.swift index 491b50f..b0a689a 100644 --- a/Sources/OversizeUI/Controls/URLField/URLField.swift +++ b/Sources/OversizeUI/Controls/URLField/URLField.swift @@ -39,7 +39,7 @@ public struct URLField: View { if state { textFieldHelper = .none - } else if let url = URL(string: urlString) { // , NSWorkspace.shared.urlForApplication(toOpen: url) != nil { + } else if let url = URL(string: urlString) { textFieldHelper = .none self.url = url } else { @@ -57,7 +57,7 @@ public struct URLField: View { textFieldHelper = .errorText } #else - if let url = URL(string: urlString) { // , NSWorkspace.shared.urlForApplication(toOpen: url) != nil { + if let url = URL(string: urlString) { textFieldHelper = .none self.url = url } else { diff --git a/Sources/OversizeUI/Core/EnvironmentKeys/Platform.swift b/Sources/OversizeUI/Core/EnvironmentKeys/Platform.swift index 51c7852..911f8a7 100644 --- a/Sources/OversizeUI/Core/EnvironmentKeys/Platform.swift +++ b/Sources/OversizeUI/Core/EnvironmentKeys/Platform.swift @@ -47,22 +47,6 @@ private struct PlatformKey: EnvironmentKey { }() } -// private struct PlatformKey: EnvironmentKey { -// -// #if os(macOS) || targetEnvironment(macCatalyst) -// static let defaultValue: Platform = .macOS -// #elseif os(watchOS) -// static let defaultValue: Platform = .watchOS -// #elseif os(visionOS) -// static let defaultValue: Platform = .vision -// #elseif os(iOS) -// static let defaultValue: Platform = .iPhone -// #else -// static let defaultValue: Platform = .other -// #endif -// -// } - public extension EnvironmentValues { var platform: Platform { get { self[PlatformKey.self] }