@@ -20,14 +20,17 @@ class AssignmentPagesViewController: UIViewController {
20
20
return pageControl
21
21
} ( )
22
22
private let pageControlView = UIView ( )
23
- private let pageController = UIPageViewController ( transitionStyle: . scroll,
24
- navigationOrientation: . horizontal,
25
- options: nil )
23
+ private let pageController = UIPageViewController ( transitionStyle: . scroll, navigationOrientation: . horizontal, options: nil )
26
24
27
25
// Even when the current Assignment changes, the popup controller
28
26
// instance will be the same but the popup URL will change
29
27
private let webController = WebViewController ( allowsOptions: false )
30
- private lazy var popupController = WebViewNavigationController ( rootViewController: webController)
28
+ private let editorController = RichTextEditorViewController ( )
29
+ private lazy var containerController
30
+ = SegmentedContainerViewController ( segments: [ ( " Web " , webController) , ( " Editor " , editorController) ] )
31
+
32
+ private lazy var popupController = WebViewNavigationController ( rootViewController: containerController)
33
+
31
34
private let submitPopupBarController = SubmitPopupBarViewController ( )
32
35
33
36
private var pendingIndex : Int ?
@@ -47,10 +50,6 @@ class AssignmentPagesViewController: UIViewController {
47
50
setPage ( assignment: assignments [ start] , index: start)
48
51
}
49
52
50
- override func loadView( ) {
51
- view = UIView ( )
52
- }
53
-
54
53
required init ? ( coder aDecoder: NSCoder ) {
55
54
fatalError ( " init(coder:) has not been implemented " )
56
55
}
@@ -76,9 +75,16 @@ class AssignmentPagesViewController: UIViewController {
76
75
webController. dismissAction = { [ weak self] in
77
76
self ? . tabBarController? . closePopup ( animated: true , completion: nil )
78
77
}
78
+ editorController. dismissAction = { [ weak self] in
79
+ self ? . tabBarController? . closePopup ( animated: true , completion: nil )
80
+ }
81
+
82
+ editorController. delegate = webController
83
+ editorController. needsTitleField = false
79
84
80
85
tabBarController? . popupInteractionStyle = . default
81
86
tabBarController? . popupBar. backgroundStyle = . regular
87
+ tabBarController? . popupContentView. popupCloseButtonStyle = . none
82
88
tabBarController? . popupBar. customBarViewController = submitPopupBarController
83
89
84
90
submitPopupBarController. titleLabel. text = " DRAG TO SUBMIT "
@@ -103,14 +109,13 @@ class AssignmentPagesViewController: UIViewController {
103
109
guard let tabBarController = tabBarController as? TabsController else {
104
110
return
105
111
}
106
- tabBarController . popupController = nil
107
- // If a new tab is selected, the UITabBarController will handle
108
- // presentation and dismissal of the popup bar
109
- if tabBarController . isMovingToNewTabFromPages {
110
- tabBarController. isMovingToNewTabFromPages = false
112
+
113
+ let isNavigationPushing = navigationController ? . viewControllers . last != self
114
+
115
+ if isMovingFromParentViewController || isNavigationPushing {
116
+ tabBarController. dismissPopupBar ( animated : true , completion : nil )
111
117
return
112
118
}
113
- tabBarController. dismissPopupBar ( animated: true , completion: nil )
114
119
}
115
120
116
121
override func viewDidAppear( _ animated: Bool ) {
@@ -121,18 +126,23 @@ class AssignmentPagesViewController: UIViewController {
121
126
guard let tabBarController = tabBarController as? TabsController else {
122
127
return
123
128
}
124
- tabBarController. popupController = popupController
125
129
126
- tabBarController. presentPopupBar ( withContentViewController: popupController,
127
- animated: true ,
128
- completion: nil )
129
- // When popping back to PagesController, LNPopupController
130
- // encounters a bug where it is entirely removed from the view
131
- // hierarchy and causes a black space to appear in its place.
132
- // Adding the views back to the tabBarController manually fixes
133
- // the bug.
134
- tabBarController. view. addSubview ( tabBarController. popupBar)
135
- tabBarController. view. addSubview ( tabBarController. popupContentView)
130
+ if tabBarController. popupPresentationState == . hidden ||
131
+ tabBarController. popupPresentationState == . closed {
132
+
133
+ tabBarController. presentPopupBar ( withContentViewController: popupController,
134
+ animated: true ,
135
+ completion: nil )
136
+
137
+ // When popping back to PagesController, LNPopupController
138
+ // encounters a bug where it is entirely removed from the view
139
+ // hierarchy and causes a black space to appear in its place.
140
+ // Adding the views back to the tabBarController manually fixes
141
+ // the bug.
142
+ tabBarController. view. addSubview ( tabBarController. popupBar)
143
+ tabBarController. view. addSubview ( tabBarController. popupContentView)
144
+ tabBarController. popupContentView. popupCloseButtonStyle = . none
145
+ }
136
146
}
137
147
}
138
148
@@ -143,7 +153,6 @@ extension AssignmentPagesViewController: UIPageViewControllerDataSource, UIPageV
143
153
guard let viewControllerIndex = pages. index ( of: viewController) else {
144
154
return nil
145
155
}
146
- setPopupURL ( viewControllerIndex: viewControllerIndex)
147
156
148
157
let previousIndex = viewControllerIndex - 1
149
158
guard previousIndex >= 0 else {
@@ -162,7 +171,6 @@ extension AssignmentPagesViewController: UIPageViewControllerDataSource, UIPageV
162
171
guard let viewControllerIndex = pages. index ( of: viewController) else {
163
172
return nil
164
173
}
165
- setPopupURL ( viewControllerIndex: viewControllerIndex)
166
174
167
175
let nextIndex = viewControllerIndex + 1
168
176
let assignmentsCount = assignments. count
@@ -190,6 +198,7 @@ extension AssignmentPagesViewController: UIPageViewControllerDataSource, UIPageV
190
198
if completed, let index = pendingIndex {
191
199
pageControl. currentPage = index
192
200
delegate? . pageController ( self , didMoveToIndex: index)
201
+ setPopupURL ( viewControllerIndex: index)
193
202
}
194
203
}
195
204
@@ -208,6 +217,9 @@ extension AssignmentPagesViewController: UIPageViewControllerDataSource, UIPageV
208
217
webController. title = assignment. title
209
218
webController. setURL ( url: url)
210
219
webController. setNeedsLoad ( to: true )
220
+ let instructions = PageView . getInstructionsString ( attributedText: assignment. attributedInstructions)
221
+ editorController. attributedContext = instructions
222
+ editorController. html = " "
211
223
}
212
224
}
213
225
0 commit comments