GetStream / whatsApp-clone-compose

📱 WhatsApp clone project demonstrates modern Android development built with Jetpack Compose and Stream Chat/Video SDK for Compose.
Apache License 2.0
1.26k stars 157 forks source link

Remove TopBar dependency on ViewModel #193

Closed shahzadansari closed 7 months ago

shahzadansari commented 7 months ago

🎯 Goal

Fix "MessageTopBar Preview is broken" issue https://github.com/GetStream/whatsApp-clone-compose/issues/192

🛠 Implementation details

@Composable WhatsAppMessageTopBar takes WhatsAppMessagesViewModel as a parameter and since we cannot instantiate ViewModel in Previews, it doesn't render the Preview.

Before

Screenshot 2024-03-17 at 4 15 03 PM

After

Screenshot 2024-03-17 at 4 14 04 PM

✍️ Explain examples

Setup a callback to trigger a function in ViewModel instead (takes videoCall flag as a param to be passed onto VM).

@Composable
fun WhatsAppMessageTopBar(
  .
  navigateToVideoCall: (Boolean) -> Unit,
  .
)