@@ -10,11 +10,13 @@ import UIKit
10
10
11
11
class AddGoalViewController : UIViewController {
12
12
13
- @IBOutlet weak var segmentedControl : UISegmentedControl !
14
- @IBOutlet weak var instructionLabel : UILabel !
15
13
@IBOutlet weak var datePicker : UIDatePicker !
14
+ @IBOutlet weak var promptView : UITextView !
16
15
@IBOutlet weak var goalWritingView : UITextView !
17
16
17
+ @IBOutlet weak var opaqueView : UIView !
18
+ @IBOutlet weak var opaqueViewYPosition : NSLayoutConstraint !
19
+
18
20
@IBOutlet weak var cubeView : CubeView !
19
21
internal var cubeFaces : [ UIImageView ] = [ ]
20
22
@@ -24,54 +26,49 @@ class AddGoalViewController: UIViewController {
24
26
public static var activeRecommendations : [ String ] = [ ]
25
27
26
28
internal var lastUpdated : Date = Date ( )
27
- internal var selectedSegment : Int = 0
28
29
29
30
override func viewDidLoad( ) {
30
31
super. viewDidLoad ( )
31
32
// Do any additional setup after loading the view.
33
+ NotificationCenter . default. addObserver ( self , selector: #selector( keyboardWillShow ( _: ) ) , name: UIResponder . keyboardWillShowNotification, object: nil )
34
+ NotificationCenter . default. addObserver ( self , selector: #selector( keyboardWillHide ( _: ) ) , name: UIResponder . keyboardWillHideNotification, object: nil )
32
35
33
- // engageTableView()
36
+ opaqueView . layer . maskedCorners = [ . layerMinXMinYCorner , . layerMaxXMinYCorner ]
34
37
35
38
let tap = UITapGestureRecognizer ( target: self , action: #selector( onCubeTap ( _: ) ) )
36
39
cubeView. addGestureRecognizer ( tap)
37
-
38
40
setupCubeView ( )
39
41
cubeView. enableMotion ( )
40
42
41
- NotificationCenter . default. addObserver ( self , selector: #selector( keyboardWillShow ( _: ) ) , name: UIResponder . keyboardWillShowNotification, object: nil )
42
- NotificationCenter . default. addObserver ( self , selector: #selector( keyboardWillHide ( _: ) ) , name: UIResponder . keyboardWillHideNotification, object: nil )
43
+ goalWritingView. delegate = self
43
44
}
44
45
45
46
override func viewDidAppear( _ animated: Bool ) {
46
47
super. viewDidAppear ( animated)
48
+ goalWritingView. becomeFirstResponder ( )
47
49
48
50
cubeView. needsTaring = true
49
51
cubeView. trackMotion ( true )
50
52
51
53
CLPProfile . shared. onFetchSuccess {
52
54
self . setupCubeView ( )
53
- // self.updateTableView ()
55
+ self . onCubeTap ( )
54
56
}
55
57
if CLPProfile . shared. basicInformation. lastModified > lastUpdated {
56
58
self . setupCubeView ( )
57
- // self.updateTableView ()
59
+ self . onCubeTap ( )
58
60
}
61
+ self . onCubeTap ( )
59
62
}
60
63
61
64
override func viewDidDisappear( _ animated: Bool ) {
62
65
super. viewDidDisappear ( animated)
63
-
66
+ goalWritingView . resignFirstResponder ( )
64
67
cubeView. trackMotion ( false )
65
68
}
66
69
67
- @IBAction func onSegmentSwitch( _ sender: UISegmentedControl ) {
68
- selectedSegment = sender. selectedSegmentIndex
69
- switch selectedSegment {
70
- case 0 : instructionLabel. text = " Tap the dice (bottom left), then tap a prompt "
71
- case 1 : instructionLabel. text = " Enter your goal and set a deadline "
72
- default : break
73
- }
74
- // updateTableView()
70
+ @IBAction func onModalViewTap( _ sender: UITapGestureRecognizer ) {
71
+ dismiss ( animated: true , completion: nil )
75
72
}
76
73
77
74
@objc func onCubeTap( _ sender: UITapGestureRecognizer ? = nil ) {
@@ -81,17 +78,32 @@ class AddGoalViewController: UIViewController {
81
78
let i = cubeView. topFaceIndex % CLPProfile. shared. basicInformation. values. count
82
79
Self . activeValueForRecs = VALUE_LIST . owned [ i] . name
83
80
84
- // updateTableView ()
81
+ updatePrompt ( )
85
82
}
86
83
}
87
84
85
+ private func updatePrompt( ) {
86
+ let prompt = Self . activeRecommendations. randomElement ( ) ?? " What's something you've always wanted to do? "
87
+ if prompt. contains ( " ? " ) {
88
+ promptView. text = prompt
89
+ goalWritingView. text = " "
90
+ } else {
91
+ promptView. text = " Personalize the given goal. It will be easier to accomplish if it's more specific. "
92
+ goalWritingView. text = prompt
93
+ }
94
+
95
+ // if !goalWritingView.isFirstResponder {
96
+ // goalWritingView.textColor = .lightGray
97
+ // }
98
+ }
99
+
88
100
private func setupCubeView( ) {
89
101
cubeFaces = cubeView. createFaces ( in: cubeView. bounds)
90
102
cubeView. situate ( in: cubeView. bounds)
91
103
92
104
let backgroundColor : UIColor ?
93
105
// cannot use ternary operator because #available is special
94
- if #available( iOS 13 . 0 , * ) { backgroundColor = . lightGray } else { backgroundColor = . lightGray }
106
+ if #available( iOS 13 . 0 , * ) { backgroundColor = . label } else { backgroundColor = . black }
95
107
96
108
var images = VALUE_LIST . owned. map ( { $0. image} )
97
109
// one image will be duplicated because user has 5 strengths
@@ -112,12 +124,9 @@ class AddGoalViewController: UIViewController {
112
124
113
125
extension AddGoalViewController : UITextViewDelegate {
114
126
func textViewDidBeginEditing( _ textView: UITextView ) {
115
- if textView. text. contains ( " ? " ) { textView. clearsOnInsertion = true }
116
127
}
117
128
118
129
func textViewDidEndEditing( _ textView: UITextView ) {
119
- // guard let indexPath = tableView.indexPathForSelectedRow else {return}
120
- // if (selectedSegment == 0 && Self.activeRecommendations.count > indexPath.row) {Self.activeRecommendations[indexPath.row] = textView.text}
121
130
}
122
131
123
132
func textView( _ textView: UITextView , shouldChangeTextIn range: NSRange , replacementText text: String ) -> Bool {
@@ -129,25 +138,24 @@ extension AddGoalViewController: UITextViewDelegate {
129
138
}
130
139
131
140
func textViewDidChange( _ textView: UITextView ) {
132
- UIView . setAnimationsEnabled ( false )
133
- textView. sizeToFit ( )
134
- // DispatchQueue.main.async {
135
- // self.tableView.beginUpdates()
136
- // self.tableView.endUpdates()
137
- // UIView.setAnimationsEnabled(true)
138
- // }
139
141
}
140
142
}
141
143
142
144
extension AddGoalViewController {
143
145
@objc func keyboardWillShow( _ notification: Notification ) {
144
146
if let keyboardSize = ( notification. userInfo ? [ UIResponder . keyboardFrameBeginUserInfoKey] as? NSValue ) ? . cgRectValue {
145
- // tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: keyboardSize.height, right: 0)
147
+ self . opaqueViewYPosition. constant = keyboardSize. height
148
+ UIView . animate ( withDuration: 0.1 ) {
149
+ self . view. layoutIfNeeded ( )
150
+ }
146
151
}
147
152
}
148
153
@objc func keyboardWillHide( _ notification: Notification ) {
149
154
if let _ = ( notification. userInfo ? [ UIResponder . keyboardFrameBeginUserInfoKey] as? NSValue ) ? . cgRectValue {
150
- // tableView.contentInset = UIEdgeInsets.zero
155
+ self . opaqueViewYPosition. constant = 0
156
+ UIView . animate ( withDuration: 0.1 ) {
157
+ self . view. layoutIfNeeded ( )
158
+ }
151
159
}
152
160
}
153
161
}
0 commit comments