Skip to content

Commit

Permalink
Fixed the inner shadow offset
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
costachung committed Nov 18, 2020
1 parent 7b50c23 commit 143b67e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Sources/Neumorphic/SoftInnerShadowViewModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private struct SoftInnerShadowViewModifier<S: Shape> : ViewModifier {
}

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


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ struct SoftButtonDemoView: View {
}.softButtonStyle(Circle(), mainColor: Color.red, textColor: Color.white, darkShadowColor: Color("redButtonDarkShadow"), lightShadowColor:Color("redButtonLightShadow"))
}

Button(action: {}) {
Text("Custom Size")
.fontWeight(.bold)
.frame(width: 300, height: 20)
}
.softButtonStyle(Capsule(), padding: 15)


HStack {
Button(action: {}) {
Expand Down Expand Up @@ -93,9 +100,14 @@ struct SoftButtonDemoView: View {
.background(
Capsule().fill(Neumorphic.shared.mainColor()).softOuterShadow()
)




}

}.navigationBarTitle("Soft Button Demo")
}
.navigationBarTitle("Soft Button Demo")
}
}
}
Expand All @@ -105,10 +117,12 @@ struct SoftButtonDemoView_Previews: PreviewProvider {
static var previews: some View {
Group {
SoftButtonDemoView()
.environment(\.colorScheme, .light)
.navigationViewStyle(StackNavigationViewStyle())
.environment(\.colorScheme, .light)

SoftButtonDemoView()
.environment(\.colorScheme, .dark)
.navigationViewStyle(StackNavigationViewStyle())
.environment(\.colorScheme, .dark)
}
}
}

0 comments on commit 143b67e

Please sign in to comment.