Skip to content

Instantly share code, notes, and snippets.

View ContactListItem.kt
/**
* A simple ListItem that displays text, detail text, a start icon, and an optional end icon.
*/
@Composable
fun ContactListItem(
text: @Composable () -> Unit,
modifier: Modifier = Modifier,
detailText: @Composable (() -> Unit)? = null,
startIcon: @Composable (() -> Unit)? = null,
endIcon: @Composable (() -> Unit)? = null,
@alexjlockwood
alexjlockwood / CircleSquare.kt
Last active Sep 26, 2020
A circle square animation implemented using Jetpack Compose. Inspired by @beesandbombs (twitter.com/beesandbombs).
View CircleSquare.kt
package com.alexjlockwood.circlesquare
import androidx.compose.animation.animatedFloat
import androidx.compose.animation.core.AnimationConstants
import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.repeatable
import androidx.compose.animation.core.tween
import androidx.compose.foundation.Canvas
import androidx.compose.runtime.Composable
@alexjlockwood
alexjlockwood / WaveSquare.kt
Created Sep 9, 2020
A composable wave square animation.
View WaveSquare.kt
package com.alexjlockwood.wavesquare
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.animation.animatedFloat
import androidx.compose.animation.core.AnimationConstants
import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.repeatable
import androidx.compose.animation.core.tween
import androidx.compose.foundation.Canvas
@alexjlockwood
alexjlockwood / PlayingWithPaths.kt
Last active Sep 2, 2020
Implementation of a 'Playing with Paths' polygon animation
View PlayingWithPaths.kt
package com.alexjlockwood.playingwithpaths
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.animation.animatedFloat
import androidx.compose.animation.core.AnimationConstants
import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.repeatable
import androidx.compose.animation.core.tween
import androidx.compose.foundation.Image
@alexjlockwood
alexjlockwood / CircularProgressIndicator.kt
Last active Sep 18, 2020
Example implementation of a CircularProgressIndicator using Jetpack Compose https://twitter.com/alexjlockwood/status/1300599202448199681
View CircularProgressIndicator.kt
package com.alexjlockwood.circularprogressindicator
import android.os.Bundle
import android.view.animation.PathInterpolator
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.animation.core.*
import androidx.compose.animation.transition
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
View ScreenshotTaker.java
package com.instabug.library.instacapture.screenshot;
import android.annotation.TargetApi;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.Bitmap.Config;
import android.graphics.PorterDuff.Mode;
@alexjlockwood
alexjlockwood / print-unlinked-colors.ts
Created Feb 3, 2020
Prints nodes that have fill/stroke colors that aren't linked to a style.
View print-unlinked-colors.ts
figma.root.children
.flatMap(pageNode => pageNode.findAll(n => true))
.forEach(node => {
if ('fills' in node && 'fillStyleId' in node) {
if (node.fills !== figma.mixed && node.fills.length > 0 && node.fillStyleId !== '') {
print(`${node.name}'s fill color is not linked to a style`);
}
}
if ('strokes' in node && 'strokeStyleId' in node) {
if (node.strokes.length > 0 && node.strokeStyleId !== '') {
@alexjlockwood
alexjlockwood / delete-unused-component.ts
Last active Apr 2, 2021
Deletes the selected component if it is private and unused in the file.
View delete-unused-component.ts
if (figma.currentPage.selection.length !== 1) {
figma.notify("🚫 Select a component");
return;
}
const [componentNode] = figma.currentPage.selection;
if (componentNode.type !== "COMPONENT") {
figma.notify("🚫 Select a component");
return;
}
@alexjlockwood
alexjlockwood / flatten-icons.ts
Last active Apr 2, 2021
Flattens all components in a Figma file. Note that this script assumes that (1) every component in the file is an icon, (2) each icon contains a single color, and (3) the icons don't use masks. The `figma.flatten` function may not work as you expect if one of these conditions aren't met.
View flatten-icons.ts
// Create a list of all component nodes in the Figma file.
const componentNodes = figma.root.children.flatMap(pageNode => {
return pageNode.findAll(node => node.type === 'COMPONENT');
}) as readonly ComponentNode[];
// Create a list of component nodes that have more than one child node.
const unflattenedComponentNodes = componentNodes.filter(componentNode => {
const childrenNodes = componentNode.findAll(() => true);
return childrenNodes.length > 1;
});
@alexjlockwood
alexjlockwood / cleanup-figma-names.ts
Last active Apr 2, 2021
Cleans up Figma component and style names
View cleanup-figma-names.ts
const components = figma.root.children.flatMap(pageNode => {
return pageNode.findAll(node => node.type === 'COMPONENT');
});
const styles = [
...figma.getLocalEffectStyles(),
...figma.getLocalGridStyles(),
...figma.getLocalPaintStyles(),
...figma.getLocalTextStyles(),
];