Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
.externalNativeBuild
.cxx
/check/detekt/reports
.idea
.idea*.class
META-INF/
Binary file not shown.
Binary file added com/petterp/floatingx/assist/FxBorderMargin.class
Binary file not shown.
Binary file not shown.
Binary file added com/petterp/floatingx/assist/FxDisplayMode.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,16 @@ class FxViewLocationHelper : FxViewBasicHelper(), View.OnLayoutChangeListener {
}

override fun onSizeChanged(w: Int, h: Int, oldW: Int, oldH: Int) {
updateViewSize()
val sizeChanged = updateViewSize()
// 初始化跳过
if (isInitLocation) return
if (needUpdateLocation) {
checkOrRestoreLocation()
} else if (sizeChanged && !config.gravity.isDefault()) {
// 当View大小改变且设置了非默认Gravity时,根据Gravity重新计算位置
val (newX, newY) = recalculatePositionByGravity()
basicView?.internalMoveToXY(newX, newY)
config.fxLog.d("fxView -> onSizeChanged: recalculated position by gravity, x:$newX, y:$newY")
} else {
basicView?.internalMoveToXY(safeX(x), safeY(y))
}
Expand Down Expand Up @@ -196,21 +201,22 @@ class FxViewLocationHelper : FxViewBasicHelper(), View.OnLayoutChangeListener {
}
}

private fun updateViewSize() {
val view = basicView ?: return
val (pW, pH) = view.parentSize() ?: return
private fun updateViewSize(): Boolean {
val view = basicView ?: return false
val (pW, pH) = view.parentSize() ?: return false
val viewH = view.height.toFloat()
val viewW = view.width.toFloat()
// 如果大小没有变化,则不更新
if (this.parentW == pW.toFloat() && this.parentH == pH.toFloat()
&& this.viewW == viewW && this.viewH == viewH
) return
) return false
this.parentW = pW.toFloat()
this.parentH = pH.toFloat()
this.viewW = viewW
this.viewH = viewH
updateMoveBoundary()
config.fxLog.d("fxView -> updateSize: parentW:$parentW,parentH:$parentH,viewW:$viewW,viewH:$viewH")
return true
}

private fun isNearestLeft(x: Float): Boolean {
Expand Down Expand Up @@ -268,6 +274,14 @@ class FxViewLocationHelper : FxViewBasicHelper(), View.OnLayoutChangeListener {
}
}

/**
* 根据当前Gravity设置重新计算位置
* 当View大小改变时,根据Gravity重新定位
*/
private fun recalculatePositionByGravity(): Pair<Float, Float> {
return getDefaultXY(parentW, parentH, viewW, viewH)
}

internal fun updateMoveBoundary() {
config.apply {
// 如果启用了半隐藏,这里需要单独处理
Expand Down