react-native-keyboard-controller 1.1.0 → 1.2.0

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 (67) hide show
  1. package/android/build.gradle +72 -3
  2. package/android/src/fabric/java/com/reactnativekeyboardcontroller/KeyboardControllerComponentsRegistry.kt +31 -0
  3. package/android/src/fabric/java/com/reactnativekeyboardcontroller/KeyboardControllerModule.kt +25 -0
  4. package/android/src/fabric/java/com/reactnativekeyboardcontroller/KeyboardControllerViewManager.kt +32 -0
  5. package/android/src/fabric/java/com/reactnativekeyboardcontroller/StatusBarManagerCompatModule.kt +25 -0
  6. package/android/src/main/java/com/reactnativekeyboardcontroller/KeyboardAnimationCallback.kt +6 -6
  7. package/android/src/main/java/com/reactnativekeyboardcontroller/{KeyboardControllerModule.kt → KeyboardControllerModuleImpl.kt} +5 -17
  8. package/android/src/main/java/com/reactnativekeyboardcontroller/KeyboardControllerPackage.kt +5 -0
  9. package/android/src/main/java/com/reactnativekeyboardcontroller/{KeyboardControllerViewManager.kt → KeyboardControllerViewManagerImpl.kt} +8 -9
  10. package/android/src/main/java/com/reactnativekeyboardcontroller/{StatusBarManagerCompatModule.kt → StatusBarManagerCompatImpl.kt} +10 -14
  11. package/android/src/main/jni/Android.mk +42 -0
  12. package/android/src/main/jni/KeyboardControllerComponentsRegistry.cpp +71 -0
  13. package/android/src/main/jni/KeyboardControllerComponentsRegistry.h +35 -0
  14. package/android/src/main/jni/OnLoad.cpp +9 -0
  15. package/android/src/paper/java/com/reactnativekeyboardcontroller/KeyboardControllerModule.kt +31 -0
  16. package/android/src/paper/java/com/reactnativekeyboardcontroller/KeyboardControllerViewManager.kt +26 -0
  17. package/android/src/paper/java/com/reactnativekeyboardcontroller/StatusBarManagerCompatModule.kt +34 -0
  18. package/ios/.clang-format +1 -1
  19. package/ios/KeyboardController.xcodeproj/project.pbxproj +18 -14
  20. package/ios/KeyboardControllerModule-Header.h +6 -2
  21. package/ios/KeyboardControllerModule.mm +105 -0
  22. package/ios/KeyboardControllerView.h +23 -0
  23. package/ios/KeyboardControllerView.mm +81 -0
  24. package/ios/{KeyboardControllerViewManager.m → KeyboardControllerViewManager.mm} +0 -0
  25. package/ios/KeyboardControllerViewManager.swift +2 -2
  26. package/ios/KeyboardMoveEvent.h +18 -0
  27. package/ios/KeyboardMoveEvent.m +74 -0
  28. package/lib/commonjs/KeyboardControllerViewNativeComponent.js +16 -0
  29. package/lib/commonjs/KeyboardControllerViewNativeComponent.js.map +1 -0
  30. package/lib/commonjs/NativeKeyboardController.js +13 -0
  31. package/lib/commonjs/NativeKeyboardController.js.map +1 -0
  32. package/lib/commonjs/NativeStatusBarManagerCompat.js +13 -0
  33. package/lib/commonjs/NativeStatusBarManagerCompat.js.map +1 -0
  34. package/lib/commonjs/architecture.js +13 -0
  35. package/lib/commonjs/architecture.js.map +1 -0
  36. package/lib/commonjs/monkey-patch.js +3 -1
  37. package/lib/commonjs/monkey-patch.js.map +1 -1
  38. package/lib/commonjs/native.js +4 -2
  39. package/lib/commonjs/native.js.map +1 -1
  40. package/lib/module/KeyboardControllerViewNativeComponent.js +4 -0
  41. package/lib/module/KeyboardControllerViewNativeComponent.js.map +1 -0
  42. package/lib/module/NativeKeyboardController.js +3 -0
  43. package/lib/module/NativeKeyboardController.js.map +1 -0
  44. package/lib/module/NativeStatusBarManagerCompat.js +3 -0
  45. package/lib/module/NativeStatusBarManagerCompat.js.map +1 -0
  46. package/lib/module/architecture.js +5 -0
  47. package/lib/module/architecture.js.map +1 -0
  48. package/lib/module/monkey-patch.js +2 -1
  49. package/lib/module/monkey-patch.js.map +1 -1
  50. package/lib/module/native.js +3 -2
  51. package/lib/module/native.js.map +1 -1
  52. package/lib/typescript/KeyboardControllerViewNativeComponent.d.ts +13 -0
  53. package/lib/typescript/NativeKeyboardController.d.ts +10 -0
  54. package/lib/typescript/NativeStatusBarManagerCompat.d.ts +10 -0
  55. package/lib/typescript/architecture.d.ts +2 -0
  56. package/lib/typescript/native.d.ts +1 -1
  57. package/package.json +16 -1
  58. package/react-native-keyboard-controller.podspec +19 -0
  59. package/src/KeyboardControllerViewNativeComponent.ts +23 -0
  60. package/src/NativeKeyboardController.ts +16 -0
  61. package/src/NativeStatusBarManagerCompat.ts +13 -0
  62. package/src/architecture.ts +4 -0
  63. package/src/monkey-patch.tsx +5 -1
  64. package/src/native.ts +12 -7
  65. package/ios/KeyboardControllerModule.m +0 -21
  66. package/ios/KeyboardControllerModule.swift +0 -53
  67. package/ios/KeyboardMoveEvent.swift +0 -41
