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 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
//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
#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
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
@available(iOS 13.0, *) | |
struct SwiftUIView: View { | |
var body: some View { | |
VStack { | |
Text("Welcome to SwiftUI") | |
.padding() | |
.font(.system(size: 15)) | |
Spacer() | |
} |
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
{ | |
"user": { | |
"type": "lead", | |
"id": 146179, | |
"name": "Rubamaga", | |
"email": "rubamaga@example.com", | |
"user_id": "22449", | |
"phone": null, | |
"created_at": 1506500350, | |
"signed_up_at": null, |
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 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) |
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 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 |
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
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) |