Skip to content

Commit 19328e4

Browse files
committed
Merge branch 'SwipeGesture' into 'main'
Swipe gesture Added to adjust focus for tv See merge request ws/client/iosapp!559
2 parents 14944a4 + b1089b7 commit 19328e4

File tree

1 file changed

+63
-2
lines changed

1 file changed

+63
-2
lines changed

WindscribeTV/ViewControllers/MainViewController.swift

+63-2
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class MainViewController: PreferredFocusedViewController {
8383
}
8484

8585
private func setupUI() {
86+
myPreferredFocusedView = connectionButton
8687
self.view.backgroundColor = UIColor.clear
8788
backgroundView.backgroundColor = UIColor.clear
8889

@@ -224,15 +225,75 @@ class MainViewController: PreferredFocusedViewController {
224225
let swipeDown = UISwipeGestureRecognizer(target: self, action: #selector(handleSwipeDown(_:)))
225226
swipeDown.direction = .down
226227
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)
227240
}
228241

229242
@objc private func handleSwipeDown(_ sender: UISwipeGestureRecognizer) {
230243
if sender.state == .ended {
231-
if UIScreen.main.focusedView == connectionButton {
244+
if connectionButton.isFocused {
232245
myPreferredFocusedView = connectionButton
233246
self.setNeedsFocusUpdate()
234247
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()
236297
}
237298
}
238299
}

0 commit comments

Comments
 (0)