Fix webtoon reader leaving a gap after zooming in a resized window
The reader measured its height once, so zooming after a split screen or window resize pinned it to the old size until the reader was reopened. Closes #1721
This commit is contained in:
+10
-9
@@ -7,6 +7,7 @@ import android.util.AttributeSet
|
|||||||
import android.view.HapticFeedbackConstants
|
import android.view.HapticFeedbackConstants
|
||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
import android.view.ViewConfiguration
|
import android.view.ViewConfiguration
|
||||||
|
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
|
||||||
import android.view.animation.DecelerateInterpolator
|
import android.view.animation.DecelerateInterpolator
|
||||||
import androidx.core.animation.doOnEnd
|
import androidx.core.animation.doOnEnd
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
@@ -30,7 +31,6 @@ class WebtoonRecyclerView @JvmOverloads constructor(
|
|||||||
private var halfHeight = 0
|
private var halfHeight = 0
|
||||||
var originalHeight = 0
|
var originalHeight = 0
|
||||||
private set
|
private set
|
||||||
private var heightSet = false
|
|
||||||
private var firstVisibleItemPosition = 0
|
private var firstVisibleItemPosition = 0
|
||||||
private var lastVisibleItemPosition = 0
|
private var lastVisibleItemPosition = 0
|
||||||
private var currentScale = DEFAULT_RATE
|
private var currentScale = DEFAULT_RATE
|
||||||
@@ -58,9 +58,9 @@ class WebtoonRecyclerView @JvmOverloads constructor(
|
|||||||
override fun onMeasure(widthSpec: Int, heightSpec: Int) {
|
override fun onMeasure(widthSpec: Int, heightSpec: Int) {
|
||||||
halfWidth = MeasureSpec.getSize(widthSpec) / 2
|
halfWidth = MeasureSpec.getSize(widthSpec) / 2
|
||||||
halfHeight = MeasureSpec.getSize(heightSpec) / 2
|
halfHeight = MeasureSpec.getSize(heightSpec) / 2
|
||||||
if (!heightSet) {
|
// While zoomed out the height is set by zooming, not by the window
|
||||||
|
if (layoutParams?.height == MATCH_PARENT) {
|
||||||
originalHeight = MeasureSpec.getSize(heightSpec)
|
originalHeight = MeasureSpec.getSize(heightSpec)
|
||||||
heightSet = true
|
|
||||||
}
|
}
|
||||||
super.onMeasure(widthSpec, heightSpec)
|
super.onMeasure(widthSpec, heightSpec)
|
||||||
}
|
}
|
||||||
@@ -193,12 +193,13 @@ class WebtoonRecyclerView @JvmOverloads constructor(
|
|||||||
|
|
||||||
setScaleRate(currentScale)
|
setScaleRate(currentScale)
|
||||||
|
|
||||||
layoutParams.height = if (currentScale < 1) {
|
if (currentScale < 1) {
|
||||||
(originalHeight / currentScale).toInt()
|
layoutParams.height = (originalHeight / currentScale).toInt()
|
||||||
|
halfHeight = layoutParams.height / 2
|
||||||
} else {
|
} else {
|
||||||
originalHeight
|
layoutParams.height = MATCH_PARENT
|
||||||
|
halfHeight = originalHeight / 2
|
||||||
}
|
}
|
||||||
halfHeight = layoutParams.height / 2
|
|
||||||
|
|
||||||
if (currentScale != DEFAULT_RATE) {
|
if (currentScale != DEFAULT_RATE) {
|
||||||
x = getPositionX(x)
|
x = getPositionX(x)
|
||||||
@@ -245,8 +246,8 @@ class WebtoonRecyclerView @JvmOverloads constructor(
|
|||||||
if (!isZooming && doubleTapZoom) {
|
if (!isZooming && doubleTapZoom) {
|
||||||
if (scaleX != DEFAULT_RATE) {
|
if (scaleX != DEFAULT_RATE) {
|
||||||
zoom(currentScale, DEFAULT_RATE, x, 0f, y, 0f)
|
zoom(currentScale, DEFAULT_RATE, x, 0f, y, 0f)
|
||||||
layoutParams.height = originalHeight
|
layoutParams.height = MATCH_PARENT
|
||||||
halfHeight = layoutParams.height / 2
|
halfHeight = originalHeight / 2
|
||||||
requestLayout()
|
requestLayout()
|
||||||
} else {
|
} else {
|
||||||
val toScale = 2f
|
val toScale = 2f
|
||||||
|
|||||||
Reference in New Issue
Block a user