Skip to content

Commit

Permalink
Up to Swift6 #major
Browse files Browse the repository at this point in the history
  • Loading branch information
aromanov91 committed Nov 3, 2024
1 parent dc6ac3e commit 6c1edab
Show file tree
Hide file tree
Showing 12 changed files with 173 additions and 132 deletions.
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 5.9
// swift-tools-version: 6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand Down Expand Up @@ -32,7 +32,7 @@ let package = Package(
.library(name: "OversizeHealthComponents", targets: ["OversizeHealthComponents"]),
.library(name: "OversizeWeatherComponents", targets: ["OversizeWeatherComponents"]),
],
dependencies: productionDependencies,
dependencies: developmentDependencies,
targets: [
.target(
name: "OversizeComponents",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import OversizeCore
import OversizeUI
import SwiftUI

@available(macOS 13, iOS 16, tvOS 16, watchOS 9, *)
@available(macOS 14, iOS 16, tvOS 16, watchOS 9, *)
public struct CurrencyPicker: View {
@Environment(\.theme) private var theme: ThemeSettings
@Binding private var selection: Locale.Currency
Expand Down Expand Up @@ -41,7 +41,7 @@ public struct CurrencyPicker: View {
}
}

@available(macOS 13, iOS 16, tvOS 16, watchOS 9, *)
@available(macOS 14, iOS 16, tvOS 16, watchOS 9, *)
struct CurrencyPicker_Previews: PreviewProvider {
static var previews: some View {
CurrencyPicker(selection: .constant("USD"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import SwiftUI

struct TabItemPreferenceKey: PreferenceKey {
static var defaultValue: [TabItem] = []
static var defaultValue: [TabItem] {
[]
}

static func reduce(value: inout [TabItem], nextValue: () -> [TabItem]) {
value += nextValue()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ import SwiftUI
}
}

extension CLLocationCoordinate2D: Equatable {}
extension CLLocationCoordinate2D: @retroactive Equatable {}

public func == (lhs: CLLocationCoordinate2D, rhs: CLLocationCoordinate2D) -> Bool {
lhs.latitude == rhs.latitude && lhs.longitude == rhs.longitude
Expand Down
3 changes: 2 additions & 1 deletion Sources/OversizeComponents/MailView/MailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@
Coordinator(self)
}

public class Coordinator: NSObject, MFMailComposeViewControllerDelegate {
public class Coordinator: NSObject, @preconcurrency MFMailComposeViewControllerDelegate {
var parent: MailView

public init(_ parent: MailView) {
self.parent = parent
}

@MainActor
public func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith _: MFMailComposeResult, error _: Error?) {
controller.dismiss(animated: true)
}
Expand Down
3 changes: 3 additions & 0 deletions Sources/OversizeComponents/PhoneSheet/PhoneSheet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import OversizeUI
import SwiftUI

@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *)
public struct PhoneSheetNumber: Hashable {
public let name: String?
public let phone: String
Expand All @@ -16,6 +17,7 @@ public struct PhoneSheetNumber: Hashable {
}
}

@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *)
public struct PhoneCallSheet: View {
private let numbers: [PhoneSheetNumber]
private let title: String
Expand Down Expand Up @@ -49,6 +51,7 @@ public struct PhoneCallSheet: View {
}
}

@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *)
struct PhoneCallSheet_Previews: PreviewProvider {
static var previews: some View {
PhoneCallSheet("Phones", numbers: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import OversizeUI
import SwiftUI

@available(iOS 15.0, macOS 14, tvOS 15.0, watchOS 9.0, *)
public struct SortingPicker<Element, Content>: View
where
Content: View,
Expand Down
22 changes: 21 additions & 1 deletion Sources/OversizeComponents/WebView/WebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public struct WebView: View {
} else {
webView
}
#elseif os(macOS)
webView
#else
EmptyView()
#endif
Expand All @@ -44,7 +46,7 @@ public struct WebView: View {
openURL(url)
}))
})
#if os(iOS)
#if os(iOS) || os(macOS)
WebViewRepresentable(url: url)
#endif
}
Expand All @@ -69,6 +71,24 @@ public struct WebView: View {
}
#endif

#if os(macOS)
public struct WebViewRepresentable: NSViewRepresentable {
private let request: URLRequest

public init(url: URL) {
request = URLRequest(url: url)
}

public func makeNSView(context _: Context) -> WKWebView {
WKWebView()
}

public func updateNSView(_ uiView: WKWebView, context _: Context) {
uiView.load(request)
}
}
#endif

struct WebView_Previews: PreviewProvider {
static var previews: some View {
WebView(url: URL(string: "https://www.apple.com")!)
Expand Down
128 changes: 66 additions & 62 deletions Sources/OversizePhotoComponents/Camera/CameraController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,78 +5,82 @@

import AVFoundation
#if canImport(UIKit)
import UIKit
import UIKit
#endif

#if os(iOS)
class CameraController: NSObject {
var captureSession: AVCaptureSession?
var frontCamera: AVCaptureDevice?
var frontCameraInput: AVCaptureDeviceInput?
var previewLayer: AVCaptureVideoPreviewLayer?
@MainActor
class CameraController: NSObject {
private var captureSession: AVCaptureSession?
private var frontCamera: AVCaptureDevice?
private var frontCameraInput: AVCaptureDeviceInput?
private var previewLayer: AVCaptureVideoPreviewLayer?

func prepare(completionHandler: @escaping (Error?) -> Void) {
func createCaptureSession() {
captureSession = AVCaptureSession()
func prepare(completionHandler: @escaping (Error?) -> Void) {
func createCaptureSession() {
captureSession = AVCaptureSession()
}

func configureCaptureDevices() throws {
guard let camera = AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .front) else {
throw CameraControllerError.noCamerasAvailable
}
func configureCaptureDevices() throws {
let camera = AVCaptureDevice.default(.builtInWideAngleCamera, for: AVMediaType.video, position: .front)

frontCamera = camera

try camera?.lockForConfiguration()
camera?.unlockForConfiguration()
frontCamera = camera
try camera.lockForConfiguration()
camera.unlockForConfiguration()
}

func configureDeviceInputs() throws {
guard let captureSession = captureSession else {
throw CameraControllerError.captureSessionIsMissing
}
func configureDeviceInputs() throws {
guard let captureSession else { throw CameraControllerError.captureSessionIsMissing }

if let frontCamera {
frontCameraInput = try AVCaptureDeviceInput(device: frontCamera)

if captureSession.canAddInput(frontCameraInput!) { captureSession.addInput(frontCameraInput!) }
else { throw CameraControllerError.inputsAreInvalid }
} else { throw CameraControllerError.noCamerasAvailable }

captureSession.startRunning()
guard let frontCamera = frontCamera else {
throw CameraControllerError.noCamerasAvailable
}

DispatchQueue(label: "prepare").async {
do {
createCaptureSession()
try configureCaptureDevices()
try configureDeviceInputs()
} catch {
DispatchQueue.main.async {
completionHandler(error)
}

return
}

DispatchQueue.main.async {
completionHandler(nil)
}

frontCameraInput = try AVCaptureDeviceInput(device: frontCamera)
if captureSession.canAddInput(frontCameraInput!) {
captureSession.addInput(frontCameraInput!)
} else {
throw CameraControllerError.inputsAreInvalid
}

captureSession.startRunning()
}

func displayPreview(on view: UIView) throws {
guard let captureSession, captureSession.isRunning else { throw CameraControllerError.captureSessionIsMissing }

previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
previewLayer?.videoGravity = AVLayerVideoGravity.resizeAspectFill
previewLayer?.connection?.videoOrientation = .portrait

view.layer.insertSublayer(previewLayer!, at: 0)
previewLayer?.frame = view.frame
Task {
do {
createCaptureSession()
try configureCaptureDevices()
try configureDeviceInputs()
completionHandler(nil)
} catch {
completionHandler(error)
}
}
}

enum CameraControllerError: Swift.Error {
case captureSessionAlreadyRunning
case captureSessionIsMissing
case inputsAreInvalid
case invalidOperation
case noCamerasAvailable
case unknown

@MainActor
func displayPreview(on view: UIView) throws {
guard let captureSession = captureSession, captureSession.isRunning else {
throw CameraControllerError.captureSessionIsMissing
}

previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
previewLayer?.videoGravity = .resizeAspectFill
previewLayer?.connection?.videoOrientation = .portrait

view.layer.insertSublayer(previewLayer!, at: 0)
previewLayer?.frame = view.bounds
}
}

enum CameraControllerError: Swift.Error {
case captureSessionAlreadyRunning
case captureSessionIsMissing
case inputsAreInvalid
case invalidOperation
case noCamerasAvailable
case unknown
}
#endif
Loading

0 comments on commit 6c1edab

Please sign in to comment.