mirror of
https://github.com/ouchadam/small-talk.git
synced 2025-02-16 12:10:45 +01:00
avoiding recreating navigation callback on recomposition
This commit is contained in:
parent
4a4fad3cc0
commit
eb497be421
@ -91,6 +91,7 @@ fun DirectoryScreen(directoryViewModel: DirectoryViewModel) {
|
|||||||
is Error -> GenericError {
|
is Error -> GenericError {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
is Content -> Content(listState, state)
|
is Content -> Content(listState, state)
|
||||||
}
|
}
|
||||||
Toolbar(title = "Messages", offset = { IntOffset(x = 0, y = toolbarOffsetHeightPx.value.roundToInt()) })
|
Toolbar(title = "Messages", offset = { IntOffset(x = 0, y = toolbarOffsetHeightPx.value.roundToInt()) })
|
||||||
@ -106,6 +107,7 @@ private fun DirectoryViewModel.ObserveEvents(listState: LazyListState, toolbarPo
|
|||||||
is OpenDownloadUrl -> {
|
is OpenDownloadUrl -> {
|
||||||
context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(it.url)))
|
context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(it.url)))
|
||||||
}
|
}
|
||||||
|
|
||||||
DirectoryEvent.ScrollToTop -> {
|
DirectoryEvent.ScrollToTop -> {
|
||||||
toolbarPosition.value = 0f
|
toolbarPosition.value = 0f
|
||||||
listState.scrollToItem(0)
|
listState.scrollToItem(0)
|
||||||
@ -121,9 +123,11 @@ val clock = Clock.systemUTC()
|
|||||||
@Composable
|
@Composable
|
||||||
private fun Content(listState: LazyListState, state: Content) {
|
private fun Content(listState: LazyListState, state: Content) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val navigateToRoom = { roomId: RoomId ->
|
val navigateToRoom = remember {
|
||||||
|
{ roomId: RoomId ->
|
||||||
context.startActivity(MessengerActivity.newInstance(context, roomId))
|
context.startActivity(MessengerActivity.newInstance(context, roomId))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
|
|
||||||
LaunchedEffect(key1 = state.overviewState) {
|
LaunchedEffect(key1 = state.overviewState) {
|
||||||
@ -247,6 +251,7 @@ private fun body(overview: RoomOverview, secondaryText: Color, typing: SyncServi
|
|||||||
color = MaterialTheme.colorScheme.primary
|
color = MaterialTheme.colorScheme.primary
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> when (val lastMessage = overview.lastMessage) {
|
else -> when (val lastMessage = overview.lastMessage) {
|
||||||
null -> {
|
null -> {
|
||||||
Text(
|
Text(
|
||||||
@ -256,6 +261,7 @@ private fun body(overview: RoomOverview, secondaryText: Color, typing: SyncServi
|
|||||||
color = secondaryText
|
color = secondaryText
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
when (overview.isGroup) {
|
when (overview.isGroup) {
|
||||||
true -> {
|
true -> {
|
||||||
@ -268,6 +274,7 @@ private fun body(overview: RoomOverview, secondaryText: Color, typing: SyncServi
|
|||||||
color = secondaryText
|
color = secondaryText
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
false -> {
|
false -> {
|
||||||
Text(
|
Text(
|
||||||
overflow = TextOverflow.Ellipsis,
|
overflow = TextOverflow.Ellipsis,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user