Skip to content

Commit

Permalink
fix: space
Browse files Browse the repository at this point in the history
  • Loading branch information
tsuzukihashi committed Jun 18, 2023
1 parent 4db86aa commit 2a7f9b1
Show file tree
Hide file tree
Showing 19 changed files with 740 additions and 738 deletions.
20 changes: 10 additions & 10 deletions Sources/AnyShape.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import SwiftUI
@available(iOS 13.0, *)
@available(macOS 12.0, *)
public struct AnyShape: Shape {
public init<S: Shape>(_ wrapped: S) {
_path = { rect in
let path = wrapped.path(in: rect)
return path
}
public init<S: Shape>(_ wrapped: S) {
_path = { rect in
let path = wrapped.path(in: rect)
return path
}
}

public func path(in rect: CGRect) -> Path {
return _path(rect)
}
private let _path: (CGRect) -> Path
public func path(in rect: CGRect) -> Path {
return _path(rect)
}

private let _path: (CGRect) -> Path
}
55 changes: 28 additions & 27 deletions Sources/CustomViews/HighlightableButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,32 @@ import SwiftUI
@available(iOS 13.0, *)
@available(macOS 12.0, *)
public struct HighlightableButton<Label>: View where Label: View {
@State private var isHighlighted = false

private let action: () -> Void
private let label: (Bool) -> Label

public init(action: @escaping () -> Void, label: @escaping (Bool) -> Label) {
self.action = action
self.label = label
}

public var body: some View {
label(isHighlighted)
.gesture(
DragGesture(minimumDistance: 0.0)
.onChanged { _ in
withAnimation {
self.isHighlighted = true
}}
.onEnded { value in
if abs(value.translation.height) <= 64 {
self.action()
}
withAnimation {
self.isHighlighted = false
}})
.animation(Animation.easeIn(duration: 0.05))
}
@State private var isHighlighted = false

private let action: () -> Void
private let label: (Bool) -> Label

public init(action: @escaping () -> Void, label: @escaping (Bool) -> Label) {
self.action = action
self.label = label
}

public var body: some View {
label(isHighlighted)
.gesture(
DragGesture(minimumDistance: 0.0)
.onChanged { _ in
withAnimation {
self.isHighlighted = true
}}
.onEnded { value in
if abs(value.translation.height) <= 64 {
self.action()
}
withAnimation {
self.isHighlighted = false
}}
)
.animation(Animation.easeIn(duration: 0.05))
}
}
136 changes: 68 additions & 68 deletions Sources/CustomViews/NeumorphismBindingButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,78 +3,78 @@ import SwiftUI
@available(iOS 13.0, *)
@available(macOS 12.0, *)
public struct NeumorphismBindingButton: View {
@EnvironmentObject var neumorphism: NeumorphismManager
@Binding var isSelected: Bool

private var shapeType: ShapeType
private var normalImage: Image
private var selectedImage: Image
private var width: CGFloat?
private var height: CGFloat?
private var imageWidth: CGFloat?
private var imageHeight: CGFloat?
private var shadowRadius: CGFloat
private var handler: (() -> Void)?

public init
(
isSelected: Binding<Bool>,
shapeType: ShapeType = .circle,
normalImage: Image = Image(systemName: "heart"),
selectedImage: Image = Image(systemName: "heart.fill"),
width: CGFloat? = nil,
height: CGFloat? = nil,
imageWidth: CGFloat? = nil,
imageHeight: CGFloat? = nil,
shadowRadius: CGFloat = 8,
handler: (() -> Void)? = nil
) {
self._isSelected = isSelected
self.shapeType = shapeType
self.normalImage = normalImage
self.selectedImage = selectedImage
self.width = width
self.height = height
self.imageWidth = imageWidth
self.imageHeight = imageHeight
self.shadowRadius = shadowRadius
self.handler = handler
}

public var body: some View {
HighlightableButton(action: {
self.isSelected.toggle()
self.handler?()
}) { isHeighlight in
(self.isSelected ? self.selectedImage : self.normalImage)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width:self.imageWidth, height: self.imageWidth)
.foregroundColor(self.neumorphism.fontColor())
.background(
Rectangle()
.clipShape(self.shapeType.anyShape)
.foregroundColor(self.neumorphism.color)
.frame(width: self.width, height: self.height)
.modifier(self.isSelected ? NeumorphismShadowModifier(radius: self.shadowRadius, isAnimation: self.isSelected ) : NeumorphismShadowModifier(radius: self.shadowRadius, isAnimation: isHeighlight))
)
.padding()
.animation(Animation.spring(response: 0.3, dampingFraction: 0.7, blendDuration: 1))
}
@EnvironmentObject var neumorphism: NeumorphismManager
@Binding var isSelected: Bool

private var shapeType: ShapeType
private var normalImage: Image
private var selectedImage: Image
private var width: CGFloat?
private var height: CGFloat?
private var imageWidth: CGFloat?
private var imageHeight: CGFloat?
private var shadowRadius: CGFloat
private var handler: (() -> Void)?

public init
(
isSelected: Binding<Bool>,
shapeType: ShapeType = .circle,
normalImage: Image = Image(systemName: "heart"),
selectedImage: Image = Image(systemName: "heart.fill"),
width: CGFloat? = nil,
height: CGFloat? = nil,
imageWidth: CGFloat? = nil,
imageHeight: CGFloat? = nil,
shadowRadius: CGFloat = 8,
handler: (() -> Void)? = nil
) {
self._isSelected = isSelected
self.shapeType = shapeType
self.normalImage = normalImage
self.selectedImage = selectedImage
self.width = width
self.height = height
self.imageWidth = imageWidth
self.imageHeight = imageHeight
self.shadowRadius = shadowRadius
self.handler = handler
}

public var body: some View {
HighlightableButton(action: {
self.isSelected.toggle()
self.handler?()
}) { isHeighlight in
(self.isSelected ? self.selectedImage : self.normalImage)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width:self.imageWidth, height: self.imageWidth)
.foregroundColor(self.neumorphism.fontColor())
.background(
Rectangle()
.clipShape(self.shapeType.anyShape)
.foregroundColor(self.neumorphism.color)
.frame(width: self.width, height: self.height)
.modifier(self.isSelected ? NeumorphismShadowModifier(radius: self.shadowRadius, isAnimation: self.isSelected ) : NeumorphismShadowModifier(radius: self.shadowRadius, isAnimation: isHeighlight))
)
.padding()
.animation(Animation.spring(response: 0.3, dampingFraction: 0.7, blendDuration: 1))
}
}
}

