Skip to content

Commit

Permalink
feat: remove usage of context receivers (#26)
Browse files Browse the repository at this point in the history
* Remove usage of context receivers

* Update Gradle files

* Update sample app
  • Loading branch information
Ezard authored Apr 9, 2023
1 parent 46835f3 commit f0085ce
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 12 deletions.
1 change: 0 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ android {
}
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs = listOf("-Xcontext-receivers")
}
@Suppress("UnstableApiUsage")
buildFeatures {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ fun ButtonManuscript() {

// set up 1 or more variants of the component
Variant(name = "Red") {
RedButton(text = text, onClick = { onClick.trigger() })
RedButton(text = text, onClick = onClick::trigger)
}
Variant(name = "Green") {
GreenButton(text = text, onClick = { onClick.trigger() })
GreenButton(text = text, onClick = onClick::trigger)
}
Variant(name = "Blue") {
BlueButton(text = text, onClick = { onClick.trigger() })
BlueButton(text = text, onClick = onClick::trigger)
}
}
}
1 change: 0 additions & 1 deletion manuscript/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ android {
}
kotlinOptions {
jvmTarget = "11"
freeCompilerArgs = listOf("-Xcontext-receivers")
}
@Suppress("UnstableApiUsage")
buildFeatures {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class Action(
/**
* Trigger an instance of this action to appear in the "Actions" section of Manuscript's bottom sheet
*/
context(ManuscriptScope)
fun trigger() {
onTrigger(this)
}
Expand All @@ -41,9 +40,8 @@ class Action(
*
* @sample [io.ezard.manuscript.actions.ActionSample]
*/
context(ManuscriptScope)
@Composable
fun action(name: String): Action {
fun ManuscriptScope.action(name: String): Action {
val data = LocalManuscriptData.current
return Action(name = name, onTrigger = data::triggerAction)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,8 @@ private fun CustomControlSample() {
*
* @sample [io.ezard.manuscript.controls.ControlSample]
*/
context(ManuscriptScope)
@Composable
fun <T> control(name: String, defaultValue: T): Control<T> {
fun <T> ManuscriptScope.control(name: String, defaultValue: T): Control<T> {
val state = remember { mutableStateOf(defaultValue) }
val data = LocalManuscriptData.current
return remember {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ internal class Variant(
*
* @sample [io.ezard.manuscript.variant.VariantSample]
*/
context(ManuscriptScope)
@Composable
fun Variant(name: String, block: @Composable () -> Unit) {
fun ManuscriptScope.Variant(name: String, block: @Composable () -> Unit) {
LocalManuscriptData.current.registerVariant(name, block)
}

Expand Down

0 comments on commit f0085ce

Please sign in to comment.