Skip to content

Commit

Permalink
remove: self
Browse files Browse the repository at this point in the history
  • Loading branch information
tsuzukihashi committed Aug 15, 2024
1 parent 2a7f9b1 commit ad5914f
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 60 deletions.
6 changes: 3 additions & 3 deletions Sources/CustomViews/HighlightableButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ public struct HighlightableButton<Label>: View where Label: View {
DragGesture(minimumDistance: 0.0)
.onChanged { _ in
withAnimation {
self.isHighlighted = true
isHighlighted = true
}}
.onEnded { value in
if abs(value.translation.height) <= 64 {
self.action()
action()
}
withAnimation {
self.isHighlighted = false
isHighlighted = false
}}
)
.animation(Animation.easeIn(duration: 0.05))
Expand Down
18 changes: 9 additions & 9 deletions Sources/CustomViews/NeumorphismBindingButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,20 @@ public struct NeumorphismBindingButton: View {

public var body: some View {
HighlightableButton(action: {
self.isSelected.toggle()
self.handler?()
isSelected.toggle()
handler?()
}) { isHeighlight in
(self.isSelected ? self.selectedImage : self.normalImage)
(isSelected ? selectedImage : normalImage)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width:self.imageWidth, height: self.imageWidth)
.foregroundColor(self.neumorphism.fontColor())
.frame(width:imageWidth, height: imageWidth)
.foregroundColor(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))
.clipShape(shapeType.anyShape)
.foregroundColor(neumorphism.color)
.frame(width: width, height: height)
.modifier(isSelected ? NeumorphismShadowModifier(radius: shadowRadius, isAnimation: isSelected ) : NeumorphismShadowModifier(radius: shadowRadius, isAnimation: isHeighlight))
)
.padding()
.animation(Animation.spring(response: 0.3, dampingFraction: 0.7, blendDuration: 1))
Expand Down
22 changes: 11 additions & 11 deletions Sources/CustomViews/NeumorphismButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,23 @@ public struct NeumorphismButton: View {

public var body: some View {
HighlightableButton(action: {
self.isSelected.toggle()
self.handler?()
isSelected.toggle()
handler?()
}) { isHeighlight in
(self.isSelected ? self.selectedImage : self.normalImage)
(isSelected ? selectedImage : normalImage)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width:self.imageWidth, height: self.imageWidth)
.foregroundColor(self.neumorphism.fontColor())
.frame(width:imageWidth, height: imageWidth)
.foregroundColor(neumorphism.fontColor())
.background(
Rectangle()
.clipShape(self.shapeType.anyShape)
.foregroundColor(self.color ?? self.neumorphism.color)
.frame(width: self.width, height: self.height)
.clipShape(shapeType.anyShape)
.foregroundColor(color ?? neumorphism.color)
.frame(width: width, height: height)
.modifier(
self.isSelected
? NeumorphismShadowModifier(baseColor: self.color, radius: self.shadowRadius, isAnimation: isHeighlight)
: NeumorphismShadowModifier(baseColor: self.color, radius: self.shadowRadius, isAnimation: isHeighlight)
isSelected
? NeumorphismShadowModifier(baseColor: color, radius: shadowRadius, isAnimation: isHeighlight)
: NeumorphismShadowModifier(baseColor: color, radius: shadowRadius, isAnimation: isHeighlight)
)
)
.padding()
Expand Down
10 changes: 5 additions & 5 deletions Sources/CustomViews/NeumorphismCircleDentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ public struct NeumorphismCircleDentView: View {

public var body: some View {
Circle()
.fill(self.neumorphism.color)
.frame(width: self.width, height: self.height)
.fill(neumorphism.color)
.frame(width: width, height: height)
.overlay(
Circle()
.stroke(self.neumorphism.color, lineWidth: 4)
.shadow(color: self.neumorphism.color.darkerColor(), radius: 4, x: 4, y: 4)
.stroke(neumorphism.color, lineWidth: 4)
.shadow(color: neumorphism.color.darkerColor(), radius: 4, x: 4, y: 4)
.clipShape(Circle())
.shadow(color: self.neumorphism.color.lighterColor(), radius: 2, x: -2, y: -2)
.shadow(color: neumorphism.color.lighterColor(), radius: 2, x: -2, y: -2)
.clipShape(Circle())
)
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/CustomViews/NeumorphismDentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public struct NeumorphismDentView: View {

public var body: some View {
Rectangle()
.fill(self.color ?? self.neumorphism.color)
.frame(width: self.width, height: self.height)
.fill(color ?? neumorphism.color)
.frame(width: width, height: height)
.neumorphismConcave(shapeType: shapeType, color: color)
}
}
Expand Down
17 changes: 9 additions & 8 deletions Sources/CustomViews/NeumorphismLabelButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import SwiftUI
public struct NeumorphismLabelButton: View {
@EnvironmentObject var neumorphism: NeumorphismManager
@State var isSelected = false

private var text: String
private var font: Font?
private var color: Color?
Expand Down Expand Up @@ -34,21 +35,21 @@ public struct NeumorphismLabelButton: View {

public var body: some View {
HighlightableButton(action: {
self.isSelected.toggle()
self.handler?()
isSelected.toggle()
handler?()
}) { isHeighlight in
ZStack {
RoundedRectangle(cornerRadius: self.cornerRadius)
.fill(self.neumorphism.color)
.frame(width: self.width, height: self.height)
RoundedRectangle(cornerRadius: cornerRadius)
.fill(neumorphism.color)
.frame(width: width, height: height)
.modifier(NeumorphismShadowModifier(isAnimation: isHeighlight))
.padding()


Text(self.text)
.font(self.font ?? .title)
Text(text)
.font(font ?? .title)
.foregroundColor(
isHeighlight ? self.color?.darkerColor() ?? self.neumorphism.fontColor() : self.color ?? self.neumorphism.fontColor())
isHeighlight ? color?.darkerColor() ?? neumorphism.fontColor() : color ?? neumorphism.fontColor())
}
.animation(Animation.spring(response: 0.3, dampingFraction: 0.7, blendDuration: 1))
}
Expand Down
38 changes: 19 additions & 19 deletions Sources/CustomViews/NeumorphismSlider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import SwiftUI
@available(macOS 12.0, *)
public struct NeumorphismSlider: View {
@EnvironmentObject var neumorphism: NeumorphismManager
@Binding var value: Double
@Binding var sliderValue: Double

var changeHandler: (() -> Void)?
var endedHandler: (() -> Void)?
Expand All @@ -30,7 +30,7 @@ public struct NeumorphismSlider: View {
self.tipColor = tipColor
self.barColor = barColor
self.showPointer = showPointer
self._value = value
self._sliderValue = value
self.changeHandler = changeHandler
self.endedHandler = endedHandler
validate()
Expand All @@ -44,46 +44,46 @@ public struct NeumorphismSlider: View {
)

ZStack(alignment: .trailing) {
RoundedRectangle(cornerRadius: self.height / 2)
.fill(barColor ?? self.neumorphism.color.darkerColor())
RoundedRectangle(cornerRadius: height / 2)
.fill(barColor ?? neumorphism.color.darkerColor())
.frame(
width: self.width * CGFloat(value),
width: width * CGFloat(sliderValue),
height: height * 0.8,
alignment: .leading)
.padding(.init(top: 8, leading: 2, bottom: 8, trailing: 2))
if self.showPointer {
if showPointer {
ZStack {
Circle()
.fill(self.neumorphism.color)
.frame(width: self.height * 1.5, height: self.height * 1.5)
.shadow(color: self.neumorphism.color.darkerColor(), radius: 4, x: 0, y: 0)
.fill(neumorphism.color)
.frame(width: height * 1.5, height: height * 1.5)
.shadow(color: neumorphism.color.darkerColor(), radius: 4, x: 0, y: 0)
}
}
}
}.gesture(
DragGesture(minimumDistance: 0)
.onChanged({ (value) in
self.value = Double(value.location.x / self.width)
self.validate()
self.changeHandler?()
sliderValue = Double(value.location.x / width)
validate()
changeHandler?()
})
.onEnded({ (value) in
self.value = Double(value.location.x / self.width)
self.validate()
self.endedHandler?()
sliderValue = Double(value.location.x / width)
validate()
endedHandler?()
})
)
}

private func validate() {
if self.value > 1.0 {
if sliderValue > 1.0 {
DispatchQueue.main.async {
self.value = 1.0
sliderValue = 1.0
}
}
if self.value < 0 {
if sliderValue < 0 {
DispatchQueue.main.async {
self.value = 0
sliderValue = 0
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Extensions/ViewExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public extension View {
y: CGFloat = 8,
isAnimation: Bool = false
) -> some View {
self.modifier(NeumorphismShadowModifier(
modifier(NeumorphismShadowModifier(
baseColor: baseColor,
radius: radius,
x: x,
Expand All @@ -23,7 +23,7 @@ public extension View {
shapeType: ShapeType = .circle,
color: Color? = nil
) -> some View {
self.modifier(NeumorphismConcaveModifier(
modifier(NeumorphismConcaveModifier(
shapeType: shapeType, color: color
))
}
Expand Down
1 change: 0 additions & 1 deletion Tests/Mock/NeumorphismManagerMock.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import SwiftUI
@testable import NeumorphismUI

@available(iOS 13.0, *)
class NeumorphismManagerMock: NeumorphismManagable {
Expand Down

0 comments on commit ad5914f

Please sign in to comment.