@@ -87,7 +87,7 @@ class CompositionPopupWindow(
87
87
// 悬浮窗口彈出位置
88
88
private var popupWindowPos = PopupPosition .fromString(theme.generalStyle.layout.position)
89
89
90
- private val mPopupWindow =
90
+ private val mPopupWindow by lazy {
91
91
PopupWindow (root).apply {
92
92
isClippingEnabled = false
93
93
inputMethodMode = PopupWindow .INPUT_METHOD_NOT_NEEDED
@@ -113,6 +113,7 @@ class CompositionPopupWindow(
113
113
.toFloat(),
114
114
)
115
115
}
116
+ }
116
117
117
118
var isCursorUpdated = false // 光標是否移動
118
119
@@ -129,11 +130,14 @@ class CompositionPopupWindow(
129
130
intArrayOf(0 , 0 ).also {
130
131
anchor.getLocationInWindow(it)
131
132
}
133
+ root.measure(View .MeasureSpec .UNSPECIFIED , View .MeasureSpec .UNSPECIFIED )
134
+ val selfWidth = root.measuredWidth
135
+ val selfHeight = root.measuredHeight
132
136
133
137
val minX = anchor.dp(popupMarginH)
134
138
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
137
141
if (isWinFixed() || ! isCursorUpdated) {
138
142
// setCandidatesViewShown(true);
139
143
when (popupWindowPos) {
@@ -174,7 +178,7 @@ class CompositionPopupWindow(
174
178
PopupPosition .LEFT , PopupPosition .RIGHT ->
175
179
y = mPopupRectF.bottom.toInt() + popupMargin
176
180
PopupPosition .LEFT_UP , PopupPosition .RIGHT_UP ->
177
- y = mPopupRectF.top.toInt() - mPopupWindow.height - popupMargin
181
+ y = mPopupRectF.top.toInt() - selfHeight - popupMargin
178
182
else -> Timber .wtf(" UNREACHABLE BRANCH" )
179
183
}
180
184
y = MathUtils .clamp(y, minY, maxY)
0 commit comments