-
-
Notifications
You must be signed in to change notification settings - Fork 534
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create ios addressheet implementation
- Loading branch information
Remon
committed
Dec 22, 2024
1 parent
a276f4d
commit 9b7b321
Showing
3 changed files
with
138 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
packages/stripe_ios/ios/Classes/AddressSheetFactory.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
// | ||
// AddressSheetFactory.swift | ||
// stripe_ios | ||
// | ||
// Created by Remon on 16/12/2024. | ||
// | ||
|
||
import Foundation | ||
|
||
public class AddressSheetViewFactory: NSObject, FlutterPlatformViewFactory{ | ||
|
||
private var messenger: FlutterBinaryMessenger | ||
private var delegate: ViewManagerDelegate | ||
|
||
init(messenger: FlutterBinaryMessenger, delegate: ViewManagerDelegate) { | ||
self.messenger = messenger | ||
self.delegate = delegate | ||
super.init() | ||
} | ||
|
||
public func create( | ||
withFrame frame: CGRect, | ||
viewIdentifier viewId: Int64, | ||
arguments args: Any? | ||
) -> FlutterPlatformView { | ||
let view = AddressSheetPlatformView( | ||
frame: frame, | ||
viewIdentifier: viewId, | ||
arguments: args, | ||
binaryMessenger: messenger) | ||
return view | ||
} | ||
|
||
public func createArgsCodec() -> any FlutterMessageCodec & NSObjectProtocol { | ||
return FlutterStandardMessageCodec.sharedInstance() | ||
} | ||
} | ||
|
||
class AddressSheetPlatformView: NSObject, FlutterPlatformView { | ||
let formView: AddressSheetView | ||
|
||
private let channel: FlutterMethodChannel | ||
func view() -> UIView { | ||
return formView | ||
} | ||
|
||
init( frame: CGRect, | ||
viewIdentifier viewId: Int64, | ||
arguments args: Any?, | ||
binaryMessenger messenger: FlutterBinaryMessenger){ | ||
|
||
channel = FlutterMethodChannel(name: "flutter.stripe/address_sheet/\(viewId)", | ||
binaryMessenger: messenger) | ||
|
||
formView = AddressSheetView() | ||
super.init() | ||
channel.setMethodCallHandler(handle) | ||
|
||
formView.onSubmitAction = onCompleteAction | ||
formView.onErrorAction = onCancelAction | ||
|
||
updateProps(args) | ||
|
||
} | ||
|
||
public func onCompleteAction(addressData: Dictionary<AnyHashable, Any>?) { | ||
channel.invokeMethod("onSubmitAction", arguments: addressData) | ||
} | ||
|
||
public func onCancelAction(errorData: Dictionary<AnyHashable, Any>?) { | ||
channel.invokeMethod("onErrorAction", arguments: errorData) | ||
} | ||
|
||
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) { | ||
switch call.method { | ||
default: | ||
result(FlutterMethodNotImplemented) | ||
} | ||
} | ||
|
||
func updateProps (_ args : Any? ) { | ||
guard let arguments = args as? [String: Any] else { | ||
return | ||
} | ||
|
||
if let presentationStyle = arguments["presentationStyle"] as? String{ | ||
formView.presentationStyle = presentationStyle | ||
} | ||
|
||
if let animationStyle = arguments["animationStyle"] as? String{ | ||
formView.animationStyle = animationStyle | ||
} | ||
|
||
if let visible = arguments["visible"] as? Bool { | ||
formView.visible = visible | ||
} | ||
|
||
if let appearance = arguments["appearance"] as? NSDictionary { | ||
formView.appearance = appearance | ||
} | ||
|
||
if let defaultValues = arguments["defaultValues"] as? NSDictionary { | ||
formView.defaultValues = defaultValues | ||
} | ||
|
||
if let additionalFields = arguments["additionalFields"] as? NSDictionary { | ||
formView.additionalFields = additionalFields | ||
} | ||
|
||
if let allowedCountries = arguments["allowedCountries"] as? [String] { | ||
formView.allowedCountries = allowedCountries | ||
} | ||
|
||
if let autocompleteCountries = arguments["autocompleteCountries"] as? [String] { | ||
formView.autocompleteCountries = autocompleteCountries | ||
} | ||
|
||
if let primaryButtonTitle = arguments["primaryButtonTitle"] as? String { | ||
formView.primaryButtonTitle = primaryButtonTitle | ||
} | ||
|
||
if let sheetTitle = arguments["sheetTitle"] as? String { | ||
formView.sheetTitle = sheetTitle | ||
} | ||
|
||
formView.didSetProps(nil) | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters