Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 6 additions & 55 deletions Sources/ComponentsKit/Components/Button/SUButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,13 @@ public struct SUButton: View {
.frame(height: self.model.height)
.contentShape(.rect)
.foregroundStyle(self.model.foregroundColor.color)
.buttonBackground(
.componentBackground(
shape: RoundedRectangle(cornerRadius: self.model.cornerRadius.value()),
model: self.model
backgroundStyle: self.model.backgroundStyle,
backgroundColor: self.model.backgroundColor?.color,
borderColor: self.model.borderColor?.color ?? .clear,
borderWidth: self.model.borderWidth,
isGlassInteractive: self.model.isInteractive
)
}
.buttonStyle(CustomButtonStyle())
Expand Down Expand Up @@ -126,56 +130,3 @@ private struct CustomButtonStyle: SwiftUI.ButtonStyle {
configuration.label
}
}

extension View {
@ViewBuilder
fileprivate func buttonBackground<BackgroundShape: InsettableShape>(
shape: BackgroundShape,
model: ButtonVM
) -> some View {
switch model.backgroundStyle {
case .solid:
self
.background(model.backgroundColor?.color ?? .clear)
.clipShape(shape)
.overlay {
shape.strokeBorder(
model.borderColor?.color ?? .clear,
lineWidth: model.borderWidth
)
}
case .blur:
self
.background {
shape
.fill(.thinMaterial)
.overlay {
shape.strokeBorder(
model.borderColor?.color ?? .clear,
lineWidth: model.borderWidth
)
}
}
.background(model.backgroundColor?.color)
.clipShape(shape)
case .liquidGlass:
if #available(iOS 26.0, *) {
self
.overlay {
shape.strokeBorder(
model.borderColor?.color ?? .clear,
lineWidth: model.borderWidth
)
}
.glassEffect(
.regular
.tint(model.backgroundColor?.color)
.interactive(model.isInteractive),
in: shape
)
} else {
self
}
}
}
}
34 changes: 8 additions & 26 deletions Sources/ComponentsKit/Components/Button/UKButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -244,32 +244,14 @@ extension UKButton {
)
}
static func backgroundEffectView(_ view: UIVisualEffectView, model: Model) {
let cornerRadius = model.cornerRadius.value(for: view.bounds.height)
view.contentView.layer.cornerRadius = cornerRadius
view.layer.cornerRadius = cornerRadius
view.layer.borderColor = model.borderColor?.uiColor.cgColor
view.layer.borderWidth = model.borderWidth
view.clipsToBounds = true

switch model.backgroundStyle {
case .solid:
view.effect = nil
view.backgroundColor = model.backgroundColor?.uiColor
case .blur:
view.effect = UIBlurEffect(style: .systemThinMaterial)
view.backgroundColor = model.backgroundColor?.uiColor
case .liquidGlass:
if #available(iOS 26.0, *) {
let effect = UIGlassEffect(style: .regular)
effect.tintColor = model.backgroundColor?.uiColor
effect.isInteractive = model.isInteractive
view.effect = effect
view.backgroundColor = nil
} else {
view.effect = nil
view.backgroundColor = model.backgroundColor?.uiColor
}
}
view.setBackgroundStyle(
model.backgroundStyle,
backgroundColor: model.backgroundColor?.uiColor,
borderColor: model.borderColor?.uiColor,
borderWidth: model.borderWidth,
cornerRadius: model.cornerRadius.value(for: view.bounds.height),
isGlassInteractive: model.isInteractive
)
}
static func titleLabel(_ label: UILabel, model: Model) {
label.textAlignment = .center
Expand Down
52 changes: 6 additions & 46 deletions Sources/ComponentsKit/Components/Card/SUCard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ public struct SUCard<Content: View>: View {
public var body: some View {
self.content()
.padding(self.model.contentPaddings.edgeInsets)
.cardBackground(
.componentBackground(
shape: RoundedRectangle(cornerRadius: self.model.cornerRadius.value),
model: self.model
backgroundStyle: self.model.backgroundStyle,
backgroundColor: self.model.backgroundColor?.color,
borderColor: self.model.borderColor.color,
borderWidth: self.model.borderWidth.value,
isGlassInteractive: self.model.isTappable
)
.shadow(self.model.shadow)
.observeSize { self.contentSize = $0 }
Expand All @@ -72,47 +76,3 @@ public struct SUCard<Content: View>: View {
.animation(.easeOut(duration: 0.05), value: self.scale)
}
}

extension View {
@ViewBuilder
fileprivate func cardBackground<BackgroundShape: InsettableShape>(
shape: BackgroundShape,
model: CardVM
) -> some View {
switch model.backgroundStyle {
case .solid:
self.background(model.backgroundColor?.color)
.clipShape(shape)
.overlay(
shape
.strokeBorder(model.borderColor.color, lineWidth: model.borderWidth.value)
)
case .blur:
self
.background {
shape
.fill(.thinMaterial)
.overlay {
shape.strokeBorder(model.borderColor.color, lineWidth: model.borderWidth.value)
}
}
.background(model.backgroundColor?.color)
.clipShape(shape)
case .liquidGlass:
if #available(iOS 26.0, *) {
self
.overlay {
shape.strokeBorder(model.borderColor.color, lineWidth: model.borderWidth.value)
}
.glassEffect(
.regular
.tint(model.backgroundColor?.color)
.interactive(model.isTappable),
in: shape
)
} else {
self
}
}
}
}
32 changes: 8 additions & 24 deletions Sources/ComponentsKit/Components/Card/UKCard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -212,30 +212,14 @@ extension UKCard {
view.shadow(model.shadow)
}
static func backgroundEffectView(_ view: UIVisualEffectView, model: Model) {
view.contentView.layer.cornerRadius = model.cornerRadius.value
view.layer.cornerRadius = model.cornerRadius.value
view.layer.borderColor = model.borderColor.cgColor
view.layer.borderWidth = model.borderWidth.value
view.clipsToBounds = true

switch model.backgroundStyle {
case .solid:
view.effect = nil
view.backgroundColor = model.backgroundColor?.uiColor
case .blur:
view.effect = UIBlurEffect(style: .systemThinMaterial)
view.backgroundColor = model.backgroundColor?.uiColor
case .liquidGlass:
if #available(iOS 26.0, *) {
let effect = UIGlassEffect(style: .regular)
effect.tintColor = model.backgroundColor?.uiColor
effect.isInteractive = model.isTappable
view.effect = effect
view.backgroundColor = nil
} else {
view.effect = nil
}
}
view.setBackgroundStyle(
model.backgroundStyle,
backgroundColor: model.backgroundColor?.uiColor,
borderColor: model.borderColor.uiColor,
borderWidth: model.borderWidth.value,
cornerRadius: model.cornerRadius.value,
isGlassInteractive: model.isTappable
)
}
}
}
47 changes: 5 additions & 42 deletions Sources/ComponentsKit/Components/Modal/SwiftUI/ModalContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,12 @@ struct ModalContent<VM: ModalVM, Header: View, Body: View, Footer: View>: View {
.padding(.bottom, self.model.contentPaddings.bottom)
}
.frame(maxWidth: self.model.size.maxWidth, alignment: .leading)
.modalBackground(
.componentBackground(
shape: RoundedRectangle(cornerRadius: model.cornerRadius.value),
model: self.model
backgroundStyle: self.model.backgroundStyle,
backgroundColor: self.model.preferredBackgroundColor?.color,
borderColor: UniversalColor.divider.color,
borderWidth: self.model.borderWidth.value
)
.padding(self.model.outerPaddings.edgeInsets)
}
Expand All @@ -72,43 +75,3 @@ struct ModalContent<VM: ModalVM, Header: View, Body: View, Footer: View>: View {
return self.bodySize.height + self.bodyTopPadding + self.bodyBottomPadding
}
}

