Change order of composables in BookmarksScreen and add previews

pull/443/head
Jolanda Verhoef 3 years ago
parent 01529f567e
commit a669302409

@ -42,6 +42,7 @@ import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.StrokeCap import androidx.compose.ui.graphics.StrokeCap
import androidx.compose.ui.graphics.drawscope.rotate import androidx.compose.ui.graphics.drawscope.rotate
import androidx.compose.ui.graphics.graphicsLayer import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.platform.LocalInspectionMode
import androidx.compose.ui.semantics.contentDescription import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
@ -56,7 +57,8 @@ fun NiaLoadingWheel(
val infiniteTransition = rememberInfiniteTransition() val infiniteTransition = rememberInfiniteTransition()
// Specifies the float animation for slowly drawing out the lines on entering // Specifies the float animation for slowly drawing out the lines on entering
val floatAnimValues = (0 until NUM_OF_LINES).map { remember { Animatable(1F) } } val startValue = if (LocalInspectionMode.current) 0F else 1F
val floatAnimValues = (0 until NUM_OF_LINES).map { remember { Animatable(startValue) } }
LaunchedEffect(floatAnimValues) { LaunchedEffect(floatAnimValues) {
(0 until NUM_OF_LINES).map { index -> (0 until NUM_OF_LINES).map { index ->
launch { launch {

@ -45,11 +45,15 @@ import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.ExperimentalLifecycleComposeApi import androidx.lifecycle.compose.ExperimentalLifecycleComposeApi
import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.google.samples.apps.nowinandroid.core.designsystem.component.NiaLoadingWheel import com.google.samples.apps.nowinandroid.core.designsystem.component.NiaLoadingWheel
import com.google.samples.apps.nowinandroid.core.designsystem.theme.NiaTheme
import com.google.samples.apps.nowinandroid.core.domain.model.SaveableNewsResource
import com.google.samples.apps.nowinandroid.core.model.data.previewNewsResources
import com.google.samples.apps.nowinandroid.core.ui.NewsFeedUiState import com.google.samples.apps.nowinandroid.core.ui.NewsFeedUiState
import com.google.samples.apps.nowinandroid.core.ui.NewsFeedUiState.Loading import com.google.samples.apps.nowinandroid.core.ui.NewsFeedUiState.Loading
import com.google.samples.apps.nowinandroid.core.ui.NewsFeedUiState.Success import com.google.samples.apps.nowinandroid.core.ui.NewsFeedUiState.Success
@ -91,6 +95,17 @@ internal fun BookmarksScreen(
} }
} }
@Composable
private fun LoadingState(modifier: Modifier = Modifier) {
NiaLoadingWheel(
modifier = modifier
.fillMaxWidth()
.wrapContentSize()
.testTag("forYou:loading"),
contentDesc = stringResource(id = R.string.saved_loading),
)
}
@Composable @Composable
private fun BookmarksGrid( private fun BookmarksGrid(
feedState: NewsFeedUiState, feedState: NewsFeedUiState,
@ -156,13 +171,33 @@ private fun EmptyState(modifier: Modifier = Modifier) {
} }
} }
@Preview
@Composable @Composable
private fun LoadingState(modifier: Modifier = Modifier) { private fun LoadingStatePreview() {
NiaLoadingWheel( NiaTheme {
modifier = modifier LoadingState()
.fillMaxWidth() }
.wrapContentSize() }
.testTag("forYou:loading"),
contentDesc = stringResource(id = R.string.saved_loading), @Preview
@Composable
private fun BookmarksGridPreview() {
NiaTheme {
BookmarksGrid(
feedState = Success(
previewNewsResources.map {
SaveableNewsResource(it, false)
}
),
removeFromBookmarks = {}
) )
}
}
@Preview
@Composable
fun EmptyStatePreview() {
NiaTheme {
EmptyState()
}
} }

Loading…
Cancel
Save