Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions packages/react-native-avoid-softinput/android/build.gradle
Original file line number Diff line number Diff line change
@@ -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']
Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,60 +14,14 @@ import com.reactnativeavoidsoftinput.events.AvoidSoftInputShownEvent
@ReactModule(name = AvoidSoftInputView.NAME)
class AvoidSoftInputViewManager :
ReactViewManager(), AvoidSoftInputViewManagerInterface<AvoidSoftInputView> {
private val delegate =
object : BaseViewManagerDelegate<ReactViewGroup, AvoidSoftInputViewManager>(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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ReactViewGroup, AvoidSoftInputViewManager>(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)
}
}
Original file line number Diff line number Diff line change
@@ -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<ReactViewGroup, AvoidSoftInputViewManager>(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)
}
}
4 changes: 2 additions & 2 deletions packages/react-native-avoid-softinput/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading