Skip to content

Commit

Permalink
Merge pull request #27 from splendo/feature/kaluga-1.0.0
Browse files Browse the repository at this point in the history
Feature/kaluga 1.0.0
  • Loading branch information
Daeda88 authored Jan 24, 2023
2 parents 5eea33b + 6f077e0 commit 9378302
Show file tree
Hide file tree
Showing 18 changed files with 209 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,4 @@ class KalugaSwiftUITests: XCTestCase {
// Put the code you want to measure the time of here.
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class KalugaSwiftUIUITests: XCTestCase {
// In UI tests it is usually best to stop immediately when a failure occurs.
continueAfterFailure = false

// In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this.
// In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run.
// The setUp method is a good place to do this.
}

override func tearDownWithError() throws {
Expand Down
1 change: 1 addition & 0 deletions sample-kaluga.sourcery.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ args:
includeAlerts: true
includeHud: true
includeDatePicker: true
includeKeyboard: true
includePartialSheet: false
73 changes: 73 additions & 0 deletions stencils/DefaultValues.stencil
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import UIKit
import SwiftUI
import Foundation
{% if argument.includeResources %}
import {{ argument.sharedFrameworkName }}
{% endif %}

extension Array: HasDefaultValue {
static func `default`() -> Self { [] }
Expand Down Expand Up @@ -50,6 +53,76 @@ extension Image: HasDefaultValue {
}
}

{% if argument.includeResources %}
extension KalugaColor: HasDefaultValue {
static func `default`() -> Self {
return KalugaColor(uiColor: UIColor.clear) as! Self
}
}

extension KalugaBackgroundStyle: HasDefaultValue {
static func `default`() -> Self {
return KalugaBackgroundStyle(
fillStyle: FillStyleSolid(color: KalugaColor.default()),
strokeStyle: StrokeStyleNone.shared,
shape: ShapeRectangle(cornerRadius: 0.0, roundedCorners: [])
) as! Self
}
}

extension TextStyle: HasDefaultValue {
static func `default`() -> Self {
return TextStyle(
font: UIFont.systemFont(ofSize: UIFont.systemFontSize),
color: KalugaColor(uiColor: UIColor.darkText),
size: Float(UIFont.systemFontSize),
alignment: KalugaTextAlignment.start
) as! Self
}
}

extension KalugaLabel: HasDefaultValue {
static func `default`() -> Self {
return KalugaLabel.Plain(
text: "",
style: TextStyle.default()
) as! Self
}
}

extension ButtonStateStyle: HasDefaultValue {
static func `default`() -> Self {
return ButtonStateStyle(
textColor: KalugaColor(uiColor: UIColor.darkText),
backgroundStyle: KalugaBackgroundStyle.default()
) as! Self
}
}

extension KalugaButtonStyle: HasDefaultValue {
static func `default`() -> Self {
return KalugaButtonStyle(
font: UIFont.systemFont(ofSize: UIFont.systemFontSize),
textSize: Float(UIFont.systemFontSize),
textAlignment: .center,
defaultStyle: ButtonStateStyle.default(),
pressedStyle: ButtonStateStyle.default(),
disabledStyle: ButtonStateStyle.default()
) as! Self
}
}

extension KalugaButton: HasDefaultValue {
static func `default`() -> Self {
return KalugaButton.Plain(
text: "",
style: KalugaButtonStyle.default(),
isEnabled: true
) {} as! Self
}
}

{% endif %}
extension Date: HasDefaultValue {
static func `default`() -> Date { Date() }
}
Expand Down
36 changes: 18 additions & 18 deletions stencils/KalugaBackgroundStyle+SwiftUI.stencil
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import {{ argument.sharedFrameworkName }}

// MARK: - BackgroundStyle

extension {{ argument.sharedFrameworkName }}.BackgroundStyle {
extension KalugaBackgroundStyle {

func toView() -> some View {
let shape: AnyShape

// make the shape
switch self.shape {
case let rectangle as {{ argument.sharedFrameworkName }}.BackgroundStyle.ShapeRectangle:
case let rectangle as KalugaBackgroundStyle.ShapeRectangle:
shape = AnyShape(
RoundedShape(
cornerRadii: .init(
Expand All @@ -29,7 +29,7 @@ extension {{ argument.sharedFrameworkName }}.BackgroundStyle {
}()
)
)
case is {{ argument.sharedFrameworkName }}.BackgroundStyle.ShapeOval:
case is KalugaBackgroundStyle.ShapeOval:
shape = AnyShape(
Capsule(style: .circular)
)
Expand All @@ -46,7 +46,7 @@ extension {{ argument.sharedFrameworkName }}.BackgroundStyle {
// https://developer.apple.com/documentation/swiftui/shapestyle
/*
switch buttonStateStyle.backgroundStyle.strokeStyle {
case let stroke as {{ argument.sharedFrameworkName }}.BackgroundStyle.StrokeStyleStroke:
case let stroke as KalugaBackgroundStyle.StrokeStyleStroke:
anyView = AnyView(
shape
.style(
Expand All @@ -62,13 +62,13 @@ extension {{ argument.sharedFrameworkName }}.BackgroundStyle {
}
*/

let finalStoke: {{ argument.sharedFrameworkName }}.BackgroundStyle.StrokeStyleStroke
let finalStoke: KalugaBackgroundStyle.StrokeStyleStroke

switch strokeStyle {
case let stroke as {{ argument.sharedFrameworkName }}.BackgroundStyle.StrokeStyleStroke:
case let stroke as KalugaBackgroundStyle.StrokeStyleStroke:
finalStoke = stroke
case is {{ argument.sharedFrameworkName }}.BackgroundStyle.StrokeStyleNone:
finalStoke = {{ argument.sharedFrameworkName }}.BackgroundStyle.StrokeStyleStroke(
case is KalugaBackgroundStyle.StrokeStyleNone:
finalStoke = KalugaBackgroundStyle.StrokeStyleStroke(
width: 0.0,
color: KalugaColor(uiColor: .clear)
)
Expand All @@ -85,7 +85,7 @@ extension {{ argument.sharedFrameworkName }}.BackgroundStyle {
}

extension View {
public func background(_ backgroundStyle: {{ argument.sharedFrameworkName }}.BackgroundStyle) -> some View {
public func background(_ backgroundStyle: KalugaBackgroundStyle) -> some View {
ModifiedContent(
content: self,
modifier: BackgroundStyleModifier(backgroundStyle: backgroundStyle)
Expand All @@ -95,14 +95,14 @@ extension View {

// MARK: - Private methods

private extension {{ argument.sharedFrameworkName }}.BackgroundStyle {
private extension KalugaBackgroundStyle {

func makeView(
shape: AnyShape,
stroke: {{ argument.sharedFrameworkName }}.BackgroundStyle.StrokeStyleStroke
stroke: KalugaBackgroundStyle.StrokeStyleStroke
) -> AnyView {
switch fillStyle {
case let solid as {{ argument.sharedFrameworkName }}.BackgroundStyle.FillStyleSolid:
case let solid as KalugaBackgroundStyle.FillStyleSolid:
return AnyView(
shape
.style(
Expand All @@ -111,7 +111,7 @@ private extension {{ argument.sharedFrameworkName }}.BackgroundStyle {
lineWidth: CGFloat(stroke.width)
)
)
case let gradient as {{ argument.sharedFrameworkName }}.BackgroundStyle.FillStyleGradient:
case let gradient as KalugaBackgroundStyle.FillStyleGradient:
return makeGradientView(shape: shape, stroke: stroke, gradient: gradient)
default:
preconditionFailure("Unknown fill style type!")
Expand All @@ -120,8 +120,8 @@ private extension {{ argument.sharedFrameworkName }}.BackgroundStyle {

func makeGradientView(
shape: AnyShape,
stroke: {{ argument.sharedFrameworkName }}.BackgroundStyle.StrokeStyleStroke,
gradient: {{ argument.sharedFrameworkName }}.BackgroundStyle.FillStyleGradient
stroke: KalugaBackgroundStyle.StrokeStyleStroke,
gradient: KalugaBackgroundStyle.FillStyleGradient
) -> AnyView {
switch gradient.gradientStyle {
case let linear as GradientStyle.Linear:
Expand Down Expand Up @@ -216,9 +216,9 @@ private extension {{ argument.sharedFrameworkName }}.BackgroundStyle {
/*
func shapeStyle(buttonStateStyle: ButtonStateStyle) -> some ShapeStyle {
switch buttonStateStyle.backgroundStyle.fillStyle {
case let solid as {{ argument.sharedFrameworkName }}.BackgroundStyle.FillStyleSolid:
case let solid as KalugaBackgroundStyle.FillStyleSolid:
return Color(solid.color.uiColor)
case let gradient as {{ argument.sharedFrameworkName }}.BackgroundStyle.FillStyleGradient:
case let gradient as KalugaBackgroundStyle.FillStyleGradient:
//preconditionFailure("To do!")
return LinearGradient(
gradient: Gradient(colors: [.blue, .black]),
Expand All @@ -233,7 +233,7 @@ private extension {{ argument.sharedFrameworkName }}.BackgroundStyle {
}

private struct BackgroundStyleModifier: ViewModifier {
let backgroundStyle: {{ argument.sharedFrameworkName }}.BackgroundStyle
let backgroundStyle: KalugaBackgroundStyle

func body(content: Content) -> some View {
content
Expand Down
44 changes: 34 additions & 10 deletions stencils/KalugaButton+SwiftUI.stencil
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,23 @@ import {{ argument.sharedFrameworkName }}

// MARK: - KalugaButton

enum ButtonFrame {
case wrapped
case absoluteFrame(width: CGFloat? = nil, height: CGFloat? = nil, alignment: Alignment = .center)
case frame(
minWidth: CGFloat? = nil,
idealWidth: CGFloat? = nil,
maxWidth: CGFloat? = nil,
minHeight: CGFloat? = nil,
idealHeight: CGFloat? = nil,
maxHeight: CGFloat? = nil,
alignment: Alignment = .center
)
}

extension KalugaButton {

func toButton() -> some View {
func toButton(buttonFrame: ButtonFrame = .wrapped) -> some View {
let buttonView: AnyView

switch self {
case let button as KalugaButton.Plain:
buttonView = makePlainButton(button: button)
Expand All @@ -17,21 +29,33 @@ extension KalugaButton {
default:
preconditionFailure("Unknown kaluga button type!")
}

return Button(
action: {
self.action()
},
label: {
buttonView
switch buttonFrame {
case .wrapped: buttonView
case let .absoluteFrame(width, height, alignment): buttonView.frame(width: width, height: height, alignment: alignment)
case let .frame(minWidth, idealWidth, maxWidth, minHeight, idealHeight, maxHeight, alignment):
buttonView.frame(
minWidth: minWidth,
idealWidth: idealWidth,
maxWidth: maxWidth,
minHeight: minHeight,
idealHeight: idealHeight,
maxHeight: maxHeight,
alignment: alignment
)
}
}
)
.buttonStyle(self.style, isEnabled: self.isEnabled)
}
}

extension View {
public func buttonStyle(_ buttonStyle: {{ argument.sharedFrameworkName }}.ButtonStyle, isEnabled: Bool = true) -> some View {
public func buttonStyle(_ buttonStyle: KalugaButtonStyle, isEnabled: Bool = true) -> some View {
ModifiedContent(
content: self,
modifier: ButtonStyleModifier(buttonStyle: buttonStyle, isEnabled: isEnabled)
Expand Down Expand Up @@ -68,11 +92,11 @@ private extension KalugaButton {

// MARK: - CustomButtonStyle

private struct CustomButtonStyle: SwiftUI.ButtonStyle {
private let buttonStyle: {{ argument.sharedFrameworkName }}.ButtonStyle
private struct CustomButtonStyle: ButtonStyle {
private let buttonStyle: KalugaButtonStyle
private let isEnabled: Bool

init(buttonStyle: {{ argument.sharedFrameworkName }}.ButtonStyle, isEnabled: Bool = true) {
init(buttonStyle: KalugaButtonStyle, isEnabled: Bool = true) {
self.buttonStyle = buttonStyle
self.isEnabled = isEnabled
}
Expand All @@ -97,7 +121,7 @@ private struct CustomButtonStyle: SwiftUI.ButtonStyle {

private struct ButtonStyleModifier: ViewModifier {

let buttonStyle: {{ argument.sharedFrameworkName }}.ButtonStyle
let buttonStyle: KalugaButtonStyle
let isEnabled: Bool

func body(content: Content) -> some View {
Expand Down
14 changes: 7 additions & 7 deletions stencils/KalugaLabel+SwiftUI.stencil
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@ extension View {
}
}

extension {{ argument.sharedFrameworkName }}.TextAlignment {
extension KalugaTextAlignment {

var textAlignment: SwiftUI.TextAlignment {
var textAlignment: TextAlignment {
switch self {
case TextAlignment.left:
case KalugaTextAlignment.left:
return .leading
case TextAlignment.right:
case KalugaTextAlignment.right:
return .trailing
case TextAlignment.end:
case KalugaTextAlignment.end:
return UIApplication.shared.userInterfaceLayoutDirection == .leftToRight ?
.trailing :
.leading
case TextAlignment.start:
case KalugaTextAlignment.start:
return .leading
case TextAlignment.center:
case KalugaTextAlignment.center:
return .center
default:
preconditionFailure("Unknown text alignment type!")
Expand Down
1 change: 0 additions & 1 deletion stencils/KalugaStyledString+SwiftUI.stencil
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ private struct AttributedText: View {
dynamicHeight = uiView.sizeThatFits(CGSize(width: uiView.bounds.width, height: CGFloat.greatestFiniteMagnitude)).height
}
}

}
}
{% endif %}
Loading

0 comments on commit 9378302

Please sign in to comment.