@lodev09/react-native-true-sheet 4.0.0-beta.17 → 4.0.0-beta.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -403,11 +403,22 @@ class TrueSheetView(private val reactContext: ThemedReactContext) :
|
|
|
403
403
|
val parentSheet = TrueSheetStackManager.getTopmostSheet()
|
|
404
404
|
val isFocusedViewWithinSheet = parentSheet?.viewController?.isFocusedViewWithinSheet() == true
|
|
405
405
|
val shouldDismissKeyboard = isFocusedViewWithinSheet || viewController.isDimmedAtDetentIndex(detentIndex)
|
|
406
|
-
if (KeyboardUtils.isKeyboardVisible(reactContext)
|
|
406
|
+
if (shouldDismissKeyboard && KeyboardUtils.isKeyboardVisible(reactContext)) {
|
|
407
407
|
viewController.saveFocusedView()
|
|
408
408
|
KeyboardUtils.dismiss(this) {
|
|
409
|
-
post {
|
|
409
|
+
post { presentSheet(detentIndex, animated, promiseCallback) }
|
|
410
410
|
}
|
|
411
|
+
// Blur like iOS so JS focus state stays in sync until restoreFocusedView() refocuses it
|
|
412
|
+
rootView.findFocus()?.clearFocus()
|
|
413
|
+
return
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
presentSheet(detentIndex, animated, promiseCallback)
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
private fun presentSheet(detentIndex: Int, animated: Boolean, promiseCallback: () -> Unit) {
|
|
420
|
+
if (viewController.isPresented) {
|
|
421
|
+
promiseCallback()
|
|
411
422
|
return
|
|
412
423
|
}
|
|
413
424
|
|
|
@@ -708,6 +708,7 @@ class TrueSheetViewController(private val reactContext: ThemedReactContext) :
|
|
|
708
708
|
if (isPresentAnimating) {
|
|
709
709
|
isPresentAnimating = false
|
|
710
710
|
finishPresent()
|
|
711
|
+
flushPendingSizeChange()
|
|
711
712
|
return
|
|
712
713
|
}
|
|
713
714
|
|
|
@@ -1233,7 +1234,7 @@ class TrueSheetViewController(private val reactContext: ThemedReactContext) :
|
|
|
1233
1234
|
if (!viewToFocus.isAttachedToWindow) return
|
|
1234
1235
|
if (viewToFocus.requestFocus()) {
|
|
1235
1236
|
viewToFocus.postDelayed({
|
|
1236
|
-
KeyboardUtils.show(viewToFocus)
|
|
1237
|
+
if (viewToFocus.isFocused) KeyboardUtils.show(viewToFocus)
|
|
1237
1238
|
}, 100)
|
|
1238
1239
|
}
|
|
1239
1240
|
}
|
|
@@ -3,6 +3,7 @@ package com.lodev09.truesheet.utils
|
|
|
3
3
|
import android.content.Context
|
|
4
4
|
import android.os.Build
|
|
5
5
|
import android.view.View
|
|
6
|
+
import android.view.WindowInsets
|
|
6
7
|
import android.view.inputmethod.InputMethodManager
|
|
7
8
|
import androidx.core.view.ViewCompat
|
|
8
9
|
import androidx.core.view.WindowInsetsAnimationCompat
|
|
@@ -36,10 +37,22 @@ object KeyboardUtils {
|
|
|
36
37
|
* Dismisses the soft keyboard with an optional callback when the animation completes.
|
|
37
38
|
*/
|
|
38
39
|
fun dismiss(view: View, onComplete: (() -> Unit)?) {
|
|
40
|
+
if (!isKeyboardVisible(view)) {
|
|
41
|
+
onComplete?.invoke()
|
|
42
|
+
return
|
|
43
|
+
}
|
|
44
|
+
|
|
39
45
|
val imm = view.context.getSystemService(Context.INPUT_METHOD_SERVICE) as? InputMethodManager
|
|
40
46
|
val focusedView = view.rootView.findFocus()
|
|
41
47
|
|
|
42
|
-
|
|
48
|
+
// A keyboard can stay up with nothing focused, e.g. a blur that lands after focus was restored,
|
|
49
|
+
// so hide it through the window instead of treating it as already hidden.
|
|
50
|
+
if (focusedView == null) {
|
|
51
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
|
52
|
+
view.windowInsetsController?.hide(WindowInsets.Type.ime())
|
|
53
|
+
} else {
|
|
54
|
+
imm?.hideSoftInputFromWindow(view.windowToken, 0)
|
|
55
|
+
}
|
|
43
56
|
onComplete?.invoke()
|
|
44
57
|
return
|
|
45
58
|
}
|
package/package.json
CHANGED