Browse Source

Add previews to TodoApp example (#909)

pull/883/merge
Arkadii Ivanov 3 years ago committed by GitHub
parent
commit
d89671218a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      examples/todoapp/desktop/build.gradle.kts
  2. 33
      examples/todoapp/desktop/src/jvmMain/kotlin/example/todo/desktop/TodoEditPreview.kt
  3. 42
      examples/todoapp/desktop/src/jvmMain/kotlin/example/todo/desktop/TodoMainPreview.kt

5
examples/todoapp/desktop/build.gradle.kts

@ -25,6 +25,11 @@ kotlin {
implementation(Deps.ArkIvanov.MVIKotlin.mvikotlinMain) implementation(Deps.ArkIvanov.MVIKotlin.mvikotlinMain)
implementation(Deps.Badoo.Reaktive.reaktive) implementation(Deps.Badoo.Reaktive.reaktive)
implementation(Deps.Badoo.Reaktive.coroutinesInterop) implementation(Deps.Badoo.Reaktive.coroutinesInterop)
// The dependencies below are required only for previews, see https://github.com/JetBrains/compose-jb/issues/908
implementation(compose.uiTooling)
implementation(project(":common:edit"))
implementation(project(":common:main"))
} }
} }
} }

33
examples/todoapp/desktop/src/jvmMain/kotlin/example/todo/desktop/TodoEditPreview.kt

@ -0,0 +1,33 @@
/*
* Should be in the compose-ui module, see https://github.com/JetBrains/compose-jb/issues/908
*/
package example.todo.desktop
import androidx.compose.desktop.ui.tooling.preview.Preview
import androidx.compose.runtime.Composable
import com.arkivanov.decompose.value.MutableValue
import com.arkivanov.decompose.value.Value
import example.todo.common.edit.TodoEdit
import example.todo.common.edit.TodoEdit.Model
import example.todo.common.ui.TodoEditContent
@Composable
@Preview
fun TodoEditContentPreview() {
TodoEditContent(TodoEditPreview())
}
class TodoEditPreview : TodoEdit {
override val models: Value<Model> =
MutableValue(
Model(
text = "Some text",
isDone = true
)
)
override fun onTextChanged(text: String) {}
override fun onDoneChanged(isDone: Boolean) {}
override fun onCloseClicked() {}
}

42
examples/todoapp/desktop/src/jvmMain/kotlin/example/todo/desktop/TodoMainPreview.kt

@ -0,0 +1,42 @@
/*
* Should be in the compose-ui module, see https://github.com/JetBrains/compose-jb/issues/908
*/
package example.todo.desktop
import androidx.compose.desktop.ui.tooling.preview.Preview
import androidx.compose.runtime.Composable
import com.arkivanov.decompose.value.MutableValue
import com.arkivanov.decompose.value.Value
import example.todo.common.main.TodoItem
import example.todo.common.main.TodoMain
import example.todo.common.main.TodoMain.Model
import example.todo.common.ui.TodoMainContent
@Preview
@Composable
fun TodoMainContentPreview() {
TodoMainContent(TodoMainPreview())
}
class TodoMainPreview : TodoMain {
override val models: Value<Model> =
MutableValue(
Model(
items = List(5) { index ->
TodoItem(
id = index.toLong(),
text = "Item $index",
isDone = index % 2 == 0
)
},
text = "Some text"
)
)
override fun onItemClicked(id: Long) {}
override fun onItemDoneChanged(id: Long, isDone: Boolean) {}
override fun onItemDeleteClicked(id: Long) {}
override fun onInputTextChanged(text: String) {}
override fun onAddItemClicked() {}
}
Loading…
Cancel
Save