removed dependency
Signed-off-by: Matt Bruce <mbrucedogs@gmail.com>
This commit is contained in:
parent
9ad348daa1
commit
9081337dc1
@ -16,15 +16,9 @@ let package = Package(
|
||||
targets: ["CasinoKit"]
|
||||
)
|
||||
],
|
||||
dependencies: [
|
||||
.package(url: "https://github.com/devicekit/DeviceKit.git", from: "5.0.0")
|
||||
],
|
||||
targets: [
|
||||
.target(
|
||||
name: "CasinoKit",
|
||||
dependencies: [
|
||||
.product(name: "DeviceKit", package: "DeviceKit")
|
||||
],
|
||||
resources: [
|
||||
.process("Resources")
|
||||
]
|
||||
|
||||
@ -1,196 +1,18 @@
|
||||
////
|
||||
//// DeviceInfo.swift
|
||||
//// CasinoKit
|
||||
////
|
||||
//// Device detection utilities using DeviceKit.
|
||||
////
|
||||
//
|
||||
// DeviceInfo.swift
|
||||
// CasinoKit
|
||||
//
|
||||
// Device detection utilities using DeviceKit.
|
||||
//
|
||||
import Foundation
|
||||
import UIKit
|
||||
|
||||
import SwiftUI
|
||||
@_exported import DeviceKit
|
||||
|
||||
/// Device information utilities for responsive layouts.
|
||||
///// Device information utilities for responsive layouts.
|
||||
public enum DeviceInfo {
|
||||
|
||||
// MARK: - Current Device
|
||||
|
||||
/// The current device.
|
||||
public static var current: Device {
|
||||
Device.current
|
||||
}
|
||||
|
||||
// MARK: - Device Size Categories
|
||||
public static var isSmallDevice: Bool {
|
||||
isSmallPhone || isPadMini
|
||||
}
|
||||
|
||||
/// Whether the current device is a small iPhone (SE series).
|
||||
/// Includes iPhone SE (1st, 2nd, 3rd gen) and their simulators.
|
||||
public static var isSmallPhone: Bool {
|
||||
let smallPhones: [Device] = [
|
||||
// iPhone SE series
|
||||
.iPhoneSE,
|
||||
.iPhoneSE2,
|
||||
.iPhoneSE3,
|
||||
// Simulators
|
||||
.simulator(.iPhoneSE),
|
||||
.simulator(.iPhoneSE2),
|
||||
.simulator(.iPhoneSE3)
|
||||
]
|
||||
return current.isOneOf(smallPhones)
|
||||
}
|
||||
|
||||
/// Whether the current device is a standard iPhone (not SE, not Pro Max/Plus).
|
||||
public static var isStandardPhone: Bool {
|
||||
current.isPhone && !isSmallPhone && !isLargePhone
|
||||
}
|
||||
|
||||
/// Whether the current device is a large iPhone (Pro Max, Plus models).
|
||||
public static var isLargePhone: Bool {
|
||||
let largePhones: [Device] = [
|
||||
// Plus models
|
||||
.iPhone6Plus, .iPhone6sPlus, .iPhone7Plus, .iPhone8Plus,
|
||||
// Max models
|
||||
.iPhoneXSMax, .iPhone11ProMax, .iPhone12ProMax,
|
||||
.iPhone13ProMax, .iPhone14Plus, .iPhone14ProMax,
|
||||
.iPhone15Plus, .iPhone15ProMax, .iPhone16Plus, .iPhone16ProMax,
|
||||
// Simulators
|
||||
.simulator(.iPhone6Plus), .simulator(.iPhone6sPlus),
|
||||
.simulator(.iPhone7Plus), .simulator(.iPhone8Plus),
|
||||
.simulator(.iPhoneXSMax), .simulator(.iPhone11ProMax),
|
||||
.simulator(.iPhone12ProMax), .simulator(.iPhone13ProMax),
|
||||
.simulator(.iPhone14Plus), .simulator(.iPhone14ProMax),
|
||||
.simulator(.iPhone15Plus), .simulator(.iPhone15ProMax),
|
||||
.simulator(.iPhone16Plus), .simulator(.iPhone16ProMax)
|
||||
]
|
||||
return current.isOneOf(largePhones)
|
||||
}
|
||||
|
||||
/// Whether the current device is an iPhone.
|
||||
public static var isPhone: Bool {
|
||||
current.isPhone
|
||||
}
|
||||
|
||||
/// Whether the current device is an iPad.
|
||||
public static var isPad: Bool {
|
||||
current.isPad
|
||||
}
|
||||
|
||||
/// Whether the current device is an iPad mini.
|
||||
/// iPad minis have smaller screens than standard iPads (7.9" or 8.3").
|
||||
/// Uses screen diagonal as fallback for reliable detection on real devices.
|
||||
public static var isPadMini: Bool {
|
||||
// First try exact device match
|
||||
let minis: [Device] = [
|
||||
.iPadMini, .iPadMini2, .iPadMini3, .iPadMini4,
|
||||
.iPadMini5, .iPadMini6, .iPadMiniA17Pro,
|
||||
.simulator(.iPadMini), .simulator(.iPadMini2), .simulator(.iPadMini3),
|
||||
.simulator(.iPadMini4), .simulator(.iPadMini5), .simulator(.iPadMini6),
|
||||
.simulator(.iPadMiniA17Pro)
|
||||
]
|
||||
if current.isOneOf(minis) {
|
||||
return true
|
||||
}
|
||||
|
||||
// Fallback: Check screen diagonal (iPad minis are 7.9" or 8.3")
|
||||
// Other iPads are 10.2" and larger
|
||||
if current.isPad {
|
||||
let diagonal = current.diagonal
|
||||
return diagonal > 0 && diagonal < 9.0
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
/// Whether the current device is a large iPad (Pro 12.9", 13").
|
||||
public static var isLargePad: Bool {
|
||||
let largePads: [Device] = [
|
||||
.iPadPro12Inch, .iPadPro12Inch2, .iPadPro12Inch3,
|
||||
.iPadPro12Inch4, .iPadPro12Inch5, .iPadPro12Inch6,
|
||||
.iPadPro13M4,
|
||||
.simulator(.iPadPro12Inch), .simulator(.iPadPro12Inch2),
|
||||
.simulator(.iPadPro12Inch3), .simulator(.iPadPro12Inch4),
|
||||
.simulator(.iPadPro12Inch5), .simulator(.iPadPro12Inch6),
|
||||
.simulator(.iPadPro13M4)
|
||||
]
|
||||
return current.isOneOf(largePads)
|
||||
}
|
||||
|
||||
/// Whether running in a simulator.
|
||||
public static var isSimulator: Bool {
|
||||
current.isSimulator
|
||||
}
|
||||
|
||||
// MARK: - Screen Size Helpers
|
||||
|
||||
/// The diagonal screen size in inches.
|
||||
public static var screenDiagonal: Double {
|
||||
current.diagonal
|
||||
}
|
||||
|
||||
/// The screen's pixels per inch.
|
||||
public static var screenPPI: Int {
|
||||
current.ppi ?? 0
|
||||
}
|
||||
|
||||
// MARK: - Device Name
|
||||
|
||||
/// A human-readable description of the current device.
|
||||
public static var deviceName: String {
|
||||
current.description
|
||||
}
|
||||
|
||||
/// The real device when running in simulator, or the device itself.
|
||||
public static var realDevice: Device {
|
||||
current.realDevice
|
||||
}
|
||||
|
||||
/// Debug info about the current device (for troubleshooting).
|
||||
public static var debugInfo: String {
|
||||
let diag = String(format: "%.1f", screenDiagonal)
|
||||
return "Device: \(current), diagonal: \(diag)\", isPadMini: \(isPadMini)"
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - SwiftUI Environment
|
||||
|
||||
/// Environment key for small phone detection.
|
||||
private struct IsSmallPhoneKey: EnvironmentKey {
|
||||
static let defaultValue: Bool = DeviceInfo.isSmallPhone
|
||||
}
|
||||
|
||||
extension EnvironmentValues {
|
||||
/// Whether the current device is a small phone (iPhone SE series).
|
||||
public var isSmallPhone: Bool {
|
||||
get { self[IsSmallPhoneKey.self] }
|
||||
set { self[IsSmallPhoneKey.self] = newValue }
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - View Extension
|
||||
|
||||
extension View {
|
||||
/// Applies different modifiers based on device size.
|
||||
/// - Parameters:
|
||||
/// - small: Modifier to apply on small phones (iPhone SE)
|
||||
/// - standard: Modifier to apply on standard phones
|
||||
/// - large: Modifier to apply on large phones (Pro Max, Plus)
|
||||
/// - pad: Modifier to apply on iPads
|
||||
@ViewBuilder
|
||||
public func deviceAdaptive<Small: View, Standard: View, Large: View, Pad: View>(
|
||||
small: (Self) -> Small,
|
||||
standard: (Self) -> Standard,
|
||||
large: (Self) -> Large,
|
||||
pad: (Self) -> Pad
|
||||
) -> some View {
|
||||
if DeviceInfo.isPad {
|
||||
pad(self)
|
||||
} else if DeviceInfo.isSmallPhone {
|
||||
small(self)
|
||||
} else if DeviceInfo.isLargePhone {
|
||||
large(self)
|
||||
} else {
|
||||
standard(self)
|
||||
}
|
||||
UIDevice.current.userInterfaceIdiom == .pad
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user