Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

Handle RTL for shape corner sizes #44

Merged
merged 7 commits into from
Feb 8, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
Expand Up @@ -122,6 +122,7 @@ data class ThemeParameters(
* @return [ThemeParameters] instance containing the resulting [Colors], [Typography]
* and [Shapes].
*/
@Composable
fun createMdcTheme(
context: Context,
density: Density = Density(context),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,18 @@ import android.content.res.TypedArray
import android.graphics.Typeface
import android.os.Build
import android.util.TypedValue
import android.view.View
import androidx.annotation.RequiresApi
import androidx.annotation.StyleRes
import androidx.compose.foundation.shape.CornerBasedShape
import androidx.compose.foundation.shape.CornerSize
import androidx.compose.foundation.shape.CutCornerShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shadow
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.Font
import androidx.compose.ui.text.font.FontFamily
Expand Down Expand Up @@ -128,6 +131,7 @@ internal fun textStyleFromTextAppearance(
}
}

@Composable
internal fun parseShapeAppearance(
context: Context,
@StyleRes id: Int,
Expand All @@ -137,18 +141,23 @@ internal fun parseShapeAppearance(
val defaultCornerSize = a.getCornerSizeOrNull(
R.styleable.ComposeThemeAdapterShapeAppearance_cornerSize
)
val cornerSizeTS = a.getCornerSizeOrNull(
val cornerSizeTL = a.getCornerSizeOrNull(
R.styleable.ComposeThemeAdapterShapeAppearance_cornerSizeTopLeft
)
val cornerSizeTE = a.getCornerSizeOrNull(
val cornerSizeTR = a.getCornerSizeOrNull(
R.styleable.ComposeThemeAdapterShapeAppearance_cornerSizeTopRight
)
val cornerSizeBS = a.getCornerSizeOrNull(
val cornerSizeBL = a.getCornerSizeOrNull(
R.styleable.ComposeThemeAdapterShapeAppearance_cornerSizeBottomLeft
)
val cornerSizeBE = a.getCornerSizeOrNull(
val cornerSizeBR = a.getCornerSizeOrNull(
R.styleable.ComposeThemeAdapterShapeAppearance_cornerSizeBottomRight
)
val isRtl = LocalConfiguration.current.layoutDirection == View.LAYOUT_DIRECTION_RTL
val cornerSizeTS = if (isRtl) cornerSizeTR else cornerSizeTL
val cornerSizeTE = if (isRtl) cornerSizeTL else cornerSizeTR
val cornerSizeBS = if (isRtl) cornerSizeBR else cornerSizeBL
val cornerSizeBE = if (isRtl) cornerSizeBL else cornerSizeBR

/**
* We do not support the individual `cornerFamilyTopLeft`, etc, since Compose only supports
Expand Down