@momo-kits/calculator-keyboard 0.112.1-rn76.74 → 0.112.1-rn76.76
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.
|
@@ -3,6 +3,8 @@ package com.calculatorkeyboard
|
|
|
3
3
|
import android.annotation.SuppressLint
|
|
4
4
|
import android.app.Activity
|
|
5
5
|
import android.graphics.Color
|
|
6
|
+
import android.graphics.PixelFormat
|
|
7
|
+
import android.view.Gravity
|
|
6
8
|
import android.view.KeyEvent
|
|
7
9
|
import android.view.View
|
|
8
10
|
import android.view.ViewGroup
|
|
@@ -15,11 +17,15 @@ import com.facebook.react.uimanager.annotations.ReactProp
|
|
|
15
17
|
import com.facebook.react.views.textinput.ReactEditText
|
|
16
18
|
import com.facebook.react.views.textinput.ReactTextInputManager
|
|
17
19
|
|
|
18
|
-
|
|
19
20
|
class RCTInputCalculator : ReactTextInputManager() {
|
|
21
|
+
|
|
20
22
|
private var layout: ConstraintLayout? = null
|
|
21
23
|
private var keyboardView: CustomKeyboardView? = null
|
|
22
|
-
private var calculatorHeight = 0
|
|
24
|
+
private var calculatorHeight: Int = 0
|
|
25
|
+
private var addedWithWM = false
|
|
26
|
+
private val ANIM_DURATION = 250L
|
|
27
|
+
|
|
28
|
+
private var outsideOverlay: View? = null
|
|
23
29
|
|
|
24
30
|
override fun getName() = REACT_CLASS
|
|
25
31
|
|
|
@@ -37,38 +43,24 @@ class RCTInputCalculator : ReactTextInputManager() {
|
|
|
37
43
|
keyboardView?.updateButtonColors(Color.parseColor(color))
|
|
38
44
|
}
|
|
39
45
|
|
|
46
|
+
@SuppressLint("ClickableViewAccessibility")
|
|
40
47
|
override fun createViewInstance(context: ThemedReactContext): ReactEditText {
|
|
41
48
|
val editText = CalculatorEditText(context)
|
|
42
|
-
|
|
43
|
-
keyboardView = CustomKeyboardView(context, editText)
|
|
44
|
-
keyboardView?.setBackgroundColor(Color.parseColor("#f2f2f6"))
|
|
49
|
+
editText.showSoftInputOnFocus = false
|
|
45
50
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
val lParams = ConstraintLayout.LayoutParams(
|
|
51
|
-
ConstraintLayout.LayoutParams.MATCH_PARENT,
|
|
52
|
-
ConstraintLayout.LayoutParams.WRAP_CONTENT
|
|
53
|
-
).apply {
|
|
54
|
-
height = calculatorHeight
|
|
55
|
-
bottomToBottom = ConstraintLayout.LayoutParams.PARENT_ID
|
|
56
|
-
setMargins(0, screenHeight - calculatorHeight, 0, 0)
|
|
57
|
-
}
|
|
58
|
-
if (context.currentActivity != null) {
|
|
59
|
-
(layout as ConstraintLayout).addView(keyboardView, lParams)
|
|
51
|
+
layout = ConstraintLayout(context)
|
|
52
|
+
keyboardView = CustomKeyboardView(context, editText).apply {
|
|
53
|
+
setBackgroundColor(Color.parseColor("#f2f2f6"))
|
|
54
|
+
elevation = 24f
|
|
60
55
|
}
|
|
61
56
|
|
|
57
|
+
val dm = context.currentActivity!!.resources.displayMetrics
|
|
58
|
+
calculatorHeight = (dm.widthPixels * 0.675f).toInt()
|
|
59
|
+
|
|
62
60
|
editText.setOnClickListener { v: View ->
|
|
63
61
|
UiThreadUtil.runOnUiThread {
|
|
64
|
-
(context
|
|
65
|
-
|
|
66
|
-
0
|
|
67
|
-
)
|
|
68
|
-
editText.setShowSoftInputOnFocus(false)
|
|
69
|
-
if (!editText.isFocused) {
|
|
70
|
-
editText.requestFocusFromJS()
|
|
71
|
-
}
|
|
62
|
+
hideIme(context, v)
|
|
63
|
+
if (!editText.isFocused) editText.requestFocusFromJS()
|
|
72
64
|
}
|
|
73
65
|
}
|
|
74
66
|
|
|
@@ -76,17 +68,15 @@ class RCTInputCalculator : ReactTextInputManager() {
|
|
|
76
68
|
override fun onFocusChange(view: CalculatorEditText, hasFocus: Boolean) {
|
|
77
69
|
UiThreadUtil.runOnUiThread {
|
|
78
70
|
if (hasFocus) {
|
|
79
|
-
|
|
71
|
+
addContentViewForDialog(context, view)
|
|
80
72
|
} else {
|
|
81
|
-
|
|
73
|
+
removeContentViewForDialog(context)
|
|
82
74
|
}
|
|
83
|
-
view.setOnKeyListener {
|
|
75
|
+
view.setOnKeyListener { v, keyCode, _ ->
|
|
84
76
|
if (keyCode == KeyEvent.KEYCODE_BACK && hasFocus) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
false
|
|
77
|
+
v.clearFocus()
|
|
78
|
+
true
|
|
79
|
+
} else false
|
|
90
80
|
}
|
|
91
81
|
}
|
|
92
82
|
}
|
|
@@ -95,34 +85,83 @@ class RCTInputCalculator : ReactTextInputManager() {
|
|
|
95
85
|
return editText
|
|
96
86
|
}
|
|
97
87
|
|
|
98
|
-
private fun
|
|
99
|
-
if (
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
layout,
|
|
105
|
-
ViewGroup.LayoutParams(
|
|
106
|
-
ViewGroup.LayoutParams.MATCH_PARENT,
|
|
107
|
-
ViewGroup.LayoutParams.MATCH_PARENT
|
|
108
|
-
)
|
|
88
|
+
private fun ensureOverlay(context: ThemedReactContext, anchor: View) {
|
|
89
|
+
if (outsideOverlay != null) return
|
|
90
|
+
outsideOverlay = View(context).apply {
|
|
91
|
+
layoutParams = ViewGroup.LayoutParams(
|
|
92
|
+
ViewGroup.LayoutParams.MATCH_PARENT,
|
|
93
|
+
ViewGroup.LayoutParams.MATCH_PARENT
|
|
109
94
|
)
|
|
110
|
-
|
|
95
|
+
setBackgroundColor(Color.TRANSPARENT)
|
|
96
|
+
isClickable = true
|
|
97
|
+
isFocusable = true
|
|
98
|
+
setOnClickListener {
|
|
99
|
+
anchor.clearFocus()
|
|
100
|
+
}
|
|
111
101
|
}
|
|
112
102
|
}
|
|
113
103
|
|
|
114
|
-
private fun
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
104
|
+
private fun addContentViewForDialog(context: ThemedReactContext, anchor: View) {
|
|
105
|
+
val root = layout ?: return
|
|
106
|
+
if (addedWithWM || root.parent != null) return
|
|
107
|
+
|
|
108
|
+
ensureOverlay(context, anchor)
|
|
109
|
+
|
|
110
|
+
if (outsideOverlay?.parent == null) {
|
|
111
|
+
root.addView(outsideOverlay)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (keyboardView?.parent == null) {
|
|
115
|
+
val lp = ConstraintLayout.LayoutParams(
|
|
116
|
+
ConstraintLayout.LayoutParams.MATCH_PARENT,
|
|
117
|
+
calculatorHeight
|
|
118
|
+
).apply {
|
|
119
|
+
bottomToBottom = ConstraintLayout.LayoutParams.PARENT_ID
|
|
123
120
|
}
|
|
121
|
+
root.addView(keyboardView, lp)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
val wm = context.getSystemService(android.content.Context.WINDOW_SERVICE) as WindowManager
|
|
125
|
+
|
|
126
|
+
val lp = WindowManager.LayoutParams(
|
|
127
|
+
WindowManager.LayoutParams.MATCH_PARENT,
|
|
128
|
+
WindowManager.LayoutParams.MATCH_PARENT,
|
|
129
|
+
WindowManager.LayoutParams.TYPE_APPLICATION_PANEL,
|
|
130
|
+
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN or
|
|
131
|
+
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
|
|
132
|
+
PixelFormat.TRANSLUCENT
|
|
133
|
+
).apply {
|
|
134
|
+
gravity = Gravity.BOTTOM
|
|
135
|
+
token = anchor.applicationWindowToken
|
|
136
|
+
softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING
|
|
124
137
|
}
|
|
138
|
+
|
|
139
|
+
root.translationY = calculatorHeight.toFloat()
|
|
140
|
+
wm.addView(root, lp)
|
|
141
|
+
addedWithWM = true
|
|
142
|
+
|
|
143
|
+
root.animate().translationY(0f).setDuration(ANIM_DURATION).start()
|
|
125
144
|
}
|
|
126
145
|
|
|
127
|
-
|
|
146
|
+
private fun removeContentViewForDialog(context: ThemedReactContext) {
|
|
147
|
+
if (!addedWithWM) return
|
|
148
|
+
val wm = context.getSystemService(android.content.Context.WINDOW_SERVICE) as WindowManager
|
|
149
|
+
val root = layout ?: return
|
|
150
|
+
|
|
151
|
+
root.animate()
|
|
152
|
+
.translationY(calculatorHeight.toFloat())
|
|
153
|
+
.setDuration(ANIM_DURATION)
|
|
154
|
+
.withEndAction {
|
|
155
|
+
try {
|
|
156
|
+
wm.removeViewImmediate(root)
|
|
157
|
+
} catch (_: Throwable) {}
|
|
158
|
+
addedWithWM = false
|
|
159
|
+
}
|
|
160
|
+
.start()
|
|
161
|
+
}
|
|
128
162
|
|
|
163
|
+
private fun hideIme(context: ThemedReactContext, v: View) {
|
|
164
|
+
val imm = context.getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
|
|
165
|
+
imm.hideSoftInputFromWindow(v.windowToken, 0)
|
|
166
|
+
}
|
|
167
|
+
}
|