Browse Source

ImageViewer material3 -> material (#2943)

pull/2954/head
dima.avdeev 2 years ago committed by GitHub
parent
commit
2d498598c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      experimental/examples/imageviewer/shared/build.gradle.kts
  2. 4
      experimental/examples/imageviewer/shared/src/androidMain/kotlin/example/imageviewer/view/CameraView.android.kt
  3. 6
      experimental/examples/imageviewer/shared/src/commonMain/kotlin/example/imageviewer/ImageViewer.common.kt
  4. 8
      experimental/examples/imageviewer/shared/src/commonMain/kotlin/example/imageviewer/style/Palette.kt
  5. 2
      experimental/examples/imageviewer/shared/src/commonMain/kotlin/example/imageviewer/view/FullscreenImageScreen.kt
  6. 19
      experimental/examples/imageviewer/shared/src/commonMain/kotlin/example/imageviewer/view/GalleryScreen.kt
  7. 37
      experimental/examples/imageviewer/shared/src/commonMain/kotlin/example/imageviewer/view/LoadingScreen.kt
  8. 14
      experimental/examples/imageviewer/shared/src/commonMain/kotlin/example/imageviewer/view/MemoryScreen.kt
  9. 16
      experimental/examples/imageviewer/shared/src/commonMain/kotlin/example/imageviewer/view/Thumbnail.kt
  10. 3
      experimental/examples/imageviewer/shared/src/commonMain/kotlin/example/imageviewer/view/Toast.kt
  11. 6
      experimental/examples/imageviewer/shared/src/desktopMain/kotlin/example/imageviewer/view/CameraView.desktop.kt
  12. 6
      experimental/examples/imageviewer/shared/src/iosMain/kotlin/example/imageviewer/view/CameraView.ios.kt

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

@ -35,7 +35,6 @@ kotlin {
implementation(compose.runtime) implementation(compose.runtime)
implementation(compose.foundation) implementation(compose.foundation)
implementation(compose.material) implementation(compose.material)
implementation(compose.material3)
@OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class) @OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
implementation(compose.components.resources) implementation(compose.components.resources)
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.0") implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.0")

4
experimental/examples/imageviewer/shared/src/androidMain/kotlin/example/imageviewer/view/CameraView.android.kt

@ -13,8 +13,8 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.size
import androidx.compose.material.Button import androidx.compose.material.Button
import androidx.compose.material3.CircularProgressIndicator import androidx.compose.material.CircularProgressIndicator
import androidx.compose.material3.Text import androidx.compose.material.Text
import androidx.compose.runtime.* import androidx.compose.runtime.*
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier

6
experimental/examples/imageviewer/shared/src/commonMain/kotlin/example/imageviewer/ImageViewer.common.kt

@ -2,11 +2,8 @@ package example.imageviewer
import androidx.compose.animation.* import androidx.compose.animation.*
import androidx.compose.animation.core.tween import androidx.compose.animation.core.tween
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Surface
import androidx.compose.runtime.* import androidx.compose.runtime.*
import androidx.compose.runtime.snapshots.SnapshotStateList import androidx.compose.runtime.snapshots.SnapshotStateList
import androidx.compose.ui.Modifier
import example.imageviewer.model.* import example.imageviewer.model.*
import example.imageviewer.view.* import example.imageviewer.view.*
@ -16,7 +13,6 @@ enum class ExternalImageViewerEvent {
Escape, Escape,
} }
@OptIn(ExperimentalAnimationApi::class)
@Composable @Composable
internal fun ImageViewerCommon( internal fun ImageViewerCommon(
dependencies: Dependencies dependencies: Dependencies
@ -48,7 +44,6 @@ internal fun ImageViewerWithProvidedDependencies(
} }
} }
Surface(modifier = Modifier.fillMaxSize()) {
AnimatedContent(targetState = navigationStack.lastWithIndex(), transitionSpec = { AnimatedContent(targetState = navigationStack.lastWithIndex(), transitionSpec = {
val previousIdx = initialState.index val previousIdx = initialState.index
val currentIdx = targetState.index val currentIdx = targetState.index
@ -112,5 +107,4 @@ internal fun ImageViewerWithProvidedDependencies(
} }
} }
} }
}
} }

