Skip to content

Instantly share code, notes, and snippets.

View bmc08gt's full-sized avatar

Brandon McAnsh bmc08gt

View GitHub Profile
@bmc08gt
bmc08gt / 00_ComposeViewController.kt
Last active March 29, 2024 20:15
Compose UI component in SwiftUI that respects intrinsic sizing
private fun measuredViewController(
onMeasured: (Double, Double) -> Unit,
content: @Composable () -> Unit,
): UIViewController = ComposeUIViewController {
Box(
modifier = Modifier.onGloballyPositioned {
onMeasured(it.size.width.toDouble(), it.size.height.toDouble())
},
) {
content()
@bmc08gt
bmc08gt / SegmentedControl.android.kt
Last active March 18, 2024 09:27
Compose Multiplatform Segmented Control
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.IntrinsicSize
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.MaterialTheme
@bmc08gt
bmc08gt / gist:ff600c505c4a41ce3a66ac513909c003
Created March 8, 2024 23:58
Xcode Crash Pod dependent on a KMM XCFramework
0x112535f04 <+0>: stp x28, x27, [sp, #-0x20]!
0x112535f08 <+4>: stp x29, x30, [sp, #0x10]
0x112535f0c <+8>: add x29, sp, #0x10
0x112535f10 <+12>: sub sp, sp, #0x5f0
0x112535f14 <+16>: mov x8, #0x0
0x112535f18 <+20>: str x8, [sp, #0x5e0]
0x112535f1c <+24>: movi.16b v0, #0x0
0x112535f20 <+28>: str q0, [sp, #0x410]
0x112535f24 <+32>: str q0, [sp, #0x5d0]
0x112535f28 <+36>: str q0, [sp, #0x5c0]
@bmc08gt
bmc08gt / Kotlin+Gif.kt
Created February 22, 2024 04:49
SwiftyGif Kotlin Style
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.suspendCancellableCoroutine
import platform.CoreFoundation.CFDataRef
import platform.CoreGraphics.CGImageRef
import platform.Foundation.CFBridgingRelease
import platform.Foundation.CFBridgingRetain
import platform.Foundation.NSData
import platform.Foundation.NSDictionary
@bmc08gt
bmc08gt / AutoSizeText.kt
Last active February 16, 2024 10:58
Autosizing Text in Jetpack Compose
import androidx.compose.material.LocalTextStyle
import androidx.compose.material.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawWithContent
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontStyle
@bmc08gt
bmc08gt / SettingsSection.kt
Created December 14, 2023 17:29
SettingsSectionScope
interface SettingsSectionScope {
fun item(
icon: ImageVector? = null,
title: String,
subtitle: String? = null,
endSlot: @Composable () -> Unit = { },
onClick: (() -> Unit)? = null,
)
@Composable
@bmc08gt
bmc08gt / SwipeToDelete.kt
Last active December 15, 2023 03:40
Jetpack Compose Modifier extension to implement swipe-to-delete via Modifier.draggable
import androidx.animation.IntToVectorConverter
import androidx.animation.tween
import androidx.compose.Composable
import androidx.compose.mutableStateOf
import androidx.compose.remember
import androidx.ui.animation.animatedFloat
import androidx.ui.animation.animatedValue
import androidx.ui.core.*
import androidx.ui.core.gesture.scrollorientationlocking.Orientation
import androidx.ui.foundation.animation.FlingConfig
import androidx.compose.animation.*
import androidx.compose.animation.core.tween
import androidx.compose.material.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.onCommit
import androidx.compose.ui.Modifier
@OptIn(ExperimentalAnimationApi::class, ExperimentalMaterialApi::class)
@Composable
fun <T> AnimatedSwipeDismiss(
@bmc08gt
bmc08gt / Chips.kt
Last active December 15, 2023 03:39
Jetpack Compose Chips
package com.planoly.ui.compose.components
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Icon
import androidx.compose.material.IconButton
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.Text
@bmc08gt
bmc08gt / Calendar.kt
Last active December 15, 2023 03:38
Jetpack Compose Calendar Implementation
interface CalendarScope {
var changeMonthAnimation: FiniteAnimationSpec<Float>
var changeMonthSwipeTriggerVelocity: Int
var header: @Composable (day: CalendarDay, actioner: (CalendarAction) -> Unit) -> Unit
var dayLabel: @Composable (dayOfWeek: DayOfWeek, labelWidth: Dp) -> Unit
var day: @Composable BoxScope.(padding: PaddingValues, day: CalendarDay, today: CalendarDay) -> Unit
var inDates: @Composable BoxScope.(padding: PaddingValues, day: CalendarDay) -> Unit
var outDates: @Composable BoxScope.(padding: PaddingValues, dayDate: CalendarDay) -> Unit
}