Skip to content

Instantly share code, notes, and snippets.

View karambirov's full-sized avatar
📱
iOS developer

Eugene Karambirov karambirov

📱
iOS developer
View GitHub Profile
extension StringProtocol {
subscript(_ offset: Int) -> String.Element {
if offset >= 0 {
self[index(startIndex, offsetBy: offset)]
} else {
self[index(endIndex, offsetBy: offset)]
}
}
@katleta3000
katleta3000 / gist:6478752b49860553cdb23846992a234f
Created July 30, 2023 19:34
iOS application push launch processing
import UIKit
import UserNotifications
final class SceneDelegate: UIResponder, UIWindowSceneDelegate {
private let pushAppLaunchRule = PushAppLaunchRule()
var window: UIWindow?
func sceneDidBecomeActive(_ scene: UIScene) {
import notify
import Combine
enum Notify {}
extension Notify {
struct Status: Error {
let rawValue: UInt32
init(_ rawValue: UInt32) {
self.rawValue = rawValue
@jasdev
jasdev / ScrimLoader.swift
Last active April 19, 2024 03:47
Rough sketch of Arc’s scrim loading view.
import SwiftUI
/**
### Exercises for the viewer
- Phase interrupt handling.
- Use Swift concurrency.
- Color scheme awareness.
- Rework animations to be more spring-like à la what shipped in `0.90.0`.
@rusik
rusik / PizzaUI.swift
Last active October 22, 2022 17:39
Implementation of half-pizza UI from Dodo Pizza on SwiftUI. Original UIKit implementation is here → https://habr.com/ru/company/dododev/blog/452876/
import SwiftUI
import Foundation
struct ContentView: View {
var body: some View {
HStack(spacing: 4) {
PizzaView(color: .blue, orientation: .left)
PizzaView(color: .red, orientation: .right)
}
}
@ryanlintott
ryanlintott / LayoutThatFits.swift
Last active December 8, 2023 15:14
An alternative to ViewThatFits. Updated version can be found here: https://github.com/ryanlintott/LayoutThatFits
//
// LayoutThatFits.swift
// WWDC22Experiments
//
// Created by Ryan Lintott on 2022-06-08.
//
import SwiftUI
struct LayoutThatFits: Layout {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
for (i, view) in scrollView.subviews.enumerated() {
var ty = 0.0
if scrollView.contentOffset.y < 0 {
// We're scrolling past the top of the scroll view.
// Translate each item in the scroll view by some amount based on its index and scroll offset.
ty = CGFloat(i) * abs(offsetY) / 8.0 * pow(1.12, CGFloat(i))
}
view.transform = CGAffineTransform(translationX: 0, y: ty)
}
@brettohland
brettohland / 1.0 FormatStyle in Excruciating Detail.md
Last active July 23, 2024 12:12
FormatStyle in Excruciating Detail
@insidegui
insidegui / ScrollViewOffsetModifier.swift
Created July 20, 2021 20:28
A SwiftUI ViewModifier that can be used to read a ScrollView's offset and store it into a @State property of the view
struct ScrollViewOffsetPreferenceKey: PreferenceKey {
static var defaultValue: CGPoint = .zero
static func reduce(value: inout CGPoint, nextValue: () -> CGPoint) {
value = nextValue()
print("value = \(value)")
}
typealias Value = CGPoint