@@ -18,20 +18,52 @@ struct TimelineView : View {
1818 @Binding var secondsToPixels : Double
1919 @Binding var selectedItem : Item ?
2020
21+ @State private var hitTestEnabled : Bool = false
22+
2123 var body : some View
2224 {
23- let videoTracks = timeline. videoTracks
24- let audioTracks = timeline. audioTracks
25+ // Lame scroll view optimizations.
26+ // It seems as though hit testing for selection causes massive slowdowns in SwiftUI
27+ // Due to how recursive hit testing happens
28+ // We disable hit testing using macos 15 onScrollPhaseChange
2529
26- ScrollView ( [ . horizontal, . vertical] )
30+ if #available( macOS 15 . 0 , * ) {
31+ ScrollView ( [ . horizontal, . vertical] )
32+ {
33+ self . timelineView ( )
34+ . allowsHitTesting ( self . hitTestEnabled)
35+ . drawingGroup ( opaque: true )
36+
37+ }
38+ . onScrollPhaseChange ( { oldPhase, newPhase, context in
39+ guard oldPhase != newPhase else { return }
40+
41+ self . hitTestEnabled = !newPhase. isScrolling
42+ } )
43+ }
44+ else
2745 {
46+ // Fallback on earlier versions
47+ ScrollView ( [ . horizontal, . vertical] )
48+ {
49+ self . timelineView ( )
50+ }
51+ }
52+ }
53+
54+ func timelineView( ) -> some View
55+ {
56+ let videoTracks = timeline. videoTracks
57+ let audioTracks = timeline. audioTracks
58+
59+ return
2860 VStack ( alignment: . leading, spacing: 3 )
2961 {
3062 TimeRulerView ( timeline: self . timeline, secondsToPixels: self . $secondsToPixels, currentTime: self . $currentTime )
3163 . frame ( height: 40 )
3264 . offset ( x: 100 )
33- //
34- // Divider()
65+ //
66+ // Divider()
3567
3668 ForEach ( 0 ..< videoTracks. count, id: \. self) { index in
3769
@@ -44,7 +76,7 @@ struct TimelineView : View {
4476 }
4577
4678 ForEach ( 0 ..< audioTracks. count, id: \. self) { index in
47-
79+
4880 let track = audioTracks [ index]
4981
5082 TrackView ( track: track,
@@ -55,6 +87,6 @@ struct TimelineView : View {
5587 }
5688 . frame ( height: CGFloat ( ( videoTracks. count + audioTracks. count) ) * 25 + 50 )
5789 . frame ( maxHeight: CGFloat ( ( videoTracks. count + audioTracks. count) ) * 500 )
58- }
90+
5991 }
6092}
0 commit comments