diff --git a/packages/react-native-avoid-softinput/android/build.gradle b/packages/react-native-avoid-softinput/android/build.gradle index 8197972..ca07533 100644 --- a/packages/react-native-avoid-softinput/android/build.gradle +++ b/packages/react-native-avoid-softinput/android/build.gradle @@ -1,3 +1,5 @@ +import groovy.json.JsonSlurper + buildscript { // Buildscript is evaluated before everything else so we can't use getExtOrDefault def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : project.properties['AvoidSoftinput_kotlinVersion'] @@ -58,6 +60,31 @@ def resolveReactNativeDirectory() { ) } +def getReactNativeVersion() { + def reactNativeDirectory = resolveReactNativeDirectory() + def reactNativePackageJsonFile = file("${reactNativeDirectory}/package.json") + def packageSlurper = new JsonSlurper() + def reactNativePackageJson = packageSlurper.parseText(reactNativePackageJsonFile.text) + def reactNativeVersion = reactNativePackageJson.version + + return reactNativeVersion.tokenize('-')[0].tokenize('.') +} + +def getReactNativeMinorVersion() { + List reactNativeVersionSegments = getReactNativeVersion() + return reactNativeVersionSegments[1].toInteger() +} + +def getReactNativeVersionFlavor() { + int minorVersion = getReactNativeMinorVersion() + + if (minorVersion >= 81) { + return "reactnative81" + } else if (minorVersion >= 77) { + return "reactnative77" + } +} + if (isNewArchitectureEnabled()) { apply plugin: "com.facebook.react" @@ -140,6 +167,26 @@ android { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } + + flavorDimensions "RNAS-RNVersion" + productFlavors { + reactnative77 { + dimension "RNAS-RNVersion" + buildConfigField("int", "RNAS_RN_V_MINOR", "77") + } + reactnative81 { + dimension "RNAS-RNVersion" + buildConfigField("int", "RNAS_RN_V_MINOR", "81") + } + } + + def flavor = getReactNativeVersionFlavor() + variantFilter { variant -> + def names = variant.flavors*.name + if (!names.contains(flavor)) { + setIgnore(true) + } + } } repositories { 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 5678974..6d97225 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,6 @@ package com.reactnativeavoidsoftinput -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.annotations.ReactProp import com.facebook.react.viewmanagers.AvoidSoftInputViewManagerInterface @@ -16,60 +14,14 @@ import com.reactnativeavoidsoftinput.events.AvoidSoftInputShownEvent @ReactModule(name = AvoidSoftInputView.NAME) class AvoidSoftInputViewManager : ReactViewManager(), AvoidSoftInputViewManagerInterface { - 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) - } - } + private val delegate = AvoidSoftInputViewManagerDelegate(this) override fun getName() = AvoidSoftInputView.NAME override fun getDelegate() = delegate - override fun createViewInstance(reactContext: ThemedReactContext): AvoidSoftInputView { - return AvoidSoftInputView(reactContext) + override fun createViewInstance(context: ThemedReactContext): AvoidSoftInputView { + return AvoidSoftInputView(context) } override fun prepareToRecycleView( diff --git a/packages/react-native-avoid-softinput/android/src/reactnative77/java/com/reactnativeavoidsoftinput/AvoidSoftInputViewDelegate.kt b/packages/react-native-avoid-softinput/android/src/reactnative77/java/com/reactnativeavoidsoftinput/AvoidSoftInputViewDelegate.kt new file mode 100644 index 0000000..7847001 --- /dev/null +++ b/packages/react-native-avoid-softinput/android/src/reactnative77/java/com/reactnativeavoidsoftinput/AvoidSoftInputViewDelegate.kt @@ -0,0 +1,46 @@ +package com.reactnativeavoidsoftinput + +import com.facebook.react.bridge.ReadableArray +import com.facebook.react.uimanager.BaseViewManagerDelegate +import com.facebook.react.views.view.ReactViewGroup + +class AvoidSoftInputViewManagerDelegate(viewManager: AvoidSoftInputViewManager) : + BaseViewManagerDelegate(viewManager) { + 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) + } +} diff --git a/packages/react-native-avoid-softinput/android/src/reactnative81/java/com/reactnativeavoidsoftinput/AvoidSoftInputViewDelegate.kt b/packages/react-native-avoid-softinput/android/src/reactnative81/java/com/reactnativeavoidsoftinput/AvoidSoftInputViewDelegate.kt new file mode 100644 index 0000000..25e938f --- /dev/null +++ b/packages/react-native-avoid-softinput/android/src/reactnative81/java/com/reactnativeavoidsoftinput/AvoidSoftInputViewDelegate.kt @@ -0,0 +1,46 @@ +package com.reactnativeavoidsoftinput + +import com.facebook.react.bridge.ReadableArray +import com.facebook.react.uimanager.BaseViewManagerDelegate +import com.facebook.react.views.view.ReactViewGroup + +class AvoidSoftInputViewManagerDelegate(viewManager: AvoidSoftInputViewManager) : + BaseViewManagerDelegate(viewManager) { + 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) + } +} diff --git a/packages/react-native-avoid-softinput/package.json b/packages/react-native-avoid-softinput/package.json index bff01d2..1d8f27f 100644 --- a/packages/react-native-avoid-softinput/package.json +++ b/packages/react-native-avoid-softinput/package.json @@ -68,8 +68,8 @@ "typescript": "5.8.3" }, "peerDependencies": { - "react": ">=18.3.1", - "react-native": ">=0.76.0" + "react": ">=19.0.0", + "react-native": ">=0.78.0" }, "release-it": { "git": { diff --git a/yarn.lock b/yarn.lock index 7d4555f..cba4401 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11320,8 +11320,8 @@ __metadata: release-it: "npm:19.0.3" typescript: "npm:5.8.3" peerDependencies: - react: ">=18.3.1" - react-native: ">=0.76.0" + react: ">=19.0.0" + react-native: ">=0.78.0" languageName: unknown linkType: soft