Repository navigation
Expand file tree
/
Copy pathSafeAreaContextModule.kt
More file actions
45 lines (40 loc) · 1.59 KB
/
Copy pathSafeAreaContextModule.kt
File metadata and controls
45 lines (40 loc) · 1.59 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
35
36
37
38
39
40
41
42
43
44
45
package com.th3rdwave.safeareacontext
import android.view.View
import android.view.ViewGroup
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.module.annotations.ReactModule
@ReactModule(name = SafeAreaContextModule.NAME)
class SafeAreaContextModule(reactContext: ReactApplicationContext?) :
NativeSafeAreaContextSpec(reactContext) {
override fun getName(): String {
return NAME
}
public override fun getTypedExportedConstants(): Map<String, Any?> {
return mapOf("initialWindowMetrics" to getInitialWindowMetrics())
}
private fun getInitialWindowMetrics(): Map<String, Any>? {
val decorView = reactApplicationContext.currentActivity?.window?.decorView as ViewGroup?
val contentView = decorView?.findViewById<View>(android.R.id.content) ?: return null
val insets = getSafeAreaInsets(decorView)
val frame = getFrame(decorView, contentView)
val corners = getRoundedCorners(decorView)
return if (insets == null || frame == null) {
null
} else
mapOf(
"insets" to edgeInsetsToJavaMap(insets),
"verticalCornerAdaptedInsets" to
edgeInsetsToJavaMap(
getCornerAdaptedInsets(decorView, insets, corners, CornerAdaptation.VERTICAL)
),
"horizontalCornerAdaptedInsets" to
edgeInsetsToJavaMap(
getCornerAdaptedInsets(decorView, insets, corners, CornerAdaptation.HORIZONTAL)
),
"frame" to rectToJavaMap(frame),
)
}
companion object {
const val NAME = "RNCSafeAreaContext"
}
}