This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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( { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum AnimationStatus { | |
case start(index:Int) | |
case stop(index:Int) | |
case stopAll | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"page": 1, | |
"results": [ | |
{ | |
"id": 185, | |
"video": false, | |
"vote_count": 8266, | |
"vote_average": 8.2, | |
"title": "A Clockwork Orange", | |
"release_date": "1971-12-18", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// CategoryTemplateView.swift | |
// Basics | |
// | |
// Created by Venkatnarayansetty, Badarinath on 12/30/20. | |
// Copyright © 2020 Badarinath Venkatnarayansetty. All rights reserved. | |
// | |
import SwiftUI |