Skip to content

Instantly share code, notes, and snippets.

View satishVekariya's full-sized avatar

Satish satishVekariya

View GitHub Profile
@satishVekariya
satishVekariya / ChatCollectionViewFlowLayout.swift
Created November 19, 2019 11:26 — forked from jochenschoellig/ChatCollectionViewFlowLayout.swift
A subclass of UICollectionViewFlowLayout to get chat behavior without turning collection view upside-down. This layout is written in Swift 3 and absolutely usable with RxSwift and RxDataSources because UI is completely separated from any logic or binding.
import UIKit
class ChatCollectionViewFlowLayout: UICollectionViewFlowLayout {
private var topMostVisibleItem = Int.max
private var bottomMostVisibleItem = -Int.max
private var offset: CGFloat = 0.0
private var visibleAttributes: [UICollectionViewLayoutAttributes]?
@satishVekariya
satishVekariya / ColoredToggle.swift
Last active May 10, 2023 07:45
A custom toggle style
import SwiftUI
/// Custom toggle style
///
/// Reference:
/// - https://www.bigmountainstudio.com/community/public/posts/11825-swiftui-togglestyle-customizing-the-toggle
struct ColoredToggleStyle: ToggleStyle {
let labelFont = Font.system(size: 14, weight: .regular)
let labelColor = Color.secondaryMain
let onColor = Color.semanticsSuccessMain
//
// LastAtBottomVStack.swift
//
//
// Created by Satish Vekariya on 21/04/2023.
//
import SwiftUI
// MARK: - LastAtBottomVStack
import Combine
import Foundation
// MARK: - Polling
/// A thread safe polling(repeat task over given time) handler object
public actor Polling {
public typealias TaskItem = () async -> Void
public typealias PollingTask = Task<Void, Never>
typealias PollingSubject = CurrentValueSubject<Int, Never>
fileprivate struct KeyboardToolBar: ViewModifier {
let focusableIds: [String]
@State private var activeId: String? = nil
func body(content: Content) -> some View {
content
.toolbar {
ToolbarItemGroup(placement: .keyboard) {
if focusableIds.count > 1 {
Button {
import Swinject /// https://github.com/Swinject/Swinject.git
import Foundation
@propertyWrapper
public struct Inject<Dependency> {
public let wrappedValue: Dependency
public init(resolver: Resolver = AppAssembler.shared.resolver) {
wrappedValue = resolver.resolve(Dependency.self)!
}
@satishVekariya
satishVekariya / CarouselLayoutGenerator.swift
Created November 10, 2023 20:32
The CarouselLayoutGenerator struct provides a convenient way to generate a UICollectionViewCompositionalLayout with a carousel-style layout.
import UIKit
/// The CarouselLayoutGenerator struct provides a convenient way to generate a UICollectionViewCompositionalLayout with a carousel-style layout.
/// This layout is suitable for creating horizontally scrolling carousels of items, commonly used in applications to showcase a series of items or images.
///
/// Example:
/// ```
/// +----------------------------+
/// | ______________________ ____|_________________ ______________________
/// | | | | | | | |
@satishVekariya
satishVekariya / CollectionViewRepresentable.swift
Last active November 13, 2023 14:39
A SwiftUI wrapper of UICollectionView that manages an ordered collection of data items and presents them using customizable layouts.
//
// CollectionViewRepresentable.swift
//
//
// Created by Satish Vekariya on 12/11/2023.
//
import SwiftUI
import UIKit
@satishVekariya
satishVekariya / VideoPlayerView.swift
Last active November 24, 2023 18:59
AvPlayer wrapper for SwiftUI
import SwiftUI
import AVKit
public struct VideoPlayerView<Overlay: View>: View {
let overlay: Overlay
let player: AVPlayer
@State private var isShowOverlay = true
public init(_ player: AVPlayer, overlay: () -> (Overlay)) {
self.player = player
@satishVekariya
satishVekariya / UShape.swift
Last active February 11, 2024 13:48
SwiftUI draw "U" shape
struct UShape: Shape {
var radius: CGFloat = 8
var inset: CGFloat = 5/2
func path(in rect: CGRect) -> Path {
var path = Path()
let rect = rect.inset(by: .init(top: 0, left: inset, bottom: inset, right: inset))
let width = rect.maxX
let height = rect.maxY