Skip to content

Commit

Permalink
Add RoundedRectangleCorner for macOS, update filed position and etc
Browse files Browse the repository at this point in the history
  • Loading branch information
aromanov91 committed Oct 6, 2024
1 parent bf97a4c commit 48fd61f
Show file tree
Hide file tree
Showing 20 changed files with 365 additions and 112 deletions.
31 changes: 27 additions & 4 deletions Sources/OversizeUI/Controls/Avatar/Avatar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
}
Expand All @@ -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
)
)
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion Sources/OversizeUI/Controls/Avatar/AvatarModifiers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
23 changes: 12 additions & 11 deletions Sources/OversizeUI/Controls/Button/FieldButtonStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}

Expand All @@ -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)
Expand All @@ -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))
)
}
}

Expand Down
5 changes: 2 additions & 3 deletions Sources/OversizeUI/Controls/IconPicker/IconPicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -109,3 +107,4 @@ public struct IconPicker: View {
}
}
}
#endif
4 changes: 4 additions & 0 deletions Sources/OversizeUI/Controls/PageControl/PageIndexView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/OversizeUI/Controls/PageView/Page.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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, *) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/OversizeUI/Controls/PriceField/PriceField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions Sources/OversizeUI/Controls/Select/MultiSelect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import SwiftUI

// swiftlint:disable all
@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *)
public struct MultiSelect<Element: Equatable, Content, Selection, Actions, ContentUnavailable>: View
where
Content: View,
Expand Down Expand Up @@ -143,6 +144,7 @@ public struct MultiSelect<Element: Equatable, Content, Selection, Actions, Conte
}
}

@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *)
public extension MultiSelect where ContentUnavailable == Never {
init(
_ label: String,
Expand All @@ -164,6 +166,7 @@ public extension MultiSelect where ContentUnavailable == Never {
}
}

@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *)
public extension MultiSelect where Actions == Never {
init(
_ label: String,
Expand All @@ -185,6 +188,7 @@ public extension MultiSelect where Actions == Never {
}
}

@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *)
public extension MultiSelect where ContentUnavailable == Never, Actions == Never {
init(
_ label: String,
Expand All @@ -206,6 +210,7 @@ public extension MultiSelect where ContentUnavailable == Never, Actions == Never
}

// swiftlint:disable all
@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *)
struct MultiSelect_Preview: PreviewProvider {
struct SelectPreview: View {
var items = ["One", "Two", "Three", "Four"]
Expand Down
5 changes: 5 additions & 0 deletions Sources/OversizeUI/Controls/Select/Select.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import SwiftUI

// swiftlint:disable all
@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *)
public struct Select<Element: Equatable, Content, Selection, Actions, ContentUnavailable: View>: View
where
Content: View,
Expand Down Expand Up @@ -138,6 +139,7 @@ public struct Select<Element: Equatable, Content, Selection, Actions, ContentUna
}
}

@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *)
public extension Select where ContentUnavailable == Never {
init(
_ label: String,
Expand All @@ -159,6 +161,7 @@ public extension Select where ContentUnavailable == Never {
}
}

@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *)
public extension Select where Actions == Never {
init(
_ label: String,
Expand All @@ -180,6 +183,7 @@ public extension Select where Actions == Never {
}
}

@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *)
public extension Select where ContentUnavailable == Never, Actions == Never {
init(
_ label: String,
Expand All @@ -201,6 +205,7 @@ public extension Select where ContentUnavailable == Never, Actions == Never {
}

// swiftlint:disable all
@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *)
struct Select_Preview: PreviewProvider {
struct SelectPreview: View {
var items = ["One", "Two", "Three", "Four"]
Expand Down
45 changes: 26 additions & 19 deletions Sources/OversizeUI/Controls/TextBox/TextBox.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ public struct TextBox: View {

public var body: some View {
VStack(alignment: textStackAlignment, spacing: textSpacing) {
titleText
Text(title)
.font(titleFont)
.onSurfaceHighEmphasisForegroundColor()

if let subtitle {
Text(subtitle)
.body(.medium)
.foregroundColor(.onSurfaceMediumEmphasis)
subtitle.map {
Text($0)
.font(subtitleFont)
.onSurfaceMediumEmphasisForegroundColor()
}
}
.multilineTextAlignment(multilineTextAlignment)
Expand Down Expand Up @@ -68,21 +70,26 @@ public struct TextBox: View {
}
}

private var titleText: some View {
Group {
switch size {
case .small:
Text(title)
.headline(.semibold)
case .medium:
Text(title)
.title2(true)
case .large:
Text(title)
.title(true)
}
private var titleFont: Font {
switch size {
case .small:
.headline.weight(.semibold)

case .medium:
.title2.weight(.bold)

case .large:
.title.weight(.semibold)
}
}

private var subtitleFont: Font {
switch size {
case .small:
.callout.weight(.regular)
default:
.body.weight(.medium)
}
.onSurfaceHighEmphasisForegroundColor()
}

public func textBoxSize(_ size: TextBoxSize) -> TextBox {
Expand Down
Loading

0 comments on commit 48fd61f

Please sign in to comment.