Skip to content

Instantly share code, notes, and snippets.

View gtokman's full-sized avatar
🏴‍☠️
Focusing

Gary Tokman gtokman

🏴‍☠️
Focusing
View GitHub Profile
@gtokman
gtokman / app.js
Created March 15, 2021 15:52
Scrollable List
import logo from "./logo.svg";
import "./App.css";
import styled from "styled-components";
function App() {
return (
<Container>
<WrapperCard>
<Card></Card>
<Card></Card>
@gtokman
gtokman / ContentView.swift
Created March 13, 2021 23:58
BottomSheet - Part 1
struct ContentView: View {
@State var isPresented: Bool = false
var body: some View {
Button(action: {}, label: {
Text("Present Bottom Sheet")
.padding()
})
.background(Color.blue)
.foregroundColor(.white)
@gtokman
gtokman / ContentView.swift
Created March 13, 2021 22:16
Show/Dismiss keyboard
import SwiftUIX
import Introspect
var body: some View {
NavigationView {
// ...
.onTapGesture {
print(friend.name)
Keyboard.main.dismiss() // inactive
}
@gtokman
gtokman / ContentView.swift
Last active March 13, 2021 20:39
Overload == operator
typealias Predicate<Element> = (Element) -> Bool
func ==<Element>(lhs: KeyPath<Element, String>, rhs: String) -> Predicate<Element> { // overload ==
return { element in
guard !rhs.isEmpty else { return true } // make sure not empty
return search(
needle: rhs.lowercased(), // search
haystack: element[keyPath: lhs].lowercased() // value for keypath
)
}
@gtokman
gtokman / ContentView.swift
Last active March 13, 2021 20:39
Search - part 2
// ...
List(friends
.filter {
search(
needle: searchText.lowercased(),
haystack: $0.name.lowercased()
)
}
)
// ...
import SwiftUIX
struct Friend: Identifiable { // Example model
let id: UUID = .init()
let name: String
}
struct ContentView: View {
@State var friends: [Friend] = [
.init(name: "Gary"),
func search(needle: String, haystack: String) -> Bool {
guard needle.count <= haystack.count else {
return false
}
if needle == haystack {
return true
}
var needleIdx = needle.startIndex
@gtokman
gtokman / TabViewPage.swift
Last active March 10, 2021 04:53
Vertical paging with TabView
struct ContentView: View {
let colors: [Color] = [
.red, .green, .blue, .gray
]
var body: some View {
GeometryReader { proxy in
TabView {
ForEach(colors, id: \.self) { color in
color // Your cell content
@gtokman
gtokman / TabViewPage.swift
Created March 10, 2021 04:44
PageTabViewStyle
struct ContentView: View {
let colors: [Color] = [
.red, .green, .blue, .gray
]
var body: some View {
GeometryReader { proxy in
TabView {
ForEach(colors, id: \.self) { color in
color // Your cell content
@gtokman
gtokman / swiftgen-custom.stencil
Created March 3, 2021 02:59
swift gen swiftui stencil
// swiftlint:disable all
// Generated using SwiftGen — https://github.com/SwiftGen/SwiftGen
{% if catalogs %}
{% set enumName %}{{param.enumName|default:"Asset"}}{% endset %}
{% set colorType %}{{param.colorTypeName|default:"ColorAsset"}}{% endset %}
{% set imageType %}{{param.imageTypeName|default:"ImageAsset"}}{% endset %}
{% set forceNamespaces %}{{param.forceProvidesNamespaces|default:"false"}}{% endset %}
{% set accessModifier %}{% if param.publicAccess %}public{% else %}internal{% endif %}{% endset %}
import SwiftUI