@lodev09/react-native-true-sheet 0.9.5 → 0.9.6
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.
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetBehavior.kt +1 -1
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetDialog.kt +6 -2
- package/android/src/main/java/com/lodev09/truesheet/core/KeyboardManager.kt +11 -6
- package/android/src/main/java/com/lodev09/truesheet/core/Utils.kt +22 -4
- package/package.json +1 -1
|
@@ -135,7 +135,7 @@ class TrueSheetBehavior(private val reactContext: ReactContext) : BottomSheetBeh
|
|
|
135
135
|
*/
|
|
136
136
|
fun configure() {
|
|
137
137
|
// Update the usable sheet height
|
|
138
|
-
maxScreenHeight = Utils.
|
|
138
|
+
maxScreenHeight = Utils.screenHeight(reactContext)
|
|
139
139
|
|
|
140
140
|
var contentHeight = 0
|
|
141
141
|
|
|
@@ -62,8 +62,12 @@ class TrueSheetDialog(
|
|
|
62
62
|
*/
|
|
63
63
|
fun registerKeyboardManager() {
|
|
64
64
|
keyboardManager.registerKeyboardListener(object : KeyboardManager.OnKeyboardListener {
|
|
65
|
-
override fun onKeyboardStateChange(isVisible: Boolean) {
|
|
66
|
-
|
|
65
|
+
override fun onKeyboardStateChange(isVisible: Boolean, visibleHeight: Int?) {
|
|
66
|
+
when (isVisible) {
|
|
67
|
+
true -> behavior.maxScreenHeight = visibleHeight ?: 0
|
|
68
|
+
else -> behavior.maxScreenHeight = Utils.screenHeight(reactContext)
|
|
69
|
+
}
|
|
70
|
+
|
|
67
71
|
behavior.footerView?.apply {
|
|
68
72
|
y = (behavior.maxScreenHeight - (sheetView.top ?: 0) - height).toFloat()
|
|
69
73
|
}
|
|
@@ -8,15 +8,20 @@ import com.facebook.react.bridge.ReactContext
|
|
|
8
8
|
|
|
9
9
|
class KeyboardManager(reactContext: ReactContext) {
|
|
10
10
|
interface OnKeyboardListener {
|
|
11
|
-
fun onKeyboardStateChange(isVisible: Boolean)
|
|
11
|
+
fun onKeyboardStateChange(isVisible: Boolean, visibleHeight: Int?)
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
private var
|
|
14
|
+
private var contentView: View? = null
|
|
15
15
|
private var onGlobalLayoutListener: OnGlobalLayoutListener? = null
|
|
16
16
|
private var isKeyboardVisible = false
|
|
17
17
|
|
|
18
|
+
init {
|
|
19
|
+
val activity = reactContext.currentActivity
|
|
20
|
+
contentView = activity?.findViewById(android.R.id.content)
|
|
21
|
+
}
|
|
22
|
+
|
|
18
23
|
fun registerKeyboardListener(listener: OnKeyboardListener?) {
|
|
19
|
-
|
|
24
|
+
contentView?.apply {
|
|
20
25
|
unregisterKeyboardListener()
|
|
21
26
|
|
|
22
27
|
onGlobalLayoutListener = object : OnGlobalLayoutListener {
|
|
@@ -28,13 +33,13 @@ class KeyboardManager(reactContext: ReactContext) {
|
|
|
28
33
|
// Will ask InputMethodManager.isAcceptingText() to detect if keyboard appeared or not.
|
|
29
34
|
val inputManager = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
|
30
35
|
if (height != previousHeight && inputManager.isAcceptingText()) {
|
|
31
|
-
listener?.onKeyboardStateChange(true)
|
|
36
|
+
listener?.onKeyboardStateChange(true, height)
|
|
32
37
|
|
|
33
38
|
previousHeight = height
|
|
34
39
|
isKeyboardVisible = true
|
|
35
40
|
}
|
|
36
41
|
} else if (isKeyboardVisible) {
|
|
37
|
-
listener?.onKeyboardStateChange(false)
|
|
42
|
+
listener?.onKeyboardStateChange(false, null)
|
|
38
43
|
previousHeight = 0
|
|
39
44
|
isKeyboardVisible = false
|
|
40
45
|
}
|
|
@@ -47,7 +52,7 @@ class KeyboardManager(reactContext: ReactContext) {
|
|
|
47
52
|
|
|
48
53
|
fun unregisterKeyboardListener() {
|
|
49
54
|
onGlobalLayoutListener?.let {
|
|
50
|
-
|
|
55
|
+
contentView?.getViewTreeObserver()?.removeOnGlobalLayoutListener(onGlobalLayoutListener)
|
|
51
56
|
}
|
|
52
57
|
}
|
|
53
58
|
}
|
|
@@ -1,14 +1,32 @@
|
|
|
1
1
|
package com.lodev09.truesheet.core
|
|
2
2
|
|
|
3
|
-
import android.
|
|
3
|
+
import android.annotation.SuppressLint
|
|
4
|
+
import android.util.DisplayMetrics
|
|
4
5
|
import com.facebook.react.bridge.Promise
|
|
5
6
|
import com.facebook.react.bridge.ReactContext
|
|
6
7
|
import com.facebook.react.uimanager.PixelUtil
|
|
7
8
|
|
|
8
9
|
object Utils {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
@SuppressLint("DiscouragedApi", "InternalInsetResource")
|
|
11
|
+
fun screenHeight(reactContext: ReactContext): Int {
|
|
12
|
+
val activity = reactContext.currentActivity ?: return 0
|
|
13
|
+
|
|
14
|
+
// Get the screen metrics
|
|
15
|
+
val displayMetrics = DisplayMetrics()
|
|
16
|
+
activity.windowManager.defaultDisplay.getMetrics(displayMetrics)
|
|
17
|
+
val screenHeight = displayMetrics.heightPixels
|
|
18
|
+
|
|
19
|
+
val resources = activity.resources
|
|
20
|
+
|
|
21
|
+
// Calculate status bar height
|
|
22
|
+
var statusBarHeight = 0
|
|
23
|
+
val resourceId: Int = resources.getIdentifier("status_bar_height", "dimen", "android")
|
|
24
|
+
if (resourceId > 0) {
|
|
25
|
+
statusBarHeight = resources.getDimensionPixelSize(resourceId)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Calculate max usable height
|
|
29
|
+
return screenHeight - statusBarHeight
|
|
12
30
|
}
|
|
13
31
|
|
|
14
32
|
fun toDIP(value: Int): Float = PixelUtil.toDIPFromPixel(value.toFloat())
|