@@ -8,6 +8,7 @@ package org.fcitx.fcitx5.android.input.candidates.floating
8
8
import android.annotation.SuppressLint
9
9
import android.content.Context
10
10
import android.view.ViewGroup
11
+ import androidx.core.view.updateLayoutParams
11
12
import androidx.recyclerview.widget.RecyclerView
12
13
import com.google.android.flexbox.AlignItems
13
14
import com.google.android.flexbox.FlexDirection
@@ -16,14 +17,15 @@ import com.google.android.flexbox.FlexboxLayoutManager
16
17
import org.fcitx.fcitx5.android.core.FcitxEvent
17
18
import org.fcitx.fcitx5.android.core.FcitxEvent.PagedCandidateEvent.LayoutHint
18
19
import org.fcitx.fcitx5.android.data.theme.Theme
19
- import splitties.dimensions.dp
20
20
import splitties.views.dsl.core.Ui
21
21
import splitties.views.dsl.recyclerview.recyclerView
22
22
23
23
class PagedCandidatesUi (override val ctx : Context , val theme : Theme ) : Ui {
24
24
25
25
private var data = FcitxEvent .PagedCandidateEvent .Data .Empty
26
26
27
+ private var isVertical = false
28
+
27
29
sealed class UiHolder (open val ui : Ui ) : RecyclerView.ViewHolder(ui.root) {
28
30
class Candidate (override val ui : LabeledCandidateItemUi ) : UiHolder(ui)
29
31
class Pagination (override val ui : PaginationUi ) : UiHolder(ui)
@@ -42,8 +44,6 @@ class PagedCandidatesUi(override val ctx: Context, val theme: Theme) : Ui {
42
44
val wrap = ViewGroup .LayoutParams .WRAP_CONTENT
43
45
ui.root.layoutParams = FlexboxLayoutManager .LayoutParams (wrap, wrap).apply {
44
46
flexGrow = 1f
45
- alignSelf = AlignItems .STRETCH
46
- minHeight = ctx.dp(20 )
47
47
}
48
48
}
49
49
}
@@ -57,6 +57,9 @@ class PagedCandidatesUi(override val ctx: Context, val theme: Theme) : Ui {
57
57
}
58
58
is UiHolder .Pagination -> {
59
59
holder.ui.update(data)
60
+ holder.ui.root.updateLayoutParams<FlexboxLayoutManager .LayoutParams > {
61
+ alignSelf = if (isVertical) AlignItems .STRETCH else AlignItems .CENTER
62
+ }
60
63
}
61
64
}
62
65
}
@@ -78,10 +81,9 @@ class PagedCandidatesUi(override val ctx: Context, val theme: Theme) : Ui {
78
81
orientation : FloatingCandidatesOrientation
79
82
) {
80
83
this .data = data
81
- val isVertical = when (orientation) {
84
+ this . isVertical = when (orientation) {
82
85
FloatingCandidatesOrientation .Automatic -> data.layoutHint == LayoutHint .Vertical
83
- FloatingCandidatesOrientation .Horizontal -> false
84
- FloatingCandidatesOrientation .Vertical -> true
86
+ else -> orientation == FloatingCandidatesOrientation .Vertical
85
87
}
86
88
candidatesLayoutManager.apply {
87
89
if (isVertical) {
0 commit comments