@@ -87,7 +87,7 @@ class CompositionPopupWindow(
8787 // 悬浮窗口彈出位置
8888 private var popupWindowPos = PopupPosition .fromString(theme.generalStyle.layout.position)
8989
90- private val mPopupWindow =
90+ private val mPopupWindow by lazy {
9191 PopupWindow (root).apply {
9292 isClippingEnabled = false
9393 inputMethodMode = PopupWindow .INPUT_METHOD_NOT_NEEDED
@@ -113,6 +113,7 @@ class CompositionPopupWindow(
113113 .toFloat(),
114114 )
115115 }
116+ }
116117
117118 var isCursorUpdated = false // 光標是否移動
118119
@@ -129,11 +130,14 @@ class CompositionPopupWindow(
129130 intArrayOf(0 , 0 ).also {
130131 anchor.getLocationInWindow(it)
131132 }
133+ root.measure(View .MeasureSpec .UNSPECIFIED , View .MeasureSpec .UNSPECIFIED )
134+ val selfWidth = root.measuredWidth
135+ val selfHeight = root.measuredHeight
132136
133137 val minX = anchor.dp(popupMarginH)
134138 val minY = anchor.dp(popupMargin)
135- val maxX = anchor.width - root.width - minX
136- val maxY = anchorY - root.height - minY
139+ val maxX = anchor.width - selfWidth - minX
140+ val maxY = anchorY - selfHeight - minY
137141 if (isWinFixed() || ! isCursorUpdated) {
138142 // setCandidatesViewShown(true);
139143 when (popupWindowPos) {
@@ -174,7 +178,7 @@ class CompositionPopupWindow(
174178 PopupPosition .LEFT , PopupPosition .RIGHT ->
175179 y = mPopupRectF.bottom.toInt() + popupMargin
176180 PopupPosition .LEFT_UP , PopupPosition .RIGHT_UP ->
177- y = mPopupRectF.top.toInt() - mPopupWindow.height - popupMargin
181+ y = mPopupRectF.top.toInt() - selfHeight - popupMargin
178182 else -> Timber .wtf(" UNREACHABLE BRANCH" )
179183 }
180184 y = MathUtils .clamp(y, minY, maxY)
0 commit comments