Skip to content

Commit ce1f713

Browse files
committed
feat(ios): add Action Button capability detection
1 parent 56b997e commit ce1f713

4 files changed

Lines changed: 66 additions & 0 deletions

File tree

‎README.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ See our detailed [changelog](CHANGELOG.md) for the latest features, improvements
3838
- [x] Detect available sensors (Touch ID, Face ID)
3939
- [x] Detect available disk space
4040
- [x] Apple Pencil support detection
41+
- [x] Action Button detection
4142

4243
## Requirements
4344

@@ -169,6 +170,14 @@ if device.isSimulator {
169170
}
170171
```
171172

173+
### Check if a device has an Action Button
174+
```swift
175+
let device = Device.current
176+
if device.hasActionButton {
177+
// Action Button specific behavior
178+
}
179+
```
180+
172181
### Get the Simulator Device
173182
```swift
174183
let device = Device.current

‎Source/Device.generated.swift‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,6 +1265,26 @@ public enum Device {
12651265
return isOneOf(Device.allDevicesWithDynamicIsland) || isOneOf(Device.allDevicesWithDynamicIsland.map(Device.simulator))
12661266
}
12671267

1268+
/// All devices that have an Action Button.
1269+
public static var allDevicesWithActionButton: [Device] {
1270+
return [
1271+
.iPhone15Pro,
1272+
.iPhone15ProMax,
1273+
.iPhone16,
1274+
.iPhone16Plus,
1275+
.iPhone16Pro,
1276+
.iPhone16ProMax,
1277+
.iPhone17,
1278+
.iPhone17Pro,
1279+
.iPhone17ProMax,
1280+
]
1281+
}
1282+
1283+
/// Returns whether or not the device has an Action Button.
1284+
public var hasActionButton: Bool {
1285+
return isOneOf(Device.allDevicesWithActionButton) || isOneOf(Device.allDevicesWithActionButton.map(Device.simulator))
1286+
}
1287+
12681288
/// All devices that have 3D Touch support.
12691289
public static var allDevicesWith3dTouchSupport: [Device] {
12701290
return [.iPhone6s, .iPhone6sPlus, .iPhone7, .iPhone7Plus, .iPhone8, .iPhone8Plus, .iPhoneX, .iPhoneXS, .iPhoneXSMax]

‎Source/Device.swift.gyb‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,26 @@ public enum Device {
727727
return isOneOf(Device.allDevicesWithDynamicIsland) || isOneOf(Device.allDevicesWithDynamicIsland.map(Device.simulator))
728728
}
729729

730+
/// All devices that have an Action Button.
731+
public static var allDevicesWithActionButton: [Device] {
732+
return [
733+
.iPhone15Pro,
734+
.iPhone15ProMax,
735+
.iPhone16,
736+
.iPhone16Plus,
737+
.iPhone16Pro,
738+
.iPhone16ProMax,
739+
.iPhone17,
740+
.iPhone17Pro,
741+
.iPhone17ProMax,
742+
]
743+
}
744+
745+
/// Returns whether or not the device has an Action Button.
746+
public var hasActionButton: Bool {
747+
return isOneOf(Device.allDevicesWithActionButton) || isOneOf(Device.allDevicesWithActionButton.map(Device.simulator))
748+
}
749+
730750
/// All devices that have 3D Touch support.
731751
public static var allDevicesWith3dTouchSupport: [Device] {
732752
return [${', '.join(list(map(lambda device: "." + device.caseName, list(filter(lambda device: device.hasForce3dTouchSupport == True, iOSDevices)))))}]

‎Tests/Tests.swift‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,23 @@ class DeviceKitTests: XCTestCase {
551551
}
552552
}
553553

554+
func testHasActionButton() {
555+
let actionButtonDevices: [Device] = [
556+
.iPhone15Pro,
557+
.iPhone15ProMax,
558+
.iPhone16,
559+
.iPhone16Plus,
560+
.iPhone16Pro,
561+
.iPhone16ProMax,
562+
.iPhone17,
563+
.iPhone17Pro,
564+
.iPhone17ProMax,
565+
]
566+
for device in Device.allRealDevices {
567+
XCTAssertTrue(device.hasActionButton == device.isOneOf(actionButtonDevices), "testHasActionButton failed for \(device.description)")
568+
}
569+
}
570+
554571
func testHas5gSupport() {
555572
let has5gDevices: [Device] = [
556573
.iPhone12,

0 commit comments

Comments
 (0)