Skip to content

fix: Square payment SDK integration #900

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 15, 2025
Merged
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
3 changes: 2 additions & 1 deletion cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@
"componentregistry",
"mapbuffer",
"nativemodule",
"reactnative"
"reactnative",
"SQIP"
],
"ignorePaths": [
"node_modules",
Expand Down
17 changes: 16 additions & 1 deletion ios/delegates/KCTextInputCompositeDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class KCTextInputCompositeDelegate: NSObject, UITextViewDelegate, UITextFieldDel
// MARK: setters/getters

public func setTextViewDelegate(delegate: UITextViewDelegate?) {
// remove KVO from any old textField
// remove KVO from any old textView
if let oldTextField = observedTextFieldForSelection {
removeSelectionRangeObserver(from: oldTextField)
}
Expand Down Expand Up @@ -96,6 +96,21 @@ class KCTextInputCompositeDelegate: NSObject, UITextViewDelegate, UITextFieldDel
}
}

public func canSubstituteTextFieldDelegate(delegate: UITextFieldDelegate?) -> Bool {
let type = String(describing: delegate)
if type.range(of: "SQIPTextFieldInputModifier") != nil {
// SQIPTextFieldInputModifier is a private class used internally by Square.
// It forwards input events to the keyboard-controller delegate.
// To prevent an infinite loop, we avoid setting our delegate in this case.
// Since Square's SDK is used imperatively and doesn't allow adding custom components,
// keyboard-controller components cannot be used in this context,
// so it's safe to skip replacing the delegate.
return false
}

return true
}

// Getter for the active delegate
public var activeDelegate: AnyObject? {
return textViewDelegate ?? textFieldDelegate
Expand Down
4 changes: 3 additions & 1 deletion ios/observers/FocusedInputObserver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,9 @@ public class FocusedInputObserver: NSObject {

private func substituteDelegate(_ input: UIResponder?) {
if let textField = input as? UITextField {
if !(textField.delegate is KCTextInputCompositeDelegate) {
if !(textField.delegate is KCTextInputCompositeDelegate),
delegate.canSubstituteTextFieldDelegate(delegate: textField.delegate)
{
delegate.setTextFieldDelegate(delegate: textField.delegate, textField: textField)
textField.delegate = delegate
}
Expand Down
Loading