Skip to content

Instantly share code, notes, and snippets.

View dladukedev's full-sized avatar

Donovan LaDuke dladukedev

View GitHub Profile
@dladukedev
dladukedev / semantics-demo.kt
Created July 21, 2023 13:17
Overview of how TalkBack interprets Different Semantic Modifiers
// Reads "One" -> "Two" -> "Three"
Row(modifier = Modifier.semantics(mergeDescendants = false) { }) {
Text("One")
Column {
Text("Two")
Text("Three")
}
}
// Reads "One Two Three"
@dladukedev
dladukedev / Turbine + Combine.kt
Created July 25, 2023 15:15
Mockup showing the issue with combine where Turbine misses elements
@Test
fun `this test fails`() = runTest {
val number = (0..2).asFlow()
val intro = listOf("Hello").asFlow()
val combined = combine(intro, number) { first, second ->
"$first $second"
}
combined.test {
@dladukedev
dladukedev / exhaustive-when.kt
Created July 31, 2023 14:53
Exhaustive when blocks in Kotlin
import kotlin.random.Random
val myInt = Random.nextInt()
val myBool = Random.nextBoolean()
// Expression - Exhaustive Required
val result = when(myInt) {
1 -> "I'm #1!"
else -> "I'm something else"
}
@dladukedev
dladukedev / colors.kt
Created August 3, 2023 15:38
Use Compose Preview to Show your Theme
package com.dladukedev.themetest.ui.theme
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.size
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
@dladukedev
dladukedev / SemanticMatchersDemo.kt
Created August 26, 2023 03:18
Show how to use the different modifying functions for SemanticMatchers
package com.dladukedev.semanticsmatchertest
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.material3.Text
import androidx.compose.ui.test.assertCountEquals
import androidx.compose.ui.test.hasAnyAncestor
import androidx.compose.ui.test.hasText
import androidx.compose.ui.test.isDialog
import androidx.compose.ui.test.isRoot
@dladukedev
dladukedev / functional-reactive-programming.kt
Last active October 12, 2023 01:38
Examples of Procedural vs Functional and Reactive styles of Programming
fun procedural() {
val numbers = (1..10).shuffled().toMutableList()
// Remove Even Numbers
var index = 0
while(index < numbers.count()) {
if(numbers[index] % 2 == 0) {
numbers.removeAt(index)
} else {
index += 1
@dladukedev
dladukedev / AlignmentExample.kt
Created November 13, 2023 21:28
Alignment vs Absolute Alignment
package com.dladukedev.alignment
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.AbsoluteAlignment
@dladukedev
dladukedev / img_star_background.png
Last active December 26, 2023 04:01
Tilling Image Background with ShaderBrush and ImageShader
img_star_background.png
@dladukedev
dladukedev / 1_StartingPoint.kt
Last active December 25, 2023 09:32
Passive UI in Jetpack Compose
package com.dladukedev.passiveui
import android.util.Log
import androidx.compose.foundation.layout.Column
import androidx.compose.material3.Checkbox
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
@dladukedev
dladukedev / FunctionReferenceAmbiguity.kt
Last active December 19, 2023 02:48
Kotlin Function Reference Ambiguity
data class AdditionClass(val str: String, val num: Int) {
fun add(addStr: String): String {
return str + addStr
}
fun add(addNum: Int): Int {
return num + addNum
}
}