Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS: Add @available tags to enable compilation back to iOS 12 #16969

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkg/apple/HelperBar/CocoaView+HelperBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ protocol HelperBarActionDelegate: AnyObject {
var isOrientationLocked: Bool { get }
}

@available(iOS 13, *)
extension CocoaView {
@objc func setupHelperBar() {
let helperVC = HelperBarViewController()
Expand All @@ -34,6 +35,7 @@ extension CocoaView {
}
}

@available(iOS 13, *)
extension CocoaView: HelperBarActionDelegate {
func keyboardButtonTapped() {
toggleCustomKeyboard()
Expand Down
5 changes: 5 additions & 0 deletions pkg/apple/HelperBar/HelperBarItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Copyright © 2022 RetroArch. All rights reserved.
//

@available(iOS 13, *)
protocol HelperBarItem {
var image: UIImage? { get }
var selectedImage: UIImage? { get }
Expand All @@ -16,10 +17,12 @@ protocol HelperBarItem {
func action()
}

@available(iOS 13, *)
extension HelperBarItem {
var tintColorOnSelection: UIColor? { nil }
}

@available(iOS 13, *)
struct KeyboardBarItem: HelperBarItem {
let image = UIImage(systemName: "keyboard")
let selectedImage = UIImage(systemName: "keyboard.fill")
Expand All @@ -42,6 +45,7 @@ struct KeyboardBarItem: HelperBarItem {
}
}

@available(iOS 13, *)
struct MouseBarItem: HelperBarItem {
let image = UIImage(systemName: "computermouse")
let selectedImage = UIImage(systemName: "computermouse.fill")
Expand All @@ -59,6 +63,7 @@ struct MouseBarItem: HelperBarItem {
}
}

@available(iOS 13, *)
struct LockOrientationBarItem: HelperBarItem {
let image = UIImage(systemName: "lock.rotation")
let selectedImage = UIImage(systemName: "lock.rotation")
Expand Down
4 changes: 4 additions & 0 deletions pkg/apple/HelperBar/HelperBarViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Copyright © 2022 RetroArch. All rights reserved.
//

@available(iOS 13, *)
class HelperBarViewController: UIViewController {
var viewModel = HelperBarViewModel()

Expand Down Expand Up @@ -137,12 +138,14 @@ class HelperBarViewController: UIViewController {
}
}

@available(iOS 13, *)
extension HelperBarViewController: UIGestureRecognizerDelegate {
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
true
}
}

@available(iOS 13, *)
extension HelperBarViewController: HelperBarViewModelDelegate {
func setNavigationBarHidden(_ isHidden: Bool) {
navigationBar.isHidden = isHidden
Expand All @@ -152,6 +155,7 @@ extension HelperBarViewController: HelperBarViewModelDelegate {
}
}

@available(iOS 13, *)
extension HelperBarViewController: UINavigationBarDelegate {
func position(for bar: UIBarPositioning) -> UIBarPosition {
return .topAttached
Expand Down
2 changes: 2 additions & 0 deletions pkg/apple/HelperBar/HelperBarViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@

import Combine

@available(iOS 13, *)
protocol HelperBarViewModelDelegate: AnyObject {
func setNavigationBarHidden(_ isHidden: Bool)
func updateNavigationBarItems()
}

@available(iOS 13, *)
class HelperBarViewModel {
@Published var didInteractWithBar = false
private var cancellable: AnyCancellable?
Expand Down
1 change: 1 addition & 0 deletions pkg/apple/MouseEmulation/CocoaView+MouseSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

extension CocoaView {
@available(iOS 13, *)
@objc func setupMouseSupport() {
mouseHandler = EmulatorTouchMouseHandler(view: view, delegate: self as? EmulatorTouchMouseHandlerDelegate)
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/apple/MouseEmulation/EmulatorTouchMouse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
import Combine
import UIKit

@available(iOS 13, *)
@objc public protocol EmulatorTouchMouseHandlerDelegate: AnyObject {
func handleMouseClick(isLeftClick: Bool, isPressed: Bool)
func handleMouseMove(x: CGFloat, y: CGFloat)
}

@available(iOS 13, *)
@objcMembers public class EmulatorTouchMouseHandler: NSObject, UIPointerInteractionDelegate {
enum MouseHoldState {
case notHeld, wait, held
Expand Down
3 changes: 3 additions & 0 deletions pkg/apple/OnScreenKeyboard/CocoaView+KeyboardSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import Foundation

@available(iOS 13, *)
extension CocoaView {
var leftKeyboardModel: EmulatorKeyboardViewModel {
return EmulatorKeyboardViewModel(keys: [
Expand Down Expand Up @@ -173,6 +174,7 @@ extension CocoaView {
}
}

@available(iOS 13, *)
extension CocoaView: EmulatorKeyboardKeyPressedDelegate {
func keyUp(_ key: KeyCoded) {
print("keyUp: code=\(key.keyCode) keyboardModifierState = \(keyboardModifierState)")
Expand All @@ -185,6 +187,7 @@ extension CocoaView: EmulatorKeyboardKeyPressedDelegate {
}
}

@available(iOS 13, *)
extension CocoaView: EmulatorKeyboardModifierPressedDelegate {
func modifierPressedWithKey(_ key: KeyCoded, enable: Bool) {
switch UInt32(key.keyCode) {
Expand Down
6 changes: 6 additions & 0 deletions pkg/apple/OnScreenKeyboard/EmulatorKeyCoded.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
// Copyright © 2022 RetroArch. All rights reserved.
//

@available(iOS 13, *)
@objc enum KeySize: Int {
case standard = 1, wide, wider
}

// represents a key that has an underlying code that gets sent to the emulator
@available(iOS 13, *)
@objc protocol KeyCoded: AnyObject {
var keyLabel: String { get }
var keyImageName: String? { get }
Expand All @@ -20,10 +22,12 @@
var isModifier: Bool { get }
}

@available(iOS 13, *)
protocol KeyRowsDataSource {
func keyForPositionAt(_ position: KeyPosition) -> KeyCoded?
}

@available(iOS 13, *)
@objc class EmulatorKeyboardKey: NSObject, KeyCoded {
let keyLabel: String
var keyImageName: String?
Expand All @@ -45,6 +49,7 @@ protocol KeyRowsDataSource {
}
}

@available(iOS 13, *)
class SpacerKey: KeyCoded {
let keyLabel = ""
let keyCode = 0
Expand All @@ -57,6 +62,7 @@ class SpacerKey: KeyCoded {
}
}

@available(iOS 13, *)
class SliderKey: KeyCoded {
let keyLabel = ""
let keyCode = 0
Expand Down
1 change: 1 addition & 0 deletions pkg/apple/OnScreenKeyboard/EmulatorKeyboardButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import UIKit

@available(iOS 13, *)
class EmulatorKeyboardButton: UIButton {
let key: KeyCoded
var toggleState = false
Expand Down
5 changes: 5 additions & 0 deletions pkg/apple/OnScreenKeyboard/EmulatorKeyboardView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,26 @@
// TODO: shift key should change the label of the keys to uppercase (need callback mechanism?)
// pan gesture to outer edges of keyboard view for better dragging

@available(iOS 13, *)
@objc protocol EmulatorKeyboardKeyPressedDelegate: AnyObject {
func keyDown(_ key: KeyCoded)
func keyUp(_ key: KeyCoded)
}

@available(iOS 13, *)
@objc protocol EmulatorKeyboardModifierPressedDelegate: AnyObject {
func modifierPressedWithKey(_ key: KeyCoded, enable: Bool)
func isModifierEnabled(key: KeyCoded) -> Bool
}

@available(iOS 13, *)
protocol EmulatorKeyboardViewDelegate: AnyObject {
func toggleAlternateKeys()
func refreshModifierStates()
func updateTransparency(toAlpha alpha: Float)
}

@available(iOS 13, *)
class EmulatorKeyboardView: UIView {

static var keyboardBackgroundColor = UIColor.systemGray6.withAlphaComponent(0.5)
Expand Down Expand Up @@ -273,6 +277,7 @@ class EmulatorKeyboardView: UIView {
}
}

@available(iOS 13, *)
extension UIImage {
static func dot(size:CGSize, color:UIColor) -> UIImage {
return UIGraphicsImageRenderer(size: size).image { context in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Copyright © 2022 RetroArch. All rights reserved.
//

@available(iOS 13, *)
@objc class EmulatorKeyboardController: UIViewController {

class EmulatorKeyboardPassthroughView: UIView {
Expand Down Expand Up @@ -118,6 +119,7 @@
}
}

@available(iOS 13, *)
extension EmulatorKeyboardController: EmulatorKeyboardViewDelegate {
func toggleAlternateKeys() {
for keyboard in [leftKeyboardView, rightKeyboardView] {
Expand Down
2 changes: 2 additions & 0 deletions pkg/apple/OnScreenKeyboard/EmulatorKeyboardViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
// Copyright © 2022 RetroArch. All rights reserved.
//

@available(iOS 13, *)
struct KeyPosition {
let row: Int
let column: Int
}

@available(iOS 13, *)
@objc class EmulatorKeyboardViewModel: NSObject, KeyRowsDataSource {
var keys = [[KeyCoded]]()
var alternateKeys: [[KeyCoded]]?
Expand Down
4 changes: 2 additions & 2 deletions pkg/apple/RetroArch_iOS13.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1795,7 +1795,7 @@
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES;
CODE_SIGN_ENTITLEMENTS = "$(IOS_CODE_SIGN_ENTITLEMENTS)";
INFOPLIST_FILE = "$(SRCROOT)/iOS/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = "$(RA_IPHONEOS_DEPLOYMENT_TARGET:default=13.0)";
IPHONEOS_DEPLOYMENT_TARGET = "$(RA_IPHONEOS_DEPLOYMENT_TARGET:default=12.0)";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -1815,7 +1815,7 @@
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES;
CODE_SIGN_ENTITLEMENTS = "$(IOS_CODE_SIGN_ENTITLEMENTS)";
INFOPLIST_FILE = "$(SRCROOT)/iOS/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = "$(RA_IPHONEOS_DEPLOYMENT_TARGET:default=13.0)";
IPHONEOS_DEPLOYMENT_TARGET = "$(RA_IPHONEOS_DEPLOYMENT_TARGET:default=12.0)";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down
Loading