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.runtime)
implementation(compose.foundation) implementation(compose.foundation)
implementation(compose.material) 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") implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1")
@OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class) @OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
implementation(compose.material3) 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.draw.clip
import androidx.compose.ui.graphics.ImageBitmap import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.painter.BitmapPainter import androidx.compose.ui.graphics.painter.BitmapPainter
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.input.key.* import androidx.compose.ui.input.key.*
import androidx.compose.ui.layout.onGloballyPositioned import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.unit.IntRect import androidx.compose.ui.unit.IntRect
@ -26,9 +27,7 @@ import example.imageviewer.core.FilterType
import example.imageviewer.model.* import example.imageviewer.model.*
import example.imageviewer.style.* import example.imageviewer.style.*
import org.jetbrains.compose.resources.ExperimentalResourceApi import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.orEmpty import org.jetbrains.compose.resources.painterResource
import org.jetbrains.compose.resources.rememberImageBitmap
import org.jetbrains.compose.resources.resource
@Composable @Composable
internal fun FullscreenImage( internal fun FullscreenImage(
@ -157,7 +156,7 @@ private fun FullscreenImageBar(
navigationIcon = { navigationIcon = {
Tooltip(localization.back) { Tooltip(localization.back) {
Image( Image(
resource("back.png").rememberImageBitmap().orEmpty(), painterResource("back.png"),
contentDescription = null, contentDescription = null,
modifier = Modifier.size(38.dp) modifier = Modifier.size(38.dp)
.clip(CircleShape) .clip(CircleShape)
@ -205,24 +204,24 @@ private fun FilterButton(
@OptIn(ExperimentalResourceApi::class) @OptIn(ExperimentalResourceApi::class)
@Composable @Composable
private fun getFilterImage(active: Boolean, type: FilterType): ImageBitmap { private fun getFilterImage(active: Boolean, type: FilterType): Painter {
return when (type) { return when (type) {
FilterType.GrayScale -> if (active) { FilterType.GrayScale -> if (active) {
resource("grayscale_on.png").rememberImageBitmap().orEmpty() painterResource("grayscale_on.png")
} else { } else {
resource("grayscale_off.png").rememberImageBitmap().orEmpty() painterResource("grayscale_off.png")
} }
FilterType.Pixel -> if (active) { FilterType.Pixel -> if (active) {
resource("pixel_on.png").rememberImageBitmap().orEmpty() painterResource("pixel_on.png")
} else { } else {
resource("pixel_off.png").rememberImageBitmap().orEmpty() painterResource("pixel_off.png")
} }
FilterType.Blur -> if (active) { FilterType.Blur -> if (active) {
resource("blur_on.png").rememberImageBitmap().orEmpty() painterResource("blur_on.png")
} else { } 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
import example.imageviewer.style.ImageviewerColors.kotlinHorizontalGradientBrush import example.imageviewer.style.ImageviewerColors.kotlinHorizontalGradientBrush
import org.jetbrains.compose.resources.ExperimentalResourceApi import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.orEmpty import org.jetbrains.compose.resources.painterResource
import org.jetbrains.compose.resources.rememberImageBitmap
import org.jetbrains.compose.resources.resource
@Composable @Composable
internal fun GalleryHeader() { internal fun GalleryHeader() {
@ -217,7 +215,7 @@ private fun TitleBar(onRefresh: () -> Unit, onToggle: () -> Unit, dependencies:
shape = CircleShape shape = CircleShape
) { ) {
Image( Image(
bitmap = resource("list_view.png").rememberImageBitmap().orEmpty(), painter = painterResource("list_view.png"),
contentDescription = null, contentDescription = null,
modifier = Modifier.size(35.dp).clickable { modifier = Modifier.size(35.dp).clickable {
onToggle() onToggle()
@ -230,7 +228,7 @@ private fun TitleBar(onRefresh: () -> Unit, onToggle: () -> Unit, dependencies:
shape = CircleShape shape = CircleShape
) { ) {
Image( Image(
bitmap = resource("refresh.png").rememberImageBitmap().orEmpty(), painter = painterResource("refresh.png"),
contentDescription = null, contentDescription = null,
modifier = Modifier.size(35.dp).clickable { modifier = Modifier.size(35.dp).clickable {
onRefresh() 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.Picture
import example.imageviewer.model.name import example.imageviewer.model.name
import org.jetbrains.compose.resources.ExperimentalResourceApi import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.orEmpty import org.jetbrains.compose.resources.painterResource
import org.jetbrains.compose.resources.rememberImageBitmap
import org.jetbrains.compose.resources.resource
@OptIn(ExperimentalResourceApi::class, ExperimentalMaterial3Api::class) @OptIn(ExperimentalResourceApi::class, ExperimentalMaterial3Api::class)
@Composable @Composable
@ -77,7 +75,7 @@ internal fun Miniature(
) )
Image( Image(
resource("dots.png").rememberImageBitmap().orEmpty(), painterResource("dots.png"),
contentDescription = null, contentDescription = null,
modifier = Modifier.height(70.dp) modifier = Modifier.height(70.dp)
.width(30.dp) .width(30.dp)

Loading…
Cancel
Save