Skip to content

Commit

Permalink
repeated nav on L/R hold
Browse files Browse the repository at this point in the history
Signed-off-by: Joseph Mattiello <[email protected]>
  • Loading branch information
JoeMatt committed Nov 16, 2024
1 parent dbd3d4b commit 3ff318e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
2 changes: 1 addition & 1 deletion PVUI/Sources/PVSwiftUI/Consoles/ConsoleGamesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ struct ConsoleGamesView: SwiftUI.View, GameContextMenuDelegate {
}
}
}
case .horizontalNavigation(let value):
case .horizontalNavigation(let value, _):
handleHorizontalNavigation(value)
case .start:
if let focusedItem = focusedItemInSection {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public enum GamepadEvent {
case buttonPress
case buttonB
case verticalNavigation(Float, Bool)
case horizontalNavigation(Float)
case horizontalNavigation(Float, Bool)
case menuToggle
case shoulderLeft
case shoulderRight
Expand Down Expand Up @@ -80,7 +80,7 @@ public class GamepadManager: ObservableObject {
if abs(yValue) == 1.0 {
self?.eventSubject.send(.verticalNavigation(yValue, dpad.up.isPressed || dpad.down.isPressed))
} else if abs(xValue) == 1.0 {
self?.eventSubject.send(.horizontalNavigation(xValue))
self?.eventSubject.send(.horizontalNavigation(xValue, dpad.left.isPressed || dpad.right.isPressed))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion PVUI/Sources/PVSwiftUI/Home/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ struct HomeView: SwiftUI.View {
}
}
}
case .horizontalNavigation(let value):
case .horizontalNavigation(let value, _):
handleHorizontalNavigation(value)
case .start:
if let focusedItem = focusedItemInSection {
Expand Down
32 changes: 32 additions & 0 deletions PVUI/Sources/PVSwiftUI/RootView/PVRootViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ public class PVRootViewController: UIViewController, GameLaunchingViewController
private var gameController: GCController?
private var controllerObserver: Any?

private var navigationTimer: Timer?
private let initialDelay: TimeInterval = 0.5
private let repeatDelay: TimeInterval = 0.15

public static func instantiate(updatesController: PVGameLibraryUpdatesController, gameLibrary: PVGameLibrary<RealmDatabaseDriver>, gameImporter: GameImporter, viewModel: PVRootViewModel) -> PVRootViewController {
let controller = PVRootViewController()
controller.updatesController = updatesController
Expand Down Expand Up @@ -103,6 +107,7 @@ public class PVRootViewController: UIViewController, GameLaunchingViewController
public override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
NotificationCenter.default.removeObserver(controllerObserver as Any)
navigationTimer?.invalidate()
gameController = nil
}

Expand Down Expand Up @@ -184,10 +189,37 @@ public class PVRootViewController: UIViewController, GameLaunchingViewController
self.showMenu()
}
case .shoulderLeft:
// Cancel existing timer
navigationTimer?.invalidate()
navigationTimer = nil

// Initial navigation
navigateToPrevious()

// Setup continuous navigation
navigationTimer = Timer.scheduledTimer(withTimeInterval: initialDelay, repeats: false) { [self] _ in
self.navigationTimer = Timer.scheduledTimer(withTimeInterval: self.repeatDelay, repeats: true) { [self] _ in
self.navigateToPrevious()
}
}
case .shoulderRight:
// Cancel existing timer
navigationTimer?.invalidate()
navigationTimer = nil

// Initial navigation
navigateToNext()

// Setup continuous navigation
navigationTimer = Timer.scheduledTimer(withTimeInterval: initialDelay, repeats: false) { [self] _ in
self.navigationTimer = Timer.scheduledTimer(withTimeInterval: repeatDelay, repeats: true) { [self] _ in
navigateToNext()
}
}
default:
// Cancel any existing timer when other buttons are pressed
navigationTimer?.invalidate()
navigationTimer = nil
break
}
}
Expand Down

0 comments on commit 3ff318e

Please sign in to comment.