Skip to content

Instantly share code, notes, and snippets.

@Arunshaik2001
Created October 27, 2022 05:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Arunshaik2001/09eca5a109ba3d8a39b9bf524a536e88 to your computer and use it in GitHub Desktop.
Save Arunshaik2001/09eca5a109ba3d8a39b9bf524a536e88 to your computer and use it in GitHub Desktop.
@Composable
fun Chats() {
val message by ChatServer.messages.observeAsState()
val inputvalue = remember { mutableStateOf(TextFieldValue()) }
val messageList = remember {
mutableStateListOf<Message>()
}
if (message != null && !messageList.contains(message)) {
messageList.add(message)
}
if (messageList.isNotEmpty()) {
Column(modifier = Modifier.fillMaxSize()) {
Text(
text = "Chat Now with ${ChatServer.currentDevice?.name ?: "Someone"}",
fontSize = 20.sp,
fontWeight = FontWeight.Bold
)
Spacer(modifier = Modifier.height(10.dp))
Surface(modifier = Modifier
.padding(all = Dp(5f))
.fillMaxHeight(fraction = 0.85f)) {
ChatsList(messageList)
}
InputField(inputvalue)
}
} else {
Column(modifier = Modifier.fillMaxSize(), horizontalAlignment = Alignment.CenterHorizontally) {
Box(
contentAlignment = Alignment.Center,
modifier = Modifier.fillMaxSize(fraction = 0.85f)
) {
Text(text = "No Chat History")
}
InputField(inputvalue = inputvalue)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment