This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun ParallaxCarouselItem( | |
imageResId: Int, | |
parallaxOffset: Float, | |
pagerHeight: Dp, | |
screenWidth: Dp, | |
density: Float, | |
) { | |
// Load the image bitmap | |
val imageBitmap = ImageBitmap.imageResource(id = imageResId) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Function to calculate draw size for the image | |
private fun ImageBitmap.calculateDrawSize(density: Float, screenWidth: Dp, pagerHeight: Dp): IntSize { | |
val originalImageWidth = width / density | |
val originalImageHeight = height / density | |
val frameAspectRatio = screenWidth / pagerHeight | |
val imageAspectRatio = originalImageWidth / originalImageHeight | |
val drawWidth = xOffset + if (frameAspectRatio > imageAspectRatio) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Padding values | |
private val cardPadding = 25.dp | |
private val imagePadding = 10.dp | |
// Shadow and shape values for the card | |
private val shadowElevation = 15.dp | |
private val borderRadius = 15.dp | |
private val shape = RoundedCornerShape(borderRadius) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import shared | |
import Combine | |
@MainActor | |
final class ReducerViewModel<S, V>: ObservableObject where S: UiState, V: ViewModel, V: StateFlowAdaptable { | |
@LazyKoin var viewModel: V | |
@Published public var state: S? | |
@Published public var error: String? | |
private var cancellables = Set<AnyCancellable>() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface StateFlowAdaptable { | |
val stateFlowAdapter: FlowAdapter<*> | |
val errorFlowAdapter: FlowAdapter<*> | |
} | |
interface UiState | |
interface UiEvent | |
abstract class Reducer<S : UiState, E : UiEvent>(initialVal: S) : ViewModel(), StateFlowAdaptable { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
guard let reducer = (viewModel as? Reducer<S, shared.UiEvent>) else { | |
return | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import shared | |
import Combine | |
@MainActor | |
final class ReducerViewModel<S: UiState, V: ViewModel>: ObservableObject { | |
@LazyKoin var viewModel: V | |
@Published public var state: S? | |
@Published public var error: String? | |
init() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface UiState | |
interface UiEvent | |
abstract class Reducer<S : UiState, E : UiEvent>(initialVal: S) : ViewModel() { | |
//... | |
private val _state: MutableStateFlow<S> = MutableStateFlow(initialVal) | |
val state: StateFlow<S> | |
get() = _state |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.graphics.BlurMaskFilter | |
import androidx.compose.ui.graphics.NativePaint | |
internal actual fun NativePaint.setMaskFilter(blurRadius: Float) { | |
this.maskFilter = BlurMaskFilter(blurRadius, BlurMaskFilter.Blur.NORMAL) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import androidx.compose.ui.graphics.NativePaint | |
import org.jetbrains.skia.FilterBlurMode | |
import org.jetbrains.skia.MaskFilter | |
internal actual fun NativePaint.setMaskFilter(blurRadius: Float) { | |
this.maskFilter = MaskFilter.makeBlur(FilterBlurMode.NORMAL, blurRadius / 2, true) | |
} |
NewerOlder