extension View {
@ViewBuilder
fileprivate func modalBackground<BackgroundShape: InsettableShape>(
shape: BackgroundShape,
model: any ModalVM
) -> some View {
switch model.backgroundStyle {
case .solid:
self.background(model.preferredBackgroundColor?.color)
.clipShape(shape)
.overlay(
shape
.strokeBorder(UniversalColor.divider.color, lineWidth: model.borderWidth.value)
)
case .blur:
self
.background {
shape
.fill(.thinMaterial)
.overlay {
shape.strokeBorder(UniversalColor.divider.color, lineWidth: model.borderWidth.value)
}
}
.background(model.preferredBackgroundColor?.color)
.clipShape(shape)
case .liquidGlass:
if #available(iOS 26.0, *) {
self.glassEffect(
.regular
.tint(model.preferredBackgroundColor?.color)
.interactive(),
in: shape
)
} else {
self
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -269,28 +269,13 @@ extension UKModalController {
view.layer.cornerRadius = model.cornerRadius.value
}
static func backgroundEffectView(_ view: UIVisualEffectView, model: VM) {
view.layer.cornerRadius = model.cornerRadius.value
view.layer.borderColor = UniversalColor.divider.cgColor
view.layer.borderWidth = model.borderWidth.value
view.clipsToBounds = true

switch model.backgroundStyle {
case .solid:
view.effect = nil
view.backgroundColor = model.preferredBackgroundColor?.uiColor
case .blur:
view.effect = UIBlurEffect(style: .systemThinMaterial)
view.backgroundColor = model.preferredBackgroundColor?.uiColor
case .liquidGlass:
if #available(iOS 26.0, *) {
let effect = UIGlassEffect(style: .regular)
effect.tintColor = model.preferredBackgroundColor?.uiColor
effect.isInteractive = true
view.effect = effect
} else {
view.effect = nil
}
}
view.setBackgroundStyle(
model.backgroundStyle,
backgroundColor: model.preferredBackgroundColor?.uiColor,
borderColor: UniversalColor.divider.uiColor,
borderWidth: model.borderWidth.value,
cornerRadius: model.cornerRadius.value
)
}
static func bodyWrapper(_ scrollView: UIScrollView) {
scrollView.delaysContentTouches = false
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import SwiftUI

extension View {
@ViewBuilder
func componentBackground<BackgroundShape: InsettableShape>(
shape: BackgroundShape,
backgroundStyle: BackgroundStyle,
backgroundColor: Color?,
borderColor: Color,
borderWidth: CGFloat,
isGlassInteractive: Bool = true
) -> some View {
switch backgroundStyle {
case .solid:
self
.background(backgroundColor ?? .clear)
.clipShape(shape)
.overlay {
shape.strokeBorder(borderColor, lineWidth: borderWidth)
}
case .blur:
self
.background {
shape
.fill(.thinMaterial)
.overlay {
shape.strokeBorder(borderColor, lineWidth: borderWidth)
}
}
.background(backgroundColor)
.clipShape(shape)
case .liquidGlass:
if #available(iOS 26.0, *) {
self
.overlay {
shape.strokeBorder(borderColor, lineWidth: borderWidth)
}
.glassEffect(
.regular
.tint(backgroundColor)
.interactive(isGlassInteractive),
in: shape
)
} else {
self
}
}
}
}
Loading