-
-
Notifications
You must be signed in to change notification settings - Fork 643
Expand file tree
/
Copy pathInsetsKt.kt
More file actions
34 lines (30 loc) · 1.3 KB
/
InsetsKt.kt
File metadata and controls
34 lines (30 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package com.swmansion.rnscreens.utils
import android.view.View
import android.view.WindowInsets
import androidx.core.view.WindowInsetsCompat
typealias InsetsCompat = androidx.core.graphics.Insets
typealias InsetsPlatform = android.graphics.Insets // Available since SDK 29
/**
* Meaningful value is available only in case the receiver is attached to window.
* Otherwise returns zero-insets.
*
* By default this method relies on `rootWindowInsets` of a view. Set `sourceWindowInsets` to change that.
*/
internal fun View.resolveInsetsOrZero(
@WindowInsetsCompat.Type.InsetsType insetType: Int,
sourceWindowInsets: WindowInsets? = rootWindowInsets,
ignoreVisibility: Boolean = false,
): InsetsCompat {
if (sourceWindowInsets == null) {
return InsetsCompat.NONE
}
// We don't use root view-aware WindowInsetsCompat to make sure we get information about display
// cutout inset being consumed by one of the ancestor views. Refer to WindowInsetsCompat
// `Impl20` implementation of getInsetsForType (case Type.DISPLAY_CUTOUT).
val windowInsetsCompat = WindowInsetsCompat.toWindowInsetsCompat(sourceWindowInsets)
return if (!ignoreVisibility) {
windowInsetsCompat.getInsets(insetType)
} else {
windowInsetsCompat.getInsetsIgnoringVisibility(insetType)
}
}