Skip to content

Instantly share code, notes, and snippets.

View badrinathvm's full-sized avatar

Badarinath Venkatnarayansetty badrinathvm

View GitHub Profile
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
@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( {
@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 / 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 / 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 / ProgressView.swift
Last active April 2, 2020 05:29
ProgressView of SwiftUI
struct ProgressView: View {
@State private var currentIndex:Int = 0
@State private var maxIterations:Int = 0
@State private var publisher = PassthroughSubject<AnimationStatus, Never>()
var body: some View {
HStack(spacing: 8) {
ForEach(0..<5) { index in
RectangleView(index: index, publisher: self.publisher)
}
@badrinathvm
badrinathvm / OnApper.Swift
Created April 2, 2020 05:20
OnApper publisher sends valyue
.onAppear {
Timer.scheduledTimer(withTimeInterval: 0.5, repeats: true) { (timer) in
if self.currentIndex < 5 {
self.publisher.send(AnimationStatus.start(index: self.currentIndex))
self.currentIndex += 1
}
}
@badrinathvm
badrinathvm / movie.json
Last active December 28, 2020 06:05
List of Movie json
{
"page": 1,
"results": [
{
"id": 185,
"video": false,
"vote_count": 8266,
"vote_average": 8.2,
"title": "A Clockwork Orange",
"release_date": "1971-12-18",
@badrinathvm
badrinathvm / Network.swift
Last active May 16, 2020 21:35
Combine Networking
import Combine
struct Welcome: Codable {
let page: Int
let results: [Result]
let totalPages, totalResults: Int
init(page:Int = 0, results: [Result], totalPages:Int = 0, totalResults: Int = 0) {
self.page = page
self.results = results
@badrinathvm
badrinathvm / CatgeoryTemplateView.swift
Created December 30, 2020 20:14
Category Template Gist
//
// CategoryTemplateView.swift
// Basics
//
// Created by Venkatnarayansetty, Badarinath on 12/30/20.
// Copyright © 2020 Badarinath Venkatnarayansetty. All rights reserved.
//
import SwiftUI