Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.swmansion.rnscreens

import android.util.Log
import android.view.View
import androidx.collection.ArraySet
import androidx.collection.arraySetOf
import androidx.core.view.OnApplyWindowInsetsListener
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
Expand All @@ -10,7 +12,7 @@ import com.facebook.react.bridge.ReactApplicationContext
import java.lang.ref.WeakReference

object InsetsObserverProxy : OnApplyWindowInsetsListener, LifecycleEventListener {
private val listeners: ArrayList<OnApplyWindowInsetsListener> = arrayListOf()
private val listeners: ArraySet<OnApplyWindowInsetsListener> = arraySetOf()
private var eventSourceView: WeakReference<View> = WeakReference(null)

// Please note semantics of this property. This is not `isRegistered`, because somebody, could unregister
Expand Down
17 changes: 17 additions & 0 deletions android/src/main/java/com/swmansion/rnscreens/Screen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,23 @@ class Screen(
}
}

override fun onAttachedToWindow() {
super.onAttachedToWindow()

// Insets handler for formSheet is added onResume but it is often
// too late if we use input with autofocus. It happens because onResume is called after
// finishing animator animation. onAttachedToWindow is called before onApplyWindowInsets
// so we use it to set the handler earlier.
// More details: https://github.com/software-mansion/react-native-screens/pull/2911
if (usesFormSheetPresentation()) {
(fragment as ScreenStackFragment?)?.sheetDelegate?.let {
InsetsObserverProxy.addOnApplyWindowInsetsListener(
it,
)
}
}
}

private fun dispatchSheetDetentChanged(
detentIndex: Int,
isStable: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class ScreenStackFragment :

private var dimmingDelegate: DimmingViewManager? = null

private var sheetDelegate: SheetDelegate? = null
internal var sheetDelegate: SheetDelegate? = null

@SuppressLint("ValidFragment")
constructor(screenView: Screen) : super(screenView)
Expand Down
Loading