Skip to content

Instantly share code, notes, and snippets.

View DreamingInBinary's full-sized avatar

Jordan Morgan DreamingInBinary

View GitHub Profile
import SwiftUI
#warning("TODO: <Connor> Make handles generic views so they are customizable rather than assuming what people want. (Provide defaults)")
#warning("TODO: <Connor> Use my custom @StateBinding property wrapper to allow consumers to optionally pass a binding to the bools for isExpanded, isMoving, isResizing. Then they can react in the parent, or they can not pass a binding and let the view handle the state internally.")
#warning("TODO: <Connor> General cleanup of calculations and code density.")
// MARK: - ViewManipulation
struct ViewManipulation: OptionSet {
@cwalo
cwalo / IndentScrollView
Last active July 9, 2024 21:36
IndentScrollView - A paging ScrollView that tracks the target content view
import SwiftUI
struct IndentScrollView: View {
let min = 0.5
let max = 3.5
let increment = 0.1
@State
var multiplier = 0.5

This gist shows how to add a tooltip including a button to show it in a header of a table created using SwiftUI. It is used in ASO Suite.

Clean-Shot-2023-05-12-at-08-39-08-2x.png

@dejager
dejager / RoundedPolygon.swift
Created October 18, 2022 05:57
A SwiftUI Shape that draws a polygon with a given number of corners and a corner radius.
//
// RoundedPolygon.swift
//
// Created by Nate on 2022-10-17.
//
import SwiftUI
struct RoundedPolygon: Shape {
@bjhomer
bjhomer / cross-view-lines.swift
Last active November 5, 2022 05:31
Creating cross-view lines in SwiftUI
//
// ContentView.swift
// SwiftUIPlayground
//
// Created by BJ Homer on 4/26/21.
//
import SwiftUI
import UIKit
import AVFoundation
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
let tableView = UITableView(frame: .zero, style: .plain)
override func viewDidLoad() {
super.viewDidLoad()
tableView.register(PlayerTableViewCell.self, forCellReuseIdentifier: "PlayerCell")
@joshdholtz
joshdholtz / ATinySampleApp.swift
Last active October 1, 2024 02:11
Super basic SwiftUI app (70 lines of code) with paywall using RevenueCat
import SwiftUI
import RevenueCat
struct Constants {
static let apiKey = "<your_api_key>" // Will look like: appl_bunchofotherstuffhere
static let entitlementName = "<your_entitlement_name>" // I use something like "pro"
}
@main
struct ATinySampleApp: App {
struct ContentView: View {
@State var pictureExpanded = false
var body: some View {
VStack(alignment: .leading, spacing: 0) {
Text("Once upon a time there was a turtle named George who made friends with a giraffe at the local water park and then they went on lots of adventures together.")
Button {
withAnimation {
pictureExpanded.toggle()
@PimCoumans
PimCoumans / AnimationSequece.swift
Last active May 21, 2024 15:12
Simple way to chain and group multiple UIView animations
import UIKit
protocol StepAnimatable {
/// Start a sequence where you add each step in the `addSteps` closure. Use the provided `AnimationSequence` object
/// to add each step which should either be an actual animation or a delay.
/// The `completion` closure is executed when the last animation has finished.
/// - Parameters:
/// - addSteps: Closure used to add steps to the provided `AnimationSequence` object
/// - completion: Executed when the last animation has finished.
@IanKeen
IanKeen / EnvironmentValues.swift
Last active January 5, 2024 08:49
SwiftUI: Peek at/extract hidden environment values
import Foundation
import SwiftUI
extension EnvironmentValues {
public func value<T>(_: T.Type = T.self, forKey key: String) -> T? {
guard let value = first(where: { name($0, equals: key) }) else {
print("No EnvironmentValue with key '\(key)' found.")
return nil
}