This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.textfieldtypinganimation | |
import android.os.Bundle | |
import androidx.activity.ComponentActivity | |
import androidx.activity.compose.setContent | |
import androidx.activity.enableEdgeToEdge | |
import androidx.compose.animation.core.Animatable | |
import androidx.compose.animation.core.AnimationVector1D | |
import androidx.compose.animation.core.Spring | |
import androidx.compose.animation.core.spring |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainActivity : ComponentActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
enableEdgeToEdge() | |
setContent { | |
TheTheme { | |
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding -> | |
val helloWorld = "Hello World!" | |
var textOrNull by remember { mutableStateOf<String?>(helloWorld) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.app.Presentation | |
import android.content.Context | |
import android.graphics.Bitmap | |
import android.graphics.Picture | |
import android.graphics.SurfaceTexture | |
import android.hardware.display.DisplayManager | |
import android.view.Display | |
import android.view.Surface | |
import android.view.ViewGroup | |
import androidx.compose.foundation.layout.Box |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainActivity : ComponentActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
WindowCompat.setDecorFitsSystemWindows(window, false) | |
super.onCreate(savedInstanceState) | |
setContent { | |
P2RTheme { | |
// A surface container using the 'background' color from the theme | |
Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) { | |
CompositionLocalProvider( | |
LocalOverscrollConfiguration provides null // Disable overscroll otherwise it consumes the drag before we get the chance |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@OptIn(ExperimentalMaterialApi::class) | |
@Composable | |
fun PullToRefreshAnimation() { | |
val path = remember { | |
GitHubLogoPath.path.toPath() | |
} | |
val lines = remember { | |
path.asAndroidPath().flatten(error = 0.5f).toList() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import androidx.compose.ui.draw.drawWithCache | |
import androidx.compose.ui.geometry.CornerRadius | |
import androidx.compose.ui.geometry.Offset | |
import androidx.compose.ui.geometry.Rect | |
import androidx.compose.ui.geometry.Size | |
import androidx.compose.ui.graphics.BlendMode | |
import androidx.compose.ui.graphics.Brush | |
import androidx.compose.ui.graphics.Color | |
import androidx.compose.ui.graphics.ColorFilter | |
import androidx.compose.ui.graphics.ImageBitmap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun TextTransition(textAndColor: Pair<String, Color>) { | |
AnimatedContent( | |
targetState = textAndColor, | |
transitionSpec = { | |
fadeIn() togetherWith fadeOut() | |
} | |
) { (text, color) -> | |
Row { | |
text.forEachIndexed { index, char -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val uiColor = MaterialTheme.colors.surface.toUIColor() | |
@OptIn(ExperimentalForeignApi::class) | |
fun Color.toUIColor(): UIColor { | |
val colorSpace = CGColorSpaceCreateDeviceRGB() | |
val components = nativeHeap.allocArray<DoubleVar>(4) | |
components[0] = red.toDouble() | |
components[1] = green.toDouble() | |
components[2] = blue.toDouble() | |
components[3] = alpha.toDouble() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* ---------------------------------------------------------------------------- | |
* "THE BEER-WARE LICENSE" (Revision 42): | |
* Sebastiano Poggi wrote this file. As long as you retain this notice you | |
* can do whatever you want with this stuff. If we meet some day, and you think | |
* this stuff is worth it, you can buy me a beer in return. Seb | |
* ---------------------------------------------------------------------------- | |
*/ | |
package dev.sebastiano.bundel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UNUserNotificationCenter { | |
func removeDeliveredNotificationsAsync(withIdentifiers identifiers: [String]) async { | |
// Calls to `UNUserNotificationCenter.current().removeDeliveredNotifications` schedule work | |
// on a background thread, with no completion handler or async/await interface. There is no | |
// way to know whether the work completed or not. If the notification service extension exits | |
// before the work has been completed, the work is cancelled and notifications are not removed. | |
// | |
// This is really poor API design on Apple's part, and even poorer documentation | |
// | |
// https://stackoverflow.com/questions/54565979#comment104110958_54680225 |
NewerOlder