@momo-kits/calculator-keyboard 0.165.1-phuc.2 → 0.165.2-beta.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 +63 -65
- package/android/CMakeLists.txt +8 -11
- package/android/build.gradle +33 -33
- package/android/gradle.properties +5 -4
- package/android/src/main/AndroidManifest.xml +2 -1
- package/android/src/main/AndroidManifestNew.xml +2 -0
- package/android/src/main/java/com/momokits/calculatorkeyboard/CalculatorKeyboardPackage.kt +7 -3
- package/android/src/main/java/com/momokits/calculatorkeyboard/native/CustomKeyboardView.kt +403 -0
- package/android/src/main/java/com/momokits/calculatorkeyboard/native/InputCalculator.kt +374 -0
- package/android/src/main/java/com/momokits/calculatorkeyboard/native/KeyboardOverlayHost.kt +212 -165
- package/android/src/main/java/com/momokits/calculatorkeyboard/native/utils/CalculatorEngine.kt +32 -0
- package/android/src/main/java/com/momokits/calculatorkeyboard/native/utils/CalculatorFormatter.kt +78 -0
- package/android/src/main/java/com/momokits/calculatorkeyboard/reactnative/Event.kt +120 -0
- package/android/src/main/java/com/momokits/calculatorkeyboard/reactnative/InputCalculatorViewManager.kt +122 -107
- package/ios/CalculatorKeyboardView.h +19 -23
- package/ios/CalculatorKeyboardView.mm +209 -178
- package/ios/InputCalculator.h +2 -3
- package/ios/InputCalculator.mm +460 -305
- package/ios/Utils.h +10 -0
- package/ios/Utils.mm +25 -0
- package/package.json +73 -69
- package/react-native-calculator-keyboard.podspec +32 -9
- package/src/InputCalculatorNativeComponent.ts +64 -50
- package/src/index.tsx +184 -175
- package/android/src/main/cpp/CMakeLists.txt +0 -20
- package/android/src/main/cpp/CalculatorCoreJNI.cpp +0 -63
- package/android/src/main/java/com/momokits/calculatorkeyboard/native/CalculatorCore.kt +0 -41
- package/android/src/main/java/com/momokits/calculatorkeyboard/native/CalculatorInputView.kt +0 -418
- package/android/src/main/java/com/momokits/calculatorkeyboard/native/CalculatorKeyboardView.kt +0 -220
- package/android/src/main/java/com/momokits/calculatorkeyboard/reactnative/InputCalculatorEvents.kt +0 -74
- package/shared/calculator/CalculatorCore.cpp +0 -405
- package/shared/calculator/CalculatorCore.h +0 -87
- package/shared/react/renderer/components/InputCalculatorSpec/ComponentDescriptors.h +0 -19
- package/shared/react/renderer/components/InputCalculatorSpec/InputCalculatorComponentDescriptor.h +0 -10
- package/shared/react/renderer/components/InputCalculatorSpec/InputCalculatorShadowNode.cpp +0 -13
- package/shared/react/renderer/components/InputCalculatorSpec/InputCalculatorShadowNode.h +0 -41
- package/shared/react/renderer/components/InputCalculatorSpec/InputCalculatorState.h +0 -42
package/README.md
CHANGED
|
@@ -1,77 +1,75 @@
|
|
|
1
|
-
#
|
|
1
|
+
# react-native-calculator-keyboard
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
React Native **0.80+ / Fabric only**.
|
|
3
|
+
react native calculator keyboard
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
import InputCalculator, { Mode, CustomKeyState } from '@momo-kits/calculator-keyboard';
|
|
5
|
+
## Installation
|
|
8
6
|
|
|
9
|
-
|
|
7
|
+
```sh
|
|
8
|
+
npm install react-native-calculator-keyboard
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
import InputCalculator from '@momo-kits/calculator-keyboard';
|
|
15
|
+
|
|
16
|
+
// ...
|
|
10
17
|
|
|
11
18
|
<InputCalculator
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
mode="NumDefault"
|
|
20
|
+
customKeyText="Next"
|
|
21
|
+
onCustomKeyEvent={() => console.log('Custom key pressed')}
|
|
22
|
+
/>;
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Requirements
|
|
26
|
+
|
|
27
|
+
**React Native 0.80+** with **Fabric (New Architecture) enabled**.
|
|
28
|
+
|
|
29
|
+
This library is **pure Fabric** implementation with:
|
|
30
|
+
|
|
31
|
+
- ✅ Zero RCTBridge dependencies
|
|
32
|
+
- ✅ Native C++ ComponentView on iOS
|
|
33
|
+
- ✅ Fabric ViewManager with codegen delegates on Android
|
|
34
|
+
- ✅ All Props, Events, Commands auto-generated by codegen
|
|
35
|
+
- ❌ No Paper (old architecture) support
|
|
36
|
+
|
|
37
|
+
### Android Setup
|
|
38
|
+
|
|
39
|
+
Add to your `gradle.properties`:
|
|
40
|
+
|
|
41
|
+
```properties
|
|
42
|
+
newArchEnabled=true
|
|
25
43
|
```
|
|
26
44
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
- The field always shows the formatted expression (`1.000.000 + 5`). `onChangeText`
|
|
30
|
-
receives that text; `onResult` receives the evaluated integer (`result`) and
|
|
31
|
-
whether the expression is currently valid.
|
|
32
|
-
- Sizing works like `<TextInput>`: width and height are measured from the
|
|
33
|
-
content/placeholder when the style does not set them and are clamped by the
|
|
34
|
-
parent and by `minWidth`/`maxWidth`.
|
|
35
|
-
- `Keyboard.dismiss()`, `ScrollView keyboardShouldPersistTaps` and `ref.blur()`
|
|
36
|
-
all close the keyboard; focusing another input hands focus over.
|
|
37
|
-
- `onKeyboardShow({ height })` / `onKeyboardHide` fire on both platforms.
|
|
38
|
-
- Keyboard avoidance: iOS uses the system input view, so `KeyboardAvoidingView`
|
|
39
|
-
and `UIScrollView` behave as with `<TextInput>`. Android has no per-app IME, so
|
|
40
|
-
the keyboard is an overlay: the library pans the window content up just
|
|
41
|
-
enough to keep the focused field visible (like `adjustPan`), and
|
|
42
|
-
`onKeyboardShow` lets a screen add bottom padding for scrolling.
|
|
43
|
-
|
|
44
|
-
All editing, formatting and evaluation logic lives in `shared/calculator`
|
|
45
|
-
(C++) and is used by both platforms, so behaviour is identical. Run its tests
|
|
46
|
-
with `yarn test:core`.
|
|
47
|
-
|
|
48
|
-
## Props
|
|
49
|
-
|
|
50
|
-
| Prop | Type | Notes |
|
|
51
|
-
|---|---|---|
|
|
52
|
-
| `value` / `defaultValue` | `string` | Controlled / initial value. |
|
|
53
|
-
| `mode` | `Mode.NumDefault` \| `Mode.NumWithCTA` | `NumWithCTA` replaces `AC` with a custom CTA key. |
|
|
54
|
-
| `customKeyText` | `string` | CTA label (default `Tiếp`). |
|
|
55
|
-
| `customKeyBackground` | `'default'` \| `'primary'` | CTA colour (theme primary). |
|
|
56
|
-
| `customKeyState` | `CustomKeyState` | `Disable` greys out and disables the CTA. |
|
|
57
|
-
| `placeholder`, `placeholderTextColor`, `selectionColor` | | Same as `<TextInput>`. |
|
|
58
|
-
| `style` | `TextStyle` | `color`, `fontSize`, `fontWeight`, `fontFamily` style the text; the rest styles the container. |
|
|
59
|
-
| `onChangeText`, `onChange`, `onResult`, `onKeyPress`, `onFocus`, `onBlur`, `onCustomKeyEvent`, `onKeyboardShow`, `onKeyboardHide` | | Events. |
|
|
60
|
-
|
|
61
|
-
Ref: `focus()`, `blur()`, `isFocused()`.
|
|
62
|
-
|
|
63
|
-
## Layout of the package
|
|
45
|
+
Then rebuild:
|
|
64
46
|
|
|
47
|
+
```bash
|
|
48
|
+
cd android && ./gradlew clean && cd ..
|
|
49
|
+
npx react-native run-android
|
|
65
50
|
```
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
51
|
+
|
|
52
|
+
### iOS Setup
|
|
53
|
+
|
|
54
|
+
**Required**: Set the environment variable before installing pods:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
cd ios
|
|
58
|
+
RCT_NEW_ARCH_ENABLED=1 pod install
|
|
59
|
+
cd ..
|
|
60
|
+
npx react-native run-ios
|
|
72
61
|
```
|
|
73
62
|
|
|
74
|
-
|
|
63
|
+
**Note**: This library uses Fabric ComponentView (`.mm` files) and will not work without `RCT_NEW_ARCH_ENABLED=1`.
|
|
64
|
+
|
|
65
|
+
## Contributing
|
|
66
|
+
|
|
67
|
+
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
|
|
68
|
+
|
|
69
|
+
## License
|
|
70
|
+
|
|
71
|
+
MIT
|
|
72
|
+
|
|
73
|
+
---
|
|
75
74
|
|
|
76
|
-
|
|
77
|
-
- Android: NDK + CMake (already required by React Native 0.80).
|
|
75
|
+
Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
|
package/android/CMakeLists.txt
CHANGED
|
@@ -1,24 +1,21 @@
|
|
|
1
|
-
# React Native codegen library (consumed by RN autolinking through
|
|
2
|
-
# react-native.config.js). Compiles the generated JNI sources plus our custom
|
|
3
|
-
# shadow node from ../shared/react. The calculator core is built separately
|
|
4
|
-
# (src/main/cpp) so it has no React dependency.
|
|
5
1
|
cmake_minimum_required(VERSION 3.13)
|
|
6
|
-
project(
|
|
2
|
+
project(InputCalculator)
|
|
7
3
|
|
|
4
|
+
set(CMAKE_VERBOSE_MAKEFILE on)
|
|
8
5
|
set(CMAKE_CXX_STANDARD 20)
|
|
9
|
-
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
10
6
|
|
|
11
|
-
file(GLOB_RECURSE
|
|
7
|
+
file(GLOB_RECURSE input_calculator_SRCS CONFIGURE_DEPENDS ../shared/*.cpp)
|
|
12
8
|
file(GLOB_RECURSE input_calculator_codegen_SRCS CONFIGURE_DEPENDS ./build/generated/source/codegen/jni/*.cpp)
|
|
13
9
|
|
|
14
10
|
add_library(
|
|
15
11
|
react_codegen_InputCalculatorSpec
|
|
16
12
|
SHARED
|
|
17
|
-
${
|
|
13
|
+
${input_calculator_SRCS}
|
|
18
14
|
${input_calculator_codegen_SRCS}
|
|
19
15
|
)
|
|
20
16
|
|
|
21
|
-
|
|
17
|
+
message(PROJECT_SOURCE_DIR="${input_calculator_SRCS}")
|
|
18
|
+
|
|
22
19
|
target_include_directories(react_codegen_InputCalculatorSpec PUBLIC ../shared)
|
|
23
20
|
target_include_directories(react_codegen_InputCalculatorSpec PUBLIC ./build/generated/source/codegen/jni)
|
|
24
21
|
|
|
@@ -26,7 +23,7 @@ target_link_libraries(
|
|
|
26
23
|
react_codegen_InputCalculatorSpec
|
|
27
24
|
fbjni
|
|
28
25
|
jsi
|
|
26
|
+
# We need to link different libraries based on whether we are building rncore or not, that's necessary
|
|
27
|
+
# because we want to break a circular dependency between react_codegen_rncore and reactnative
|
|
29
28
|
reactnative
|
|
30
29
|
)
|
|
31
|
-
|
|
32
|
-
target_compile_options(react_codegen_InputCalculatorSpec PRIVATE -Wall -fexceptions -frtti -std=c++20 -DLOG_TAG=\"ReactNative\")
|
package/android/build.gradle
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
buildscript {
|
|
2
|
+
// Buildscript is evaluated before everything else so we can't use getExtOrDefault
|
|
2
3
|
def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["CalculatorKeyboard_kotlinVersion"]
|
|
3
4
|
|
|
4
5
|
repositories {
|
|
@@ -7,12 +8,17 @@ buildscript {
|
|
|
7
8
|
}
|
|
8
9
|
|
|
9
10
|
dependencies {
|
|
10
|
-
classpath "com.android.tools.build:gradle:
|
|
11
|
+
classpath "com.android.tools.build:gradle:7.2.1"
|
|
11
12
|
// noinspection DifferentKotlinGradleVersion
|
|
12
13
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
|
13
14
|
}
|
|
14
15
|
}
|
|
15
16
|
|
|
17
|
+
def reactNativeArchitectures() {
|
|
18
|
+
def value = rootProject.getProperties().get("reactNativeArchitectures")
|
|
19
|
+
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
|
|
20
|
+
}
|
|
21
|
+
|
|
16
22
|
def isNewArchitectureEnabled() {
|
|
17
23
|
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
|
|
18
24
|
}
|
|
@@ -32,38 +38,32 @@ def getExtOrIntegerDefault(name) {
|
|
|
32
38
|
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["CalculatorKeyboard_" + name]).toInteger()
|
|
33
39
|
}
|
|
34
40
|
|
|
35
|
-
|
|
36
|
-
|
|
41
|
+
def supportsNamespace() {
|
|
42
|
+
def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
|
|
43
|
+
def major = parsed[0].toInteger()
|
|
44
|
+
def minor = parsed[1].toInteger()
|
|
37
45
|
|
|
38
|
-
|
|
46
|
+
// Namespace support was added in 7.3.0
|
|
47
|
+
return (major == 7 && minor >= 3) || major >= 8
|
|
48
|
+
}
|
|
39
49
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
50
|
+
android {
|
|
51
|
+
if (supportsNamespace()) {
|
|
52
|
+
namespace "com.momokits.calculatorkeyboard"
|
|
43
53
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
arguments "-DANDROID_STL=c++_shared"
|
|
54
|
+
sourceSets {
|
|
55
|
+
main {
|
|
56
|
+
manifest.srcFile "src/main/AndroidManifestNew.xml"
|
|
48
57
|
}
|
|
49
58
|
}
|
|
50
59
|
}
|
|
51
60
|
|
|
52
|
-
|
|
53
|
-
externalNativeBuild {
|
|
54
|
-
cmake {
|
|
55
|
-
path "src/main/cpp/CMakeLists.txt"
|
|
56
|
-
}
|
|
57
|
-
}
|
|
61
|
+
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
|
|
58
62
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
+
defaultConfig {
|
|
64
|
+
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
|
|
65
|
+
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
|
|
63
66
|
|
|
64
|
-
packagingOptions {
|
|
65
|
-
// The app already ships libc++_shared.so through React Native.
|
|
66
|
-
excludes = ["**/libc++_shared.so"]
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
buildTypes {
|
|
@@ -77,12 +77,8 @@ android {
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
compileOptions {
|
|
80
|
-
sourceCompatibility JavaVersion.
|
|
81
|
-
targetCompatibility JavaVersion.
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
kotlinOptions {
|
|
85
|
-
jvmTarget = "17"
|
|
80
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
81
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
86
82
|
}
|
|
87
83
|
}
|
|
88
84
|
|
|
@@ -94,8 +90,12 @@ repositories {
|
|
|
94
90
|
def kotlin_version = getExtOrDefault("kotlinVersion")
|
|
95
91
|
|
|
96
92
|
dependencies {
|
|
97
|
-
|
|
93
|
+
// For < 0.71, this will be from the local maven repo
|
|
94
|
+
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
|
|
95
|
+
//noinspection GradleDynamicVersion
|
|
96
|
+
implementation "com.facebook.react:react-native:+"
|
|
98
97
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
99
|
-
implementation
|
|
100
|
-
implementation
|
|
98
|
+
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
|
99
|
+
implementation("org.mariuszgromada.math:MathParser.org-mXparser:5.2.1")
|
|
101
100
|
}
|
|
101
|
+
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
CalculatorKeyboard_kotlinVersion=
|
|
2
|
-
CalculatorKeyboard_minSdkVersion=
|
|
3
|
-
CalculatorKeyboard_targetSdkVersion=
|
|
4
|
-
CalculatorKeyboard_compileSdkVersion=
|
|
1
|
+
CalculatorKeyboard_kotlinVersion=1.7.0
|
|
2
|
+
CalculatorKeyboard_minSdkVersion=21
|
|
3
|
+
CalculatorKeyboard_targetSdkVersion=31
|
|
4
|
+
CalculatorKeyboard_compileSdkVersion=31
|
|
5
|
+
CalculatorKeyboard_ndkversion=21.4.7075529
|
|
@@ -6,9 +6,13 @@ import com.facebook.react.bridge.ReactApplicationContext
|
|
|
6
6
|
import com.facebook.react.uimanager.ViewManager
|
|
7
7
|
import com.momokits.calculatorkeyboard.reactnative.InputCalculatorViewManager
|
|
8
8
|
|
|
9
|
+
|
|
9
10
|
class CalculatorKeyboardPackage : ReactPackage {
|
|
10
|
-
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule>
|
|
11
|
+
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
|
|
12
|
+
return emptyList()
|
|
13
|
+
}
|
|
11
14
|
|
|
12
|
-
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>>
|
|
13
|
-
listOf(InputCalculatorViewManager())
|
|
15
|
+
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
|
|
16
|
+
return listOf(InputCalculatorViewManager())
|
|
17
|
+
}
|
|
14
18
|
}
|