Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# (unreleased)

- Add Swift Package Manager (SPM) support

# [4.1.0](https://github.com/SimformSolutionsPvtLtd/flutter_credit_card/tree/4.1.0)

- Fixed floating event stream bad state exception [#157](https://github.com/SimformSolutionsPvtLtd/flutter_credit_card/issues/157).
Expand Down
41 changes: 0 additions & 41 deletions example/ios/Podfile

This file was deleted.

2 changes: 1 addition & 1 deletion example/ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import UIKit
import Flutter

@UIApplicationMain
@main
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
Expand Down
2 changes: 1 addition & 1 deletion example/macos/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Cocoa
import FlutterMacOS

@NSApplicationMain
@main
class AppDelegate: FlutterAppDelegate {
override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
return true
Expand Down
7 changes: 0 additions & 7 deletions ios/Classes/Constants.swift

This file was deleted.

15 changes: 0 additions & 15 deletions ios/Classes/FlutterCreditCardPlugin.swift

This file was deleted.

58 changes: 0 additions & 58 deletions ios/Classes/gyroscope/GyroscopeChannelImpl.swift

This file was deleted.

40 changes: 0 additions & 40 deletions ios/Classes/gyroscope/GyroscopeStreamHandler.swift

This file was deleted.

7 changes: 3 additions & 4 deletions ios/flutter_credit_card.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ and float.
s.license = { :type => 'MIT', :file => '../LICENSE' }
s.author = { 'Simform Solutions' => 'developer@simform.com' }
s.source = { :http => 'https://github.com/SimformSolutionsPvtLtd/flutter_credit_card/tree/master' }
s.source_files = 'Classes/**/*'
s.source_files = 'flutter_credit_card/Sources/flutter_credit_card/**/*.swift'
s.dependency 'Flutter'
s.platform = :ios, '11.0'
s.platform = :ios, '12.0'

# Flutter.framework does not contain a i386 slice.
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' }
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }
s.swift_version = '5.0'
end
24 changes: 24 additions & 0 deletions ios/flutter_credit_card/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// swift-tools-version: 5.9
import PackageDescription

let package = Package(
name: "flutter_credit_card",
platforms: [
.iOS("12.0")
],
products: [
.library(name: "flutter-credit-card", targets: ["flutter_credit_card"])
],
dependencies: [
.package(name: "FlutterFramework", path: "../FlutterFramework")
],
targets: [
.target(
name: "flutter_credit_card",
dependencies: [
.product(name: "FlutterFramework", package: "FlutterFramework")
],
path: "Sources/flutter_credit_card"
)
]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
enum Constants {
static let gyroEventChannel = "com.simform.flutter_credit_card/gyroscope"
static let gyroMethodChannel = "com.simform.flutter_credit_card"
static let initiateEvents = "initiateEvents"
static let cancelEvents = "cancelEvents"
static let isGyroAvailable = "isGyroscopeAvailable"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import CoreMotion
import Flutter

public class FlutterCreditCardPlugin: NSObject, FlutterPlugin {
private var gyroscopeChannel: GyroscopeChannelImpl?

public static func register(with registrar: FlutterPluginRegistrar) {
let instance = FlutterCreditCardPlugin()
instance.gyroscopeChannel = GyroscopeChannelImpl(messenger: registrar.messenger())
}

public func detachFromEngine(for registrar: FlutterPluginRegistrar) {
gyroscopeChannel = nil
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import CoreMotion
import Flutter

internal class GyroscopeChannelImpl {
private var motionManager: CMMotionManager?
private var eventChannel: FlutterEventChannel?
private var methodChannel: FlutterMethodChannel?
private var streamHandler: GyroscopeStreamHandler?

init(messenger: FlutterBinaryMessenger) {
eventChannel = FlutterEventChannel(name: Constants.gyroEventChannel, binaryMessenger: messenger)
methodChannel = FlutterMethodChannel(
name: Constants.gyroMethodChannel, binaryMessenger: messenger)
methodChannel?.setMethodCallHandler(onMethodCall)
}

deinit {
eventStreamDisposal()
methodChannel?.setMethodCallHandler(nil)
methodChannel = nil
}

private func onMethodCall(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
switch call.method {
case Constants.initiateEvents:
eventStreamSetup()
result(nil)
case Constants.isGyroAvailable:
result(hasGyroAvailability())
case Constants.cancelEvents:
eventStreamDisposal()
result(nil)
default:
result(FlutterMethodNotImplemented)
}
}

private func eventStreamSetup() {
motionManager = CMMotionManager()
if !hasGyroAvailability() {
motionManager = nil
return
}

streamHandler = streamHandler ?? GyroscopeStreamHandler(motionManager: motionManager!)
eventChannel?.setStreamHandler(streamHandler)
}

private func eventStreamDisposal() {
_ = streamHandler?.onCancel(withArguments: nil)
eventChannel?.setStreamHandler(nil)
streamHandler = nil
motionManager = nil
}

private func hasGyroAvailability() -> Bool {
return motionManager?.isGyroAvailable ?? false
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import CoreMotion
import Flutter
import UIKit

internal class GyroscopeStreamHandler: NSObject, FlutterStreamHandler {
private var motionManager: CMMotionManager?

init(motionManager: CMMotionManager) {
self.motionManager = motionManager
// Gyroscope event interval set to 60 fps, specified in seconds.
self.motionManager!.gyroUpdateInterval = 0.016666
super.init()
}

public func onListen(withArguments arguments: Any?, eventSink sink: @escaping FlutterEventSink)
-> FlutterError?
{
motionManager?.startGyroUpdates(to: OperationQueue()) { (gyroData, error) in
if let rotationRate = gyroData?.rotationRate {
sink(GyroscopeStreamHandler.processForOrientation(rotationRate))
}
}
return nil
}

public func onCancel(withArguments arguments: Any?) -> FlutterError? {
motionManager?.stopGyroUpdates()
motionManager = nil
return nil
}

static private func processForOrientation(_ rotation: CMRotationRate) -> [Double] {
switch UIDevice.current.orientation {
case UIDeviceOrientation.landscapeLeft:
return [-rotation.y, rotation.x, rotation.z]
case UIDeviceOrientation.landscapeRight:
return [rotation.y, -rotation.x, rotation.z]
default:
return [rotation.x, rotation.y, rotation.z]
}
}
}
Loading