Skip to content

Instantly share code, notes, and snippets.

View badrinathvm's full-sized avatar

Badarinath Venkatnarayansetty badrinathvm

View GitHub Profile
@badrinathvm
badrinathvm / AnimationStatus.swift
Created April 2, 2020 05:09
Animation Status for SwiftUI
enum AnimationStatus {
case start(index:Int)
case stop(index:Int)
case stopAll
}
@badrinathvm
badrinathvm / RectangleView.swift
Last active April 2, 2020 05:08
SwiftUI View for Rectangle
struct RectangleView: View {
var index: Int
@State private var animate = false
var publisher:PassthroughSubject<AnimationStatus, Never>
var body: some View {
Rectangle()
.foregroundColor(Color.green)
.frame(width: 50, height: 10)
.opacity(animate ? 1: 0.2)
.animation(.easeInOut)
@badrinathvm
badrinathvm / Pack.Swift
Created March 31, 2020 16:54
Wrapper for embedding UIViewController in SwiftUI app.
//MARK:- Packs the UIKit's ViewController in SwiftUI View.
public struct Pack<Packed: UIViewController> : UIViewControllerRepresentable {
public typealias Updater = (Packed, Context) -> Void
//two closures for each of the method requirement of UIViewControllerRepresentable
public var makeViewController: () -> Packed
public var updateViewController: Updater
//autoclosure here creates the viewcontrollers lazily, @escaping to preserve the closure to execute asynchronously
@badrinathvm
badrinathvm / SwiftUI_UIKit.swift
Last active February 12, 2020 23:02
SwiftUI_UIKit
#if canImport(SwiftUI) && !arch(arm) && os(iOS) || os(watchOS) // fails compilation
#if canImport(SwiftUI) && !arch(arm) && os(iOS) && os(watchOS) // passes compilation
@available(iOS 13.0, *)
struct AdviceContentView: View {
var slideTitle: String
var slideDescription: String
var iconProps:ImageComponent
var body: some View {
VStack {
iconProps[keyPath: \ImageComponent.image.value].map( {
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let swiftUIView = UIHostingController(rootView: SwiftUIView())
swiftUIView.view.translatesAutoresizingMaskIntoConstraints = false
self.addSubview(swiftUIView.view)
swiftUIView.view.layout {
$0.top == self.view.topAnchor
$0.leading == self.view.leadingAnchor
@available(iOS 13.0, *)
struct SwiftUIView: View {
var body: some View {
VStack {
Text("Welcome to SwiftUI")
.padding()
.font(.system(size: 15))
Spacer()
}
@badrinathvm
badrinathvm / sample.json
Created November 13, 2019 17:08
JSON Sample
{
"user": {
"type": "lead",
"id": 146179,
"name": "Rubamaga",
"email": "rubamaga@example.com",
"user_id": "22449",
"phone": null,
"created_at": 1506500350,
"signed_up_at": null,
@badrinathvm
badrinathvm / CircularShapes.swift
Created November 9, 2019 17:45
Text Not expanding it's size when placed inside ScrollView
import Foundation
import SwiftUI
struct MoreCircleShapes: View {
var body: some View {
VStack(spacing: 10) {
Circle().fill(Color.purple).frame(height: 100).padding()
Text("Note : Fill Modifier apples specifically to shapes nopt a view.")
.frame(maxWidth: .infinity)
@badrinathvm
badrinathvm / AnimateParticlesWithCustomPath.swift
Created September 8, 2019 09:25
Animate Particles With Custom Path
import UIKit
class ViewController: UIViewController {
let width: CGFloat = 240.0
let height: CGFloat = 160.0
override func viewDidLoad() {
super.viewDidLoad()
let sineView = HingeView(frame: UIScreen.main.bounds)
sineView.backgroundColor = .yellow
@badrinathvm
badrinathvm / CustomPath.swift
Created September 8, 2019 06:48
Add a custom path
func customPath() -> UIBezierPath {
let path = UIBezierPath()
path.move(to: CGPoint(x: 0, y: 200))
let endPoint = CGPoint(x: 500, y: 200)
let randomYShift = 200 + drand48() * 300
let cp1 = CGPoint(x: 100, y: 100 - randomYShift)
let cp2 = CGPoint(x: 200, y: 100 + randomYShift + 400)