-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathImageUtils.kt
More file actions
27 lines (22 loc) · 999 Bytes
/
ImageUtils.kt
File metadata and controls
27 lines (22 loc) · 999 Bytes
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
package com.reactnativenavigation.utils
import android.view.View
import android.view.ViewParent
import com.reactnativenavigation.react.ReactView
import com.reactnativenavigation.viewcontrollers.viewcontroller.overlay.OverlayLayout
fun areDimensionsWithInheritedScaleEqual(a: View, b: View): Boolean {
val (aScaleX, aScaleY) = computeInheritedScale(a)
val (bScaleX, bScaleY) = computeInheritedScale(b)
return a.width * aScaleX == b.width * bScaleX &&
a.height * aScaleY == b.height * bScaleY
}
fun computeInheritedScale(v: View): Scale {
return computeInheritedScale(v.parent, Scale(x = v.scaleX, y = v.scaleY))
}
private fun computeInheritedScale(v: ViewParent, childrenScale: Scale): Scale {
return if (v is ReactView || v is OverlayLayout || v.parent == null) {
childrenScale
} else {
computeInheritedScale(v.parent, Scale(x = childrenScale.x * v.scaleX, y = childrenScale.y * v.scaleY))
}
}
data class Scale(val x: Float, val y: Float)