Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
392 changes: 392 additions & 0 deletions Challenge2/Challenge2.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{
"images" : [
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "40x40"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "40x40"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "60x60"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "60x60"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "20x20"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "20x20"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "29x29"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "29x29"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "40x40"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "40x40"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "76x76"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "76x76"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "83.5x83.5"
},
{
"idiom" : "ios-marketing",
"scale" : "1x",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions Challenge2/Challenge2/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "IMG_3167.jpg",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "IMG_5122.jpg",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions Challenge2/Challenge2/Challenge2App.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// Challenge2App.swift
// Challenge2
//
// Created by Matt Pfeiffer on 7/29/22.
//

import SwiftUI

@main
struct Challenge2App: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
22 changes: 22 additions & 0 deletions Challenge2/Challenge2/ContentView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// ContentView.swift
// Challenge2
//
// Created by Matt Pfeiffer on 7/29/22.
//

import SwiftUI

let charcoal = Color.init(white: 0.15)

struct ContentView: View {
var body: some View {
AirdropView()
}
}

struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
32 changes: 32 additions & 0 deletions Challenge2/Challenge2/Extensions/Gradient+Extensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// Gradient+Extensions.swift
// Challenge2
//
// Created by Matt Pfeiffer on 7/29/22.
//

import SwiftUI

public extension Gradient {
static var shiny: Gradient {
Gradient(colors: [
Color.white.opacity(0.0125),
Color.white.opacity(0.025),
Color.white.opacity(0.05),
Color.white.opacity(0.1),
Color.white.opacity(0.2),
Color.white.opacity(0.25),
Color.white.opacity(0.375),
Color.white.opacity(0.5),
Color.white.opacity(0.75),
Color.white.opacity(0.5),
Color.white.opacity(0.375),
Color.white.opacity(0.25),
Color.white.opacity(0.175),
Color.white.opacity(0.1),
Color.white.opacity(0.05),
Color.white.opacity(0.025),
Color.white.opacity(0.0125),
])
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// AirdropTargetView.swift
// Challenge2
//
// Created by Matt Pfeiffer on 7/29/22.
//

import SwiftUI

struct AirdropTargetView: View {
@ObservedObject var viewModel: AirdropTargetViewModel

init(name: String, image: Image? = nil) {
viewModel = AirdropTargetViewModel(name: name, image: image)
}

var body: some View {
ZStack {

VStack(spacing: 2) {
PersonProgressView(image: viewModel.image,
progress: viewModel.progress,
sendState: viewModel.sendState)
.frame(width: 150, height: 150)
.padding(.bottom, 10)

Text("\(viewModel.name)'s iPhone")
.foregroundColor(.white)
.font(.system(size: 14))

Text(viewModel.stateText)
.opacity(viewModel.opacity)
.foregroundColor(viewModel.sendState.color)
.font(.system(size: 14))
}
.contentShape(Rectangle())
.onTapGesture {
viewModel.simulateInitiate()
}
}
.onDisappear {
viewModel.timer?.invalidate()
}
}
}
struct AirdropTargetView_Previews: PreviewProvider {
static var previews: some View {
AirdropTargetView(name: "Mock Name")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
//
// AirdropTargetViewModel.swift
// Challenge2
//
// Created by Matt Pfeiffer on 7/29/22.
//

import SwiftUI

class AirdropTargetViewModel: ObservableObject {
@Published var sendState: AirdropSendState = .preSend
@Published var progress: CGFloat = 0.0
@Published var opacity: Double = 1.0

var name: String
var image: Image?

var timer: Timer?

var stateText: String {
switch sendState {
case .preSend:
return "from Matt"
case .connecting:
return "Waiting..."
case .inProgress:
return "Sending..."
case .done:
return "Sent"
}
}

init(name: String, image: Image? = nil) {
self.name = name
self.image = image
}

func simulateInitiate() {
progress = 0.0
sendState = .connecting
withAnimation(.easeInOut(duration: 1.0).repeatForever(autoreverses: true)) {
opacity = 0.0
}

let waitTime: TimeInterval = 2.0
DispatchQueue.main.asyncAfter(deadline: .now() + waitTime) {
self.simulateConnected()
}
}

func simulateConnected() {
sendState = .inProgress
withAnimation(.easeInOut(duration: 0.1)) {
self.opacity = 1.0
}

timer = Timer.scheduledTimer(timeInterval: 0.01,
target: self,
selector: #selector(stepProgress),
userInfo: nil,
repeats: true)
}

@objc func stepProgress() {
DispatchQueue.main.async {
self.progress += 0.005



if self.progress > 1.0 {
self.simulateCompleted()
}
}
}

func simulateCompleted() {
timer?.invalidate()

// slight delay so that the progress finishes before fadeout
let waitTime: TimeInterval = 0.1
DispatchQueue.main.asyncAfter(deadline: .now() + waitTime) {
self.sendState = .done
}
}
}
Loading