feat(ios): refine native ui controls
This commit is contained in:
@@ -6,18 +6,22 @@ public struct AIButtonStyle: ButtonStyle {
|
||||
case secondary
|
||||
case danger
|
||||
|
||||
var foregroundColor: Color {
|
||||
var foregroundColor: Color { foregroundColor(isEnabled: true) }
|
||||
|
||||
var backgroundColor: Color { backgroundColor(isEnabled: true) }
|
||||
|
||||
func foregroundColor(isEnabled: Bool) -> Color {
|
||||
switch self {
|
||||
case .primary, .danger: return .white
|
||||
case .secondary: return AITheme.ink
|
||||
case .primary, .danger: return .white.opacity(isEnabled ? 1 : 0.72)
|
||||
case .secondary: return isEnabled ? AITheme.ink : AITheme.muted
|
||||
}
|
||||
}
|
||||
|
||||
var backgroundColor: Color {
|
||||
func backgroundColor(isEnabled: Bool) -> Color {
|
||||
switch self {
|
||||
case .primary: return AITheme.primary
|
||||
case .secondary: return AITheme.surface
|
||||
case .danger: return AITheme.danger
|
||||
case .primary: return isEnabled ? AITheme.primary : AITheme.primary.opacity(0.35)
|
||||
case .secondary: return isEnabled ? AITheme.surface : AITheme.canvas
|
||||
case .danger: return isEnabled ? AITheme.danger : AITheme.danger.opacity(0.30)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,6 +34,7 @@ public struct AIButtonStyle: ButtonStyle {
|
||||
|
||||
private let kind: Kind
|
||||
private let size: Size
|
||||
@Environment(\.isEnabled) private var isEnabled
|
||||
|
||||
public init(kind: Kind = .secondary, size: Size = .regular) {
|
||||
self.kind = kind
|
||||
@@ -43,17 +48,25 @@ public struct AIButtonStyle: ButtonStyle {
|
||||
case .regular: AITheme.buttonHeight
|
||||
}
|
||||
|
||||
configuration.label
|
||||
.font(.system(size: 15, weight: .semibold))
|
||||
.foregroundStyle(kind.foregroundColor)
|
||||
.frame(minWidth: 44, minHeight: height)
|
||||
.padding(.horizontal, 14)
|
||||
.background(kind.backgroundColor)
|
||||
.clipShape(RoundedRectangle(cornerRadius: AITheme.buttonRadius))
|
||||
.overlay {
|
||||
RoundedRectangle(cornerRadius: AITheme.buttonRadius)
|
||||
.strokeBorder(kind == .secondary ? AITheme.line : .clear)
|
||||
}
|
||||
configuration.label
|
||||
.font(.system(size: 16, weight: .semibold))
|
||||
.foregroundStyle(kind.foregroundColor(isEnabled: isEnabled))
|
||||
.frame(minWidth: minimumWidth, minHeight: height)
|
||||
.padding(.horizontal, kind == .secondary ? 12 : 14)
|
||||
.background(kind.backgroundColor(isEnabled: isEnabled))
|
||||
.clipShape(RoundedRectangle(cornerRadius: AITheme.buttonRadius))
|
||||
.overlay {
|
||||
RoundedRectangle(cornerRadius: AITheme.buttonRadius)
|
||||
.strokeBorder(kind == .secondary || !isEnabled ? AITheme.line : .clear)
|
||||
}
|
||||
.opacity(configuration.isPressed ? 0.78 : 1)
|
||||
}
|
||||
|
||||
private var minimumWidth: CGFloat {
|
||||
switch size {
|
||||
case .compact: return AITheme.compactButtonMinWidth
|
||||
case .regular: return AITheme.regularButtonMinWidth
|
||||
case .large: return 92
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user