@@ -12,7 +12,17 @@ class JetpackPrologueViewController: UIViewController {
1212 return view
1313 } ( )
1414
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 {
1626 let gradientLayer = CAGradientLayer ( )
1727
1828 // 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 {
2939 gradientLayer. locations = FeatureFlag . newLandingScreen. enabled ? [ 0.0 , 0.2 , 0.5 , 1.0 ] : [ 0.0 , 0.9 ]
3040
3141 return gradientLayer
32- } ( )
42+ }
3343
3444 override func viewDidLoad( ) {
3545 super. viewDidLoad ( )
3646
3747 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
4552 }
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
6363 }
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
6489 // 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)
7194 }
7295
7396 func updateLabel( for traitCollection: UITraitCollection ) {
@@ -80,8 +103,15 @@ class JetpackPrologueViewController: UIViewController {
80103
81104 override func traitCollectionDidChange( _ previousTraitCollection: UITraitCollection ? ) {
82105 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)
85115 }
86116
87117 override func viewDidLayoutSubviews( ) {
@@ -93,7 +123,7 @@ class JetpackPrologueViewController: UIViewController {
93123 }
94124
95125 /// Slightly moves the logo / text when moving the device
96- private func addParallax( ) {
126+ private func addParallax( to view : UIView ) {
97127 let amount = Constants . parallaxAmount
98128
99129 let horizontal = UIInterpolatingMotionEffect ( keyPath: " center.x " , type: . tiltAlongHorizontalAxis)
@@ -107,7 +137,7 @@ class JetpackPrologueViewController: UIViewController {
107137 let group = UIMotionEffectGroup ( )
108138 group. motionEffects = [ horizontal, vertical]
109139
110- stackView . addMotionEffect ( group)
140+ view . addMotionEffect ( group)
111141 }
112142
113143 private struct Constants {
0 commit comments