Skip to content

Commit 2fc5593

Browse files
Add new method skeletonShape
1 parent 1cfdd16 commit 2fc5593

File tree

6 files changed

+21
-15
lines changed

6 files changed

+21
-15
lines changed

Example/Example.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@
303303
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
304304
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
305305
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
306-
MACOSX_DEPLOYMENT_TARGET = 12.3;
306+
MACOSX_DEPLOYMENT_TARGET = 13.0;
307307
MARKETING_VERSION = 1.0;
308308
PRODUCT_BUNDLE_IDENTIFIER = dev.litecode.Example;
309309
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -339,7 +339,7 @@
339339
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
340340
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
341341
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
342-
MACOSX_DEPLOYMENT_TARGET = 12.3;
342+
MACOSX_DEPLOYMENT_TARGET = 13.0;
343343
MARKETING_VERSION = 1.0;
344344
PRODUCT_BUNDLE_IDENTIFIER = dev.litecode.Example;
345345
PRODUCT_NAME = "$(TARGET_NAME)";

Example/Example/ExampleView.swift

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import EasySkeleton
1010

1111
struct ExampleView: View {
1212

13-
@State private var isSkeletonActive = false
13+
@State private var isSkeletonActive = true
1414

1515
var body: some View {
1616
ZStack {
@@ -50,7 +50,6 @@ struct ExampleView: View {
5050
.skeletonCornerRadius(16, style: .continuous)
5151
.setSkeleton(
5252
self.$isSkeletonActive,
53-
animationType: .solid(Color.black),
5453
animation: Animation.default,
5554
transition: AnyTransition.opacity
5655
)
@@ -136,8 +135,6 @@ struct HeaderView: View {
136135
}
137136
}
138137

139-
struct ExampleView_Previews: PreviewProvider {
140-
static var previews: some View {
141-
ExampleView()
142-
}
138+
#Preview {
139+
ExampleView()
143140
}

Package.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
// swift-tools-version: 5.6
1+
// swift-tools-version: 5.10
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription
55

66
let package = Package(
77
name: "EasySkeleton",
88
platforms: [
9-
.iOS(.v14),
10-
.tvOS(.v14),
11-
.macOS(.v11)
9+
.iOS(.v16),
10+
.tvOS(.v16),
11+
.macOS(.v13)
1212
],
1313
products: [
1414
.library(

Sources/EasySkeleton/EasySkeleton.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public struct SkeletonData {
2828

2929
public fileprivate(set) var cornerRadius: CGFloat = 0
3030
public fileprivate(set) var cornerStyle: RoundedCornerStyle = .circular
31+
public fileprivate(set) var customShape: AnyShape?
3132

3233
public fileprivate(set) var skeletonWidth: CGFloat?
3334
public fileprivate(set) var skeletonHeight: CGFloat?
@@ -84,14 +85,22 @@ public extension View {
8485
}
8586
}
8687

87-
// Apply width and/or height modification for skeleton
88+
/// Apply width and/or height modification for skeleton
8889
func skeletonFrame(width: CGFloat? = nil, height: CGFloat? = nil) -> some View {
8990
self.transformEnvironment(\.skeleton) { skeleton in
9091
height.flatMap { skeleton.skeletonHeight = $0 }
9192
width.flatMap { skeleton.skeletonWidth = $0 }
9293
}
9394
}
9495

96+
/// Change shape for skeleton.
97+
/// - Parameter shape: New shape for skeleton. Set nil to return default skeleton.
98+
func skeletonShape<S: Shape>(_ shape: S?) -> some View {
99+
self.transformEnvironment(\.skeleton) { skeleton in
100+
skeleton.customShape = shape.flatMap(AnyShape.init)
101+
}
102+
}
103+
95104
/// Change state for nested skeletons settings in environment
96105
/// - Parameter isActive: Control visible state for skeletons.
97106
/// - Parameter animationType: Set animation behaviour for skeletons.

Sources/EasySkeleton/Extensions/Color+Skeleton.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public extension Color {
6666
#elseif os(watchOS)
6767
return Color.secondary
6868
#elseif os(macOS)
69-
return Color(.alternateSelectedControlColor)
69+
return Color(NSColor(red: 0.82, green: 0.82, blue: 0.84, alpha: 1))
7070
#endif
7171
}
7272
}

Sources/EasySkeleton/Extensions/View+Skeleton.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ private struct SkeletonShape: Shape {
5959
@State private var opacity: Double = 1
6060

6161
func path(in rect: CGRect) -> Path {
62-
RoundedRectangle(cornerRadius: self.skeleton.cornerRadius).path(in: rect)
62+
skeleton.customShape?.path(in: rect) ?? RoundedRectangle(cornerRadius: self.skeleton.cornerRadius).path(in: rect)
6363
}
6464

6565
var body: some View {

0 commit comments

Comments
 (0)