Skip to content

Commit

Permalink
Setup multiple previews (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzadansari authored Feb 24, 2024
1 parent 1b0bb6b commit 84fae06
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package com.example.ui_character_details.ui

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.slideInVertically
import androidx.compose.animation.slideOutVertically
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
Expand All @@ -25,14 +22,15 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage
import coil.request.ImageRequest
import com.example.character_domain.Character
import com.example.character_domain.example
import com.example.components.DefaultScreenUI
import com.example.components.Previews
import com.example.components.isInPreview
import com.example.components.theme.ModularizedRickAndMortyAppTheme
import com.example.modularized_rickandmortyapp.components.R as componentsR

@Composable
Expand Down Expand Up @@ -116,8 +114,10 @@ fun CharacterDetailsScreen(
}
}

@Preview
@Previews
@Composable
fun PreviewCharacterDetailsScreen() {
CharacterDetailsScreen(state = CharacterDetailsState(character = Character.example), onTriggerEvent = {})
ModularizedRickAndMortyAppTheme {
CharacterDetailsScreen(state = CharacterDetailsState(character = Character.example), onTriggerEvent = {})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ package com.example.ui_character_list.components

import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
Expand All @@ -18,14 +16,14 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage
import coil.request.ImageRequest
import com.example.character_domain.Character
import com.example.character_domain.example
import com.example.components.Previews
import com.example.components.isInPreview
import com.example.modularized_rickandmortyapp.character.ui_character_list.R
import com.example.components.theme.ModularizedRickAndMortyAppTheme
import com.example.modularized_rickandmortyapp.components.R as componentsR

@Composable
Expand Down Expand Up @@ -70,8 +68,10 @@ fun CharacterListItem(
}
}

@Preview
@Previews
@Composable
fun PreviewCharacterListItem() {
CharacterListItem(character = Character.example, onCharacterSelected = {})
ModularizedRickAndMortyAppTheme {
CharacterListItem(character = Character.example, onCharacterSelected = {})
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
package com.example.ui_character_list.ui

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.spring
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.scaleIn
import androidx.compose.animation.scaleOut
import androidx.compose.animation.slideInVertically
import androidx.compose.animation.slideOut
import androidx.compose.animation.slideOutHorizontally
import androidx.compose.animation.slideOutVertically
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.layout.Arrangement
Expand All @@ -30,11 +24,12 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.example.character_domain.Character
import com.example.character_domain.example
import com.example.components.DefaultScreenUI
import com.example.components.Previews
import com.example.components.theme.ModularizedRickAndMortyAppTheme
import com.example.ui_character_list.components.CharacterListItem
import kotlinx.coroutines.launch

Expand Down Expand Up @@ -103,13 +98,15 @@ fun CharactersListScreen(
}
}

@Preview
@Previews
@Composable
fun PreviewCharactersListScreen() {
val characters = buildList {
repeat(100) {
add(Character.example.copy(id = it)) // Replacing "id" with current index as LazyColumn key { } requires a unique identifier for each item
}
}
CharactersListScreen(state = CharactersListState(characters = characters), navigateToDetailScreen = {}, onTriggerEvent = {})
ModularizedRickAndMortyAppTheme {
CharactersListScreen(state = CharactersListState(characters = characters), navigateToDetailScreen = {}, onTriggerEvent = {})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.window.DialogProperties
import com.example.components.theme.ModularizedRickAndMortyAppTheme

@Composable
fun GenericErrorDialog(title: String, modifier: Modifier = Modifier, description: String?, onRetry: (() -> Unit)? = null, onDismiss: () -> Unit) {
Expand Down Expand Up @@ -44,10 +44,12 @@ fun GenericErrorDialog(title: String, modifier: Modifier = Modifier, description
)
}

@Preview
@Previews
@Composable
fun PreviewGenericDialog() {
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
GenericErrorDialog(title = "Title", description = "Description", onDismiss = {})
ModularizedRickAndMortyAppTheme {
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
GenericErrorDialog(title = "Title", description = "Description", onDismiss = {})
}
}
}
13 changes: 13 additions & 0 deletions components/src/main/java/com/example/components/Previews.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.components

import android.content.res.Configuration
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.Wallpapers

@Preview(apiLevel = 33, uiMode = Configuration.UI_MODE_NIGHT_NO or Configuration.UI_MODE_TYPE_NORMAL, name = "Light")
@Preview(apiLevel = 33, uiMode = Configuration.UI_MODE_NIGHT_YES or Configuration.UI_MODE_TYPE_NORMAL, name = "Dark")
@Preview(apiLevel = 33, wallpaper = Wallpapers.GREEN_DOMINATED_EXAMPLE, name = "Green")
@Preview(apiLevel = 33, wallpaper = Wallpapers.RED_DOMINATED_EXAMPLE, name = "Red")
@Preview(apiLevel = 33, wallpaper = Wallpapers.YELLOW_DOMINATED_EXAMPLE, name = "Yellow")
@Preview(apiLevel = 33, wallpaper = Wallpapers.BLUE_DOMINATED_EXAMPLE, name = "Blue")
annotation class Previews

0 comments on commit 84fae06

Please sign in to comment.