Browse Source

ImageViewer: use painterResource from resource library. (#2761)

pull/2764/head
Nikita Lipsky 2 years ago committed by GitHub
parent
commit
0d0c9f64d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      experimental/examples/imageviewer/shared/build.gradle.kts
  2. 21
      experimental/examples/imageviewer/shared/src/commonMain/kotlin/example/imageviewer/view/FullscreenImage.kt
  3. 8
      experimental/examples/imageviewer/shared/src/commonMain/kotlin/example/imageviewer/view/MainScreen.kt
  4. 6
      experimental/examples/imageviewer/shared/src/commonMain/kotlin/example/imageviewer/view/Miniature.kt

2
experimental/examples/imageviewer/shared/build.gradle.kts

@ -34,7 +34,7 @@ kotlin {
implementation(compose.runtime)
implementation(compose.foundation)
implementation(compose.material)
implementation("org.jetbrains.compose.components:components-resources:1.3.0-beta04-dev879")
implementation("org.jetbrains.compose.components:components-resources:1.4.0-alpha01-dev942")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1")
@OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
implementation(compose.material3)

21
experimental/examples/imageviewer/shared/src/commonMain/kotlin/example/imageviewer/view/FullscreenImage.kt

@ -15,6 +15,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.painter.BitmapPainter
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.input.key.*
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.unit.IntRect
@ -26,9 +27,7 @@ import example.imageviewer.core.FilterType
import example.imageviewer.model.*
import example.imageviewer.style.*
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.orEmpty
import org.jetbrains.compose.resources.rememberImageBitmap
import org.jetbrains.compose.resources.resource
import org.jetbrains.compose.resources.painterResource
@Composable
internal fun FullscreenImage(
@ -157,7 +156,7 @@ private fun FullscreenImageBar(
navigationIcon = {
Tooltip(localization.back) {
Image(
resource("back.png").rememberImageBitmap().orEmpty(),
painterResource("back.png"),
contentDescription = null,
modifier = Modifier.size(38.dp)
.clip(CircleShape)
@ -205,24 +204,24 @@ private fun FilterButton(
@OptIn(ExperimentalResourceApi::class)
@Composable
private fun getFilterImage(active: Boolean, type: FilterType): ImageBitmap {
private fun getFilterImage(active: Boolean, type: FilterType): Painter {
return when (type) {
FilterType.GrayScale -> if (active) {
resource("grayscale_on.png").rememberImageBitmap().orEmpty()
painterResource("grayscale_on.png")
} else {
resource("grayscale_off.png").rememberImageBitmap().orEmpty()
painterResource("grayscale_off.png")
}
FilterType.Pixel -> if (active) {
resource("pixel_on.png").rememberImageBitmap().orEmpty()
painterResource("pixel_on.png")
} else {
resource("pixel_off.png").rememberImageBitmap().orEmpty()
painterResource("pixel_off.png")
}
FilterType.Blur -> if (active) {
resource("blur_on.png").rememberImageBitmap().orEmpty()
painterResource("blur_on.png")
} else {
resource("blur_off.png").rememberImageBitmap().orEmpty()
painterResource("blur_off.png")
}
}
}

8
experimental/examples/imageviewer/shared/src/commonMain/kotlin/example/imageviewer/view/MainScreen.kt

@ -49,9 +49,7 @@ import example.imageviewer.model.bigUrl
import example.imageviewer.style.ImageviewerColors
import example.imageviewer.style.ImageviewerColors.kotlinHorizontalGradientBrush
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.orEmpty
import org.jetbrains.compose.resources.rememberImageBitmap
import org.jetbrains.compose.resources.resource
import org.jetbrains.compose.resources.painterResource
@Composable
internal fun GalleryHeader() {
@ -217,7 +215,7 @@ private fun TitleBar(onRefresh: () -> Unit, onToggle: () -> Unit, dependencies:
shape = CircleShape
) {
Image(
bitmap = resource("list_view.png").rememberImageBitmap().orEmpty(),
painter = painterResource("list_view.png"),
contentDescription = null,
modifier = Modifier.size(35.dp).clickable {
onToggle()
@ -230,7 +228,7 @@ private fun TitleBar(onRefresh: () -> Unit, onToggle: () -> Unit, dependencies:
shape = CircleShape
) {
Image(
bitmap = resource("refresh.png").rememberImageBitmap().orEmpty(),
painter = painterResource("refresh.png"),
contentDescription = null,
modifier = Modifier.size(35.dp).clickable {
onRefresh()

6
experimental/examples/imageviewer/shared/src/commonMain/kotlin/example/imageviewer/view/Miniature.kt

@ -28,9 +28,7 @@ import androidx.compose.ui.unit.dp
import example.imageviewer.model.Picture
import example.imageviewer.model.name
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.orEmpty
import org.jetbrains.compose.resources.rememberImageBitmap
import org.jetbrains.compose.resources.resource
import org.jetbrains.compose.resources.painterResource
@OptIn(ExperimentalResourceApi::class, ExperimentalMaterial3Api::class)
@Composable
@ -77,7 +75,7 @@ internal fun Miniature(
)
Image(
resource("dots.png").rememberImageBitmap().orEmpty(),
painterResource("dots.png"),
contentDescription = null,
modifier = Modifier.height(70.dp)
.width(30.dp)

Loading…
Cancel
Save