3
3
* Created by Freek (github.com/frzi).
4
4
*/
5
5
6
+ import AVKit
6
7
import SwiftUI
7
8
8
9
/// The Doom Wipe transition modifier
@@ -16,36 +17,28 @@ struct DoomWipeTransitionModifier: ViewModifier {
16
17
return globalRandomSeed
17
18
}
18
19
19
- @State private var viewDimensions : CGSize = . zero
20
20
@State private var randomSeed = Self . globalAdvancedRandomSeed ( )
21
21
22
- let animationPosition : CGFloat
22
+ let progress : CGFloat
23
23
let direction : DoomWipeShader . WipeDirection
24
24
25
25
private var shader : Shader {
26
26
DoomWipeShader (
27
- dimensions: viewDimensions,
28
- animationPosition: animationPosition,
27
+ progress: progress,
29
28
seed: randomSeed,
30
29
direction: direction
31
30
) . shader
32
31
}
33
32
34
- init ( animationPosition : CGFloat , direction: DoomWipeShader . WipeDirection = . down) {
35
- self . animationPosition = animationPosition
33
+ init ( progress : CGFloat , direction: DoomWipeShader . WipeDirection = . down) {
34
+ self . progress = progress
36
35
self . direction = direction
37
36
}
38
37
39
38
func body( content: Content ) -> some View {
40
39
content
41
40
. compositingGroup ( )
42
41
. layerEffect ( shader, maxSampleOffset: . zero, isEnabled: true )
43
- . background ( GeometryReader { reader in
44
- HStack { }
45
- . onAppear {
46
- viewDimensions = reader. size
47
- }
48
- } )
49
42
}
50
43
}
51
44
@@ -55,8 +48,8 @@ extension AnyTransition {
55
48
. asymmetric(
56
49
insertion: . identity,
57
50
removal: . modifier(
58
- active: DoomWipeTransitionModifier ( animationPosition : 1 ) ,
59
- identity: DoomWipeTransitionModifier ( animationPosition : 0 )
51
+ active: DoomWipeTransitionModifier ( progress : 1 ) ,
52
+ identity: DoomWipeTransitionModifier ( progress : 0 )
60
53
)
61
54
)
62
55
}
@@ -66,8 +59,8 @@ extension AnyTransition {
66
59
. asymmetric(
67
60
insertion: . identity,
68
61
removal: . modifier(
69
- active: DoomWipeTransitionModifier ( animationPosition : 1 , direction: direction) ,
70
- identity: DoomWipeTransitionModifier ( animationPosition : 0 , direction: direction)
62
+ active: DoomWipeTransitionModifier ( progress : 1 , direction: direction) ,
63
+ identity: DoomWipeTransitionModifier ( progress : 0 , direction: direction)
71
64
)
72
65
)
73
66
}
0 commit comments