Skip to content

Commit 143b67e

Browse files
committed
Fixed the inner shadow offset
- Fixed the size of inner shadow offset. It is too large when the width of the shape is larger than its height. - Updated the demo.
1 parent 7b50c23 commit 143b67e

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

Sources/Neumorphic/SoftInnerShadowViewModifier.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ private struct SoftInnerShadowViewModifier<S: Shape> : ViewModifier {
3232
}
3333

3434
fileprivate func shadowOffset(_ geo: GeometryProxy) -> CGFloat {
35-
return geo.size.width * 0.5 * min(max(spread, 0), 1)
35+
return (geo.size.width <= geo.size.height ? geo.size.width : geo.size.height) * 0.5 * min(max(spread, 0), 1)
3636
}
3737

3838

neumorphic-ios-example/neumorphic-ios-example/SoftButtonDemoView.swift

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ struct SoftButtonDemoView: View {
4949
}.softButtonStyle(Circle(), mainColor: Color.red, textColor: Color.white, darkShadowColor: Color("redButtonDarkShadow"), lightShadowColor:Color("redButtonLightShadow"))
5050
}
5151

52+
Button(action: {}) {
53+
Text("Custom Size")
54+
.fontWeight(.bold)
55+
.frame(width: 300, height: 20)
56+
}
57+
.softButtonStyle(Capsule(), padding: 15)
58+
5259

5360
HStack {
5461
Button(action: {}) {
@@ -93,9 +100,14 @@ struct SoftButtonDemoView: View {
93100
.background(
94101
Capsule().fill(Neumorphic.shared.mainColor()).softOuterShadow()
95102
)
103+
104+
105+
106+
96107
}
97108

98-
}.navigationBarTitle("Soft Button Demo")
109+
}
110+
.navigationBarTitle("Soft Button Demo")
99111
}
100112
}
101113
}
@@ -105,10 +117,12 @@ struct SoftButtonDemoView_Previews: PreviewProvider {
105117
static var previews: some View {
106118
Group {
107119
SoftButtonDemoView()
108-
.environment(\.colorScheme, .light)
120+
.navigationViewStyle(StackNavigationViewStyle())
121+
.environment(\.colorScheme, .light)
109122

110123
SoftButtonDemoView()
111-
.environment(\.colorScheme, .dark)
124+
.navigationViewStyle(StackNavigationViewStyle())
125+
.environment(\.colorScheme, .dark)
112126
}
113127
}
114128
}

0 commit comments

Comments
 (0)