forked from readium/kotlin-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use material3 for Compose views (readium#460)
- Loading branch information
1 parent
9696c43
commit 33a0c77
Showing
11 changed files
with
112 additions
and
59 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
41 changes: 41 additions & 0 deletions
41
test-app/src/main/java/org/readium/r2/testapp/utils/compose/EmphasisProvider.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.readium.r2.testapp.utils.compose | ||
|
||
import androidx.compose.material3.LocalContentColor | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.ProvideTextStyle | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.CompositionLocalProvider | ||
import androidx.compose.runtime.ProvidedValue | ||
import androidx.compose.runtime.compositionLocalOf | ||
import androidx.compose.ui.text.TextStyle | ||
import androidx.compose.ui.text.font.FontWeight | ||
|
||
val LocalContentEmphasis = compositionLocalOf { Emphasis.Medium } | ||
|
||
enum class Emphasis { | ||
Disabled, | ||
Medium, | ||
High | ||
} | ||
|
||
@Composable | ||
fun EmphasisProvider(emphasis: ProvidedValue<Emphasis>, content: @Composable () -> Unit) { | ||
val contentColor = when (emphasis.value) { | ||
Emphasis.Disabled -> MaterialTheme.colorScheme.onSurface.copy(alpha = 0.38f) | ||
Emphasis.Medium -> MaterialTheme.colorScheme.onSurfaceVariant | ||
Emphasis.High -> MaterialTheme.colorScheme.onSurface | ||
} | ||
val fontWeight = when (emphasis.value) { | ||
Emphasis.High -> FontWeight.Bold | ||
else -> FontWeight.Normal | ||
} | ||
|
||
CompositionLocalProvider( | ||
LocalContentColor provides contentColor, | ||
content = { | ||
ProvideTextStyle(value = TextStyle(fontWeight = fontWeight)) { | ||
content() | ||
} | ||
} | ||
) | ||
} |
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