@@ -83,6 +83,7 @@ class MainViewController: PreferredFocusedViewController {
83
83
}
84
84
85
85
private func setupUI( ) {
86
+ myPreferredFocusedView = connectionButton
86
87
self . view. backgroundColor = UIColor . clear
87
88
backgroundView. backgroundColor = UIColor . clear
88
89
@@ -224,15 +225,75 @@ class MainViewController: PreferredFocusedViewController {
224
225
let swipeDown = UISwipeGestureRecognizer ( target: self , action: #selector( handleSwipeDown ( _: ) ) )
225
226
swipeDown. direction = . down
226
227
view. addGestureRecognizer ( swipeDown)
228
+
229
+ let swipeUp = UISwipeGestureRecognizer ( target: self , action: #selector( handleSwipeUp ( _: ) ) )
230
+ swipeUp. direction = . up
231
+ view. addGestureRecognizer ( swipeUp)
232
+
233
+ let swipeleft = UISwipeGestureRecognizer ( target: self , action: #selector( handleSwipeLeft ( _: ) ) )
234
+ swipeleft. direction = . left
235
+ view. addGestureRecognizer ( swipeleft)
236
+
237
+ let swipeRight = UISwipeGestureRecognizer ( target: self , action: #selector( handleSwipeRight ( _: ) ) )
238
+ swipeRight. direction = . right
239
+ view. addGestureRecognizer ( swipeRight)
227
240
}
228
241
229
242
@objc private func handleSwipeDown( _ sender: UISwipeGestureRecognizer ) {
230
243
if sender. state == . ended {
231
- if UIScreen . main . focusedView == connectionButton {
244
+ if connectionButton. isFocused {
232
245
myPreferredFocusedView = connectionButton
233
246
self . setNeedsFocusUpdate ( )
234
247
self . updateFocusIfNeeded ( )
235
- router. routeTo ( to: . serverList( bestLocation: self . bestLocation) , from: self )
248
+ DispatchQueue . main. async {
249
+ self . router. routeTo ( to: . serverList( bestLocation: self . bestLocation) , from: self )
250
+ }
251
+ }
252
+ }
253
+ }
254
+
255
+ @objc private func handleSwipeUp( _ sender: UISwipeGestureRecognizer ) {
256
+ if sender. state == . ended {
257
+ if connectionButton. isFocused {
258
+ myPreferredFocusedView = notificationButton
259
+ self . setNeedsFocusUpdate ( )
260
+ self . updateFocusIfNeeded ( )
261
+ }
262
+ }
263
+ }
264
+
265
+ @objc private func handleSwipeRight( _ sender: UISwipeGestureRecognizer ) {
266
+ if sender. state == . ended {
267
+ if preferredFocusedView == notificationButton {
268
+ myPreferredFocusedView = helpButton
269
+ self . setNeedsFocusUpdate ( )
270
+ self . updateFocusIfNeeded ( )
271
+ } else if preferredFocusedView == settingsButton || settingsButton. isFocused {
272
+ myPreferredFocusedView = notificationButton
273
+ self . setNeedsFocusUpdate ( )
274
+ self . updateFocusIfNeeded ( )
275
+ } else if preferredFocusedView == helpButton {
276
+ myPreferredFocusedView = upgradeButton
277
+ self . setNeedsFocusUpdate ( )
278
+ self . updateFocusIfNeeded ( )
279
+ }
280
+ }
281
+ }
282
+
283
+ @objc private func handleSwipeLeft( _ sender: UISwipeGestureRecognizer ) {
284
+ if sender. state == . ended {
285
+ if preferredFocusedView == notificationButton {
286
+ myPreferredFocusedView = settingsButton
287
+ self . setNeedsFocusUpdate ( )
288
+ self . updateFocusIfNeeded ( )
289
+ } else if preferredFocusedView == helpButton {
290
+ myPreferredFocusedView = notificationButton
291
+ self . setNeedsFocusUpdate ( )
292
+ self . updateFocusIfNeeded ( )
293
+ } else if preferredFocusedView == upgradeButton {
294
+ myPreferredFocusedView = helpButton
295
+ self . setNeedsFocusUpdate ( )
296
+ self . updateFocusIfNeeded ( )
236
297
}
237
298
}
238
299
}
0 commit comments