From 3b87663b9f56f46f04cc61ab65578ac405e5a489 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20M=C4=99drek?= Date: Sat, 28 Jun 2025 12:26:26 +0200 Subject: [PATCH] fix: incompatibilities or deprecations with new architecture code --- .../AvoidSoftInputPackage.kt | 4 +- .../AvoidSoftInputViewManager.kt | 86 ++++++++++++++----- .../AvoidSoftInputViewManager.kt | 26 +++--- .../ios/AvoidSoftInputViewComponentView.mm | 1 + .../react-native-avoid-softinput/package.json | 4 +- yarn.lock | 4 +- 6 files changed, 85 insertions(+), 40 deletions(-) diff --git a/packages/react-native-avoid-softinput/android/src/main/java/com/reactnativeavoidsoftinput/AvoidSoftInputPackage.kt b/packages/react-native-avoid-softinput/android/src/main/java/com/reactnativeavoidsoftinput/AvoidSoftInputPackage.kt index 6c2b066..23b6417 100644 --- a/packages/react-native-avoid-softinput/android/src/main/java/com/reactnativeavoidsoftinput/AvoidSoftInputPackage.kt +++ b/packages/react-native-avoid-softinput/android/src/main/java/com/reactnativeavoidsoftinput/AvoidSoftInputPackage.kt @@ -1,6 +1,6 @@ package com.reactnativeavoidsoftinput -import com.facebook.react.TurboReactPackage +import com.facebook.react.BaseReactPackage import com.facebook.react.bridge.NativeModule import com.facebook.react.bridge.ReactApplicationContext import com.facebook.react.module.annotations.ReactModule @@ -9,7 +9,7 @@ import com.facebook.react.module.model.ReactModuleInfoProvider import com.facebook.react.turbomodule.core.interfaces.TurboModule import com.facebook.react.uimanager.ViewManager -class AvoidSoftInputPackage : TurboReactPackage() { +class AvoidSoftInputPackage : BaseReactPackage() { override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? { return when (name) { AvoidSoftInputModuleImpl.NAME -> AvoidSoftInputModule(reactContext) diff --git a/packages/react-native-avoid-softinput/android/src/newarch/java/com/reactnativeavoidsoftinput/AvoidSoftInputViewManager.kt b/packages/react-native-avoid-softinput/android/src/newarch/java/com/reactnativeavoidsoftinput/AvoidSoftInputViewManager.kt index e7453a5..5678974 100644 --- a/packages/react-native-avoid-softinput/android/src/newarch/java/com/reactnativeavoidsoftinput/AvoidSoftInputViewManager.kt +++ b/packages/react-native-avoid-softinput/android/src/newarch/java/com/reactnativeavoidsoftinput/AvoidSoftInputViewManager.kt @@ -1,8 +1,9 @@ package com.reactnativeavoidsoftinput -import com.facebook.react.common.MapBuilder +import com.facebook.react.bridge.ReadableArray +import com.facebook.react.module.annotations.ReactModule +import com.facebook.react.uimanager.BaseViewManagerDelegate import com.facebook.react.uimanager.ThemedReactContext -import com.facebook.react.uimanager.ViewManagerDelegate import com.facebook.react.uimanager.annotations.ReactProp import com.facebook.react.viewmanagers.AvoidSoftInputViewManagerInterface import com.facebook.react.views.view.ReactViewGroup @@ -12,16 +13,60 @@ import com.reactnativeavoidsoftinput.events.AvoidSoftInputHeightChangedEvent import com.reactnativeavoidsoftinput.events.AvoidSoftInputHiddenEvent import com.reactnativeavoidsoftinput.events.AvoidSoftInputShownEvent +@ReactModule(name = AvoidSoftInputView.NAME) class AvoidSoftInputViewManager : ReactViewManager(), AvoidSoftInputViewManagerInterface { - override fun getName(): String { - return AvoidSoftInputView.NAME - } + private val delegate = + object : BaseViewManagerDelegate(this) { + override fun setProperty(view: ReactViewGroup, propName: String, value: Any?) { + when (propName) { + "avoidOffset" -> + mViewManager.setAvoidOffset( + view as AvoidSoftInputView, + (value as Double?)?.toFloat() ?: 0f + ) + "easing" -> mViewManager.setEasing(view as AvoidSoftInputView, value as String?) + "enabled" -> + mViewManager.setEnabled( + view as AvoidSoftInputView, + value as Boolean? ?: true + ) + "hideAnimationDelay" -> + mViewManager.setHideAnimationDelay( + view as AvoidSoftInputView, + (value as Double?)?.toInt() ?: 300 + ) + "hideAnimationDuration" -> + mViewManager.setHideAnimationDuration( + view as AvoidSoftInputView, + (value as Double?)?.toInt() ?: 220 + ) + "showAnimationDelay" -> + mViewManager.setShowAnimationDelay( + view as AvoidSoftInputView, + (value as Double?)?.toInt() ?: 0 + ) + "showAnimationDuration" -> + mViewManager.setShowAnimationDuration( + view as AvoidSoftInputView, + (value as Double?)?.toInt() ?: 660 + ) + else -> super.setProperty(view, propName, value) + } + } + + override fun receiveCommand( + view: ReactViewGroup, + commandName: String, + args: ReadableArray? + ) { + super.receiveCommand(view, commandName, args) + } + } + + override fun getName() = AvoidSoftInputView.NAME - // ReactViewManager is not generic, so it doesn't let to pass any view that extends - // ReactViewGroup - // However, ReactViewManager does not use any delegate, so we can skip it and handle props here - override fun getDelegate(): ViewManagerDelegate? = null + override fun getDelegate() = delegate override fun createViewInstance(reactContext: ThemedReactContext): AvoidSoftInputView { return AvoidSoftInputView(reactContext) @@ -74,18 +119,17 @@ class AvoidSoftInputViewManager : } override fun getExportedCustomDirectEventTypeConstants(): MutableMap { - return MapBuilder.of( - AvoidSoftInputAppliedOffsetChangedEvent.NAME, - MapBuilder.of( - "registrationName", - AvoidSoftInputView.ON_SOFT_INPUT_APPLIED_OFFSET_CHANGE - ), - AvoidSoftInputHeightChangedEvent.NAME, - MapBuilder.of("registrationName", AvoidSoftInputView.ON_SOFT_INPUT_HEIGHT_CHANGE), - AvoidSoftInputHiddenEvent.NAME, - MapBuilder.of("registrationName", AvoidSoftInputView.ON_SOFT_INPUT_HIDDEN), - AvoidSoftInputShownEvent.NAME, - MapBuilder.of("registrationName", AvoidSoftInputView.ON_SOFT_INPUT_SHOWN) + return hashMapOf( + AvoidSoftInputAppliedOffsetChangedEvent.NAME to + hashMapOf( + "registrationName" to AvoidSoftInputView.ON_SOFT_INPUT_APPLIED_OFFSET_CHANGE + ), + AvoidSoftInputHeightChangedEvent.NAME to + hashMapOf("registrationName" to AvoidSoftInputView.ON_SOFT_INPUT_HEIGHT_CHANGE), + AvoidSoftInputHiddenEvent.NAME to + hashMapOf("registrationName" to AvoidSoftInputView.ON_SOFT_INPUT_HIDDEN), + AvoidSoftInputShownEvent.NAME to + hashMapOf("registrationName" to AvoidSoftInputView.ON_SOFT_INPUT_SHOWN) ) } } diff --git a/packages/react-native-avoid-softinput/android/src/oldarch/java/com/reactnativeavoidsoftinput/AvoidSoftInputViewManager.kt b/packages/react-native-avoid-softinput/android/src/oldarch/java/com/reactnativeavoidsoftinput/AvoidSoftInputViewManager.kt index 6d8f5ff..0176cf1 100644 --- a/packages/react-native-avoid-softinput/android/src/oldarch/java/com/reactnativeavoidsoftinput/AvoidSoftInputViewManager.kt +++ b/packages/react-native-avoid-softinput/android/src/oldarch/java/com/reactnativeavoidsoftinput/AvoidSoftInputViewManager.kt @@ -1,6 +1,6 @@ package com.reactnativeavoidsoftinput -import com.facebook.react.common.MapBuilder +import com.facebook.react.module.annotations.ReactModule import com.facebook.react.uimanager.ThemedReactContext import com.facebook.react.uimanager.annotations.ReactProp import com.facebook.react.views.view.ReactViewGroup @@ -10,6 +10,7 @@ import com.reactnativeavoidsoftinput.events.AvoidSoftInputHeightChangedEvent import com.reactnativeavoidsoftinput.events.AvoidSoftInputHiddenEvent import com.reactnativeavoidsoftinput.events.AvoidSoftInputShownEvent +@ReactModule(name = AvoidSoftInputView.NAME) class AvoidSoftInputViewManager : ReactViewManager() { override fun getName(): String { return AvoidSoftInputView.NAME @@ -66,18 +67,17 @@ class AvoidSoftInputViewManager : ReactViewManager() { } override fun getExportedCustomDirectEventTypeConstants(): MutableMap { - return MapBuilder.of( - AvoidSoftInputAppliedOffsetChangedEvent.NAME, - MapBuilder.of( - "registrationName", - AvoidSoftInputView.ON_SOFT_INPUT_APPLIED_OFFSET_CHANGE - ), - AvoidSoftInputHeightChangedEvent.NAME, - MapBuilder.of("registrationName", AvoidSoftInputView.ON_SOFT_INPUT_HEIGHT_CHANGE), - AvoidSoftInputHiddenEvent.NAME, - MapBuilder.of("registrationName", AvoidSoftInputView.ON_SOFT_INPUT_HIDDEN), - AvoidSoftInputShownEvent.NAME, - MapBuilder.of("registrationName", AvoidSoftInputView.ON_SOFT_INPUT_SHOWN) + return hashMapOf( + AvoidSoftInputAppliedOffsetChangedEvent.NAME to + hashMapOf( + "registrationName" to AvoidSoftInputView.ON_SOFT_INPUT_APPLIED_OFFSET_CHANGE + ), + AvoidSoftInputHeightChangedEvent.NAME to + hashMapOf("registrationName" to AvoidSoftInputView.ON_SOFT_INPUT_HEIGHT_CHANGE), + AvoidSoftInputHiddenEvent.NAME to + hashMapOf("registrationName" to AvoidSoftInputView.ON_SOFT_INPUT_HIDDEN), + AvoidSoftInputShownEvent.NAME to + hashMapOf("registrationName" to AvoidSoftInputView.ON_SOFT_INPUT_SHOWN) ) } } diff --git a/packages/react-native-avoid-softinput/ios/AvoidSoftInputViewComponentView.mm b/packages/react-native-avoid-softinput/ios/AvoidSoftInputViewComponentView.mm index 54e854b..85f895d 100644 --- a/packages/react-native-avoid-softinput/ios/AvoidSoftInputViewComponentView.mm +++ b/packages/react-native-avoid-softinput/ios/AvoidSoftInputViewComponentView.mm @@ -74,6 +74,7 @@ - (void)willMoveToSuperview:(UIView *)newSuperview - (void)prepareForRecycle { + [super prepareForRecycle]; [self cleanupManager]; } diff --git a/packages/react-native-avoid-softinput/package.json b/packages/react-native-avoid-softinput/package.json index dbdb86e..85713d2 100644 --- a/packages/react-native-avoid-softinput/package.json +++ b/packages/react-native-avoid-softinput/package.json @@ -68,8 +68,8 @@ "typescript": "5.7.3" }, "peerDependencies": { - "react": ">=18.2.0", - "react-native": ">=0.73.0" + "react": ">=18.3.1", + "react-native": ">=0.76.0" }, "release-it": { "git": { diff --git a/yarn.lock b/yarn.lock index 8dbaee2..6294285 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10611,8 +10611,8 @@ __metadata: release-it: "npm:17.6.0" typescript: "npm:5.7.3" peerDependencies: - react: ">=18.2.0" - react-native: ">=0.73.0" + react: ">=18.3.1" + react-native: ">=0.76.0" languageName: unknown linkType: soft