@@ -12,7 +12,17 @@ class JetpackPrologueViewController: UIViewController {
12
12
return view
13
13
} ( )
14
14
15
- var gradientLayer : CALayer = {
15
+ private lazy var logoImageView : UIImageView = {
16
+ let imageView = UIImageView ( image: UIImage ( named: " jetpack-logo " ) )
17
+ imageView. translatesAutoresizingMaskIntoConstraints = false
18
+ return imageView
19
+ } ( )
20
+
21
+ private lazy var gradientLayer : CALayer = {
22
+ makeGradientLayer ( )
23
+ } ( )
24
+
25
+ private func makeGradientLayer( ) -> CAGradientLayer {
16
26
let gradientLayer = CAGradientLayer ( )
17
27
18
28
// Start color is the background color with no alpha because if we use clear it will fade to black
@@ -29,45 +39,58 @@ class JetpackPrologueViewController: UIViewController {
29
39
gradientLayer. locations = FeatureFlag . newLandingScreen. enabled ? [ 0.0 , 0.2 , 0.5 , 1.0 ] : [ 0.0 , 0.9 ]
30
40
31
41
return gradientLayer
32
- } ( )
42
+ }
33
43
34
44
override func viewDidLoad( ) {
35
45
super. viewDidLoad ( )
36
46
37
47
view. backgroundColor = JetpackPrologueStyleGuide . backgroundColor
38
- if FeatureFlag . newLandingScreen. enabled {
39
- let viewModel = JetpackPromptsViewModel ( )
40
- let jetpackAnimatedView = UIView . embedSwiftUIView ( JetpackLandingScreenView ( viewModel: viewModel) )
41
- view. addSubview ( jetpackAnimatedView)
42
- view. pinSubviewToAllEdges ( jetpackAnimatedView)
43
- } else {
44
- view. addSubview ( starFieldView)
48
+
49
+ guard FeatureFlag . newLandingScreen. enabled else {
50
+ loadOldPrologueView ( )
51
+ return
45
52
}
46
- view. layer. addSublayer ( gradientLayer)
47
- if FeatureFlag . newLandingScreen. enabled {
48
- stackView. isHidden = true
49
- titleLabel. isHidden = true
50
- let logoImageView = UIImageView ( image: UIImage ( named: " jetpack-logo " ) )
51
- logoImageView. translatesAutoresizingMaskIntoConstraints = false
52
- view. addSubview ( logoImageView)
53
- NSLayoutConstraint . activate ( [
54
- logoImageView. widthAnchor. constraint ( equalToConstant: 72 ) ,
55
- logoImageView. heightAnchor. constraint ( equalTo: logoImageView. widthAnchor) ,
56
- logoImageView. centerXAnchor. constraint ( equalTo: view. centerXAnchor) ,
57
- logoImageView. topAnchor. constraint ( equalTo: view. topAnchor, constant: 72 )
58
- ] )
59
- } else {
60
- titleLabel. text = NSLocalizedString ( " Site security and performance \n from your pocket " , comment: " Prologue title label, the \n force splits it into 2 lines. " )
61
- titleLabel. textColor = JetpackPrologueStyleGuide . Title. textColor
62
- titleLabel. font = JetpackPrologueStyleGuide . Title. font
53
+ loadNewPrologueView ( )
54
+ }
55
+
56
+ private func loadNewPrologueView( ) {
57
+ // hide old view unused elements
58
+ stackView. isHidden = true
59
+ titleLabel. isHidden = true
60
+ // complex gradient background
61
+ if let backgroundImage = UIImage ( named: " JPBackground " ) {
62
+ view. layer. contents = backgroundImage. cgImage
63
63
}
64
+ // animated view
65
+ let viewModel = JetpackPromptsViewModel ( )
66
+ let jetpackAnimatedView = UIView . embedSwiftUIView ( JetpackLandingScreenView ( viewModel: viewModel) )
67
+ view. addSubview ( jetpackAnimatedView)
68
+ view. pinSubviewToAllEdges ( jetpackAnimatedView)
69
+ // Jetpack logo with parallax
70
+ view. addSubview ( logoImageView)
71
+ addParallax ( to: logoImageView)
72
+ // linear gradient above the animated view
73
+ view. layer. insertSublayer ( gradientLayer, below: logoImageView. layer)
74
+ // constraints
75
+ NSLayoutConstraint . activate ( [
76
+ logoImageView. widthAnchor. constraint ( equalToConstant: 72 ) ,
77
+ logoImageView. heightAnchor. constraint ( equalTo: logoImageView. widthAnchor) ,
78
+ logoImageView. centerXAnchor. constraint ( equalTo: view. centerXAnchor) ,
79
+ logoImageView. topAnchor. constraint ( equalTo: view. topAnchor, constant: 72 )
80
+ ] )
81
+ }
82
+
83
+ private func loadOldPrologueView( ) {
84
+ view. addSubview ( starFieldView)
85
+ view. layer. addSublayer ( gradientLayer)
86
+ titleLabel. text = NSLocalizedString ( " Site security and performance \n from your pocket " , comment: " Prologue title label, the \n force splits it into 2 lines. " )
87
+ titleLabel. textColor = JetpackPrologueStyleGuide . Title. textColor
88
+ titleLabel. font = JetpackPrologueStyleGuide . Title. font
64
89
// Move the layers to appear below everything else
65
- if !FeatureFlag. newLandingScreen. enabled {
66
- starFieldView. layer. zPosition = Constants . starLayerPosition
67
- gradientLayer. zPosition = Constants . gradientLayerPosition
68
- addParallax ( )
69
- updateLabel ( for: traitCollection)
70
- }
90
+ starFieldView. layer. zPosition = Constants . starLayerPosition
91
+ gradientLayer. zPosition = Constants . gradientLayerPosition
92
+ addParallax ( to: stackView)
93
+ updateLabel ( for: traitCollection)
71
94
}
72
95
73
96
func updateLabel( for traitCollection: UITraitCollection ) {
@@ -80,8 +103,15 @@ class JetpackPrologueViewController: UIViewController {
80
103
81
104
override func traitCollectionDidChange( _ previousTraitCollection: UITraitCollection ? ) {
82
105
super. traitCollectionDidChange ( previousTraitCollection)
83
- guard !FeatureFlag. newLandingScreen. enabled else { return }
84
- updateLabel ( for: traitCollection)
106
+
107
+ guard FeatureFlag . newLandingScreen. enabled,
108
+ previousTraitCollection? . userInterfaceStyle != traitCollection. userInterfaceStyle else {
109
+ updateLabel ( for: traitCollection)
110
+ return
111
+ }
112
+ gradientLayer. removeFromSuperlayer ( )
113
+ gradientLayer = makeGradientLayer ( )
114
+ view. layer. insertSublayer ( gradientLayer, below: logoImageView. layer)
85
115
}
86
116
87
117
override func viewDidLayoutSubviews( ) {
@@ -93,7 +123,7 @@ class JetpackPrologueViewController: UIViewController {
93
123
}
94
124
95
125
/// Slightly moves the logo / text when moving the device
96
- private func addParallax( ) {
126
+ private func addParallax( to view : UIView ) {
97
127
let amount = Constants . parallaxAmount
98
128
99
129
let horizontal = UIInterpolatingMotionEffect ( keyPath: " center.x " , type: . tiltAlongHorizontalAxis)
@@ -107,7 +137,7 @@ class JetpackPrologueViewController: UIViewController {
107
137
let group = UIMotionEffectGroup ( )
108
138
group. motionEffects = [ horizontal, vertical]
109
139
110
- stackView . addMotionEffect ( group)
140
+ view . addMotionEffect ( group)
111
141
}
112
142
113
143
private struct Constants {
0 commit comments