mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-21 09:20:19 +01:00
Add rememberRecipientField composable function for reading live recipient fields.
This commit is contained in:
committed by
Cody Henthorne
parent
df170dac32
commit
7616ec1fd2
@@ -9,23 +9,16 @@ import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalInspectionMode
|
||||
import androidx.compose.ui.viewinterop.AndroidView
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.rx3.asFlow
|
||||
import org.thoughtcrime.securesms.components.AvatarImageView
|
||||
import org.thoughtcrime.securesms.database.model.ProfileAvatarFileDetails
|
||||
import org.thoughtcrime.securesms.profiles.AvatarHelper
|
||||
import org.thoughtcrime.securesms.recipients.Recipient
|
||||
import org.thoughtcrime.securesms.util.NameUtil
|
||||
import org.thoughtcrime.securesms.recipients.rememberRecipientField
|
||||
|
||||
@Composable
|
||||
fun AvatarImage(
|
||||
@@ -41,15 +34,12 @@ fun AvatarImage(
|
||||
)
|
||||
} else {
|
||||
val context = LocalContext.current
|
||||
var state: AvatarImageState by remember {
|
||||
mutableStateOf(AvatarImageState(null, recipient, ProfileAvatarFileDetails.NO_DETAILS))
|
||||
}
|
||||
|
||||
LaunchedEffect(recipient.id) {
|
||||
Recipient.observable(recipient.id).asFlow()
|
||||
.collectLatest {
|
||||
state = AvatarImageState(NameUtil.getAbbreviation(it.getDisplayName(context)), it, AvatarHelper.getAvatarFileDetails(context, it.id))
|
||||
}
|
||||
val avatarImageState by rememberRecipientField(recipient) {
|
||||
AvatarImageState(
|
||||
getDisplayName(context),
|
||||
this,
|
||||
profileAvatarFileDetails
|
||||
)
|
||||
}
|
||||
|
||||
AndroidView(
|
||||
@@ -62,9 +52,9 @@ fun AvatarImage(
|
||||
modifier = modifier.background(color = Color.Transparent, shape = CircleShape)
|
||||
) {
|
||||
if (useProfile) {
|
||||
it.setAvatarUsingProfile(state.self)
|
||||
it.setAvatarUsingProfile(avatarImageState.self)
|
||||
} else {
|
||||
it.setAvatar(state.self)
|
||||
it.setAvatar(avatarImageState.self)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user