Skip to content

Commit

Permalink
fix: wrong type of type when keyboard hides
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillzyusko committed Dec 8, 2024
1 parent 4504f01 commit 6d57605
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 22 deletions.
24 changes: 2 additions & 22 deletions ios/events/KeyboardEventEmitterPayload.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,15 @@
import Foundation
import UIKit

public class KeyboardTypeConverter: NSObject {
private static let keyboardTypeToStringMapping: [UIKeyboardType: String] = [
.default: "default",
.asciiCapable: "ascii-capable",
.numbersAndPunctuation: "numbers-and-punctuation",
.URL: "url",
.numberPad: "number-pad",
.phonePad: "phone-pad",
.namePhonePad: "name-phone-pad",
.emailAddress: "email-address",
.decimalPad: "decimal-pad",
.twitter: "twitter",
.webSearch: "web-search",
.asciiCapableNumberPad: "ascii-capable-number-pad",
]

public static func string(from keyboardType: UIKeyboardType?) -> String {
return keyboardTypeToStringMapping[keyboardType ?? .default] ?? "default"
}
}

public func buildEventParams(_ height: Double, _ duration: Int, _ responder: UIResponder?) -> [AnyHashable: Any] {
var data = [AnyHashable: Any]()
let input = FocusedInputHolder.shared.get()

data["height"] = height
data["duration"] = duration
data["timestamp"] = Date.currentTimeStamp
data["target"] = responder.reactViewTag
data["type"] = KeyboardTypeConverter.string(from: (responder as? TextInput)?.keyboardType)
data["type"] = input?.keyboardType.name ?? "default"

return data
}
30 changes: 30 additions & 0 deletions ios/extensions/UIKeyboardType.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// UIKeyboardType.swift
// Pods
//
// Created by Kiryl Ziusko on 08/12/2024.
//

import Foundation
import UIKit

extension UIKeyboardType {
private static let keyboardTypeToStringMapping: [UIKeyboardType: String] = [
.default: "default",
.asciiCapable: "ascii-capable",
.numbersAndPunctuation: "numbers-and-punctuation",
.URL: "url",
.numberPad: "number-pad",
.phonePad: "phone-pad",
.namePhonePad: "name-phone-pad",
.emailAddress: "email-address",
.decimalPad: "decimal-pad",
.twitter: "twitter",
.webSearch: "web-search",
.asciiCapableNumberPad: "ascii-capable-number-pad",
]

var name: String {
return UIKeyboardType.keyboardTypeToStringMapping[self] ?? "default"
}
}

0 comments on commit 6d57605

Please sign in to comment.