1+ package com.qmuiteam.qmuidemo.fragment.lab
2+
3+ import androidx.compose.foundation.background
4+ import androidx.compose.foundation.layout.*
5+ import androidx.compose.foundation.lazy.LazyColumn
6+ import androidx.compose.foundation.lazy.rememberLazyListState
7+ import androidx.compose.material.Text
8+ import androidx.compose.runtime.Composable
9+ import androidx.compose.ui.Modifier
10+ import androidx.compose.ui.graphics.Color
11+ import androidx.compose.ui.text.style.TextOverflow
12+ import androidx.compose.ui.unit.dp
13+ import androidx.compose.ui.unit.sp
14+ import androidx.constraintlayout.compose.ChainStyle
15+ import androidx.constraintlayout.compose.ConstraintLayout
16+ import androidx.constraintlayout.compose.Dimension
17+ import com.qmuiteam.compose.core.ui.QMUITopBarBackIconItem
18+ import com.qmuiteam.compose.core.ui.QMUITopBarTextItem
19+ import com.qmuiteam.compose.core.ui.QMUITopBarWithLazyScrollState
20+ import com.qmuiteam.photo.activity.QMUIPhotoPickerActivity
21+ import com.qmuiteam.qmui.arch.annotation.LatestVisitRecord
22+ import com.qmuiteam.qmuidemo.R
23+ import com.qmuiteam.qmuidemo.activity.QDPhotoPickerActivity
24+ import com.qmuiteam.qmuidemo.base.ComposeBaseFragment
25+ import com.qmuiteam.qmuidemo.lib.annotation.Widget
26+
27+ @Widget(name = " QMUI Compose Tip" , iconRes = R .mipmap.icon_grid_in_progress)
28+ @LatestVisitRecord
29+ class QDComposeTipFragment : ComposeBaseFragment () {
30+ @Composable
31+ override fun PageContent () {
32+ Column (modifier = Modifier .fillMaxSize()) {
33+ val scrollState = rememberLazyListState()
34+ QMUITopBarWithLazyScrollState (
35+ scrollState = scrollState,
36+ title = " QMUIPhoto" ,
37+ leftItems = arrayListOf (
38+ QMUITopBarBackIconItem {
39+ popBackStack()
40+ }
41+ ),
42+ rightItems = arrayListOf (
43+ QMUITopBarTextItem (" Pick a Picture" ) {
44+ val activity = activity ? : return @QMUITopBarTextItem
45+ val intent = QMUIPhotoPickerActivity .intentOf(activity, QDPhotoPickerActivity ::class .java)
46+ startActivity(intent)
47+ }
48+ )
49+ )
50+ LazyColumn (
51+ state = scrollState,
52+ modifier = Modifier
53+ .fillMaxWidth()
54+ .weight(1f )
55+ .background(Color .White )
56+ ) {
57+ item {
58+ Column (
59+ modifier = Modifier
60+ .fillMaxWidth()
61+ .padding(12 .dp)
62+ ) {
63+ Text (
64+ text = " 在 UI 开发过程中,经常会遇到如下一个需求:\n " +
65+ " 假设一个布局是 【头像】【人名】【推荐信息】,正常用 LinearLayout 实现, " +
66+ " 是没有任何问题的,但是要求在人名过长,整体内容会超过容器宽度时," +
67+ " 不要省略推荐信息,而是省略人名信息。" ,
68+ fontSize = 13 .sp,
69+ modifier = Modifier .padding(vertical = 12 .dp)
70+ )
71+ Row (
72+ modifier = Modifier .fillMaxWidth().height(100 .dp)
73+ ) {
74+ ConstraintLayout (
75+ modifier = Modifier
76+ .weight(1f )
77+ .fillMaxHeight()
78+ .background(Color .LightGray )
79+ ) {
80+ val (one, two, three) = createRefs()
81+ createHorizontalChain(one, two, three, chainStyle = ChainStyle .Packed (0f ))
82+ Text (
83+ " 此处不压缩" ,
84+ color = Color .White ,
85+ maxLines = 1 ,
86+ modifier = Modifier
87+ .background(Color .Red )
88+ .constrainAs(one) {
89+ top.linkTo(parent.top)
90+ bottom.linkTo(parent.bottom)
91+ start.linkTo(parent.start)
92+ end.linkTo(two.start)
93+ })
94+ Text (
95+ " 此处如果内容有那么一点点过长,那就压缩省略压缩省略压缩省略" ,
96+ color = Color .White ,
97+ maxLines = 1 ,
98+ overflow = TextOverflow .Ellipsis ,
99+ modifier = Modifier
100+ .background(Color .Green )
101+ .constrainAs(two) {
102+ width = Dimension .preferredWrapContent
103+ top.linkTo(parent.top)
104+ bottom.linkTo(parent.bottom)
105+ start.linkTo(one.end)
106+ end.linkTo(three.start)
107+ })
108+ Text (
109+ " 此处也不压缩" ,
110+ color = Color .White ,
111+ maxLines = 1 ,
112+ modifier = Modifier
113+ .background(Color .Black )
114+ .constrainAs(three) {
115+ top.linkTo(parent.top)
116+ bottom.linkTo(parent.bottom)
117+ start.linkTo(two.end)
118+ end.linkTo(parent.end)
119+ })
120+ }
121+ Box (
122+ modifier = Modifier
123+ .fillMaxHeight()
124+ .width(50 .dp)
125+ .background(Color .Blue )
126+ )
127+ }
128+
129+ }
130+ }
131+ }
132+ }
133+ }
134+ }
0 commit comments