其他
什么?Compose可以开发PC应用了?
https://juejin.cn/user/4019470242152616
左侧Colum又上到下配合Spacer完美 中间的Box内部ListView加搜索框 右侧ListView
* @param defaultPath 默认图片路径
* @param selectedPath 选择路径
* @param path 实际路径
* @param selected 是否选中
*/
data class WxSelectedBean(val defaultPath:String,var selectedPath:String,var path:String,var selected:Boolean)
val isAppReady = mutableStateOf(false)
val position = ArrayList<WxSelectedBean>()
fun initData() {
var selectedDatas = arrayListOf<WxSelectedBean>()
selectedDatas.add(
WxSelectedBean(
"images/head_lhc.png",
"images/head_lhc.png",
"images/head_lhc.png",
false
)
)
selectedDatas.add(
WxSelectedBean(
"images/message_unselected.png",
"images/message_selected.png",
"images/message_selected.png",
true
)
)
selectedDatas.add(
WxSelectedBean(
"images/person_unselected.png",
"images/person_selected.png",
"images/person_unselected.png",
false
)
)
selectedDatas.add(
WxSelectedBean(
"images/connected_unselecte.png",
"images/connected_selected.png",
"images/connected_unselecte.png",
false
)
)
selectedDatas.add(
WxSelectedBean(
"images/file_default.png",
"images/file_default.png",
"images/file_default.png",
false
)
)
selectedDatas.add(
WxSelectedBean(
"images/frends.png",
"images/frends.png",
"images/frends.png",
false
)
)
selectedDatas.add(
WxSelectedBean(
"images/phone.png",
"images/phone.png",
"images/phone.png",
false
)
)
selectedDatas.add(
WxSelectedBean(
"images/mulu.png",
"images/mulu.png",
"images/mulu.png",
false
)
)
position.addAll(selectedDatas)
}
override fun onAbandoned() {
}
override fun onForgotten() {
}
override fun onRemembered() {
}
}
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.desktop.Window
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.material.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.rotate
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.graphics.*
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.drawIntoCanvas
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.unit.dp
import module_view.WxSelectedBean
import module_view.WxViewModel
fun main() = Window {
WxViewModel.initData()
var wxData by remember { mutableStateOf(WxViewModel.position) }
//选中的索引
var selectedIndex by remember { mutableStateOf(1) }
//图片选中动画执行与否
var imageAnimal by remember { mutableStateOf(true) }
//图片旋转动画
val imageAngle: Float by animateFloatAsState(
if (imageAnimal) {
0f
} else {
360f
}, animationSpec = TweenSpec(durationMillis = 1001)
)
MaterialTheme {
Scaffold {
Row {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier.fillMaxHeight().width(66.dp)
.background(Color(247, 242, 243))
) {
ImageRes(
getPath(wxData, selectedIndex, 0),
modifier = Modifier.padding(top = 30.dp).size(48.dp)
.clickable(role = Role.Image) {
imageAnimal = !imageAnimal
}.rotate(imageAngle)
)
ImageRes(
getPath(wxData, selectedIndex, 1),
modifier = Modifier.padding(vertical = 20.dp).size(42.dp).clickable {
selectedIndex = 1
})
ImageRes(getPath(wxData, selectedIndex, 2),
modifier = Modifier.size(32.dp).clickable {
selectedIndex = 2
})
ImageRes(
getPath(wxData, selectedIndex, 3),
modifier = Modifier.padding(vertical = 20.dp).size(30.dp).clickable {
selectedIndex = 3
}
)
ImageRes(getPath(wxData, selectedIndex, 4), modifier = Modifier.size(30.dp))
ImageRes(
getPath(wxData, selectedIndex, 5),
modifier = Modifier.padding(vertical = 20.dp).size(30.dp)
)
Spacer(modifier = Modifier.weight(1f))
ImageRes(
getPath(wxData, selectedIndex, 6),
modifier = Modifier.padding(vertical = 20.dp).size(35.dp)
)
ImageRes(
getPath(wxData, selectedIndex, 7),
modifier = Modifier.padding(vertical = 20.dp).size(30.dp)
)
}
}
}
}
}
/**
* @param wxData 数据集合
* @param selectedIndex 选中的索引
* @param currenIndex 当前Image对应的索引
* return 返回各个按钮选中和未选中图片路径
*/
private fun getPath(
wxData: ArrayList<WxSelectedBean>,
selectedIndex: Int,
currenIndex: Int
): String {
return if (selectedIndex == currenIndex) {
wxData[currenIndex].selectedPath
} else {
wxData[currenIndex].defaultPath
}
}
LazyColunm()
Row{
TextFile()
Box{
Image()
}
}
}
* 分钟微信中间界面
*/
@Composable
fun centerView() {
var inputValue by remember { mutableStateOf("搜索") }
Box() {
Column(
modifier = Modifier
.width(320.dp)
.background(Color.Red)
.verticalScroll(rememberScrollState())
) {
列表内容
}
Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.width(320.dp).background(Color.White).padding(8.dp)) {
TextField(
value = inputValue,
onValueChange = {
inputValue = it
},
colors = TextFieldDefaults.textFieldColors(
unfocusedIndicatorColor = Color.Transparent,
focusedIndicatorColor = Color.Transparent,
backgroundColor = Color.Transparent
),
modifier = Modifier.padding(8.dp).background(
color = Color(247, 242, 243), shape = RoundedCornerShape(20),
).height(26.dp).width(250.dp),
leadingIcon = {
Icon(
bitmap = getImageBitmap("images/sousuo.png"),
"",
modifier = Modifier.size(10.dp)
)
},
)
Box(
contentAlignment = Alignment.Center,
modifier = Modifier.size(26.dp).background(
color = Color(247, 242, 243),
shape = RoundedCornerShape(10)
).clip(shape = RoundedCornerShape(10))
) {
ImageRes(
"images/jia.png",
modifier = Modifier.size(18.dp)
)
}
}
}
}
Image()
Column{
Row{
Text("主管老婆大人")
Text("06:42")
}
Text("[文件]20202323002030320302.png")
}
}
state = scrollLazyState,
modifier = Modifier
.width(300.dp)
.padding(top = 70.dp)
) {
items(100) { index ->
Row (Modifier.background(selectedColor(selectedIndex,index)).padding(top=10.dp,start = 15.dp,bottom = 10.dp,end = 15.dp).clickable {
selectedIndex = index
}){
Image(bitmap = getImageBitmap("images/head_lhc.png"),"",modifier = Modifier.width(45.dp))
Column(verticalArrangement=Arrangement.SpaceBetween,horizontalAlignment = Alignment.Start,modifier = Modifier.width(300.dp).padding(start = 10.dp)){
Row(horizontalArrangement = Arrangement.SpaceBetween,modifier = Modifier.width(300.dp)) {
Text("主管老婆大人",fontSize = 14.sp)
Text("06:42",fontSize = 11.sp,color = Color(111,111,111))
}
Spacer(Modifier.height(6.dp))
Text("[文件]202023230ll.png",fontSize = 12.sp,color = Color(111,111,111))
}
}
}
}
detectTapGestures(
onTap = {
selectedIndex = index
}
)
}
wxDatas.add(WxListBean("主管老婆大人","images/item_a.png","[文件]20211999lll.pdf","6:45",0))
wxDatas.add(WxListBean("CSDN付费专栏作者交流群","images/item_b.png","杨修张:如果博客设置权限,是不是每个人都看不到了...","7:45",1))
wxDatas.add(WxListBean("CSDN社区专家","images/item_c.png","不是每个人都可以坐吃享受天下美食...","7:45",2))
wxDatas.add(WxListBean("郭比蓝","images/item_d.png","撸啊撸","7:45",3))
wxDatas.add(WxListBean("公众号","images/item_e.png","郭霖:Compose UI 带来的精彩...","10:45",4))
wxDatas.add(WxListBean("Flutter交流群","images/items_h.png","java Dart Kotlin js ...","10:35",5))
wxDatas.add(WxListBean("小江","images/items_u.png","clickable点击水波纹能去掉不?","7:45",5))
wxDatas.add(WxListBean("lemone","images/items_g.png","我来了带他过来,如果他来了就可以面试了","13:45",5))
wxDatas.add(WxListBean("窒息","images/item_c.png","撸啊撸","7:45",3))
wxDatas.add(WxListBean("公众健康","images/item_b.png","郭霖:Compose UI 带来的精彩...","17:45",4))
顶部Row 聊天列表部分 输入框部分
Text("主管老婆大人")
Image(bitmap)
}
fun RightView() {
Column {
Row(
modifier = Modifier.height(55.dp).fillMaxWidth().background(Color(243, 243, 243)).padding(15.dp),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Text("主管老婆大人")
Image(bitmap = getImageBitmap("images/gengduo.png"), "")
}
Spacer(Modifier.weight(1f))
TextField(
value = "hello", onValueChange = {
}, modifier = Modifier.height(226.dp).fillMaxWidth(),
colors = TextFieldDefaults.textFieldColors(
cursorColor = Color.Gray,
backgroundColor = Color(243, 243, 243),
unfocusedIndicatorColor = Color.Transparent,
focusedIndicatorColor = Color.Transparent,
)
)
}
}
* @param userID 用户ID
* @param headPath 头像
* @param message 消息
* @param messageImg 消息图片
* @param messageType 消息类型
*
*/
data class WxMessageBean(
val userID: String,
var headPath: String,
var message: String,
var messageImg: String,
var messageType: MessageType
)
//聊天详情内容
wxMessages.add(WxMessageBean("002","images/item_a.png","有美女照片没有?","images/mn_1.png",MessageType.MESSAGE))
wxMessages.add(WxMessageBean("001","images/item_d.png","","images/mn_1.png",MessageType.IMAGE))
wxMessages.add(WxMessageBean("001","images/item_d.png","漂亮不?还有...","images/mn_1.png",MessageType.MESSAGE))
wxMessages.add(WxMessageBean("001","images/item_d.png","","images/mn_2.png",MessageType.IMAGE))
wxMessages.add(WxMessageBean("002","images/item_a.png","有没有健身的妹纸呀?这些美女照片太多了没意思...要刚柔并进。你的明白吧?","images/mn_1.png",MessageType.MESSAGE))
wxMessages.add(WxMessageBean("001","images/item_d.png","安心学技术多好,看啥美女对不?","images/mn_2.png",MessageType.MESSAGE))
wxMessages.add(WxMessageBean("001","images/item_d.png","Compose最近看了一眼,也能跨平台呢?","images/mn_2.png",MessageType.MESSAGE))
wxMessages.add(WxMessageBean("002","images/item_a.png","是的没错! 但是我觉得Flutter目前更胜一筹在Web端方面","images/mn_1.png",MessageType.MESSAGE))
fun RightView() {
var inputText by remember { mutableStateOf("") }
Column {
Row(
modifier = Modifier.height(55.dp).fillMaxWidth().background(Color(247, 242, 243, 100))
.padding(15.dp),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Text("郭b蓝")
Image(bitmap = getImageBitmap("images/gengduo.png"), "")
}
Spacer(Modifier.height(1.dp).fillMaxWidth().background(Color(222, 222, 222)))
LazyColumn(Modifier.weight(1f).fillMaxWidth().background(Color(247, 242, 243, 100))) {
items(WxViewModel.wxMessages.size) { index ->
val wxmessage = WxViewModel.wxMessages[index]
if (wxmessage.userID == "001") {
Box {
Row(Modifier.padding(10.dp)) {
Image(
bitmap = getImageBitmap(wxmessage.headPath),
"",
modifier = Modifier.size(45.dp),
contentScale = ContentScale.FillWidth
)
if (wxmessage.messageType == MessageType.MESSAGE) {
Text(
text = wxmessage.message,
fontSize = 13.sp,
modifier = Modifier.background(
color = Color.White,
shape = RoundedCornerShape(20)
).clip(shape = RoundedCornerShape(20)).padding(10.dp)
)
} else {
Image(
bitmap = getImageBitmap(wxmessage.messageImg),
"",
modifier = Modifier.size(80.dp)
)
}
}
}
} else {
Row(
modifier = Modifier.fillMaxWidth().padding(15.dp),
horizontalArrangement = Arrangement.End
) {
Row {
if (wxmessage.messageType == MessageType.MESSAGE) {
Text(
text = wxmessage.message,
fontSize = 13.sp,
modifier = Modifier.width(250.dp).background(
color = Color.White,
shape = RoundedCornerShape(20)
).clip(shape = RoundedCornerShape(20)).padding(10.dp)
)
} else {
Image(
bitmap = getImageBitmap(wxmessage.messageImg),
"",
modifier = Modifier.size(80.dp)
)
}
Image(
bitmap = getImageBitmap(wxmessage.headPath),
"",
modifier = Modifier.padding(start= 10.dp).size(40.dp),
contentScale = ContentScale.FillBounds
)
}
}
}
}
}
Spacer(Modifier.height(1.dp).fillMaxWidth().background(Color(222, 222, 222)))
TextField(
value = inputText, onValueChange = {
inputText = it
}, modifier = Modifier.height(226.dp).fillMaxWidth(),
colors = TextFieldDefaults.textFieldColors(
cursorColor = Color.Gray,
backgroundColor = Color(247, 242, 243, 100),
unfocusedIndicatorColor = Color.Transparent,
focusedIndicatorColor = Color.Transparent,
)
)
}
}
Row(
modifier = Modifier.background(Color(247, 242, 243, 100)).padding(start = 15.dp,end = 15.dp,top=15.dp)
.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween
) {
Row(verticalAlignment = Alignment.CenterVertically) {
Image(
bitmap = getImageBitmap("images/wx_face.png"),
"",
modifier = Modifier.padding(horizontal = 5.dp),
)
Image(
bitmap = getImageBitmap("images/wx_file.png"),
"",
modifier = Modifier.padding(horizontal = 5.dp),
)
Image(
bitmap = getImageBitmap("images/wx_jd.png"),
"",
modifier = Modifier.padding(horizontal = 5.dp),
)
Image(
bitmap = getImageBitmap("images/wx_msg.png"),
"",
modifier = Modifier.padding(horizontal = 5.dp).clickable {
WxViewModel.wxMessages.add(WxMessageBean("002","images/item_a.png",inputText,"images/mn_2.png",MessageType.MESSAGE))
send=!send
GlobalScope.launch{
state.animateScrollTo(yPosition)
}
}
)
}
Row(verticalAlignment = Alignment.CenterVertically) {
Image(
bitmap = getImageBitmap("images/wx_phone.png"),
"",
modifier = Modifier.padding(horizontal = 5.dp)
)
Image(
bitmap = getImageBitmap("images/wx_sp.png"),
"",
modifier = Modifier.padding(horizontal = 5.dp)
)
}
}
TextField(
value = inputText, onValueChange = {
inputText = it
}, modifier = Modifier.height(226.dp).fillMaxWidth(),
colors = TextFieldDefaults.textFieldColors(
cursorColor = Color.Gray,
backgroundColor = Color(247, 242, 243, 100),
unfocusedIndicatorColor = Color.Transparent,
focusedIndicatorColor = Color.Transparent,
),
keyboardActions = KeyboardActions(
onDone = {
}
)
)
}