Skip to content

Commit 704d632

Browse files
committed
fix(#238): build issues on RN81, drop support for RN < 78
1 parent c41cc77 commit 704d632

6 files changed

Lines changed: 146 additions & 55 deletions

File tree

packages/react-native-avoid-softinput/android/build.gradle

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import groovy.json.JsonSlurper
2+
13
buildscript {
24
// Buildscript is evaluated before everything else so we can't use getExtOrDefault
35
def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : project.properties['AvoidSoftinput_kotlinVersion']
@@ -58,6 +60,31 @@ def resolveReactNativeDirectory() {
5860
)
5961
}
6062

63+
def getReactNativeVersion() {
64+
def reactNativeDirectory = resolveReactNativeDirectory()
65+
def reactNativePackageJsonFile = file("${reactNativeDirectory}/package.json")
66+
def packageSlurper = new JsonSlurper()
67+
def reactNativePackageJson = packageSlurper.parseText(reactNativePackageJsonFile.text)
68+
def reactNativeVersion = reactNativePackageJson.version
69+
70+
return reactNativeVersion.tokenize('-')[0].tokenize('.')
71+
}
72+
73+
def getReactNativeMinorVersion() {
74+
List reactNativeVersionSegments = getReactNativeVersion()
75+
return reactNativeVersionSegments[1].toInteger()
76+
}
77+
78+
def getReactNativeVersionFlavor() {
79+
int minorVersion = getReactNativeMinorVersion()
80+
81+
if (minorVersion >= 81) {
82+
return "reactnative81"
83+
} else if (minorVersion >= 77) {
84+
return "reactnative77"
85+
}
86+
}
87+
6188
if (isNewArchitectureEnabled()) {
6289
apply plugin: "com.facebook.react"
6390

@@ -140,6 +167,26 @@ android {
140167
sourceCompatibility JavaVersion.VERSION_1_8
141168
targetCompatibility JavaVersion.VERSION_1_8
142169
}
170+
171+
flavorDimensions "RNAS-RNVersion"
172+
productFlavors {
173+
reactnative77 {
174+
dimension "RNAS-RNVersion"
175+
buildConfigField("int", "RNAS_RN_V_MINOR", "77")
176+
}
177+
reactnative81 {
178+
dimension "RNAS-RNVersion"
179+
buildConfigField("int", "RNAS_RN_V_MINOR", "81")
180+
}
181+
}
182+
183+
def flavor = getReactNativeVersionFlavor()
184+
variantFilter { variant ->
185+
def names = variant.flavors*.name
186+
if (!names.contains(flavor)) {
187+
setIgnore(true)
188+
}
189+
}
143190
}
144191

145192
repositories {

packages/react-native-avoid-softinput/android/src/newarch/java/com/reactnativeavoidsoftinput/AvoidSoftInputViewManager.kt

Lines changed: 3 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package com.reactnativeavoidsoftinput
22

3-
import com.facebook.react.bridge.ReadableArray
43
import com.facebook.react.module.annotations.ReactModule
5-
import com.facebook.react.uimanager.BaseViewManagerDelegate
64
import com.facebook.react.uimanager.ThemedReactContext
75
import com.facebook.react.uimanager.annotations.ReactProp
86
import com.facebook.react.viewmanagers.AvoidSoftInputViewManagerInterface
@@ -16,60 +14,14 @@ import com.reactnativeavoidsoftinput.events.AvoidSoftInputShownEvent
1614
@ReactModule(name = AvoidSoftInputView.NAME)
1715
class AvoidSoftInputViewManager :
1816
ReactViewManager(), AvoidSoftInputViewManagerInterface<AvoidSoftInputView> {
19-
private val delegate =
20-
object : BaseViewManagerDelegate<ReactViewGroup, AvoidSoftInputViewManager>(this) {
21-
override fun setProperty(view: ReactViewGroup, propName: String, value: Any?) {
22-
when (propName) {
23-
"avoidOffset" ->
24-
mViewManager.setAvoidOffset(
25-
view as AvoidSoftInputView,
26-
(value as Double?)?.toFloat() ?: 0f
27-
)
28-
"easing" -> mViewManager.setEasing(view as AvoidSoftInputView, value as String?)
29-
"enabled" ->
30-
mViewManager.setEnabled(
31-
view as AvoidSoftInputView,
32-
value as Boolean? ?: true
33-
)
34-
"hideAnimationDelay" ->
35-
mViewManager.setHideAnimationDelay(
36-
view as AvoidSoftInputView,
37-
(value as Double?)?.toInt() ?: 300
38-
)
39-
"hideAnimationDuration" ->
40-
mViewManager.setHideAnimationDuration(
41-
view as AvoidSoftInputView,
42-
(value as Double?)?.toInt() ?: 220
43-
)
44-
"showAnimationDelay" ->
45-
mViewManager.setShowAnimationDelay(
46-
view as AvoidSoftInputView,
47-
(value as Double?)?.toInt() ?: 0
48-
)
49-
"showAnimationDuration" ->
50-
mViewManager.setShowAnimationDuration(
51-
view as AvoidSoftInputView,
52-
(value as Double?)?.toInt() ?: 660
53-
)
54-
else -> super.setProperty(view, propName, value)
55-
}
56-
}
57-
58-
override fun receiveCommand(
59-
view: ReactViewGroup,
60-
commandName: String,
61-
args: ReadableArray?
62-
) {
63-
super.receiveCommand(view, commandName, args)
64-
}
65-
}
17+
private val delegate = AvoidSoftInputViewManagerDelegate(this)
6618

6719
override fun getName() = AvoidSoftInputView.NAME
6820

6921
override fun getDelegate() = delegate
7022

71-
override fun createViewInstance(reactContext: ThemedReactContext): AvoidSoftInputView {
72-
return AvoidSoftInputView(reactContext)
23+
override fun createViewInstance(context: ThemedReactContext): AvoidSoftInputView {
24+
return AvoidSoftInputView(context)
7325
}
7426

7527
override fun prepareToRecycleView(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.reactnativeavoidsoftinput
2+
3+
import com.facebook.react.bridge.ReadableArray
4+
import com.facebook.react.uimanager.BaseViewManagerDelegate
5+
import com.facebook.react.views.view.ReactViewGroup
6+
7+
class AvoidSoftInputViewManagerDelegate(viewManager: AvoidSoftInputViewManager) :
8+
BaseViewManagerDelegate<ReactViewGroup, AvoidSoftInputViewManager>(viewManager) {
9+
override fun setProperty(view: ReactViewGroup, propName: String, value: Any?) {
10+
when (propName) {
11+
"avoidOffset" ->
12+
mViewManager.setAvoidOffset(
13+
view as AvoidSoftInputView,
14+
(value as Double?)?.toFloat() ?: 0f
15+
)
16+
"easing" -> mViewManager.setEasing(view as AvoidSoftInputView, value as String?)
17+
"enabled" ->
18+
mViewManager.setEnabled(view as AvoidSoftInputView, value as Boolean? ?: true)
19+
"hideAnimationDelay" ->
20+
mViewManager.setHideAnimationDelay(
21+
view as AvoidSoftInputView,
22+
(value as Double?)?.toInt() ?: 300
23+
)
24+
"hideAnimationDuration" ->
25+
mViewManager.setHideAnimationDuration(
26+
view as AvoidSoftInputView,
27+
(value as Double?)?.toInt() ?: 220
28+
)
29+
"showAnimationDelay" ->
30+
mViewManager.setShowAnimationDelay(
31+
view as AvoidSoftInputView,
32+
(value as Double?)?.toInt() ?: 0
33+
)
34+
"showAnimationDuration" ->
35+
mViewManager.setShowAnimationDuration(
36+
view as AvoidSoftInputView,
37+
(value as Double?)?.toInt() ?: 660
38+
)
39+
else -> super.setProperty(view, propName, value)
40+
}
41+
}
42+
43+
override fun receiveCommand(view: ReactViewGroup, commandName: String, args: ReadableArray?) {
44+
super.receiveCommand(view, commandName, args)
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.reactnativeavoidsoftinput
2+
3+
import com.facebook.react.bridge.ReadableArray
4+
import com.facebook.react.uimanager.BaseViewManagerDelegate
5+
import com.facebook.react.views.view.ReactViewGroup
6+
7+
class AvoidSoftInputViewManagerDelegate(viewManager: AvoidSoftInputViewManager) :
8+
BaseViewManagerDelegate<ReactViewGroup, AvoidSoftInputViewManager>(viewManager) {
9+
override fun setProperty(view: ReactViewGroup, propName: String, value: Any?) {
10+
when (propName) {
11+
"avoidOffset" ->
12+
mViewManager.setAvoidOffset(
13+
view as AvoidSoftInputView,
14+
(value as Double?)?.toFloat() ?: 0f
15+
)
16+
"easing" -> mViewManager.setEasing(view as AvoidSoftInputView, value as String?)
17+
"enabled" ->
18+
mViewManager.setEnabled(view as AvoidSoftInputView, value as Boolean? ?: true)
19+
"hideAnimationDelay" ->
20+
mViewManager.setHideAnimationDelay(
21+
view as AvoidSoftInputView,
22+
(value as Double?)?.toInt() ?: 300
23+
)
24+
"hideAnimationDuration" ->
25+
mViewManager.setHideAnimationDuration(
26+
view as AvoidSoftInputView,
27+
(value as Double?)?.toInt() ?: 220
28+
)
29+
"showAnimationDelay" ->
30+
mViewManager.setShowAnimationDelay(
31+
view as AvoidSoftInputView,
32+
(value as Double?)?.toInt() ?: 0
33+
)
34+
"showAnimationDuration" ->
35+
mViewManager.setShowAnimationDuration(
36+
view as AvoidSoftInputView,
37+
(value as Double?)?.toInt() ?: 660
38+
)
39+
else -> super.setProperty(view, propName, value)
40+
}
41+
}
42+
43+
override fun receiveCommand(view: ReactViewGroup, commandName: String, args: ReadableArray) {
44+
super.receiveCommand(view, commandName, args)
45+
}
46+
}

packages/react-native-avoid-softinput/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@
6868
"typescript": "5.8.3"
6969
},
7070
"peerDependencies": {
71-
"react": ">=18.3.1",
72-
"react-native": ">=0.76.0"
71+
"react": ">=19.0.0",
72+
"react-native": ">=0.78.0"
7373
},
7474
"release-it": {
7575
"git": {

yarn.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11320,8 +11320,8 @@ __metadata:
1132011320
release-it: "npm:19.0.3"
1132111321
typescript: "npm:5.8.3"
1132211322
peerDependencies:
11323-
react: ">=18.3.1"
11324-
react-native: ">=0.76.0"
11323+
react: ">=19.0.0"
11324+
react-native: ">=0.78.0"
1132511325
languageName: unknown
1132611326
linkType: soft
1132711327

0 commit comments

Comments
 (0)