Skip to content

Instantly share code, notes, and snippets.

View sliskiCode's full-sized avatar
:octocat:

Piotr Ślesarew sliskiCode

:octocat:
View GitHub Profile
import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
@Composable
fun Widget(name: String) {
// UI code...
}
@Preview
@Composable
@sliskiCode
sliskiCode / Sugar.kt
Created January 8, 2018 18:01
6 magic sugars that can make your Kotlin codebase happier #31
infix fun openSearch(block: SearchToolbar.() -> Unit): SearchToolbar {
// Testing framework code
return SearchToolbar.apply(block)
}
@sliskiCode
sliskiCode / Sugar.kt
Last active January 8, 2018 19:48
6 magic sugars that can make your Kotlin codebase happier #30
fun toolbar(block: Toolbar.() -> Unit): Toolbar = Toolbar.apply(block)
object Toolbar {
fun openSearch(block: SearchToolbar.() -> Unit): SearchToolbar {
// Testing framework code
return SearchToolbar.apply(block)
}
}
@sliskiCode
sliskiCode / Sugar.kt
Last active January 8, 2018 11:09
6 magic sugars that can make your Kotlin codebase happier #29
val searchQuery = "foo"
toolbar {
}. openSearch() {
type(searchQuery)
}
@sliskiCode
sliskiCode / Sugar.kt
Created January 2, 2018 12:40
6 magic sugars that can make your Kotlin codebase happier #28
val searchQuery = "foo"
toolbar {
} openSearch {
type(searchQuery)
}
@sliskiCode
sliskiCode / Sugar.kt
Last active January 8, 2018 19:48
6 magic sugars that can make your Kotlin codebase happier #27
fun navigation(block: NavController.() -> Unit): Unit = NavController.block()
object NavController {
fun openScreenOne() {
// Testing framework code
}
}
@sliskiCode
sliskiCode / Sugar.kt
Last active January 2, 2018 10:20
6 magic sugars that can make your Kotlin codebase happier #26
class SearchTest : UITest() {
@Before
fun setup() {
navigation {
openScreenOne()
}
}
@Test
@sliskiCode
sliskiCode / Sugar.kt
Last active January 2, 2018 11:18
6 magic sugars that can make your Kotlin codebase happier #25
verticalLayout {
val name = editText()
button("Say Hello") {
onClick {
toast("Hello, ${name.text}!")
}
}
}
@sliskiCode
sliskiCode / Sugar.kt
Created December 15, 2017 12:00
6 magic sugars that can make your Kotlin codebase happier #24
class Component : ComponentInterface {
private val navigable: Navigable = NavigableImpl()
private val searchable: Searchable = SearchableImpl()
override val onNavigationClick by ref(navigable::onNavigationClick)
override var searchText by ref(searchable::searchText)
}
@sliskiCode
sliskiCode / Sugar.kt
Last active May 26, 2018 23:41
6 magic sugars that can make your Kotlin codebase happier #23
class ReferencedProperty<T>(private val get: () -> T,
private val set: (T) -> Unit = {}) {
operator fun getValue(thisRef: Any?,
property: KProperty<*>): T = get()
operator fun setValue(thisRef: Any?,
property: KProperty<*>,
value: T) = set(value)
}