Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.zomato.sushi.compose.components.calender.core

import androidx.compose.ui.text.intl.Locale
import kotlinx.datetime.DayOfWeek
import java.util.Calendar

actual fun firstDayOfWeekFromLocale(locale: Locale): DayOfWeek {
val javaLocale = java.util.Locale(locale.language, locale.region)

val firstDay = Calendar.getInstance(javaLocale).firstDayOfWeek

return when (firstDay) {
Calendar.MONDAY -> DayOfWeek.MONDAY
Calendar.TUESDAY -> DayOfWeek.TUESDAY
Calendar.WEDNESDAY -> DayOfWeek.WEDNESDAY
Calendar.THURSDAY -> DayOfWeek.THURSDAY
Calendar.FRIDAY -> DayOfWeek.FRIDAY
Calendar.SATURDAY -> DayOfWeek.SATURDAY
Calendar.SUNDAY -> DayOfWeek.SUNDAY
else -> DayOfWeek.MONDAY
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.zomato.sushi.compose.components.calender.data

import android.util.Log

internal actual fun log(tag: String, message: String) {
Log.w(tag, message)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.zomato.sushi.compose.atoms.color

import androidx.annotation.FloatRange
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
Expand All @@ -12,6 +13,8 @@ import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.graphics.TileMode
import androidx.compose.ui.unit.dp
import com.zomato.sushi.compose.atoms.color.SushiGradientColorSpec.GradientType
Expand All @@ -28,6 +31,7 @@ import com.zomato.sushi.compose.foundation.ThemedProps
import com.zomato.sushi.compose.foundation.ThemedPropsProvider
import com.zomato.sushi.compose.foundation.getThemedProps
import com.zomato.sushi.compose.internal.SushiPreview
import com.zomato.sushi.compose.modifiers.foreground.foreground
import kotlinx.collections.immutable.PersistentList
import kotlinx.collections.immutable.mutate
import kotlinx.collections.immutable.persistentListOf
Expand Down Expand Up @@ -312,6 +316,87 @@ fun List<ColorSpec>.asSushiGradientColorSpec(): SushiGradientColorSpec {
return SushiGradientColorSpec(this.toPersistentList())
}

/**
* Modifier that applies [SushiGradientColorSpec] as foreground.
*
* @param gradient the gradient to apply
* @param shape the shape to apply
* @param alpha the alpha value to apply
* @param defaultTileMode The default tile mode to use if not specified in the gradient type
* @param defaultGradientType The default gradient type to use if not specified in the SushiGradientColorData
* @return A modifier that applies the gradient as background
*/
@Composable
fun Modifier.foreground(
gradient: SushiGradientColorSpec,
shape: Shape = RectangleShape,
@FloatRange(from = 0.0, to = 1.0) alpha: Float = 1.0f,
defaultTileMode: TileMode = TileMode.Clamp,
defaultGradientType: SushiGradientColorSpec.GradientType = SushiGradientColorSpec.GradientType.Linear(defaultLinearDirection)
): Modifier {
return this.foreground(
gradient.toBrush(
defaultTileMode = defaultTileMode,
defaultGradientType = defaultGradientType
),
shape = shape, alpha = alpha
)
}


/**
* Modifier that applies [SushiGradientColorSpec] as background.
*
* @param gradient the gradient to apply
* @param shape the shape to apply
* @param alpha the alpha value to apply
* @param defaultTileMode The default tile mode to use if not specified in the gradient type
* @param defaultGradientType The default gradient type to use if not specified in the SushiGradientColorData
* @return A modifier that applies the gradient as background
*/
@Composable
fun Modifier.background(
gradient: SushiGradientColorSpec,
shape: Shape = RectangleShape,
@FloatRange(from = 0.0, to = 1.0) alpha: Float = 1.0f,
defaultTileMode: TileMode = TileMode.Clamp,
defaultGradientType: SushiGradientColorSpec.GradientType = SushiGradientColorSpec.GradientType.Linear(defaultLinearDirection)
): Modifier {
return this.background(
gradient.toBrush(
defaultTileMode = defaultTileMode,
defaultGradientType = defaultGradientType
),
shape = shape, alpha = alpha
)
}

/**
* Modifier that applies a list of [SushiGradientColorSpec] as layered backgrounds.
*
* Gradients are applied from first (bottom-most layer) to last (top-most layer), matching
* the intuitive "painter's order" — the last element in the list visually appears on top.
*
* **Note**: the list size must be stable across recompositions. Changing the number of
* gradients will reset the composition slots held by each [toBrush] call.
*
* @param gradients the ordered list of gradients to layer; returns unchanged modifier if empty
* @param defaultTileMode The default tile mode to use if not specified in the gradient type
* @param defaultGradientType The default gradient type to use if not specified in the gradient
* @return A modifier that applies all gradients as stacked backgrounds
*/
@Composable
fun Modifier.background(
gradients: List<SushiGradientColorSpec>,
defaultTileMode: TileMode = TileMode.Clamp,
defaultGradientType: SushiGradientColorSpec.GradientType = SushiGradientColorSpec.GradientType.Linear(defaultLinearDirection)
): Modifier {
if (gradients.isEmpty()) return this
return gradients.fold(this) { acc, gradient ->
acc.background(gradient.toBrush(defaultTileMode, defaultGradientType))
}
}

@SushiPreview
@Composable
private fun SushiGradientPreview() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.rotate
import androidx.compose.ui.draw.scale
import androidx.compose.ui.graphics.BlendMode
import androidx.compose.ui.graphics.ColorFilter
Expand Down Expand Up @@ -98,6 +99,7 @@ private fun SushiImageImpl(
contentDescription,
modifier
.ifNonNull(onClick) { this.clickable(onClick = it) }
.ifNonNull(props.rotation) { this.rotate(it) }
.ifNonNull(border) { this.border(it) }
.ifNonNull(props.shape) { this.clip(it) }
.ifNonNull(height) { this.height(it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import com.zomato.sushi.compose.atoms.color.ColorSpec
* @property scaleFactor Additional scaling factor applied to the image size
* @property alignment How the image should be aligned within its bounds
* @property colorFilter Optional filter to apply color transformations to the image
* @property rotation Rotation angle in degrees for the image (from the center) in clockwise rotation (Negative degrees also supported).
*
* @author gupta.anirudh@zomato.com
*/
Expand All @@ -47,4 +48,5 @@ data class SushiImageProps(
val scaleFactor: Float? = null,
val alignment: Alignment? = null,
val colorFilter: ColorFilter? = null,
val rotation: Float? = null
)
Loading