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
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<AvoidSoftInputView> {
override fun getName(): String {
return AvoidSoftInputView.NAME
}
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)
}
}

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<ReactViewGroup>? = null
override fun getDelegate() = delegate

override fun createViewInstance(reactContext: ThemedReactContext): AvoidSoftInputView {
return AvoidSoftInputView(reactContext)
Expand Down Expand Up @@ -74,18 +119,17 @@ class AvoidSoftInputViewManager :
}

override fun getExportedCustomDirectEventTypeConstants(): MutableMap<String, Any> {
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)
)
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -66,18 +67,17 @@ class AvoidSoftInputViewManager : ReactViewManager() {
}

override fun getExportedCustomDirectEventTypeConstants(): MutableMap<String, Any> {
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)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ - (void)willMoveToSuperview:(UIView *)newSuperview

- (void)prepareForRecycle
{
[super prepareForRecycle];
[self cleanupManager];
}

Expand Down
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.7.3"
},
"peerDependencies": {
"react": ">=18.2.0",
"react-native": ">=0.73.0"
"react": ">=18.3.1",
"react-native": ">=0.76.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 @@ -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

Expand Down
Loading