@@ -14,9 +14,6 @@ buildscript {
14
14
  }
15
15
  }
16
16
 
17
- apply plugin: 'com.android.library'
18
- apply plugin: 'kotlin-android'
19
-
20
17
  def getExtOrDefault(name) {
21
18
  return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['KeyboardController_' + name]
22
19
  }
@@ -25,6 +22,22 @@ def getExtOrIntegerDefault(name) {
25
22
  return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['KeyboardController_' + name]).toInteger()
26
23
  }
27
24
 
25
+ def isNewArchitectureEnabled() {
26
+ return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
27
+ }
28
+
29
+ def reactNativeArchitectures() {
30
+ def value = project.getProperties().get("reactNativeArchitectures")
31
+ return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
32
+ }
33
+
34
+ apply plugin: 'com.android.library'
35
+ apply plugin: 'kotlin-android'
36
+
37
+ if (isNewArchitectureEnabled()) {
38
+ apply plugin: 'com.facebook.react'
39
+ }
40
+
28
41
  android {
29
42
  compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')
30
43
  defaultConfig {
@@ -32,7 +45,53 @@ android {
32
45
  targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
33
46
  versionCode 1
34
47
  versionName "1.0"
48
+ buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
49
+ if (isNewArchitectureEnabled()) {
50
+ var appProject = rootProject.allprojects.find { it.plugins.hasPlugin('com.android.application') }
51
+ externalNativeBuild {
52
+ ndkBuild {
53
+ arguments "APP_PLATFORM=android-21",
54
+ "APP_STL=c++_shared",
55
+ "NDK_TOOLCHAIN_VERSION=clang",
56
+ "GENERATED_SRC_DIR=${appProject.buildDir}/generated/source",
57
+ "PROJECT_BUILD_DIR=${appProject.buildDir}",
58
+ "REACT_ANDROID_DIR=${appProject.rootDir}/../node_modules/react-native/ReactAndroid",
59
+ "REACT_ANDROID_BUILD_DIR=${appProject.rootDir}/../node_modules/react-native/ReactAndroid/build"
60
+ cFlags "-Wall", "-Werror", "-fexceptions", "-frtti", "-DWITH_INSPECTOR=1"
61
+ cppFlags "-std=c++17"
62
+ targets "reactnativekeyboardcontroller_modules"
63
+ }
64
+ }
65
+ }
66
+ ndk {
67
+ abiFilters (*reactNativeArchitectures())
68
+ }
69
+ }
35
70
 
71
+ if (isNewArchitectureEnabled()) {
72
+ externalNativeBuild {
73
+ ndkBuild {
74
+ path "src/main/jni/Android.mk"
75
+ }
76
+ }
77
+
78
+ packagingOptions {
79
+ exclude "**/libreact_render_*.so"
80
+ exclude "**/librrc_root.so"
81
+ }
82
+ }
83
+
84
+ sourceSets {
85
+ main {
86
+ if (isNewArchitectureEnabled()) {
87
+ java.srcDirs += [
88
+ 'src/fabric',
89
+ 'build/generated/source/codegen/java'
90
+ ]
91
+ } else {
92
+ java.srcDirs += ['src/paper']
93
+ }
94
+ }
36
95
  }
37
96
 
38
97
  buildTypes {
@@ -127,3 +186,13 @@ dependencies {
127
186
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
128
187
  implementation 'androidx.core:core-ktx:1.5.0-beta03'
129
188
  }
189
+
190
+ if (isNewArchitectureEnabled()) {
191
+ react {
192
+ reactNativeDir = rootProject.file("../node_modules/react-native/")
193
+ jsRootDir = file("../src/")
194
+ codegenDir = rootProject.file("../node_modules/react-native-codegen/")
195
+ libraryName = "reactnativekeyboardcontroller"
196
+ codegenJavaPackageName = "com.reactnativekeyboardcontroller"
197
+ }
198
+ }
@@ -0,0 +1,31 @@
1
+ package com.reactnativekeyboardcontroller
2
+
3
+ import com.facebook.jni.HybridData
4
+ import com.facebook.proguard.annotations.DoNotStrip
5
+ import com.facebook.react.fabric.ComponentFactory
6
+ import com.facebook.soloader.SoLoader
7
+
8
+ @DoNotStrip
9
+ class KeyboardControllerComponentsRegistry @DoNotStrip private constructor(componentFactory: ComponentFactory) {
10
+ companion object {
11
+ @DoNotStrip
12
+ fun register(componentFactory: ComponentFactory): KeyboardControllerComponentsRegistry {
13
+ return KeyboardControllerComponentsRegistry(componentFactory)
14
+ }
15
+
16
+ init {
17
+ SoLoader.loadLibrary("fabricjni")
18
+ SoLoader.loadLibrary("reactnativekeyboardcontroller_modules")
19
+ }
20
+ }
21
+
22
+ @DoNotStrip
23
+ private val mHybridData: HybridData
24
+
25
+ @DoNotStrip
26
+ private external fun initHybrid(componentFactory: ComponentFactory): HybridData
27
+
28
+ init {
29
+ mHybridData = initHybrid(componentFactory)
30
+ }
31
+ }
@@ -0,0 +1,25 @@
1
+ package com.reactnativekeyboardcontroller
2
+
3
+ import com.facebook.react.bridge.ReactApplicationContext
4
+
5
+ class KeyboardControllerModule(mReactContext: ReactApplicationContext) : NativeKeyboardControllerSpec(mReactContext) {
6
+ private val module = KeyboardControllerModuleImpl(mReactContext)
7
+
8
+ override fun getName(): String = KeyboardControllerModuleImpl.NAME
9
+
10
+ override fun setInputMode(mode: Double) {
11
+ module.setInputMode(mode.toInt())
12
+ }
13
+
14
+ override fun setDefaultMode() {
15
+ module.setDefaultMode()
16
+ }
17
+
18
+ override fun addListener(eventName: String?) {
19
+ /* Required for RN built-in Event Emitter Calls. */
20
+ }
21
+
22
+ override fun removeListeners(count: Double) {
23
+ /* Required for RN built-in Event Emitter Calls. */
24
+ }
25
+ }
@@ -0,0 +1,32 @@
1
+ package com.reactnativekeyboardcontroller
2
+
3
+ import com.facebook.react.bridge.ReactApplicationContext
4
+ import com.facebook.react.uimanager.ThemedReactContext
5
+ import com.facebook.react.uimanager.ViewManagerDelegate
6
+ import com.facebook.react.viewmanagers.KeyboardControllerViewManagerDelegate
7
+ import com.facebook.react.viewmanagers.KeyboardControllerViewManagerInterface
8
+ import com.facebook.react.views.view.ReactViewGroup
9
+ import com.facebook.react.views.view.ReactViewManager
10
+
11
+ class KeyboardControllerViewManager(mReactContext: ReactApplicationContext) : ReactViewManager(), KeyboardControllerViewManagerInterface<ReactViewGroup> {
12
+ private val manager = KeyboardControllerViewManagerImpl(mReactContext)
13
+ private val mDelegate = KeyboardControllerViewManagerDelegate(this)
14
+
15
+ override fun getDelegate(): ViewManagerDelegate<ReactViewGroup?> {
16
+ return mDelegate
17
+ }
18
+
19
+ override fun getName(): String = KeyboardControllerViewManagerImpl.NAME
20
+
21
+ override fun createViewInstance(context: ThemedReactContext): ReactViewGroup {
22
+ return manager.createViewInstance(context)
23
+ }
24
+
25
+ override fun setStatusBarTranslucent(view: ReactViewGroup, value: Boolean) {
26
+ return manager.setStatusBarTranslucent(view, value)
27
+ }
28
+
29
+ override fun getExportedCustomDirectEventTypeConstants(): MutableMap<String, Any> {
30
+ return manager.getExportedCustomDirectEventTypeConstants()
31
+ }
32
+ }
@@ -0,0 +1,25 @@
1
+ package com.reactnativekeyboardcontroller
2
+
3
+ import com.facebook.react.bridge.ReactApplicationContext
4
+
5
+ class StatusBarManagerCompatModule(private val mReactContext: ReactApplicationContext) : NativeStatusBarManagerCompatSpec(mReactContext) {
6
+ private val module = StatusBarManagerCompatImpl(mReactContext)
7
+
8
+ override fun getName(): String = StatusBarManagerCompatImpl.NAME
9
+
10
+ override fun setHidden(hidden: Boolean) {
11
+ module.setHidden(hidden)
12
+ }
13
+
14
+ override fun setColor(color: Double, animated: Boolean) {
15
+ module.setColor(color.toInt(), animated)
16
+ }
17
+
18
+ override fun setTranslucent(translucent: Boolean) {
19
+ module.setTranslucent(translucent)
20
+ }
21
+
22
+ override fun setStyle(style: String) {
23
+ module.setStyle(style)
24
+ }
25
+ }
@@ -15,8 +15,9 @@ import com.facebook.react.bridge.Arguments
15
15
  import com.facebook.react.bridge.ReactApplicationContext
16
16
  import com.facebook.react.bridge.WritableMap
17
17
  import com.facebook.react.modules.core.DeviceEventManagerModule
18
- import com.facebook.react.uimanager.UIManagerModule
18
+ import com.facebook.react.uimanager.UIManagerHelper
19
19
  import com.facebook.react.uimanager.events.Event
20
+ import com.facebook.react.uimanager.events.EventDispatcher
20
21
  import com.facebook.react.views.view.ReactViewGroup
21
22
  import com.reactnativekeyboardcontroller.events.KeyboardTransitionEvent
22
23
 
@@ -132,7 +133,7 @@ class KeyboardAnimationCallback(
132
133
 
133
134
  var progress = 0.0
134
135
  try {
135
- progress = Math.abs((height.toDouble() / persistentKeyboardHeight))
136
+ progress = Math.abs((height.toDouble() / persistentKeyboardHeight)).let { if (it.isNaN()) 0.0 else it }
136
137
  } catch (e: ArithmeticException) {
137
138
  // do nothing, send progress as 0
138
139
  }
@@ -167,10 +168,9 @@ class KeyboardAnimationCallback(
167
168
  }
168
169
 
169
170
  private fun sendEventToJS(event: Event<*>) {
170
- context
171
- ?.getNativeModule(UIManagerModule::class.java)
172
- ?.eventDispatcher
173
- ?.dispatchEvent(event)
171
+ val eventDispatcher: EventDispatcher? =
172
+ UIManagerHelper.getEventDispatcherForReactTag(context, view.id)
173
+ eventDispatcher?.dispatchEvent(event)
174
174
  }
175
175
 
176
176
  private fun emitEvent(event: String, params: WritableMap) {
@@ -2,38 +2,26 @@ package com.reactnativekeyboardcontroller
2
2
 
3
3
  import android.view.WindowManager
4
4
  import com.facebook.react.bridge.ReactApplicationContext
5
- import com.facebook.react.bridge.ReactContextBaseJavaModule
6
- import com.facebook.react.bridge.ReactMethod
7
5
  import com.facebook.react.bridge.UiThreadUtil
8
6
 
9
- class KeyboardControllerModule(private val mReactContext: ReactApplicationContext) : ReactContextBaseJavaModule(mReactContext) {
7
+ class KeyboardControllerModuleImpl(private val mReactContext: ReactApplicationContext) {
10
8
  private val mDefaultMode: Int = mReactContext.currentActivity?.window?.attributes?.softInputMode ?: WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED
11
9
 
12
- override fun getName(): String = "KeyboardController"
13
-
14
- @ReactMethod(isBlockingSynchronousMethod = true)
15
10
  fun setInputMode(mode: Int) {
16
11
  setSoftInputMode(mode)
17
12
  }
18
13
 
19
- @ReactMethod(isBlockingSynchronousMethod = true)
20
14
  fun setDefaultMode() {
21
15
  setSoftInputMode(mDefaultMode)
22
16
  }
23
17
 
24
- @ReactMethod
25
- fun addListener(eventName: String?) {
26
- /* Required for RN built-in Event Emitter Calls. */
27
- }
28
-
29
- @ReactMethod
30
- fun removeListeners(count: Int?) {
31
- /* Required for RN built-in Event Emitter Calls. */
32
- }
33
-
34
18
  private fun setSoftInputMode(mode: Int) {
35
19
  UiThreadUtil.runOnUiThread {
36
20
  mReactContext.currentActivity?.window?.setSoftInputMode(mode)
37
21
  }
38
22
  }
23
+
24
+ companion object {
25
+ const val NAME = "KeyboardController"
26
+ }
39
27
  }
@@ -4,6 +4,7 @@ import com.facebook.react.ReactPackage
4
4
  import com.facebook.react.bridge.NativeModule
5
5
  import com.facebook.react.bridge.ReactApplicationContext
6
6
  import com.facebook.react.uimanager.ViewManager
7
+ import com.facebook.soloader.SoLoader
7
8
 
8
9
  class KeyboardControllerPackage : ReactPackage {
9
10
  override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
@@ -11,6 +12,10 @@ class KeyboardControllerPackage : ReactPackage {
11
12
  }
12
13
 
13
14
  override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
15
+ if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
16
+ SoLoader.loadLibrary("reactnativekeyboardcontroller_modules")
17
+ }
18
+
14
19
  return listOf(KeyboardControllerViewManager(reactContext))
15
20
  }
16
21
  }
@@ -8,19 +8,15 @@ import androidx.core.view.WindowInsetsCompat
8
8
  import com.facebook.react.bridge.ReactApplicationContext
9
9
  import com.facebook.react.common.MapBuilder
10
10
  import com.facebook.react.uimanager.ThemedReactContext
11
- import com.facebook.react.uimanager.annotations.ReactProp
12
11
  import com.facebook.react.views.view.ReactViewGroup
13
- import com.facebook.react.views.view.ReactViewManager
14
12
  import com.reactnativekeyboardcontroller.events.KeyboardTransitionEvent
15
13
 
16
- class KeyboardControllerViewManager(reactContext: ReactApplicationContext) : ReactViewManager() {
17
- private val TAG = KeyboardControllerViewManager::class.qualifiedName
14
+ class KeyboardControllerViewManagerImpl(reactContext: ReactApplicationContext) {
15
+ private val TAG = KeyboardControllerViewManagerImpl::class.qualifiedName
18
16
  private var mReactContext = reactContext
19
17
  private var isStatusBarTranslucent = false
20
18
 
21
- override fun getName() = "KeyboardControllerView"
22
-
23
- override fun createViewInstance(reactContext: ThemedReactContext): ReactViewGroup {
19
+ fun createViewInstance(reactContext: ThemedReactContext): ReactViewGroup {
24
20
  val view = EdgeToEdgeReactViewGroup(reactContext)
25
21
  val activity = mReactContext.currentActivity
26
22
 
@@ -56,12 +52,11 @@ class KeyboardControllerViewManager(reactContext: ReactApplicationContext) : Rea
56
52
  return view
57
53
  }
58
54
 
59
- @ReactProp(name = "statusBarTranslucent")
60
55
  fun setStatusBarTranslucent(view: ReactViewGroup, isStatusBarTranslucent: Boolean) {
61
56
  this.isStatusBarTranslucent = isStatusBarTranslucent
62
57
  }
63
58
 
64
- override fun getExportedCustomDirectEventTypeConstants(): MutableMap<String, Any> {
59
+ fun getExportedCustomDirectEventTypeConstants(): MutableMap<String, Any> {
65
60
  val map: MutableMap<String, Any> = MapBuilder.of(
66
61
  KeyboardTransitionEvent.EVENT_NAME,
67
62
  MapBuilder.of("registrationName", "onKeyboardMove")
@@ -69,4 +64,8 @@ class KeyboardControllerViewManager(reactContext: ReactApplicationContext) : Rea
69
64
 
70
65
  return map
71
66
  }
67
+
68
+ companion object {
69
+ const val NAME = "KeyboardControllerView"
70
+ }
72
71
  }
@@ -8,18 +8,13 @@ import androidx.annotation.RequiresApi
8
8
  import androidx.core.view.WindowInsetsCompat
9
9
  import androidx.core.view.WindowInsetsControllerCompat
10
10
  import com.facebook.react.bridge.ReactApplicationContext
11
- import com.facebook.react.bridge.ReactContextBaseJavaModule
12
- import com.facebook.react.bridge.ReactMethod
13
11
  import com.facebook.react.bridge.UiThreadUtil
14
12
 
15
- class StatusBarManagerCompatModule(private val mReactContext: ReactApplicationContext) : ReactContextBaseJavaModule(mReactContext) {
16
- private val TAG = StatusBarManagerCompatModule::class.qualifiedName
13
+ class StatusBarManagerCompatImpl(private val mReactContext: ReactApplicationContext) {
14
+ private val TAG = StatusBarManagerCompatImpl::class.qualifiedName
17
15
  private var controller: WindowInsetsControllerCompat? = null
18
16
 
19
- override fun getName(): String = "StatusBarManagerCompat"
20
-
21
- @ReactMethod
22
- private fun setHidden(hidden: Boolean) {
17
+ fun setHidden(hidden: Boolean) {
23
18
  UiThreadUtil.runOnUiThread {
24
19
  if (hidden) {
25
20
  getController()?.hide(WindowInsetsCompat.Type.statusBars())
@@ -30,8 +25,7 @@ class StatusBarManagerCompatModule(private val mReactContext: ReactApplicationCo
30
25
  }
31
26
 
32
27
  @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
33
- @ReactMethod
34
- private fun setColor(color: Int, animated: Boolean) {
28
+ fun setColor(color: Int, animated: Boolean) {
35
29
  val activity = mReactContext.currentActivity
36
30
  if (activity == null) {
37
31
  Log.w(TAG, "StatusBarManagerCompatModule: Ignored status bar change, current activity is null.")
@@ -55,8 +49,7 @@ class StatusBarManagerCompatModule(private val mReactContext: ReactApplicationCo
55
49
  }
56
50
  }
57
51
 
58
- @ReactMethod
59
- private fun setTranslucent(translucent: Boolean) {
52
+ fun setTranslucent(translucent: Boolean) {
60
53
  // the status bar is translucent by default (once you wrapped App in Provider,
61
54
  // and EdgeToEdgeReactViewGroup has been mounted and called
62
55
  // `setDecorFitsSystemWindows(window, false)`. By default this library applies default padding
@@ -70,8 +63,7 @@ class StatusBarManagerCompatModule(private val mReactContext: ReactApplicationCo
70
63
  // app requires to dynamically manage it - just shoot an issue and I will try to add a support fot that.
71
64
  }
72
65
 
73
- @ReactMethod
74
- private fun setStyle(style: String) {
66
+ fun setStyle(style: String) {
75
67
  UiThreadUtil.runOnUiThread {
76
68
  getController()?.isAppearanceLightStatusBars = style == "dark-content"
77
69
  }
@@ -92,4 +84,8 @@ class StatusBarManagerCompatModule(private val mReactContext: ReactApplicationCo
92
84
 
93
85
  return this.controller
94
86
  }
87
+
88
+ companion object {
89
+ const val NAME = "StatusBarManagerCompat"
90
+ }
95
91
  }
@@ -0,0 +1,42 @@
1
+ KEYBOARD_CONTROLLER_MAIN_THIS_DIR := $(call my-dir)
2
+
3
+ include $(REACT_ANDROID_DIR)/Android-prebuilt.mk
4
+
5
+ include $(KEYBOARD_CONTROLLER_MAIN_THIS_DIR)/../../../build/generated/source/codegen/jni/Android.mk
6
+
7
+ include $(CLEAR_VARS)
8
+
9
+ LOCAL_PATH := $(KEYBOARD_CONTROLLER_MAIN_THIS_DIR)
10
+ LOCAL_MODULE := reactnativekeyboardcontroller_modules
11
+
12
+ LOCAL_C_INCLUDES := $(LOCAL_PATH) $(GENERATED_SRC_DIR)/codegen/jni
13
+ LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp) $(wildcard $(GENERATED_SRC_DIR)/codegen/jni/*.cpp)
14
+ LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) $(GENERATED_SRC_DIR)/codegen/jni
15
+
16
+ # Please note as one of the library listed is libreact_codegen_samplelibrary
17
+ # This name will be generated as libreact_codegen_<library-name>
18
+ # where <library-name> is the one you specified in the Gradle configuration
19
+ LOCAL_SHARED_LIBRARIES := libjsi \
20
+ libfbjni \
21
+ libglog \
22
+ libfolly_runtime \
23
+ libyoga \
24
+ libreact_nativemodule_core \
25
+ libturbomodulejsijni \
26
+ librrc_view \
27
+ libreact_render_core \
28
+ libreact_render_graphics \
29
+ libfabricjni \
30
+ libreact_debug \
31
+ libreact_render_componentregistry \
32
+ libreact_render_debug \
33
+ libruntimeexecutor \
34
+ libreact_render_mapbuffer \
35
+ libreact_codegen_rncore \
36
+ libreact_codegen_reactnativekeyboardcontroller
37
+
38
+ LOCAL_CFLAGS := \
39
+ -DLOG_TAG=\"ReactNative\"
40
+ LOCAL_CFLAGS += -fexceptions -frtti -std=c++17 -Wall
41
+
42
+ include $(BUILD_SHARED_LIBRARY)
@@ -0,0 +1,71 @@
1
+ #include "KeyboardControllerComponentsRegistry.h"
2
+
3
+ #include <CoreComponentsRegistry.h>
4
+ #include <fbjni/fbjni.h>
5
+ #include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>
6
+ #include <react/renderer/components/rncore/ComponentDescriptors.h>
7
+ #include <react/renderer/components/reactnativekeyboardcontroller/ComponentDescriptors.h>
8
+ #include <memory>
9
+
10
+ namespace facebook {
11
+ namespace react {
12
+
13
+ KeyboardControllerComponentsRegistry::KeyboardControllerComponentsRegistry(
14
+ ComponentFactory *delegate)
15
+ : delegate_(delegate) {}
16
+
17
+ std::shared_ptr<ComponentDescriptorProviderRegistry const>
18
+ KeyboardControllerComponentsRegistry::sharedProviderRegistry() {
19
+ auto providerRegistry = CoreComponentsRegistry::sharedProviderRegistry();
20
+
21
+ // react-native-keyboard-controller
22
+ providerRegistry->add(concreteComponentDescriptorProvider<KeyboardControllerViewComponentDescriptor>());
23
+
24
+ return providerRegistry;
25
+ }
26
+
27
+ jni::local_ref<KeyboardControllerComponentsRegistry::jhybriddata>
28
+ KeyboardControllerComponentsRegistry::initHybrid(
29
+ jni::alias_ref<jclass>,
30
+ ComponentFactory *delegate) {
31
+ auto instance = makeCxxInstance(delegate);
32
+
33
+ auto buildRegistryFunction =
34
+ [](EventDispatcher::Weak const &eventDispatcher,
35
+ ContextContainer::Shared const &contextContainer)
36
+ -> ComponentDescriptorRegistry::Shared {
37
+ auto registry = KeyboardControllerComponentsRegistry::sharedProviderRegistry()
38
+ ->createComponentDescriptorRegistry(
39
+ {eventDispatcher, contextContainer});
40
+
41
+ auto mutableRegistry =
42
+ std::const_pointer_cast<ComponentDescriptorRegistry>(registry);
43
+
44
+ mutableRegistry->setFallbackComponentDescriptor(
45
+ std::make_shared<UnimplementedNativeViewComponentDescriptor>(
46
+ ComponentDescriptorParameters{
47
+ eventDispatcher, contextContainer, nullptr}));
48
+
49
+ return registry;
50
+ };
51
+
52
+ delegate->buildRegistryFunction = buildRegistryFunction;
53
+ return instance;
54
+ }
55
+
56
+ void KeyboardControllerComponentsRegistry::registerNatives() {
57
+ registerHybrid({
58
+ makeNativeMethod("initHybrid", KeyboardControllerComponentsRegistry::initHybrid),
59
+ });
60
+
61
+ // This is a temporary solution that allows components exported by react-native-keyboard-controller
62
+ // library to be added to the main component registry. This code is triggered
63
+ // when c++ react-native-keyboard-controller library is initialized and is needed because RN's autolinking
64
+ // does not currently support Fabric components. As a consequence, users would need
65
+ // to manually put library initialization calls in their ReactNativeHost implementation
66
+ // which is undesirable.
67
+ sharedProviderRegistry();
68
+ }
69
+
70
+ } // namespace react
71
+ } // namespace facebook
@@ -0,0 +1,35 @@
1
+ #pragma once
2
+
3
+ #include <ComponentFactory.h>
4
+ #include <fbjni/fbjni.h>
5
+ #include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>
6
+ #include <react/renderer/componentregistry/ComponentDescriptorRegistry.h>
7
+ #include <memory>
8
+
9
+ namespace facebook {
10
+ namespace react {
11
+
12
+ class KeyboardControllerComponentsRegistry
13
+ : public facebook::jni::HybridClass<KeyboardControllerComponentsRegistry> {
14
+ public:
15
+ constexpr static auto kJavaDescriptor =
16
+ "Lcom/reactnativekeyboardcontroller/KeyboardControllerComponentsRegistry;";
17
+
18
+ static void registerNatives();
19
+
20
+ explicit KeyboardControllerComponentsRegistry(ComponentFactory *delegate);
21
+
22
+ private:
23
+ friend HybridBase;
24
+
25
+ static std::shared_ptr<ComponentDescriptorProviderRegistry const> sharedProviderRegistry();
26
+
27
+ const ComponentFactory *delegate_;
28
+
29
+ static jni::local_ref<jhybriddata> initHybrid(
30
+ jni::alias_ref<jclass>,
31
+ ComponentFactory *delegate);
32
+ };
33
+
34
+ } // namespace react
35
+ } // namespace facebook
@@ -0,0 +1,9 @@
1
+ #include <fbjni/fbjni.h>
2
+
3
+ #include "KeyboardControllerComponentsRegistry.h"
4
+
5
+ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) {
6
+ return facebook::jni::initialize(vm, [] {
7
+ facebook::react::KeyboardControllerComponentsRegistry::registerNatives();
8
+ });
9
+ }
@@ -0,0 +1,31 @@
1
+ package com.reactnativekeyboardcontroller
2
+
3
+ import com.facebook.react.bridge.ReactApplicationContext
4
+ import com.facebook.react.bridge.ReactContextBaseJavaModule
5
+ import com.facebook.react.bridge.ReactMethod
6
+
7
+ class KeyboardControllerModule(mReactContext: ReactApplicationContext) : ReactContextBaseJavaModule(mReactContext) {
8
+ private val module = KeyboardControllerModuleImpl(mReactContext)
9
+
10
+ override fun getName(): String = KeyboardControllerModuleImpl.NAME
11
+
12
+ @ReactMethod(isBlockingSynchronousMethod = true)
13
+ fun setInputMode(mode: Int) {
14
+ module.setInputMode(mode)
15
+ }
16
+
17
+ @ReactMethod(isBlockingSynchronousMethod = true)
18
+ fun setDefaultMode() {
19
+ module.setDefaultMode()
20
+ }
21
+
22
+ @ReactMethod
23
+ fun addListener(eventName: String?) {
24
+ /* Required for RN built-in Event Emitter Calls. */
25
+ }
26
+
27
+ @ReactMethod
28
+ fun removeListeners(count: Int?) {
29
+ /* Required for RN built-in Event Emitter Calls. */
30
+ }
31
+ }
@@ -0,0 +1,26 @@
1
+ package com.reactnativekeyboardcontroller
2
+
3
+ import com.facebook.react.bridge.ReactApplicationContext
4
+ import com.facebook.react.uimanager.ThemedReactContext
5
+ import com.facebook.react.uimanager.annotations.ReactProp
6
+ import com.facebook.react.views.view.ReactViewGroup
7
+ import com.facebook.react.views.view.ReactViewManager
8
+
9
+ class KeyboardControllerViewManager(mReactContext: ReactApplicationContext) : ReactViewManager() {
10
+ private val manager = KeyboardControllerViewManagerImpl(mReactContext)
11
+
12
+ override fun getName(): String = KeyboardControllerViewManagerImpl.NAME
13
+
14
+ override fun createViewInstance(reactContext: ThemedReactContext): ReactViewGroup {
15
+ return manager.createViewInstance(reactContext)
16
+ }
17
+
18
+ @ReactProp(name = "statusBarTranslucent")
19
+ fun setStatusBarTranslucent(view: ReactViewGroup, isStatusBarTranslucent: Boolean) {
20
+ manager.setStatusBarTranslucent(view, isStatusBarTranslucent)
21
+ }
22
+
23
+ override fun getExportedCustomDirectEventTypeConstants(): MutableMap<String, Any> {
24
+ return manager.getExportedCustomDirectEventTypeConstants()
25
+ }
26
+ }
@@ -0,0 +1,34 @@
1
+ package com.reactnativekeyboardcontroller
2
+
3
+ import android.os.Build
4
+ import androidx.annotation.RequiresApi
5
+ import com.facebook.react.bridge.ReactApplicationContext
6
+ import com.facebook.react.bridge.ReactContextBaseJavaModule
7
+ import com.facebook.react.bridge.ReactMethod
8
+
9
+ class StatusBarManagerCompatModule(private val mReactContext: ReactApplicationContext) : ReactContextBaseJavaModule(mReactContext) {
10
+ private val module = StatusBarManagerCompatImpl(mReactContext)
11
+
12
+ override fun getName(): String = StatusBarManagerCompatImpl.NAME
13
+
14
+ @ReactMethod
15
+ private fun setHidden(hidden: Boolean) {
16
+ module.setHidden(hidden)
17
+ }
18
+
19
+ @ReactMethod
20
+ @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
21
+ private fun setColor(color: Int, animated: Boolean) {
22
+ module.setColor(color, animated)
23
+ }
24
+
25
+ @ReactMethod
26
+ private fun setTranslucent(translucent: Boolean) {
27
+ module.setTranslucent(translucent)
28
+ }
29
+
30
+ @ReactMethod
31
+ private fun setStyle(style: String) {
32
+ module.setStyle(style)
33
+ }
34
+ }