Skip to content

Commit

Permalink
Merge pull request #18 from splendo/linter-errors
Browse files Browse the repository at this point in the history
Linter errors
  • Loading branch information
Daeda88 authored Feb 21, 2022
2 parents e565282 + c9b480e commit 7702048
Show file tree
Hide file tree
Showing 16 changed files with 228 additions and 199 deletions.
1 change: 1 addition & 0 deletions stencils/DefaultValues.stencil
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// swiftlint:disable force_cast
import UIKit
import SwiftUI
import Foundation
Expand Down
271 changes: 136 additions & 135 deletions stencils/KalugaBackgroundStyle+SwiftUI.stencil
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// swiftlint:disable file_length
{% if argument.includeResources %}
import SwiftUI
import {{ argument.sharedFrameworkName }}
Expand All @@ -11,29 +12,29 @@ extension {{ argument.sharedFrameworkName }}.BackgroundStyle {

// make the shape
switch self.shape {
case let rectangle as {{ argument.sharedFrameworkName }}.BackgroundStyle.ShapeRectangle:
shape = AnyShape (
RoundedShape(
cornerRadii: .init(
width: CGFloat(rectangle.cornerRadiusX),
height: CGFloat(rectangle.cornerRadiusY)
),
corners: {
var corners: UIRectCorner = []
if rectangle.roundedCorners.contains(.topLeft) { corners.insert(.topLeft) }
if rectangle.roundedCorners.contains(.topRight) { corners.insert(.topRight) }
if rectangle.roundedCorners.contains(.bottomLeft) { corners.insert(.bottomLeft) }
if rectangle.roundedCorners.contains(.bottomRight) { corners.insert(.bottomRight) }
return corners
}()
)
case let rectangle as {{ argument.sharedFrameworkName }}.BackgroundStyle.ShapeRectangle:
shape = AnyShape(
RoundedShape(
cornerRadii: .init(
width: CGFloat(rectangle.cornerRadiusX),
height: CGFloat(rectangle.cornerRadiusY)
),
corners: {
var corners: UIRectCorner = []
if rectangle.roundedCorners.contains(.topLeft) { corners.insert(.topLeft) }
if rectangle.roundedCorners.contains(.topRight) { corners.insert(.topRight) }
if rectangle.roundedCorners.contains(.bottomLeft) { corners.insert(.bottomLeft) }
if rectangle.roundedCorners.contains(.bottomRight) { corners.insert(.bottomRight) }
return corners
}()
)
case is {{ argument.sharedFrameworkName }}.BackgroundStyle.ShapeOval:
shape = AnyShape (
Capsule(style: .circular)
)
default:
preconditionFailure("Unknown shape type!")
)
case is {{ argument.sharedFrameworkName }}.BackgroundStyle.ShapeOval:
shape = AnyShape(
Capsule(style: .circular)
)
default:
preconditionFailure("Unknown shape type!")
}

// apply stoke to shape if needed
Expand All @@ -45,34 +46,34 @@ extension {{ argument.sharedFrameworkName }}.BackgroundStyle {
// https://developer.apple.com/documentation/swiftui/shapestyle
/*
switch buttonStateStyle.backgroundStyle.strokeStyle {
case let stroke as {{ argument.sharedFrameworkName }}.BackgroundStyle.StrokeStyleStroke:
anyView = AnyView(
shape
.style(
fillStyle: fillStyle(buttonStateStyle: buttonStateStyle),
strokeStyle: Color(stroke.color.uiColor),
lineWidth: CGFloat(stroke.width)
)
default:
anyView = AnyView(
shape
.fill(shapeStyle(buttonStateStyle: buttonStateStyle))
)
case let stroke as {{ argument.sharedFrameworkName }}.BackgroundStyle.StrokeStyleStroke:
anyView = AnyView(
shape
.style(
fillStyle: fillStyle(buttonStateStyle: buttonStateStyle),
strokeStyle: Color(stroke.color.uiColor),
lineWidth: CGFloat(stroke.width)
)
default:
anyView = AnyView(
shape
.fill(shapeStyle(buttonStateStyle: buttonStateStyle))
)
}
*/

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

switch strokeStyle {
case let stroke as {{ argument.sharedFrameworkName }}.BackgroundStyle.StrokeStyleStroke:
finalStoke = stroke
case is {{ argument.sharedFrameworkName }}.BackgroundStyle.StrokeStyleNone:
finalStoke = {{ argument.sharedFrameworkName }}.BackgroundStyle.StrokeStyleStroke(
width: 0.0,
color: Color(uiColor: .clear)
)
default:
preconditionFailure("Unknown stroke style type!")
case let stroke as {{ argument.sharedFrameworkName }}.BackgroundStyle.StrokeStyleStroke:
finalStoke = stroke
case is {{ argument.sharedFrameworkName }}.BackgroundStyle.StrokeStyleNone:
finalStoke = {{ argument.sharedFrameworkName }}.BackgroundStyle.StrokeStyleStroke(
width: 0.0,
color: Color(uiColor: .clear)
)
default:
preconditionFailure("Unknown stroke style type!")
}

// return the view
Expand Down Expand Up @@ -101,19 +102,19 @@ private extension {{ argument.sharedFrameworkName }}.BackgroundStyle {
stroke: {{ argument.sharedFrameworkName }}.BackgroundStyle.StrokeStyleStroke
) -> AnyView {
switch fillStyle {
case let solid as {{ argument.sharedFrameworkName }}.BackgroundStyle.FillStyleSolid:
return AnyView(
shape
.style(
fill: Color(solid.color.uiColor),
stroke: Color(stroke.color.uiColor),
lineWidth: CGFloat(stroke.width)
)
)
case let gradient as {{ argument.sharedFrameworkName }}.BackgroundStyle.FillStyleGradient:
return makeGradientView(shape: shape, stroke: stroke, gradient: gradient)
default:
preconditionFailure("Unknown fill style type!")
case let solid as {{ argument.sharedFrameworkName }}.BackgroundStyle.FillStyleSolid:
return AnyView(
shape
.style(
fill: Color(solid.color.uiColor),
stroke: Color(stroke.color.uiColor),
lineWidth: CGFloat(stroke.width)
)
)
case let gradient as {{ argument.sharedFrameworkName }}.BackgroundStyle.FillStyleGradient:
return makeGradientView(shape: shape, stroke: stroke, gradient: gradient)
default:
preconditionFailure("Unknown fill style type!")
}
}

Expand All @@ -123,53 +124,53 @@ private extension {{ argument.sharedFrameworkName }}.BackgroundStyle {
gradient: {{ argument.sharedFrameworkName }}.BackgroundStyle.FillStyleGradient
) -> AnyView {
switch gradient.gradientStyle {
case let linear as GradientStyle.Linear:
let gradient = self.makeGradientColor(colorPoints: linear.colorPoints)
let linearPoints = makeLinearPoints(orientation: linear.orientation)
return AnyView(
shape
.style(
fill: LinearGradient(
case let linear as GradientStyle.Linear:
let gradient = self.makeGradientColor(colorPoints: linear.colorPoints)
let linearPoints = makeLinearPoints(orientation: linear.orientation)
return AnyView(
shape
.style(
fill: LinearGradient(
gradient: gradient,
startPoint: linearPoints.startPoint,
endPoint: linearPoints.endPoint
),
stroke: Color(stroke.color.uiColor),
lineWidth: CGFloat(stroke.width)
)
)
case let radial as GradientStyle.Radial:
let gradient = self.makeGradientColor(colorPoints: radial.colorPoints)
return AnyView(
shape
.style(
fill:
RadialGradient(
gradient: gradient,
startPoint: linearPoints.startPoint,
endPoint: linearPoints.endPoint
center: .center,
startRadius: 0,
endRadius: CGFloat(radial.radius)
),
stroke: Color(stroke.color.uiColor),
lineWidth: CGFloat(stroke.width)
)
)
case let radial as GradientStyle.Radial:
let gradient = self.makeGradientColor(colorPoints: radial.colorPoints)
return AnyView(
shape
.style(
fill:
RadialGradient(
gradient: gradient,
center: .center,
startRadius: 0,
endRadius: CGFloat(radial.radius)
),
stroke: Color(stroke.color.uiColor),
lineWidth: CGFloat(stroke.width)
)
)
case let angular as GradientStyle.Angular:
let gradient = self.makeGradientColor(colorPoints: angular.colorPoints)
return AnyView(
shape
.style(
fill:
AngularGradient(
gradient: gradient,
center: .center
),
stroke: Color(stroke.color.uiColor),
lineWidth: CGFloat(stroke.width)
)
)
default:
preconditionFailure("Unknown gradient style type!")
stroke: Color(stroke.color.uiColor),
lineWidth: CGFloat(stroke.width)
)
)
case let angular as GradientStyle.Angular:
let gradient = self.makeGradientColor(colorPoints: angular.colorPoints)
return AnyView(
shape
.style(
fill:
AngularGradient(
gradient: gradient,
center: .center
),
stroke: Color(stroke.color.uiColor),
lineWidth: CGFloat(stroke.width)
)
)
default:
preconditionFailure("Unknown gradient style type!")
}
}

Expand All @@ -186,24 +187,24 @@ private extension {{ argument.sharedFrameworkName }}.BackgroundStyle {

func makeLinearPoints(orientation: GradientStyle.LinearOrientation) -> (startPoint: UnitPoint, endPoint: UnitPoint) {
switch orientation {
case .leftRight:
return (startPoint: .leading, endPoint: .trailing)
case .rightLeft:
return (startPoint: .trailing, endPoint: .leading)
case .topBottom:
return (startPoint: .top, endPoint: .bottom)
case .topLeftBottomRight:
return (startPoint: .topLeading, endPoint: .bottomTrailing)
case .topRightBottomLeft:
return (startPoint: .topTrailing, endPoint: .bottomLeading)
case .bottomTop:
return (startPoint: .bottom, endPoint: .top)
case .bottomLeftTopRight:
return (startPoint: .bottomLeading, endPoint: .bottomTrailing)
case .bottomRightTopLeft:
return (startPoint: .bottomTrailing, endPoint: .bottomLeading)
default:
preconditionFailure("Unknown linear orientation type!")
case .leftRight:
return (startPoint: .leading, endPoint: .trailing)
case .rightLeft:
return (startPoint: .trailing, endPoint: .leading)
case .topBottom:
return (startPoint: .top, endPoint: .bottom)
case .topLeftBottomRight:
return (startPoint: .topLeading, endPoint: .bottomTrailing)
case .topRightBottomLeft:
return (startPoint: .topTrailing, endPoint: .bottomLeading)
case .bottomTop:
return (startPoint: .bottom, endPoint: .top)
case .bottomLeftTopRight:
return (startPoint: .bottomLeading, endPoint: .bottomTrailing)
case .bottomRightTopLeft:
return (startPoint: .bottomTrailing, endPoint: .bottomLeading)
default:
preconditionFailure("Unknown linear orientation type!")
}
}

Expand All @@ -215,25 +216,25 @@ private extension {{ argument.sharedFrameworkName }}.BackgroundStyle {
/*
func shapeStyle(buttonStateStyle: ButtonStateStyle) -> some ShapeStyle {
switch buttonStateStyle.backgroundStyle.fillStyle {
case let solid as {{ argument.sharedFrameworkName }}.BackgroundStyle.FillStyleSolid:
return Color(solid.color.uiColor)
case let gradient as {{ argument.sharedFrameworkName }}.BackgroundStyle.FillStyleGradient:
//preconditionFailure("To do!")
return LinearGradient(
gradient: Gradient(colors: [.blue, .black]),
startPoint: .top,
endPoint: .bottom
)
default:
preconditionFailure("Unknown fill style type!")
case let solid as {{ argument.sharedFrameworkName }}.BackgroundStyle.FillStyleSolid:
return Color(solid.color.uiColor)
case let gradient as {{ argument.sharedFrameworkName }}.BackgroundStyle.FillStyleGradient:
//preconditionFailure("To do!")
return LinearGradient(
gradient: Gradient(colors: [.blue, .black]),
startPoint: .top,
endPoint: .bottom
)
default:
preconditionFailure("Unknown fill style type!")
}
}
*/
}

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

func body(content: Content) -> some View {
content
.background(backgroundStyle.toView())
Expand All @@ -242,10 +243,10 @@ fileprivate struct BackgroundStyleModifier: ViewModifier {

// MARK: - RoundedShape

fileprivate struct RoundedShape: Shape {
private struct RoundedShape: Shape {
var cornerRadii: CGSize = .zero
var corners: UIRectCorner = .allCorners

func path(in rect: CGRect) -> Path {
let path = UIBezierPath(
roundedRect: rect,
Expand Down
Loading

0 comments on commit 7702048

Please sign in to comment.