Skip to main content

UI Previews

Previewing your Composable functions is a powerful feature of Android Studio.

Most of Stream Video SDK's UI components rely on Call, ParticipantState and other types which are difficult to mock.

So we provide a useful library called stream-video-android-previewdata that allows you to get mock instances of them and write your preview or test codes for Stream Video UI components easily.

You'll be able to build your own preview Composable functions like so:

Dogfooding (Call Join)Dogfooding (Call Lobby)Dogfooding (Call)
DogfoodingDogfoodingDogfooding

Usage

To use this library, add the dependency below below to your module's build.gradle file:

dependencies {
implementation "io.getstream:stream-video-android-previewdata:$stream_version"
}

Now, you can implement your preview composable like the example below:

@Preview
@Composable
private fun CallContentPreview() {
StreamMockUtils.initializeStreamVideo(LocalContext.current)
VideoTheme {
CallContent(
modifier = Modifier.background(color = VideoTheme.colors.appBackground),
call = mockCall,
)
}
}

After adding the above example to your project, you'll see the following previews in Android Studio:

Preview fro CallContent

You should follow the steps below to make your previews work well:

  1. Initialize a mock StreamVideo with the following method: StreamMockUtils.initializeStreamVideo.
  2. Wrap your composable with the VideoTheme.
  3. Use the provided mock instances for Stream Video UI components.

This library provides the following mocks:

  • mockCall: Mock a Call that contains few of mock users.
  • mockParticipant: Mock a ParticipantState instance.
  • mockParticipantList: Mock a list of ParticipantState instances.
  • mockUsers: Mock a list of User instances.
  • mockVideoMediaTrack: Mock a new MediaTrack instance.

For example, you can build a preview Composable for ParticipantVideo as in the example below:

@Preview
@Composable
private fun ParticipantVideoPreview() {
StreamMockUtils.initializeStreamVideo(LocalContext.current)
VideoTheme {
ParticipantVideoRenderer(
call = mockCall,
participant = mockParticipant,
)
}
}

After adding the above example to your project, you'll see the following previews in Android Studio:

Preview fro ParticipantVideo

Did you find this page helpful?