Skip to content

Instantly share code, notes, and snippets.

Avatar
🍎
iOS, Swift, SwiftUI

Sarun Wongpatcharapakorn sarunw

🍎
iOS, Swift, SwiftUI
View GitHub Profile
View FloatingPanel.swift
class FloatingPanel: NSPanel {
init(contentRect: NSRect, backing: NSWindow.BackingStoreType, defer flag: Bool) {
// Not sure if .titled does affect anything here. Kept it because I think it might help with accessibility but I did not test that.
super.init(contentRect: contentRect, styleMask: [.nonactivatingPanel, .resizable, .closable, .fullSizeContentView], backing: backing, defer: flag)
// Set this if you want the panel to remember its size/position
// self.setFrameAutosaveName("a unique name")
// Allow the pannel to be on top of almost all other windows
@sarunw
sarunw / LandscapeModifier.swift
Created Mar 16, 2021
Preview a device in landscape with SwiftUI Previews
View LandscapeModifier.swift
struct LandscapeModifier: ViewModifier {
let height = UIScreen.main.bounds.width
let width = UIScreen.main.bounds.height
var isPad: Bool {
return height >= 768
}
var isRegularWidth: Bool {
return height >= 414
@sarunw
sarunw / extractViewsFromContent.swift
Created Dec 30, 2020 — forked from stleamist/extractViewsFromContent.swift
An experimental way to extract SwiftUI views from an TupleView built by ViewBuilder.
View extractViewsFromContent.swift
import SwiftUI
func extractViewsFromContent<Content: View> (@ViewBuilder content: () -> Content) -> [Any] {
let tupleView = content()
let tupleViewMirror = Mirror(reflecting: tupleView)
let tuple = tupleViewMirror.children.first!.value
let tupleMirror = Mirror(reflecting: tuple)
let views = tupleMirror.children.map { $0.value }
return views
}
View TripleToggleStyle.swift
// SwiftUI Custom Styles (TripleToggleStyle)
// https://swiftui-lab.com
// https://swiftui-lab.com/custom-styling
import SwiftUI
// MARK: - TripleToggle View
public struct TripleToggle: View {
@Environment(\.tripleToggleStyle) var style: AnyTripleToggleStyle
@sarunw
sarunw / UIColor.swift
Created Oct 7, 2020 — forked from nbasham/UIColor.swift
Swift 4: Convert CSS color names and RGB hex values to UIColor. UIColor from hex 3, 4, 6, and 8 characters in length with or without # prefix. UIColor to hex. UIColor extension that creates immutable UIColor instances from hexadecimal and CSS color name strings (e.g. ff0, #f00, ff0000, ff0000ff, Pink, aZure, CLEAR, nil). Conversely, you can obta…
View UIColor.swift
//
// UIColor.swift
// previously Color+HexAndCSSColorNames.swift
//
// Created by Norman Basham on 12/8/15.
// Copyright ©2018 Black Labs. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
@sarunw
sarunw / Lottie.stencil
Created Jul 17, 2020 — forked from djbe/Lottie.stencil
SwiftGen template for Lottie animations
View Lottie.stencil
// Generated using SwiftGen — https://github.com/SwiftGen/SwiftGen
{% if files %}
{% set accessModifier %}{% if param.publicAccess %}public{% else %}internal{% endif %}{% endset %}
{% set documentPrefix %}{{param.documentName|default:"Document"}}{% endset %}
import Lottie
import UIKit
// swiftlint:disable superfluous_disable_command
// swiftlint:disable file_length
View apple_rsa.pub
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlxrwmuYSAsTfn+lUu4go
ZSXBD9ackM9OJuwUVQHmbZo6GW4Fu/auUdN5zI7Y1dEDfgt7m7QXWbHuMD01HLnD
4eRtY+RNwCWdjNfEaY/esUPY3OVMrNDI15Ns13xspWS3q+13kdGv9jHI28P87RvM
pjz/JCpQ5IM44oSyRnYtVJO+320SB8E2Bw92pmrenbp67KRUzTEVfGU4+obP5RZ0
9OxvCr1io4KJvEOjDJuuoClF66AT72WymtoMdwzUmhINjR0XSqK6H0MdWsjw7ysy
d/JhmqX5CAaT9Pgi0J8lU/pcl215oANqjy7Ob+VMhug9eGyxAWVfu/1u6QJKePlE
+wIDAQAB
-----END PUBLIC KEY-----
@sarunw
sarunw / mac-keys-unicode.md
Created Oct 24, 2019 — forked from zmwangx/mac-keys-unicode.md
Unicode characters for special keys on the Mac keyboard (not necessarily Mac specific). #symbols
View mac-keys-unicode.md

⌘ – &#x2318;&#8984; – the Command Key symbol
⌥ – &#x2325;&#8997; – the Option Key symbol
⇧ – &#x21E7;&#8679; – the Shift Key symbol
⌃ – &#x2303;&#8963; – the Control Key symbol
⎋ – &#x238B;&#9099; – the ESC Key symbol
⇪ – &#x21ea;&#8682; – the Capslock symbol
⏎ – &#x23ce;&#9166; – the Return symbol
⌫ – &#x232b;&#9003; – the Delete / Backspace symbol
⇥ – &#x21E5;&#8677; – the Tab Key symbol

@sarunw
sarunw / google-service-env.sh
Created Aug 22, 2019
Xcode script for support multiple env Google service.
View google-service-env.sh
echo "copy from GoogleService-Info-$CONFIGURATION.plist to $SRCROOT/[PROJECT_NAME]/GoogleService-Info.plist"
cp "$SRCROOT/[PROJECT_NAME]/GoogleService-Info-$CONFIGURATION.plist" "$SRCROOT/[PROJECT_NAME]/GoogleService-Info.plist"
echo "Clean up"
find "$SRCROOT/[PROJECT_NAME]/container/" -not -path '*/\.*' -type f -maxdepth 1 -delete
if [ "${CONFIGURATION}" = "Debug" ] || [ "${CONFIGURATION}" = "Release" ]; then
echo "copy from $SRCROOT/[PROJECT_NAME]/container/Release/ to $SRCROOT/[PROJECT_NAME]/container/"
cp -r "$SRCROOT/[PROJECT_NAME]/container/Release/" "$SRCROOT/[PROJECT_NAME]/container/"
@sarunw
sarunw / 11ty_contains.js
Created Jul 27, 2019 — forked from danfascia/11ty_contains.js
11ty filter to filter a collection (array) by key:value pair - used to filter on custom taxonomies other than tags (source: https://paulrobertlloyd.com/)
View 11ty_contains.js
/**
* Select objects in array whose key includes a value
*
* @param {Array} arr Array to test
* @param {String} key Key to inspect
* @param {String} value Value key needs to include
* @return {String} Filtered array
*
*/
module.exports = function (arr, key, value) {