Skip to content

Instantly share code, notes, and snippets.

View Juhnkerg's full-sized avatar

Junkai Zheng Juhnkerg

View GitHub Profile
@cyrilchandelier
cyrilchandelier / UIScrollView+Bounce.swift
Created August 21, 2019 01:42
An extension to detect if scrollview is bouncing
extension UIScrollView {
var isBouncing: Bool {
return isBouncingTop || isBouncingBottom
}
var isBouncingTop: Bool {
return contentOffset.y < topInsetForBouncing - contentInset.top
}
var isBouncingBottom: Bool {
@timothycosta
timothycosta / UIScrollViewWrapper.swift
Created July 5, 2019 03:25
UIScrollView wrapped for SwiftUI
//
// UIScrollViewWrapper.swift
// lingq-5
//
// Created by Timothy Costa on 2019/07/05.
// Copyright © 2019 timothycosta.com. All rights reserved.
//
import SwiftUI
@timothycosta
timothycosta / UIViewController+SwiftUI.swift
Last active November 9, 2024 23:09
Using UIViewController via the SwiftUI Environment
struct ViewControllerHolder {
weak var value: UIViewController?
init(_ value: UIViewController?) {
self.value = value
}
}
struct ViewControllerKey: EnvironmentKey {
static var defaultValue: ViewControllerHolder { return ViewControllerHolder(UIApplication.shared.windows.first?.rootViewController ) }
@danhalliday
danhalliday / LaunchCounter.swift
Last active June 1, 2023 07:25
iOS First Launch Helper
import Foundation
/// Registers how many times an app has been launched, using UserDefaults as storage.
class LaunchCounter {
private var defaults: UserDefaults
private var defaultsKey = "launchCount"
/// Initialise, optionally with a custom UserDefaults instance
init(defaults: UserDefaults = .standard) {