Skip to content

Instantly share code, notes, and snippets.

View sebaslogen's full-sized avatar

Sebas LG sebaslogen

View GitHub Profile
@sebaslogen
sebaslogen / ActivityLifecycleComposable.kt
Last active September 27, 2024 08:51
Update Activity reference (from Compose) on configuration changes (Activity recreation)
import android.app.Activity
import android.content.Context
import android.content.ContextWrapper
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.RememberObserver
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.core.app.ComponentActivity
android {
testOptions {
unitTests {
includeAndroidResources = true
}
}
}
dependencies {
testImplementation 'junit:junit:4.+'
Button(
modifier = Modifier.testTag("First Button"),
onClick = clickListener) {
Text("Push first destination")
}
@Before
@Throws(Exception::class)
fun setUp() {
ShadowLog.stream = System.out // Redirect Logcat to console
}
@RunWith(AndroidJUnit4::class) // Update: back in 2022, this used to be @RunWith(RobolectricTestRunner::class)
class MyTests {
@get:Rule val composeTestRule = createComposeRule()
@Test fun `when I test, then it works`() {
// Some test code here
}
}
@sebaslogen
sebaslogen / main.dart
Created January 12, 2020 22:00
Flutter Neumorphism
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
@sebaslogen
sebaslogen / main.dart
Created January 10, 2020 20:33
Flutter colored slider experiment
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,

Keybase proof

I hereby claim:

  • I am sebaslogen on github.
  • I am sebaslogen (https://keybase.io/sebaslogen) on keybase.
  • I have a public key ASC32nccv5aNWfjyCGsuI4fwejoCRfoApEyoxnwE5TwRjgo

To claim this, I am signing this object:

@sebaslogen
sebaslogen / create-playlist-button.json
Last active January 27, 2020 13:02
Create playlist button from Server Driven UI JSON example for post
"button": {
"title": "Create your first playlist",
"action": {
"type": "command",
"url": "/command/endpoint?path=%2Fcommand%2Fcreate-playlist",
"prompt": {
"type": "textInput",
"message": "Give your playlist a name.",
"placeholder": "My first playlist",
"confirmButtonTitle": "Create"
@sebaslogen
sebaslogen / sdui-data-classes.kt
Last active August 9, 2019 13:58
Server Driven UI post: Kotlin data classes
data class ComponentScreen(val title: String?, val sections: List<Section> = emptyList())
sealed class Section
data class AlbumListSection(val title: String?, val items: List<AlbumListItem>) : Section()
data class ShelfSection(val shelfStyle: ShelfItemStyle, val items: List<ShelfItem>) : Section()
data class TrackListSection(val items: List<TrackListItem>) : Section()
data class AlbumListItem(val title: String, val image: String, val action: Action)