Skip to content

Commit

Permalink
135
Browse files Browse the repository at this point in the history
  • Loading branch information
stephencelis committed Feb 15, 2021
1 parent a894218 commit 1c3f93f
Show file tree
Hide file tree
Showing 16 changed files with 1,007 additions and 0 deletions.

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,17 @@
//
// AnimationsApp.swift
// Animations
//
// Created by Point-Free on 2/9/21.
//

import SwiftUI

@main
struct AnimationsApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
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
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
97 changes: 97 additions & 0 deletions 0135-swiftui-animation-pt1/Animations/Animations/ContentView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import SwiftUI

struct ContentView: View {
@State var circleCenter = CGPoint.zero
@State var circleColor = Color.black
@State var isCircleScaled = false
@State var isResetting = false

var body: some View {
VStack {
Circle()
.fill(self.circleColor)
// .animation(.linear)
.overlay(Text("Hi"))
.frame(width: 50, height: 50)
.scaleEffect(self.isCircleScaled ? 2 : 1)
// .animation(nil, value: self.isCircleScaled)
// .animation(.disabled)
.offset(x: self.circleCenter.x - 25, y: self.circleCenter.y - 25)
// .animation(self.isResetting ? nil : .spring(response: 0.3, dampingFraction: 0.1))
.gesture(
DragGesture(minimumDistance: 0).onChanged { value in
withAnimation(.spring(response: 0.3, dampingFraction: 0.1)) {
self.circleCenter = value.location
}
}
)
.foregroundColor(self.isCircleScaled ? .red : nil)
// if self.isCircleScaled {
// circle.foregroundColor(.red)
// } else {
// circle
// }

Toggle(
"Scale",
isOn: self.$isCircleScaled.animation(.spring(response: 0.3, dampingFraction: 0.1))

// Binding(
// get: { self.isCircleScaled },
// set: { isOn in
// withAnimation(.spring(response: 0.3, dampingFraction: 0.1)) {
// self.isCircleScaled = isOn
// }
// }
// )

)

Button("Cycle colors") {
[Color.red, .blue, .green, .purple, .black]
.enumerated()
.forEach { offset, color in
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(offset)) {
withAnimation(.linear) {
self.circleColor = color
}

// withAnimation: (() -> R) -> R
// Async<A> = ((A) -> Void) -> Void
// ((A) -> R) -> R
}
}
// DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
// self.circleColor = .blue
// }
// DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
// self.circleColor = .green
// }
// DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
// self.circleColor = .purple
// }
// DispatchQueue.main.asyncAfter(deadline: .now() + 4) {
// self.circleColor = .black
// }
}

Button("Reset") {
// self.isResetting = true
withAnimation {
self.circleCenter = .zero
self.circleColor = .black
}
self.isCircleScaled = false
// DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(1)) {
// self.isResetting = false
// }
}
}
}
}

struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
50 changes: 50 additions & 0 deletions 0135-swiftui-animation-pt1/Animations/Animations/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?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>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<true/>
</dict>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
<key>UILaunchScreen</key>
<dict/>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
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,33 @@
//
// AnimationsTests.swift
// AnimationsTests
//
// Created by Point-Free on 2/9/21.
//

import XCTest
@testable import Animations

class AnimationsTests: XCTestCase {

override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.
}

override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}

func testExample() throws {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
}

func testPerformanceExample() throws {
// This is an example of a performance test case.
self.measure {
// Put the code you want to measure the time of here.
}
}

}
22 changes: 22 additions & 0 deletions 0135-swiftui-animation-pt1/Animations/AnimationsTests/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?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>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
Loading

0 comments on commit 1c3f93f

Please sign in to comment.