@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.
Files changed (37) hide show
  1. package/README.md +63 -65
  2. package/android/CMakeLists.txt +8 -11
  3. package/android/build.gradle +33 -33
  4. package/android/gradle.properties +5 -4
  5. package/android/src/main/AndroidManifest.xml +2 -1
  6. package/android/src/main/AndroidManifestNew.xml +2 -0
  7. package/android/src/main/java/com/momokits/calculatorkeyboard/CalculatorKeyboardPackage.kt +7 -3
  8. package/android/src/main/java/com/momokits/calculatorkeyboard/native/CustomKeyboardView.kt +403 -0
  9. package/android/src/main/java/com/momokits/calculatorkeyboard/native/InputCalculator.kt +374 -0
  10. package/android/src/main/java/com/momokits/calculatorkeyboard/native/KeyboardOverlayHost.kt +212 -165
  11. package/android/src/main/java/com/momokits/calculatorkeyboard/native/utils/CalculatorEngine.kt +32 -0
  12. package/android/src/main/java/com/momokits/calculatorkeyboard/native/utils/CalculatorFormatter.kt +78 -0
  13. package/android/src/main/java/com/momokits/calculatorkeyboard/reactnative/Event.kt +120 -0
  14. package/android/src/main/java/com/momokits/calculatorkeyboard/reactnative/InputCalculatorViewManager.kt +122 -107
  15. package/ios/CalculatorKeyboardView.h +19 -23
  16. package/ios/CalculatorKeyboardView.mm +209 -178
  17. package/ios/InputCalculator.h +2 -3
  18. package/ios/InputCalculator.mm +460 -305
  19. package/ios/Utils.h +10 -0
  20. package/ios/Utils.mm +25 -0
  21. package/package.json +73 -69
  22. package/react-native-calculator-keyboard.podspec +32 -9
  23. package/src/InputCalculatorNativeComponent.ts +64 -50
  24. package/src/index.tsx +184 -175
  25. package/android/src/main/cpp/CMakeLists.txt +0 -20
  26. package/android/src/main/cpp/CalculatorCoreJNI.cpp +0 -63
  27. package/android/src/main/java/com/momokits/calculatorkeyboard/native/CalculatorCore.kt +0 -41
  28. package/android/src/main/java/com/momokits/calculatorkeyboard/native/CalculatorInputView.kt +0 -418
  29. package/android/src/main/java/com/momokits/calculatorkeyboard/native/CalculatorKeyboardView.kt +0 -220
  30. package/android/src/main/java/com/momokits/calculatorkeyboard/reactnative/InputCalculatorEvents.kt +0 -74
  31. package/shared/calculator/CalculatorCore.cpp +0 -405
  32. package/shared/calculator/CalculatorCore.h +0 -87
  33. package/shared/react/renderer/components/InputCalculatorSpec/ComponentDescriptors.h +0 -19
  34. package/shared/react/renderer/components/InputCalculatorSpec/InputCalculatorComponentDescriptor.h +0 -10
  35. package/shared/react/renderer/components/InputCalculatorSpec/InputCalculatorShadowNode.cpp +0 -13
  36. package/shared/react/renderer/components/InputCalculatorSpec/InputCalculatorShadowNode.h +0 -41
  37. package/shared/react/renderer/components/InputCalculatorSpec/InputCalculatorState.h +0 -42
package/README.md CHANGED
@@ -1,77 +1,75 @@
1
- # @momo-kits/calculator-keyboard
1
+ # react-native-calculator-keyboard
2
2
 
3
- Native amount input with a built-in calculator keyboard (`+ − × ÷ =`) for
4
- React Native **0.80+ / Fabric only**.
3
+ react native calculator keyboard
5
4
 
6
- ```tsx
7
- import InputCalculator, { Mode, CustomKeyState } from '@momo-kits/calculator-keyboard';
5
+ ## Installation
8
6
 
9
- const [value, setValue] = useState('');
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
- value={value}
13
- onChangeText={setValue}
14
- onResult={e => console.log(e.nativeEvent.result, e.nativeEvent.valid)}
15
- mode={Mode.NumWithCTA}
16
- customKeyText="Tiếp"
17
- customKeyBackground="primary"
18
- customKeyState={CustomKeyState.Default}
19
- onCustomKeyEvent={() => submit()}
20
- placeholder="đ"
21
- placeholderTextColor="#cfcfcf"
22
- selectionColor="#a50064"
23
- style={{ fontSize: 36, fontWeight: '700', color: '#000' }}
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
- ## Behaviour
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
- src/ JS component + codegen spec
67
- shared/calculator/ platform-independent C++ core (+ __tests__)
68
- shared/react/ custom Fabric ShadowNode/State (measureContent)
69
- ios/ RCTViewComponentView + UIKit keyboard (inputView)
70
- android/src/main/cpp/ JNI bridge to the core (libmomocalculator.so)
71
- android/src/main/java/ native/ (Android views) reactnative/ (ViewManager)
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
- ## Requirements
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
- - `newArchEnabled=true` (Android) / `RCT_NEW_ARCH_ENABLED=1` (iOS).
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)
@@ -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(InputCalculatorSpec)
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 input_calculator_shadow_SRCS CONFIGURE_DEPENDS ../shared/react/*.cpp)
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
- ${input_calculator_shadow_SRCS}
13
+ ${input_calculator_SRCS}
18
14
  ${input_calculator_codegen_SRCS}
19
15
  )
20
16
 
21
- # ../shared first so its ComponentDescriptors.h shadows the generated one.
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\")
@@ -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:8.6.0"
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
- android {
36
- namespace "com.momokits.calculatorkeyboard"
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
- compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
46
+ // Namespace support was added in 7.3.0
47
+ return (major == 7 && minor >= 3) || major >= 8
48
+ }
39
49
 
40
- defaultConfig {
41
- minSdkVersion getExtOrIntegerDefault("minSdkVersion")
42
- targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
50
+ android {
51
+ if (supportsNamespace()) {
52
+ namespace "com.momokits.calculatorkeyboard"
43
53
 
44
- externalNativeBuild {
45
- cmake {
46
- cppFlags "-std=c++20"
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
- // JNI bridge to the shared calculator core (shared/calculator).
53
- externalNativeBuild {
54
- cmake {
55
- path "src/main/cpp/CMakeLists.txt"
56
- }
57
- }
61
+ compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
58
62
 
59
- buildFeatures {
60
- prefab false
61
- buildConfig false
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.VERSION_17
81
- targetCompatibility JavaVersion.VERSION_17
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
- implementation "com.facebook.react:react-android"
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 "androidx.appcompat:appcompat:1.7.0"
100
- implementation "androidx.activity:activity:1.9.3"
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.0.21
2
- CalculatorKeyboard_minSdkVersion=24
3
- CalculatorKeyboard_targetSdkVersion=35
4
- CalculatorKeyboard_compileSdkVersion=35
1
+ CalculatorKeyboard_kotlinVersion=1.7.0
2
+ CalculatorKeyboard_minSdkVersion=21
3
+ CalculatorKeyboard_targetSdkVersion=31
4
+ CalculatorKeyboard_compileSdkVersion=31
5
+ CalculatorKeyboard_ndkversion=21.4.7075529
@@ -1,2 +1,3 @@
1
- <manifest xmlns:android="http://schemas.android.com/apk/res/android">
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
+ package="com.momokits.calculatorkeyboard">
2
3
  </manifest>
@@ -0,0 +1,2 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ </manifest>
@@ -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> = emptyList()
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
  }