8
experimental/examples/imageviewer/shared/src/commonMain/kotlin/example/imageviewer/style/Palette.kt

@ -1,9 +1,9 @@
package example.imageviewer.style package example.imageviewer.style
import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.LocalTextStyle import androidx.compose.material.LocalTextStyle
import androidx.compose.material3.MaterialTheme import androidx.compose.material.MaterialTheme
import androidx.compose.material3.ProvideTextStyle import androidx.compose.material.ProvideTextStyle
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
@ -51,7 +51,7 @@ object ImageviewerColors {
internal fun ImageViewerTheme(content: @Composable () -> Unit) { internal fun ImageViewerTheme(content: @Composable () -> Unit) {
isSystemInDarkTheme() // todo check and change colors isSystemInDarkTheme() // todo check and change colors
MaterialTheme( MaterialTheme(
colorScheme = MaterialTheme.colorScheme.copy( colors = MaterialTheme.colors.copy(
background = ImageviewerColors.background, background = ImageviewerColors.background,
onBackground = ImageviewerColors.onBackground onBackground = ImageviewerColors.onBackground
) )

2
experimental/examples/imageviewer/shared/src/commonMain/kotlin/example/imageviewer/view/FullscreenImageScreen.kt

@ -84,8 +84,6 @@ internal fun FullscreenImageScreen(
) )
ZoomControllerView(Modifier, scalableState) ZoomControllerView(Modifier, scalableState)
} }
} else {
LoadingScreen()
} }
TopLayout( TopLayout(

19
experimental/examples/imageviewer/shared/src/commonMain/kotlin/example/imageviewer/view/GalleryScreen.kt

@ -2,30 +2,20 @@
package example.imageviewer.view package example.imageviewer.view
import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.AnimatedContentScope
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.animation.core.FastOutSlowInEasing
import androidx.compose.animation.core.tween
import androidx.compose.animation.with
import androidx.compose.foundation.Image import androidx.compose.foundation.Image
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.grid.GridCells import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.itemsIndexed import androidx.compose.foundation.lazy.grid.itemsIndexed
import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.MaterialTheme import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.* import androidx.compose.runtime.*
import androidx.compose.runtime.snapshots.SnapshotStateList import androidx.compose.runtime.snapshots.SnapshotStateList
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import example.imageviewer.* import example.imageviewer.*
import example.imageviewer.model.* import example.imageviewer.model.*
@ -33,7 +23,6 @@ import example.imageviewer.style.ImageviewerColors
import org.jetbrains.compose.resources.ExperimentalResourceApi import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.painterResource import org.jetbrains.compose.resources.painterResource
enum class GalleryStyle { enum class GalleryStyle {
SQUARES, SQUARES,
LIST LIST
@ -75,7 +64,7 @@ internal fun GalleryScreen(
} }
} }
Column(modifier = Modifier.background(MaterialTheme.colorScheme.background)) { Column(modifier = Modifier.background(MaterialTheme.colors.background)) {
Box { Box {
picture?.let { picture?.let {
PreviewImage( PreviewImage(
@ -125,9 +114,8 @@ private fun SquaresGalleryView(
selectedImage: PictureData?, selectedImage: PictureData?,
onSelect: (PictureData) -> Unit, onSelect: (PictureData) -> Unit,
) { ) {
Column {
Spacer(Modifier.height(4.dp))
LazyVerticalGrid( LazyVerticalGrid(
modifier = Modifier.padding(top = 4.dp),
columns = GridCells.Adaptive(minSize = 130.dp), columns = GridCells.Adaptive(minSize = 130.dp),
verticalArrangement = Arrangement.spacedBy(1.dp), verticalArrangement = Arrangement.spacedBy(1.dp),
horizontalArrangement = Arrangement.spacedBy(1.dp) horizontalArrangement = Arrangement.spacedBy(1.dp)
@ -141,7 +129,6 @@ private fun SquaresGalleryView(
) )
} }
} }
}
} }
@OptIn(ExperimentalResourceApi::class) @OptIn(ExperimentalResourceApi::class)

37
experimental/examples/imageviewer/shared/src/commonMain/kotlin/example/imageviewer/view/LoadingScreen.kt

@ -1,37 +0,0 @@
package example.imageviewer.view
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
@Composable
internal fun LoadingScreen(text: String = "") {
Box(
modifier = Modifier.fillMaxSize().background(color = MaterialTheme.colorScheme.background)
) {
Box(modifier = Modifier.align(Alignment.Center)) {
Surface(/*elevation = 4.dp, */shape = CircleShape) {
CircularProgressIndicator(
modifier = Modifier.size(50.dp).padding(3.dp, 3.dp, 4.dp, 4.dp)
)
}
}
Text(
text = text,
modifier = Modifier.align(Alignment.Center).offset(0.dp, 70.dp),
style = MaterialTheme.typography.bodyMedium
)
}
}

14
experimental/examples/imageviewer/shared/src/commonMain/kotlin/example/imageviewer/view/MemoryScreen.kt

@ -9,7 +9,7 @@ import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyRow import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.* import androidx.compose.material.*
import androidx.compose.runtime.* import androidx.compose.runtime.*
import androidx.compose.runtime.snapshots.SnapshotStateList import androidx.compose.runtime.snapshots.SnapshotStateList
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
@ -25,14 +25,13 @@ 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.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import example.imageviewer.ImageProvider
import example.imageviewer.LocalImageProvider import example.imageviewer.LocalImageProvider
import example.imageviewer.model.* import example.imageviewer.model.*
import example.imageviewer.style.ImageviewerColors import example.imageviewer.style.ImageviewerColors
import org.jetbrains.compose.resources.ExperimentalResourceApi import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.painterResource import org.jetbrains.compose.resources.painterResource
@OptIn(ExperimentalResourceApi::class, ExperimentalMaterial3Api::class) @OptIn(ExperimentalResourceApi::class)
@Composable @Composable
internal fun MemoryScreen( internal fun MemoryScreen(
pictures: SnapshotStateList<PictureData>, pictures: SnapshotStateList<PictureData>,
@ -71,12 +70,12 @@ internal fun MemoryScreen(
) )
} }
} }
Box(modifier = Modifier.background(MaterialTheme.colorScheme.background)) { Box(modifier = Modifier.background(MaterialTheme.colors.background)) {
Column { Column {
Headliner("Note") Headliner("Note")
Collapsible(memoryPage.picture.description) Collapsible(memoryPage.picture.description)
Headliner("Related memories") Headliner("Related memories")
RelatedMemoriesVisualizer(pictures, imageProvider, onSelectRelatedMemory) RelatedMemoriesVisualizer(pictures, onSelectRelatedMemory)
Headliner("Place") Headliner("Place")
val locationShape = RoundedCornerShape(10.dp) val locationShape = RoundedCornerShape(10.dp)
LocationVisualizer( LocationVisualizer(
@ -224,7 +223,6 @@ internal fun Headliner(s: String) {
@Composable @Composable
internal fun RelatedMemoriesVisualizer( internal fun RelatedMemoriesVisualizer(
ps: List<PictureData>, ps: List<PictureData>,
imageProvider: ImageProvider,
onSelectRelatedMemory: (PictureData) -> Unit onSelectRelatedMemory: (PictureData) -> Unit
) { ) {
Box( Box(
@ -235,7 +233,7 @@ internal fun RelatedMemoriesVisualizer(
horizontalArrangement = Arrangement.spacedBy(8.dp) horizontalArrangement = Arrangement.spacedBy(8.dp)
) { ) {
itemsIndexed(ps) { idx, item -> itemsIndexed(ps) { idx, item ->
RelatedMemory(idx, item, imageProvider, onSelectRelatedMemory) RelatedMemory(item, onSelectRelatedMemory)
} }
} }
} }
@ -243,9 +241,7 @@ internal fun RelatedMemoriesVisualizer(
@Composable @Composable
internal fun RelatedMemory( internal fun RelatedMemory(
index: Int,
galleryEntry: PictureData, galleryEntry: PictureData,
imageProvider: ImageProvider,
onSelectRelatedMemory: (PictureData) -> Unit onSelectRelatedMemory: (PictureData) -> Unit
) { ) {
Box(Modifier.size(130.dp).clip(RoundedCornerShape(8.dp))) { Box(Modifier.size(130.dp).clip(RoundedCornerShape(8.dp))) {

16
experimental/examples/imageviewer/shared/src/commonMain/kotlin/example/imageviewer/view/Thumbnail.kt

@ -7,7 +7,7 @@ import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.* import androidx.compose.material.*
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
@ -19,7 +19,7 @@ import example.imageviewer.model.PictureData
import org.jetbrains.compose.resources.ExperimentalResourceApi import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.painterResource import org.jetbrains.compose.resources.painterResource
@OptIn(ExperimentalResourceApi::class, ExperimentalMaterial3Api::class) @OptIn(ExperimentalResourceApi::class)
@Composable @Composable
internal fun Thumbnail( internal fun Thumbnail(
picture: PictureData, picture: PictureData,
@ -30,15 +30,12 @@ internal fun Thumbnail(
Card( Card(
modifier = Modifier.padding(start = 10.dp, end = 10.dp).height(70.dp) modifier = Modifier.padding(start = 10.dp, end = 10.dp).height(70.dp)
.fillMaxWidth(), .fillMaxWidth(),
onClick = { onClickSelect() },
shape = RoundedCornerShape(200.dp), shape = RoundedCornerShape(200.dp),
border = BorderStroke(1.dp, Color.White), border = BorderStroke(1.dp, Color.White),
colors = CardDefaults.cardColors( backgroundColor = MaterialTheme.colors.background,
containerColor = MaterialTheme.colorScheme.background, contentColor = MaterialTheme.colors.onBackground
contentColor = MaterialTheme.colorScheme.onBackground
)
) { ) {
Box(Modifier.clickable { onClickSelect() }) {
Row(modifier = Modifier.padding(end = 30.dp)) { Row(modifier = Modifier.padding(end = 30.dp)) {
Tooltip(picture.name) { Tooltip(picture.name) {
ThumbnailImage( ThumbnailImage(
@ -53,7 +50,7 @@ internal fun Thumbnail(
text = picture.name, text = picture.name,
modifier = Modifier.weight(1f).align(Alignment.CenterVertically) modifier = Modifier.weight(1f).align(Alignment.CenterVertically)
.padding(start = 16.dp), .padding(start = 16.dp),
style = MaterialTheme.typography.titleLarge style = MaterialTheme.typography.subtitle1
) )
Image( Image(
@ -67,4 +64,5 @@ internal fun Thumbnail(
) )
} }
} }
}
} }

3
experimental/examples/imageviewer/shared/src/commonMain/kotlin/example/imageviewer/view/Toast.kt

@ -5,7 +5,8 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.* import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.MutableState import androidx.compose.runtime.MutableState

6
experimental/examples/imageviewer/shared/src/desktopMain/kotlin/example/imageviewer/view/CameraView.desktop.kt

@ -6,8 +6,8 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Button import androidx.compose.material.Button
import androidx.compose.material3.Text import androidx.compose.material.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
@ -15,8 +15,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import example.imageviewer.* import example.imageviewer.*
import example.imageviewer.LocalLocalization
import example.imageviewer.createNewPhotoNameAndDescription
import example.imageviewer.model.PictureData import example.imageviewer.model.PictureData
import example.imageviewer.model.createCameraPictureData import example.imageviewer.model.createCameraPictureData
import org.jetbrains.compose.resources.ExperimentalResourceApi import org.jetbrains.compose.resources.ExperimentalResourceApi

6
experimental/examples/imageviewer/shared/src/iosMain/kotlin/example/imageviewer/view/CameraView.ios.kt

@ -2,9 +2,9 @@ package example.imageviewer.view
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
import androidx.compose.material3.Button import androidx.compose.material.Button
import androidx.compose.material3.CircularProgressIndicator import androidx.compose.material.CircularProgressIndicator
import androidx.compose.material3.Text import androidx.compose.material.Text
import androidx.compose.runtime.* import androidx.compose.runtime.*
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier

Loading…
Cancel
Save