@available(iOS 13.0, *)
@available(macOS 12.0, *)
struct NeumorphismBindingButton_Previews: PreviewProvider {
static let neumorphism = NeumorphismManager(
lightColor: Color(hex: "C1D2EB"),
darkColor: Color(hex: "2C292C")
)
static var previews: some View {
NeumorphismBindingButton(isSelected: .constant(true))
.environmentObject(neumorphism)
.previewLayout(.sizeThatFits)
}
static let neumorphism = NeumorphismManager(
lightColor: Color(hex: "C1D2EB"),
darkColor: Color(hex: "2C292C")
)

static var previews: some View {
NeumorphismBindingButton(isSelected: .constant(true))
.environmentObject(neumorphism)
.previewLayout(.sizeThatFits)
}
}
144 changes: 72 additions & 72 deletions Sources/CustomViews/NeumorphismButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,83 +3,83 @@ import SwiftUI
@available(iOS 13.0, *)
@available(macOS 12.0, *)
public struct NeumorphismButton: View {
@EnvironmentObject var neumorphism: NeumorphismManager
@State var isSelected = false

private var shapeType: ShapeType
private var normalImage: Image
private var selectedImage: Image
private var width: CGFloat?
private var height: CGFloat?
private var imageWidth: CGFloat?
private var imageHeight: CGFloat?
private var color: Color?
private var shadowRadius: CGFloat
private var handler: (() -> Void)?

public init
(
shapeType: ShapeType = .circle,
normalImage: Image = Image(systemName: "heart"),
selectedImage: Image = Image(systemName: "heart.fill"),
width: CGFloat? = nil,
height: CGFloat? = nil,
imageWidth: CGFloat? = nil,
imageHeight: CGFloat? = nil,
color: Color? = nil,
shadowRadius: CGFloat = 8,
handler: (() -> Void)? = nil
) {
self.shapeType = shapeType
self.normalImage = normalImage
self.selectedImage = selectedImage
self.width = width
self.height = height
self.imageWidth = imageWidth
self.imageHeight = imageHeight
self.color = color
self.shadowRadius = shadowRadius
self.handler = handler
}

public var body: some View {
HighlightableButton(action: {
self.isSelected.toggle()
self.handler?()
}) { isHeighlight in
(self.isSelected ? self.selectedImage : self.normalImage)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width:self.imageWidth, height: self.imageWidth)
.foregroundColor(self.neumorphism.fontColor())
.background(
Rectangle()
.clipShape(self.shapeType.anyShape)
.foregroundColor(self.color ?? self.neumorphism.color)
.frame(width: self.width, height: self.height)
.modifier(
self.isSelected
? NeumorphismShadowModifier(baseColor: self.color, radius: self.shadowRadius, isAnimation: isHeighlight)
: NeumorphismShadowModifier(baseColor: self.color, radius: self.shadowRadius, isAnimation: isHeighlight)
)
@EnvironmentObject var neumorphism: NeumorphismManager
@State var isSelected = false

private var shapeType: ShapeType
private var normalImage: Image
private var selectedImage: Image
private var width: CGFloat?
private var height: CGFloat?
private var imageWidth: CGFloat?
private var imageHeight: CGFloat?
private var color: Color?
private var shadowRadius: CGFloat
private var handler: (() -> Void)?

public init
(
shapeType: ShapeType = .circle,
normalImage: Image = Image(systemName: "heart"),
selectedImage: Image = Image(systemName: "heart.fill"),
width: CGFloat? = nil,
height: CGFloat? = nil,
imageWidth: CGFloat? = nil,
imageHeight: CGFloat? = nil,
color: Color? = nil,
shadowRadius: CGFloat = 8,
handler: (() -> Void)? = nil
) {
self.shapeType = shapeType
self.normalImage = normalImage
self.selectedImage = selectedImage
self.width = width
self.height = height
self.imageWidth = imageWidth
self.imageHeight = imageHeight
self.color = color
self.shadowRadius = shadowRadius
self.handler = handler
}

public var body: some View {
HighlightableButton(action: {
self.isSelected.toggle()
self.handler?()
}) { isHeighlight in
(self.isSelected ? self.selectedImage : self.normalImage)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width:self.imageWidth, height: self.imageWidth)
.foregroundColor(self.neumorphism.fontColor())
.background(
Rectangle()
.clipShape(self.shapeType.anyShape)
.foregroundColor(self.color ?? self.neumorphism.color)
.frame(width: self.width, height: self.height)
.modifier(
self.isSelected
? NeumorphismShadowModifier(baseColor: self.color, radius: self.shadowRadius, isAnimation: isHeighlight)
: NeumorphismShadowModifier(baseColor: self.color, radius: self.shadowRadius, isAnimation: isHeighlight)
)
.padding()
.animation(Animation.spring(response: 0.3, dampingFraction: 0.7, blendDuration: 1))
}
)
.padding()
.animation(Animation.spring(response: 0.3, dampingFraction: 0.7, blendDuration: 1))
}
}
}

@available(iOS 13.0, *)
@available(macOS 12.0, *)
struct ContentView_Previews: PreviewProvider {
static let neumorphism = NeumorphismManager(
lightColor: Color(hex: "C1D2EB"),
darkColor: Color(hex: "2C292C")
)
static var previews: some View {
NeumorphismButton()
.environmentObject(neumorphism)
.previewLayout(.sizeThatFits)
}
static let neumorphism = NeumorphismManager(
lightColor: Color(hex: "C1D2EB"),
darkColor: Color(hex: "2C292C")
)

static var previews: some View {
NeumorphismButton()
.environmentObject(neumorphism)
.previewLayout(.sizeThatFits)
}
}
Loading

0 comments on commit 2a7f9b1

Please sign in to comment.