Skip to content

Conversation

@hitsubunnu
Copy link
Member

Summary

This PR adds comprehensive SwiftUI support to the QRScanner framework, enabling seamless integration with modern iOS applications built using SwiftUI.

Key Features

SwiftUI Wrapper: New QRScannerSwiftUIView that implements UIViewRepresentable to bridge the existing UIKit-based QRScannerView to SwiftUI
Modern Architecture: Utilizes Swift's MainActor for thread-safe UI updates instead of legacy DispatchQueue.main.async
Complete Sample App: Added QRScannerSwiftUISample demonstrating real-world usage patterns
iOS 14+ Support: Updated minimum deployment target from iOS 10.0 to iOS 14.0 to support modern SwiftUI features
Type-Safe Configuration: Comprehensive configuration options with sensible defaults

Technical Implementation

SwiftUI Integration

  • QRScannerSwiftUIView acts as a bridge between UIKit and SwiftUI
  • Implements proper lifecycle management with @Binding properties
  • Supports all existing QRScanner configuration options
  • Provides callback-based event handling for scan results and errors

Modern Swift Concurrency

  • Replaced DispatchQueue.main.async with Task { @MainActor in } for better performance
  • Type-safe main thread updates for UI state changes
  • Improved integration with SwiftUI's reactive architecture

Project Structure

  • Added SwiftUI wrapper to main QRScanner framework
  • Created standalone SwiftUI sample application
  • Updated workspace to include both UIKit and SwiftUI samples
  • Maintained backward compatibility with existing UIKit implementation

Usage Example

import SwiftUI
import QRScanner

struct ContentView: View {
    @State private var isScanning = true
    @State private var isTorchOn = false
    
    var body: some View {
        QRScannerSwiftUIView(
            configuration: .init(isBlurEffectEnabled: true),
            isScanning: $isScanning,
            torchActive: $isTorchOn,
            onSuccess: { code in
                print("QR Code scanned: \(code)")
            },
            onFailure: { error in
                print("Scanner error: \(error.localizedDescription)")
            }
        )
    }
}

Breaking Changes

iOS Deployment Target: Minimum iOS version increased from 10.0 to 14.0

  • This change enables SwiftUI support and modern Swift concurrency features
  • Affects all package managers: CocoaPods, Swift Package Manager, and manual integration
  • Developers targeting iOS versions below 14.0 should continue using previous versions

Test Plan

  • SwiftUI sample app builds and runs successfully
  • QR code scanning functionality works in SwiftUI environment
  • Torch toggle functionality operates correctly
  • Camera permission handling works as expected
  • Framework builds successfully with updated deployment target
  • Existing UIKit sample continues to function normally
  • Swift Package Manager integration updated
  • CocoaPods specification updated

Compatibility

  • iOS 14.0+: Full SwiftUI support with all features
  • Existing UIKit code: No changes required, fully backward compatible
  • Package Managers: Updated specifications for CocoaPods and SPM

🤖 Generated with Claude Code

hitsubunnu and others added 10 commits July 4, 2025 17:16
- Add QRScannerSwiftUIView: UIViewRepresentable wrapper for QRScannerView
- Create QRScannerSwiftUISample: SwiftUI demo application
- Update minimum iOS deployment target from 10.0 to 14.0 across all targets
- Integrate SwiftUI sample into QRScanner.xcworkspace
- Implement modern Swift concurrency with MainActor instead of DispatchQueue
- Add comprehensive SwiftUI usage documentation

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@hitsubunnu hitsubunnu merged commit 5ff64fd into master Jul 4, 2025
2 checks passed
@hitsubunnu hitsubunnu deleted the support-swiftui branch July 4, 2025 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant