@momo-kits/calculator-keyboard 0.150.2-beta.20 → 0.150.2-beta.20-sp.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -3
- package/android/src/main/java/com/calculatorkeyboard/CalculatorKeyboardPackage.kt +1 -1
- package/android/src/main/java/com/calculatorkeyboard/CustomKeyboardView.kt +43 -31
- package/android/src/main/java/com/calculatorkeyboard/RCTInputCalculator.kt +27 -34
- package/ios/CalculatorKeyboardView.h +30 -0
- package/ios/CalculatorKeyboardView.mm +231 -0
- package/ios/NativeInputCalculator.h +11 -0
- package/ios/NativeInputCalculator.mm +200 -0
- package/package.json +75 -59
- package/react-native-calculator-keyboard.podspec +5 -4
- package/src/NativeInputCalculatorNativeComponent.ts +55 -0
- package/src/index.tsx +25 -34
- package/ios/CalculatorKeyboardView.swift +0 -153
- package/ios/InputCalculator-Bridging-Header.h +0 -23
- package/ios/InputCalculator.m +0 -85
- package/ios/InputCalculator.swift +0 -158
- package/ios/extension.swift +0 -23
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
#import <React/RCTBridgeModule.h>
|
|
2
|
-
#import <React/RCTViewManager.h>
|
|
3
|
-
#import <React/RCTBaseTextInputViewManager.h>
|
|
4
|
-
#import <React/RCTSinglelineTextInputView.h>
|
|
5
|
-
#import <React/RCTUITextField.h>
|
|
6
|
-
#import <React/RCTBaseTextInputViewManager.h>
|
|
7
|
-
|
|
8
|
-
#import <React/RCTBridge.h>
|
|
9
|
-
#import <React/RCTConvert.h>
|
|
10
|
-
#import <React/RCTFont.h>
|
|
11
|
-
#import <React/RCTShadowView+Layout.h>
|
|
12
|
-
#import <React/RCTShadowView.h>
|
|
13
|
-
#import <React/RCTUIManager.h>
|
|
14
|
-
#import <React/RCTUIManagerObserverCoordinator.h>
|
|
15
|
-
#import <React/RCTUIManagerUtils.h>
|
|
16
|
-
|
|
17
|
-
#import <React/RCTBaseTextInputShadowView.h>
|
|
18
|
-
#import <React/RCTBaseTextInputView.h>
|
|
19
|
-
#import <React/RCTConvert+Text.h>
|
|
20
|
-
|
|
21
|
-
@interface Calculator : NSObject <RCTBridgeModule>
|
|
22
|
-
|
|
23
|
-
@end
|
package/ios/InputCalculator.m
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
#import <InputCalculator-Bridging-Header.h>
|
|
2
|
-
|
|
3
|
-
@implementation Calculator
|
|
4
|
-
|
|
5
|
-
- (dispatch_queue_t)methodQueue
|
|
6
|
-
{
|
|
7
|
-
return dispatch_get_main_queue();
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
RCT_EXPORT_MODULE()
|
|
11
|
-
|
|
12
|
-
@end
|
|
13
|
-
|
|
14
|
-
@interface RCT_EXTERN_MODULE(RCTInputCalculator, RCTViewManager)
|
|
15
|
-
|
|
16
|
-
RCT_REMAP_VIEW_PROPERTY(autoCapitalize, backedTextInputView.autocapitalizationType, UITextAutocapitalizationType)
|
|
17
|
-
RCT_REMAP_VIEW_PROPERTY(autoCorrect, backedTextInputView.autocorrectionType, UITextAutocorrectionType)
|
|
18
|
-
RCT_REMAP_VIEW_PROPERTY(contextMenuHidden, backedTextInputView.contextMenuHidden, BOOL)
|
|
19
|
-
RCT_REMAP_VIEW_PROPERTY(editable, backedTextInputView.editable, BOOL)
|
|
20
|
-
RCT_REMAP_VIEW_PROPERTY(enablesReturnKeyAutomatically, backedTextInputView.enablesReturnKeyAutomatically, BOOL)
|
|
21
|
-
RCT_REMAP_VIEW_PROPERTY(keyboardAppearance, backedTextInputView.keyboardAppearance, UIKeyboardAppearance)
|
|
22
|
-
RCT_REMAP_VIEW_PROPERTY(placeholder, backedTextInputView.placeholder, NSString)
|
|
23
|
-
RCT_REMAP_VIEW_PROPERTY(placeholderTextColor, backedTextInputView.placeholderColor, UIColor)
|
|
24
|
-
RCT_REMAP_VIEW_PROPERTY(returnKeyType, backedTextInputView.returnKeyType, UIReturnKeyType)
|
|
25
|
-
RCT_REMAP_VIEW_PROPERTY(selectionColor, backedTextInputView.tintColor, UIColor)
|
|
26
|
-
RCT_REMAP_VIEW_PROPERTY(spellCheck, backedTextInputView.spellCheckingType, UITextSpellCheckingType)
|
|
27
|
-
RCT_REMAP_VIEW_PROPERTY(caretHidden, backedTextInputView.caretHidden, BOOL)
|
|
28
|
-
RCT_REMAP_VIEW_PROPERTY(clearButtonMode, backedTextInputView.clearButtonMode, UITextFieldViewMode)
|
|
29
|
-
RCT_REMAP_VIEW_PROPERTY(scrollEnabled, backedTextInputView.scrollEnabled, BOOL)
|
|
30
|
-
RCT_REMAP_VIEW_PROPERTY(secureTextEntry, backedTextInputView.secureTextEntry, BOOL)
|
|
31
|
-
RCT_REMAP_VIEW_PROPERTY(smartInsertDelete, backedTextInputView.smartInsertDeleteType, UITextSmartInsertDeleteType)
|
|
32
|
-
|
|
33
|
-
RCT_EXPORT_VIEW_PROPERTY(autoFocus, BOOL)
|
|
34
|
-
RCT_EXPORT_VIEW_PROPERTY(submitBehavior, NSString)
|
|
35
|
-
RCT_EXPORT_VIEW_PROPERTY(clearTextOnFocus, BOOL)
|
|
36
|
-
RCT_EXPORT_VIEW_PROPERTY(keyboardType, UIKeyboardType)
|
|
37
|
-
RCT_EXPORT_VIEW_PROPERTY(showSoftInputOnFocus, BOOL)
|
|
38
|
-
RCT_EXPORT_VIEW_PROPERTY(maxLength, NSNumber)
|
|
39
|
-
RCT_EXPORT_VIEW_PROPERTY(selectTextOnFocus, BOOL)
|
|
40
|
-
RCT_EXPORT_VIEW_PROPERTY(selection, RCTTextSelection)
|
|
41
|
-
RCT_EXPORT_VIEW_PROPERTY(inputAccessoryViewID, NSString)
|
|
42
|
-
RCT_EXPORT_VIEW_PROPERTY(textContentType, NSString)
|
|
43
|
-
RCT_EXPORT_VIEW_PROPERTY(passwordRules, NSString)
|
|
44
|
-
|
|
45
|
-
RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock)
|
|
46
|
-
RCT_EXPORT_VIEW_PROPERTY(onKeyPressSync, RCTDirectEventBlock)
|
|
47
|
-
RCT_EXPORT_VIEW_PROPERTY(onChangeSync, RCTDirectEventBlock)
|
|
48
|
-
RCT_EXPORT_VIEW_PROPERTY(onSelectionChange, RCTDirectEventBlock)
|
|
49
|
-
RCT_EXPORT_VIEW_PROPERTY(onScroll, RCTDirectEventBlock)
|
|
50
|
-
|
|
51
|
-
RCT_EXPORT_VIEW_PROPERTY(mostRecentEventCount, NSInteger)
|
|
52
|
-
|
|
53
|
-
RCT_EXPORT_SHADOW_PROPERTY(text, NSString)
|
|
54
|
-
RCT_EXPORT_SHADOW_PROPERTY(placeholder, NSString)
|
|
55
|
-
RCT_EXPORT_SHADOW_PROPERTY(onContentSizeChange, RCTDirectEventBlock)
|
|
56
|
-
RCT_EXPORT_VIEW_PROPERTY(value, NSString)
|
|
57
|
-
RCT_EXPORT_VIEW_PROPERTY(onFocus, RCTBubblingEventBlock)
|
|
58
|
-
RCT_EXPORT_VIEW_PROPERTY(onBlur, RCTBubblingEventBlock)
|
|
59
|
-
RCT_EXPORT_VIEW_PROPERTY(onKeyPress, RCTBubblingEventBlock)
|
|
60
|
-
RCT_EXPORT_VIEW_PROPERTY(onCustomKeyEvent, RCTDirectEventBlock)
|
|
61
|
-
|
|
62
|
-
RCT_EXPORT_METHOD(focus : (nonnull NSNumber *)viewTag)
|
|
63
|
-
{
|
|
64
|
-
[self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
|
|
65
|
-
UIView *view = viewRegistry[viewTag];
|
|
66
|
-
[view reactFocus];
|
|
67
|
-
}];
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
RCT_EXPORT_METHOD(blur : (nonnull NSNumber *)viewTag)
|
|
71
|
-
{
|
|
72
|
-
[self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
|
|
73
|
-
UIView *view = viewRegistry[viewTag];
|
|
74
|
-
[view reactBlur];
|
|
75
|
-
}];
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
RCT_EXPORT_VIEW_PROPERTY(keyboardColor, UIColor)
|
|
79
|
-
RCT_EXPORT_VIEW_PROPERTY(customKeyText, NSString)
|
|
80
|
-
RCT_EXPORT_VIEW_PROPERTY(customKeyBackground, NSString)
|
|
81
|
-
RCT_EXPORT_VIEW_PROPERTY(customKeyTextColor, NSString)
|
|
82
|
-
RCT_EXPORT_VIEW_PROPERTY(customKeyState, NSString)
|
|
83
|
-
|
|
84
|
-
@end
|
|
85
|
-
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import Foundation
|
|
2
|
-
import UIKit
|
|
3
|
-
|
|
4
|
-
@objc(RCTInputCalculator)
|
|
5
|
-
class RCTInputCalculator: RCTBaseTextInputViewManager {
|
|
6
|
-
override func view() -> UIView! {
|
|
7
|
-
return InputCalculator(bridge: bridge)
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
override static func requiresMainQueueSetup() -> Bool {
|
|
11
|
-
return true
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
class InputCalculator: RCTSinglelineTextInputView {
|
|
17
|
-
var bridge: RCTBridge?
|
|
18
|
-
var keyboardView: CalculatorKeyboardView?
|
|
19
|
-
|
|
20
|
-
@objc var onFocus: RCTBubblingEventBlock?
|
|
21
|
-
@objc var onBlur: RCTBubblingEventBlock?
|
|
22
|
-
@objc var onKeyPress: RCTBubblingEventBlock?
|
|
23
|
-
@objc var onCustomKeyEvent: RCTDirectEventBlock?
|
|
24
|
-
|
|
25
|
-
@objc var customKeyText: String? {
|
|
26
|
-
didSet { keyboardView?.customKeyText = customKeyText as String? }
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
@objc var customKeyBackground: String? {
|
|
30
|
-
didSet { keyboardView?.customKeyBackground = customKeyBackground }
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
@objc var customKeyTextColor: String? {
|
|
34
|
-
didSet { keyboardView?.customKeyTextColor = customKeyTextColor }
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
@objc var customKeyState: String? {
|
|
38
|
-
didSet { keyboardView?.customKeyState = customKeyState }
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
@objc func beginEditingInput(_ note: Notification) { onFocus?([:]) }
|
|
42
|
-
@objc func endEditingInput(_ note: Notification) { onBlur?([:]) }
|
|
43
|
-
|
|
44
|
-
@objc var value: String = "" {
|
|
45
|
-
didSet {
|
|
46
|
-
guard let tf = backedTextInputView as? UITextField else { return }
|
|
47
|
-
let old = tf.text ?? ""
|
|
48
|
-
if old == value { return }
|
|
49
|
-
|
|
50
|
-
let isFirstResponder = tf.isFirstResponder
|
|
51
|
-
let atEnd = isFirstResponder && tf.offset(from: tf.beginningOfDocument, to: tf.selectedTextRange?.start ?? tf.endOfDocument) == old.count
|
|
52
|
-
tf.text = value
|
|
53
|
-
if !isFirstResponder || atEnd,
|
|
54
|
-
let end = tf.position(from: tf.beginningOfDocument, offset: value.count) {
|
|
55
|
-
tf.selectedTextRange = tf.textRange(from: end, to: end)
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
@objc var keyboardColor: UIColor = UIColor(hex: "#d9d9d9") {
|
|
61
|
-
didSet {
|
|
62
|
-
self.keyboardView?.setKeyboardColor(keyboardColor)
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
override init(bridge: RCTBridge) {
|
|
68
|
-
super.init(bridge: bridge)
|
|
69
|
-
self.bridge = bridge
|
|
70
|
-
self.keyboardView = CalculatorKeyboardView()
|
|
71
|
-
self.keyboardView!.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: 240 + getbottomInset())
|
|
72
|
-
self.keyboardView!.input = self
|
|
73
|
-
|
|
74
|
-
backedTextInputView.inputView = self.keyboardView
|
|
75
|
-
backedTextInputView.inputView?.reloadInputViews()
|
|
76
|
-
|
|
77
|
-
NotificationCenter.default.addObserver(
|
|
78
|
-
self,
|
|
79
|
-
selector: #selector(beginEditingInput(_:)),
|
|
80
|
-
name: UITextField.textDidBeginEditingNotification,
|
|
81
|
-
object: backedTextInputView
|
|
82
|
-
)
|
|
83
|
-
NotificationCenter.default.addObserver(
|
|
84
|
-
self,
|
|
85
|
-
selector: #selector(endEditingInput(_:)),
|
|
86
|
-
name: UITextField.textDidEndEditingNotification,
|
|
87
|
-
object: backedTextInputView
|
|
88
|
-
)
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
func getbottomInset() -> CGFloat {
|
|
92
|
-
let window = UIApplication.shared.windows.first?.rootViewController?.view
|
|
93
|
-
let bottom = (window?.safeAreaInsets.bottom ?? 0) > 0 ? 21 : 0
|
|
94
|
-
return CGFloat(bottom)
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
func keyDidPress(_ key: String) {
|
|
98
|
-
backedTextInputView.insertText(key)
|
|
99
|
-
value += key
|
|
100
|
-
|
|
101
|
-
if let bridge = bridge {
|
|
102
|
-
bridge.eventDispatcher().sendTextEvent(with: .change, reactTag: reactTag, text: value, key: "\(key)", eventCount: 1)
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
func onBackSpace() {
|
|
107
|
-
value = value.dropLast().description
|
|
108
|
-
DispatchQueue.main.async {
|
|
109
|
-
if let range = self.backedTextInputView.selectedTextRange,
|
|
110
|
-
let fromRange = self.backedTextInputView.position(from: range.start, offset: -1),
|
|
111
|
-
let newRange = self.backedTextInputView.textRange(from: fromRange, to: range.start)
|
|
112
|
-
{
|
|
113
|
-
self.backedTextInputView.replace(newRange, withText: "")
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if let bridge = bridge {
|
|
118
|
-
bridge.eventDispatcher().sendTextEvent(with: .change, reactTag: reactTag, text: value, key: "back", eventCount: 1)
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
func calculateResult() {
|
|
123
|
-
guard let textField = backedTextInputView as? UITextField,
|
|
124
|
-
let text = textField.text?.replacingOccurrences(of: "×", with: "*").replacingOccurrences(of: "÷", with: "/")
|
|
125
|
-
else {
|
|
126
|
-
return
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
let pattern = "^\\s*(-?\\d+(\\.\\d+)?\\s*[-+*/]\\s*)*-?\\d+(\\.\\d+)?\\s*$"
|
|
130
|
-
let regex = try? NSRegularExpression(pattern: pattern)
|
|
131
|
-
let range = NSRange(location: 0, length: text.utf16.count)
|
|
132
|
-
|
|
133
|
-
if regex?.firstMatch(in: text, options: [], range: range) != nil {
|
|
134
|
-
let expression = NSExpression(format: text)
|
|
135
|
-
if let result = expression.expressionValue(with: nil, context: nil) as? NSNumber {
|
|
136
|
-
textField.text = result.stringValue
|
|
137
|
-
value = result.stringValue
|
|
138
|
-
|
|
139
|
-
if let bridge = bridge {
|
|
140
|
-
bridge.eventDispatcher().sendTextEvent(with: .change, reactTag: reactTag, text: value, key: "=", eventCount: 1)
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
else {
|
|
145
|
-
print("Invalid expression")
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
func emitCustomKey() {
|
|
150
|
-
onCustomKeyEvent?([:])
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
func emitKeyPress(_ key: String) {
|
|
154
|
-
onKeyPress?(["key": key])
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
}
|
|
158
|
-
|
package/ios/extension.swift
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import Foundation
|
|
3
|
-
import UIKit
|
|
4
|
-
|
|
5
|
-
extension UIColor {
|
|
6
|
-
convenience init(hex: String) {
|
|
7
|
-
let hex = hex.trimmingCharacters(in: CharacterSet.alphanumerics.inverted)
|
|
8
|
-
var int = UInt64()
|
|
9
|
-
Scanner(string: hex).scanHexInt64(&int)
|
|
10
|
-
let a, r, g, b: UInt64
|
|
11
|
-
switch hex.count {
|
|
12
|
-
case 3: // RGB (12-bit)
|
|
13
|
-
(a, r, g, b) = (255, (int >> 8) * 17, (int >> 4 & 0xF) * 17, (int & 0xF) * 17)
|
|
14
|
-
case 6: // RGB (24-bit)
|
|
15
|
-
(a, r, g, b) = (255, int >> 16, int >> 8 & 0xFF, int & 0xFF)
|
|
16
|
-
case 8: // ARGB (32-bit)
|
|
17
|
-
(a, r, g, b) = (int >> 24, int >> 16 & 0xFF, int >> 8 & 0xFF, int & 0xFF)
|
|
18
|
-
default:
|
|
19
|
-
(a, r, g, b) = (255, 0, 0, 0)
|
|
20
|
-
}
|
|
21
|
-
self.init(red: CGFloat(r) / 255, green: CGFloat(g) / 255, blue: CGFloat(b) / 255, alpha: CGFloat(a) / 255)
|
|
22
|
-
}
|
|
23
|
-
}
|