Skip to content

Instantly share code, notes, and snippets.

View fgiris's full-sized avatar

Fatih Giriş fgiris

View GitHub Profile
@Composable
fun ImageSplitViewer(modifier: Modifier) {
val widthTargetState = remember { mutableStateOf(0.dp) }
val widthPosition = animateDpAsState(
targetValue = widthTargetState.value,
animationSpec = tween(durationMillis = 5000)
)
Box {
Image(
@Composable
fun Test() {
val animationTargetState = remember { mutableStateOf(0f) }
val animationState = animateFloatAsState(targetValue = animationTargetState.value)
LaunchedEffect(Unit) {
delay(2000)
// Trigger the animation so does the recomposition in the composable which
// the `animationState.value` is read
import kotlinx.coroutines.*
import org.junit.Test
class CoroutinePlaygroundTest {
@Test
fun catchingExceptionAroundAsyncCoroutineBuilder_ShouldNotHandleTheException() {
val coroutineScope = CoroutineScope(newSingleThreadContext("MyCoroutineScope"))
var asyncExceptionHandled = false
runBlocking {
launch {
// There could be a race condition with the parent coroutine and this nested
// runBlocking will block the thread which means nothing in parent will be executed
// even if it is an another coroutine
runBlocking {
launch {
hang()
}
}
<resources>
<style name="Theme.StylesNThemes" parent="Theme.AppCompat.DayNight.DarkActionBar">
<item name="colorPrimary">@color/purple_500</item>
</style>
<style name="MyButton" parent="Widget.AppCompat.Button">
<item name="android:background">@drawable/button_background</item>
<item name="android:textColor">@color/white</item>
<!-- Setting a theme attribute inside the MyButton style -->
<item name="colorPrimary">@color/red</item>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="2dp" />
<solid android:color="?colorPrimary" />
<padding
android:bottom="4dp"
android:left="8dp"
android:right="8dp"
android:top="4dp" />
</shape>
class SingleLineHeaderTextView : AppCompatTextView {
private val DEF_STYLE_RES = R.style.Widget_StylesNThemes_TextView_Header_SingleLine
// Other view attributes and constructors
constructor(
context: Context,
attrs: AttributeSet,
defStyleAttr: Int
) : super(
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
style="@style/Widget.StylesNThemes.TextView.Header.SingleLine"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
<resources>
<style name="Widget.StylesNThemes.TextView.Header.SingleLine" parent="Widget.MaterialComponents.TextView">
<item name="android:singleLine">true</item>
<!-- If we were not using text appearance then we had to set all attributes inside
TextAppearance.StylesNThemes.Header here -->
<item name="android:textAppearance">@style/TextAppearance.StylesNThemes.Header</item>
</style>
</resources>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:textAppearance="@style/TextAppearance.StylesNThemes.Header"