Skip to content

Commit 42b756e

Browse files
author
Trent Guillory
committed
Make ID generic
1 parent 3a2f012 commit 42b756e

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

SnapToScrollDemo/SnapToScrollDemo.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10-
84C99CD826D99BA100C1D5C4 /* Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84C99CD726D99BA100C1D5C4 /* Model.swift */; };
10+
84C99CD826D99BA100C1D5C4 /* CellModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84C99CD726D99BA100C1D5C4 /* CellModel.swift */; };
1111
84D9FA3626D9753600F87EF5 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D9FA3526D9753600F87EF5 /* AppDelegate.swift */; };
1212
84D9FA3826D9753600F87EF5 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D9FA3726D9753600F87EF5 /* SceneDelegate.swift */; };
1313
84D9FA3A26D9753600F87EF5 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D9FA3926D9753600F87EF5 /* ContentView.swift */; };
@@ -18,7 +18,7 @@
1818
/* End PBXBuildFile section */
1919

2020
/* Begin PBXFileReference section */
21-
84C99CD726D99BA100C1D5C4 /* Model.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Model.swift; sourceTree = "<group>"; };
21+
84C99CD726D99BA100C1D5C4 /* CellModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CellModel.swift; sourceTree = "<group>"; };
2222
84D9FA3226D9753600F87EF5 /* SnapToScrollDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SnapToScrollDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
2323
84D9FA3526D9753600F87EF5 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
2424
84D9FA3726D9753600F87EF5 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
@@ -67,7 +67,7 @@
6767
84D9FA3526D9753600F87EF5 /* AppDelegate.swift */,
6868
84D9FA3726D9753600F87EF5 /* SceneDelegate.swift */,
6969
84D9FA3926D9753600F87EF5 /* ContentView.swift */,
70-
84C99CD726D99BA100C1D5C4 /* Model.swift */,
70+
84C99CD726D99BA100C1D5C4 /* CellModel.swift */,
7171
);
7272
path = Sources;
7373
sourceTree = "<group>";
@@ -174,7 +174,7 @@
174174
84D9FA3626D9753600F87EF5 /* AppDelegate.swift in Sources */,
175175
84D9FA3826D9753600F87EF5 /* SceneDelegate.swift in Sources */,
176176
84D9FA3A26D9753600F87EF5 /* ContentView.swift in Sources */,
177-
84C99CD826D99BA100C1D5C4 /* Model.swift in Sources */,
177+
84C99CD826D99BA100C1D5C4 /* CellModel.swift in Sources */,
178178
);
179179
runOnlyForDeploymentPostprocessing = 0;
180180
};

SnapToScrollDemo/Sources/Model.swift renamed to SnapToScrollDemo/Sources/CellModel.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
1+
//
22
//
33
//import Foundation
44
//
5-
//struct Model: Identifiable {
5+
//struct CellModel: Identifiable {
66
//
77
// var systemImage: String
88
// var

Sources/HStackSnap.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public struct HStackSnap<Content: View>: View {
3232

3333
for pref in preferences {
3434

35-
itemFrames[pref.id] = pref
35+
itemFrames[pref.id.hashValue] = pref
3636
}
3737

3838
})
@@ -95,7 +95,7 @@ public struct HStackSnap<Content: View>: View {
9595
/// Calculated offset based on `SnapLocation`
9696
@State private var targetOffset: CGFloat
9797

98-
@State private var itemFrames: [UUID: ContentPreferenceData] = [:]
98+
@State private var itemFrames: [Int: ContentPreferenceData] = [:]
9999

100100
private let coordinateSpace: String
101101
}

Sources/Model/ContentPreferenceKey.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import SwiftUI
55

66
struct ContentPreferenceData: Equatable {
77

8-
let id: UUID
8+
let id: Int
99
let rect: CGRect
1010
}
1111

Sources/Views/GeometryReaderOverlay.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import Foundation
22
import SwiftUI
33

4-
public struct GeometryReaderOverlay: View {
4+
public struct GeometryReaderOverlay<ID: Hashable>: View {
55

66
// MARK: Lifecycle
77

8-
public init(id: UUID, coordinateSpace: String = "SnapToScroll") {
8+
public init(id: ID, coordinateSpace: String = "SnapToScroll") {
99

1010
self.id = id
1111
self.coordinateSpace = coordinateSpace
@@ -21,13 +21,13 @@ public struct GeometryReaderOverlay: View {
2121
.preference(
2222
key: ContentPreferenceKey.self,
2323
value: [ContentPreferenceData(
24-
id: id,
24+
id: id.hashValue,
2525
rect: geometry.frame(in: .named(coordinateSpace)))])
2626
}
2727
}
2828

2929
// MARK: Internal
3030

31-
let id: UUID
31+
let id: ID
3232
let coordinateSpace: String
3333
}

0 commit comments

Comments
 (0)