android / android/nowinandroid

[FR]: Replace custom preview annotations with androidx.compose.ui.tooling.preview alternatives

Open
#1,923 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Kotlin
Stars
21.8k
Forks
4.6k
Avg merge
19h 20m
Merged PRs (30d)
2

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Describe the problem

The current nowinandroid project uses custom annotations for previews that replicate functionality already available in the Jetpack Compose tooling library:

- `com.google.samples.apps.nowinandroid.core.designsystem.ThemePreviews` for showing light and dark themes.

- `com.google.samples.apps.nowinandroid.core.ui.DevicePreviews` for showing different device sizes.

This introduces boilerplate code and maintenance overhead for a feature that is now officially supported by the Compose library itself.

### Describe the solution

Replace the custom annotations with the standard androidx.compose.ui.tooling.preview alternatives:

1. Replace `ThemePreviews` with `PreviewLightDark`:
`PreviewLightDark` from `androidx.compose.ui.tooling.preview` provides a cleaner, built-in way to render composables in both light and dark themes. This would allow for the removal of the `ThemePreviews.kt` file.
2. Replace `DevicePreviews` with `PreviewScreenSizes`:
`PreviewScreenSizes` from `androidx.compose.ui.tooling.preview` offers a direct and idiomatic way to display a composable across a range of screen sizes. This would allow for the removal of the `DevicePreviews.kt` file.

### Additional context

_No response_

### Code of Conduct

- [x] I agree to follow this project's Code of Conduct

Contributor guide

Open the contributing guide

Research direction

Start by reading core/designsystem/ThemePreviews.kt and core/ui/DevicePreviews.kt, then locate their usages across the project. Replace those usages with PreviewLightDark and PreviewScreenSizes from androidx.compose.ui.tooling.preview, remove the two custom annotation files, and verify that the project builds and previews still cover the intended themes and screen sizes.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, kotlin
Domain
mobile, tooling
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.