Add example for day 87

This commit is contained in:
CypherPoet 2020-01-19 00:10:00 -06:00
parent 7f5e852d28
commit 356b0fa381
3 changed files with 111 additions and 0 deletions

View File

@ -23,6 +23,7 @@
F326145623D31201009EC215 /* CoreHapticsExample+ViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F326145523D31201009EC215 /* CoreHapticsExample+ViewModel.swift */; };
F326145923D319D7009EC215 /* AllowsHitTestingExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = F326145823D319D7009EC215 /* AllowsHitTestingExample.swift */; };
F326145B23D31E94009EC215 /* ContentShapeExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = F326145A23D31E94009EC215 /* ContentShapeExample.swift */; };
F378A9B123D408FB00296A76 /* ReducingMotionExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = F378A9B023D408FB00296A76 /* ReducingMotionExample.swift */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@ -44,6 +45,7 @@
F326145523D31201009EC215 /* CoreHapticsExample+ViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CoreHapticsExample+ViewModel.swift"; sourceTree = "<group>"; };
F326145823D319D7009EC215 /* AllowsHitTestingExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AllowsHitTestingExample.swift; sourceTree = "<group>"; };
F326145A23D31E94009EC215 /* ContentShapeExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentShapeExample.swift; sourceTree = "<group>"; };
F378A9B023D408FB00296A76 /* ReducingMotionExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReducingMotionExample.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -99,6 +101,7 @@
children = (
F326144F23D2AA98009EC215 /* Gestures */,
F326143F23D1699C009EC215 /* RootView.swift */,
F378A9AF23D4089800296A76 /* Accessibility */,
F326145723D319C3009EC215 /* Hit Testing */,
F326145023D2AAAA009EC215 /* Haptics */,
);
@ -161,6 +164,14 @@
path = "Hit Testing";
sourceTree = "<group>";
};
F378A9AF23D4089800296A76 /* Accessibility */ = {
isa = PBXGroup;
children = (
F378A9B023D408FB00296A76 /* ReducingMotionExample.swift */,
);
path = Accessibility;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
@ -237,6 +248,7 @@
F326145923D319D7009EC215 /* AllowsHitTestingExample.swift in Sources */,
F326145423D2FF4B009EC215 /* CoreHapticsExample.swift in Sources */,
F326142523D16901009EC215 /* AppDelegate.swift in Sources */,
F378A9B123D408FB00296A76 /* ReducingMotionExample.swift in Sources */,
F326144823D176E7009EC215 /* BasicLongPressGestureExample.swift in Sources */,
F326145223D2AAB7009EC215 /* UIKitHapticsExample.swift in Sources */,
F326142723D16901009EC215 /* SceneDelegate.swift in Sources */,

View File

@ -0,0 +1,92 @@
//
// ReducingMotionExample.swift
// Project17Concepts
//
// Created by CypherPoet on 1/18/20.
//
//
import SwiftUI
func withMotionSensitiveAnimation<Content>(
_ animation: Animation = .default,
body: () throws -> Content
) rethrows -> Content {
if UIAccessibility.isReduceMotionEnabled {
return try body()
} else {
return try withAnimation(animation, body)
}
}
struct ReducingMotionExample {
@State private var buttonScaleState: ButtonScaleState = .up
}
// MARK: - View
extension ReducingMotionExample: View {
var body: some View {
Button(action: {
withMotionSensitiveAnimation(Animation.easeOut(duration: 0.4)) {
self.buttonScaleState = self.buttonScaleState == .up ? .down : .up
}
}) {
Text("Scale \(buttonScaleState == .up ? "Down" : "Up")")
.foregroundColor(.primary)
.padding()
.frame(width: 100, height: 100)
}
.background(
Circle()
.fill(Color.pink)
.frame(width: 100, height: 100)
)
.scaleEffect(buttonScaleState.scaleValue)
}
}
// MARK: - Computeds
extension ReducingMotionExample {
}
// MARK: - View Variables
extension ReducingMotionExample {
}
// MARK: - Private Helpers
private extension ReducingMotionExample {
}
extension ReducingMotionExample {
private enum ButtonScaleState {
case up
case down
var scaleValue: CGFloat {
switch self {
case .up:
return 1.0
case .down:
return 0.7
}
}
}
}
// MARK: - Preview
struct ReducingMotionExample_Previews: PreviewProvider {
static var previews: some View {
ReducingMotionExample()
}
}

View File

@ -70,6 +70,13 @@ extension RootView: View {
destination: ContentShapeExample()
)
}
Section(header: Text("Accessbility")) {
NavigationLink(
"Reducing Motion",
destination: ReducingMotionExample()
)
}
}
.navigationBarTitle("Project 17 Concepts")
.listStyle(GroupedListStyle())