### Install BezelKit via Swift Package Manager Source: https://context7.com/markbattistella/bezelkit/llms.txt Add the dependency to your Package.swift file or via the Xcode UI. ```swift // In Package.swift dependencies: [ .package(url: "https://github.com/markbattistella/BezelKit", from: "1.0.0") ] // Target dependency .target( name: "YourApp", dependencies: ["BezelKit"] ) // Or in Xcode: // 1. File → Swift Packages → Add Package Dependency // 2. Enter: https://github.com/markbattistella/BezelKit // 3. Select version and target ``` -------------------------------- ### Implement BezelKit in a SwiftUI App Source: https://context7.com/markbattistella/bezelkit/llms.txt Demonstrates configuring global fallbacks and using bezel-aware corner radii in a layout. Use .deviceBezel(with:) to calculate nested radii. ```swift import SwiftUI import BezelKit @main struct BezelKitDemoApp: App { init() { // Configure fallbacks early in app lifecycle CGFloat.setFallbackConfig( FallbackConfig( iOS: (12.0, true), macOS: (10.0, true), visionOS: (20.0, true) ) ) } var body: some Scene { WindowGroup { DeviceBezelCardView() } } } struct DeviceBezelCardView: View { @State private var bezelError: String? private let cardPadding: CGFloat = 16 private let innerPadding: CGFloat = 32 var body: some View { ZStack { // Background matches device screen bezel RoundedRectangle(cornerRadius: .deviceBezel) .fill(Color.black) // Card with first level inset RoundedRectangle(cornerRadius: .deviceBezel(with: cardPadding)) .fill(Color.blue.opacity(0.3)) .padding(cardPadding) // Content area with second level inset VStack(spacing: 20) { Text("BezelKit Demo") .font(.title) .foregroundColor(.white) Text("Device Bezel: \(CGFloat.deviceBezel, specifier: "%.2f")pt") .foregroundColor(.white.opacity(0.8)) Text("Inner Radius: \(CGFloat.deviceBezel(with: innerPadding), specifier: "%.2f")pt") .foregroundColor(.white.opacity(0.8)) if let error = bezelError { Text("Error: \(error)") .foregroundColor(.red) .font(.caption) } } .padding(innerPadding) } .ignoresSafeArea() .onAppear { DeviceBezel.errorCallback = { error in bezelError = error.localizedDescription } } } } ``` -------------------------------- ### Import BezelKit Source: https://github.com/markbattistella/bezelkit/blob/main/README.md Include the BezelKit module in your Swift file to access its functionality. ```swift import BezelKit ``` -------------------------------- ### Configure Fallback Bezel Size Source: https://github.com/markbattistella/bezelkit/blob/main/README.md Set a global fallback bezel size and enable zero-check behavior during application initialization. ```swift import UIKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Sets a fallback value of 10.0 on iOS and enables zero-check CGFloat.setFallbackConfig( FallbackConfig( iOS: (10.0, true) ) ) return true } } ``` ```swift import SwiftUI @main struct YourApp: App { init() { // Sets a fallback value of 10.0 on iOS and enables zero-check CGFloat.setFallbackConfig( FallbackConfig( iOS: (10.0, true) ) ) } var body: some Scene { WindowGroup { ContentView() } } } ``` -------------------------------- ### Configuring Platform-Specific Fallback Values Source: https://context7.com/markbattistella/bezelkit/llms.txt Define default bezel values for different platforms using FallbackConfig. The applyIfZero parameter controls whether the fallback is used when the device bezel is zero. ```swift import SwiftUI import BezelKit @main struct MyApp: App { init() { // Configure fallback values for each platform // Tuple format: (fallbackValue, applyIfZero) CGFloat.setFallbackConfig( FallbackConfig( iOS: (10.0, true), // Use 10.0 on iOS when bezel is 0 or unknown macOS: (8.0, true), // Use 8.0 on macOS macCatalyst: (8.0, true), // Use 8.0 on Mac Catalyst tvOS: (0.0, false), // No fallback on tvOS watchOS: (25.0, true), // Use 25.0 on watchOS visionOS: (20.0, true) // Use 20.0 on visionOS ) ) } var body: some Scene { WindowGroup { ContentView() } } } ``` ```swift // UIKit AppDelegate setup import UIKit import BezelKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { // iOS-only fallback: 10pt when device bezel is zero CGFloat.setFallbackConfig( FallbackConfig(iOS: (10.0, true)) ) return true } } ``` -------------------------------- ### Adaptive Corner Radius with BezelKit in SwiftUI Source: https://github.com/markbattistella/bezelkit/blob/main/README.md Shows how to use BezelKit's `.deviceBezel` to create adaptive corner radii for shapes in SwiftUI. This ensures UI elements correctly fit various device bezels. ```swift import SwiftUI import BezelKit struct ContentView: View { var body: some View { RoundedRectangle(cornerRadius: .deviceBezel) .stroke(.green, lineWidth: 20) .ignoresSafeArea() } } ``` -------------------------------- ### Implement Error Handling Source: https://github.com/markbattistella/bezelkit/blob/main/README.md Use the error callback to manage issues like missing device data or parsing errors. ```swift import SwiftUI import BezelKit struct ContentView: View { @State private var showErrorAlert: Bool = false @State private var errorMessage: String = "" var body: some View { RoundedRectangle(cornerRadius: .deviceBezel) .stroke(Color.green, lineWidth: 20) .ignoresSafeArea() .alert(isPresented: $showErrorAlert) { Alert(title: Text("Error"), message: Text(errorMessage), dismissButton: .default(Text("Got it!"))) } .onAppear { DeviceBezel.errorCallback = { error in errorMessage = error.localizedDescription showErrorAlert = true } } } } ``` ```swift import UIKit import BezelKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() DeviceBezel.errorCallback = { [weak self] error in let alert = UIAlertController(title: "Error", message: error.localizedDescription, preferredStyle: .alert) alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil)) self?.present(alert, animated: true, completion: nil) } let bezelValue = CGFloat.deviceBezel // Use bezelValue for your views } } ``` -------------------------------- ### Static Corner Radius in SwiftUI Source: https://github.com/markbattistella/bezelkit/blob/main/README.md Demonstrates using a fixed corner radius for a shape in SwiftUI. This approach does not adapt to different device bezels. ```swift import SwiftUI struct ContentView: View { var body: some View { RoundedRectangle(cornerRadius: 60) .stroke(.green, lineWidth: 20) .ignoresSafeArea() } } ``` -------------------------------- ### Generate Bezel Data with Swift CLI Source: https://github.com/markbattistella/bezelkit/blob/main/README.md Command to run the BezelGenerator Swift CLI tool from the Generator directory. This tool extracts bezel data from iOS Simulators. ```bash swift run BezelGenerator ``` -------------------------------- ### Calculate Perfect Scaling Source: https://github.com/markbattistella/bezelkit/blob/main/README.md Manually calculate an inner corner radius based on the device bezel and a distance offset. ```swift let outerBezel: CGFloat = .deviceBezel let innerBezel = outerBezel - distance // Perfect ratio ``` -------------------------------- ### Calculating Nested Corner Radii Source: https://context7.com/markbattistella/bezelkit/llms.txt Use deviceBezel(with:) to calculate the inner corner radius for nested UI elements to maintain visual proportions. ```swift import SwiftUI import BezelKit struct NestedRoundedView: View { let padding: CGFloat = 20 var body: some View { ZStack { // Outer rectangle matches device bezel RoundedRectangle(cornerRadius: .deviceBezel) .fill(Color.blue) // Inner rectangle with perfectly scaled corner radius RoundedRectangle(cornerRadius: .deviceBezel(with: padding)) .fill(Color.white) .padding(padding) } .ignoresSafeArea() } } // Manual calculation equivalent let outerBezel: CGFloat = .deviceBezel // e.g., 55.0 on iPhone 15 Pro let innerBezel = outerBezel - 20 // 35.0 - maintains visual harmony ``` -------------------------------- ### Access Device Bezel Size Source: https://github.com/markbattistella/bezelkit/blob/main/README.md Retrieve the current device's bezel radius as a CGFloat. ```swift let currentBezel: CGFloat = .deviceBezel ``` -------------------------------- ### Access Device Bezel Values Source: https://github.com/markbattistella/bezelkit/blob/main/README.md Retrieve the current device bezel value, which returns the fallback if configured or defaults to 0.0. ```swift // With fallback set to 10.0 and zero check enabled let currentBezel = CGFloat.deviceBezel print("Current device bezel: \(currentBezel)") // Output will be 10.0 if the device is not in the JSON data or the bezel is zero ``` ```swift // With no fallback set and zero check disabled let currentBezel = CGFloat.deviceBezel print("Current device bezel: \(currentBezel)") // Output will be 0.0 if the device is not in the JSON data ``` -------------------------------- ### Handle DeviceBezel Errors in SwiftUI and UIKit Source: https://context7.com/markbattistella/bezelkit/llms.txt Register an error callback to handle resource loading or parsing failures. The callback should be set before accessing bezel data to ensure errors are captured. ```swift import SwiftUI import BezelKit struct ContentView: View { @State private var showErrorAlert = false @State private var errorMessage = "" var body: some View { RoundedRectangle(cornerRadius: .deviceBezel) .stroke(Color.green, lineWidth: 20) .ignoresSafeArea() .alert("BezelKit Error", isPresented: $showErrorAlert) { Button("OK", role: .cancel) { } } message: { Text(errorMessage) } .onAppear { DeviceBezel.errorCallback = { error in switch error { case .resourceNotFound: errorMessage = "Bezel database file not found" case .dataParsingFailed(let details): errorMessage = "Failed to parse bezel data: \(details)" } showErrorAlert = true } } } } ``` ```swift import UIKit import BezelKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() DeviceBezel.errorCallback = { [weak self] error in let message: String switch error { case .resourceNotFound: message = "Could not find bezel database" case .dataParsingFailed(let details): message = "Data error: \(details)" } let alert = UIAlertController( title: "BezelKit Error", message: message, preferredStyle: .alert ) alert.addAction(UIAlertAction(title: "OK", style: .default)) self?.present(alert, animated: true) } // This triggers data loading and potential error callback let bezel = CGFloat.deviceBezel print("Loaded bezel: \(bezel)") } } ``` -------------------------------- ### Pull Request Title Format Source: https://github.com/markbattistella/bezelkit/blob/main/README.md Specifies the required format for pull request titles, including the date and a descriptive title. This format aids in tracking and sorting contributions. ```text YYYY-mm-dd - {title} eg. 2023-08-24 - Updated README file ``` -------------------------------- ### Accessing Device Bezel Size in SwiftUI and UIKit Source: https://context7.com/markbattistella/bezelkit/llms.txt Use the static .deviceBezel property to retrieve the current device's corner radius. Returns 0.0 for devices without curved corners. ```swift import SwiftUI import BezelKit struct ContentView: View { var body: some View { // Create a rounded rectangle that matches the device's screen corners RoundedRectangle(cornerRadius: .deviceBezel) .stroke(Color.green, lineWidth: 20) .ignoresSafeArea() } } ``` ```swift // UIKit usage import UIKit import BezelKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() let bezelRadius = CGFloat.deviceBezel print("Device bezel radius: \(bezelRadius)") // Output: "Device bezel radius: 55.0" (on iPhone 15 Pro) // Output: "Device bezel radius: 0.0" (on iPhone SE) let roundedView = UIView() roundedView.layer.cornerRadius = bezelRadius roundedView.layer.masksToBounds = true } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.