Skip to content

Commit

Permalink
remove remember to recalculate value when orientation change
Browse files Browse the repository at this point in the history
  • Loading branch information
Fethi Tewelde committed Oct 3, 2024
1 parent 2524336 commit a41e10f
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
<string name="show_less">Show Less</string>
<string name="production_places">Production Places</string>

<string name="permission_denied">Please grant storage permission.</string>
<string name="permission_denied">Please grant storage permission in Settings.</string>
<string name="permission_denied_ios">Allow access to photos in Settings.</string>
<string name="settings">Settings</string>
<string name="saving_failed">Image not saved, try again later.</string>
<string name="saving_success">Image saved.</string>
Expand Down
18 changes: 8 additions & 10 deletions feature/arts/src/androidMain/kotlin/Utils.android.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,23 @@ import android.os.Build
import android.os.Environment
import android.provider.MediaStore
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalView
import com.tewelde.rijksmuseum.core.model.Art
import com.tewelde.rijksmuseum.resources.Res
import com.tewelde.rijksmuseum.resources.permission_denied
import io.github.vinceglb.filekit.core.FileKitPlatformSettings
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import okio.FileSystem
import org.jetbrains.compose.resources.StringResource
import kotlin.coroutines.coroutineContext

@Composable
actual fun screenHeight(): Int {
val view = LocalView.current
return remember { view.resources.displayMetrics.heightPixels }
}
actual fun screenHeight(): Int = LocalView.current.resources.displayMetrics.heightPixels

@Composable
actual fun screenWidth(): Int {
val view = LocalView.current
return remember { view.resources.displayMetrics.widthPixels }
}
actual fun screenWidth(): Int = LocalView.current.resources.displayMetrics.widthPixels


actual class FileUtil(private val context: Context) {
Expand Down Expand Up @@ -77,4 +73,6 @@ actual val Art.artUrl: String
get() = this.webImage.url

actual val minGridSize: Int
get() = 175
get() = 175

actual val permissionDeniedMessage: StringResource = Res.string.permission_denied
3 changes: 3 additions & 0 deletions feature/arts/src/commonMain/kotlin/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import androidx.compose.runtime.Composable
import com.tewelde.rijksmuseum.core.model.Art
import io.github.vinceglb.filekit.core.FileKitPlatformSettings
import okio.FileSystem
import org.jetbrains.compose.resources.StringResource

@Composable
expect fun screenHeight(): Int
Expand All @@ -11,6 +12,8 @@ expect fun screenWidth(): Int

expect val Art.artUrl: String

expect val permissionDeniedMessage: StringResource

expect val minGridSize: Int

expect class FileUtil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ import com.tewelde.rijksmuseum.feature.arts.detail.model.DetailState
import com.tewelde.rijksmuseum.feature.arts.detail.model.State
import com.tewelde.rijksmuseum.feature.arts.gallery.components.BackButton
import com.tewelde.rijksmuseum.resources.Res
import com.tewelde.rijksmuseum.resources.permission_denied
import com.tewelde.rijksmuseum.resources.saving_failed
import com.tewelde.rijksmuseum.resources.saving_success
import com.tewelde.rijksmuseum.resources.settings
import org.jetbrains.compose.resources.getString
import permissionDeniedMessage
import screenHeight
import screenWidth

Expand Down Expand Up @@ -106,7 +106,7 @@ fun DetailScreen(
LaunchedEffect(uiState.showPermissionError) {
if (uiState.showPermissionError) {
onShowSnackbar(
getString(Res.string.permission_denied),
getString(permissionDeniedMessage),
getString(Res.string.settings),
SnackbarDuration.Long
).run {
Expand Down
18 changes: 8 additions & 10 deletions feature/arts/src/desktopMain/kotlin/Utils.desktop.kt
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.platform.LocalWindowInfo
import com.tewelde.rijksmuseum.core.model.Art
import com.tewelde.rijksmuseum.resources.Res
import com.tewelde.rijksmuseum.resources.permission_denied
import io.github.vinceglb.filekit.core.FileKit
import io.github.vinceglb.filekit.core.FileKitPlatformSettings
import okio.FileSystem
import org.jetbrains.compose.resources.StringResource

@OptIn(ExperimentalComposeUiApi::class)
@Composable
actual fun screenHeight(): Int {
val view = LocalWindowInfo.current
return remember { view.containerSize.height }
}
actual fun screenHeight(): Int = LocalWindowInfo.current.containerSize.height

@OptIn(ExperimentalComposeUiApi::class)
@Composable
actual fun screenWidth(): Int {
val view = LocalWindowInfo.current
return remember { view.containerSize.width }
}
actual fun screenWidth(): Int = LocalWindowInfo.current.containerSize.width


actual class FileUtil {
Expand Down Expand Up @@ -54,4 +50,6 @@ actual val Art.artUrl: String
get() = this.headerImage?.url ?: this.webImage.url

actual val minGridSize: Int
get() = 325
get() = 325

actual val permissionDeniedMessage: StringResource = Res.string.permission_denied
17 changes: 7 additions & 10 deletions feature/arts/src/iosMain/kotlin/Utils.ios.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.platform.LocalWindowInfo
import com.tewelde.rijksmuseum.core.model.Art
import com.tewelde.rijksmuseum.resources.Res
import com.tewelde.rijksmuseum.resources.permission_denied_ios
import io.github.vinceglb.filekit.core.FileKitPlatformSettings
import kotlinx.cinterop.ExperimentalForeignApi
import kotlinx.cinterop.allocArrayOf
Expand All @@ -12,6 +13,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.IO
import kotlinx.coroutines.launch
import okio.FileSystem
import org.jetbrains.compose.resources.StringResource
import platform.Foundation.NSData
import platform.Foundation.create
import platform.UIKit.UIImage
Expand All @@ -20,17 +22,11 @@ import kotlin.coroutines.coroutineContext

@OptIn(ExperimentalComposeUiApi::class)
@Composable
actual fun screenHeight(): Int {
val view = LocalWindowInfo.current
return remember { view.containerSize.height }
}
actual fun screenHeight(): Int = LocalWindowInfo.current.containerSize.height

@OptIn(ExperimentalComposeUiApi::class)
@Composable
actual fun screenWidth(): Int {
val view = LocalWindowInfo.current
return remember { view.containerSize.width }
}
actual fun screenWidth(): Int = LocalWindowInfo.current.containerSize.width

actual class FileUtil {
actual fun filesystem(): FileSystem? = FileSystem.SYSTEM
Expand Down Expand Up @@ -79,4 +75,5 @@ actual val Art.artUrl: String
get() = this.webImage.url

actual val minGridSize: Int
get() = 175
get() = 175
actual val permissionDeniedMessage: StringResource = Res.string.permission_denied_ios
16 changes: 7 additions & 9 deletions feature/arts/src/wasmJsMain/kotlin/Utils.wasmJs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,19 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.platform.LocalWindowInfo
import com.tewelde.rijksmuseum.core.model.Art
import com.tewelde.rijksmuseum.resources.*
import io.github.vinceglb.filekit.core.FileKit
import io.github.vinceglb.filekit.core.FileKitPlatformSettings
import okio.FileSystem
import org.jetbrains.compose.resources.StringResource

@OptIn(ExperimentalComposeUiApi::class)
@Composable
actual fun screenHeight(): Int {
val view = LocalWindowInfo.current
return remember { view.containerSize.height }
}
actual fun screenHeight(): Int = LocalWindowInfo.current.containerSize.height

@OptIn(ExperimentalComposeUiApi::class)
@Composable
actual fun screenWidth(): Int {
val view = LocalWindowInfo.current
return remember { view.containerSize.width }
}
actual fun screenWidth(): Int = LocalWindowInfo.current.containerSize.width

actual class FileUtil {
actual fun filesystem(): FileSystem? = null
Expand Down Expand Up @@ -54,4 +50,6 @@ actual val Art.artUrl: String
get() = this.headerImage?.url ?: this.webImage.url

actual val minGridSize: Int
get() = 325
get() = 325

actual val permissionDeniedMessage: StringResource = Res.string.permission_denied

0 comments on commit a41e10f

Please sign in to comment.