This file contains hidden or 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
| final class MockURLProtocol: URLProtocol { | |
| override class func canInit(with request: URLRequest) -> Bool { true } | |
| } |
This file contains hidden or 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 CameraPermission: Permission { | |
| var status: AVAuthorizationStatus { | |
| AVCaptureDevice.authorizationStatus(for: .video) | |
| } | |
| func request(completion: @escaping (AVAuthorizationStatus) -> ()) { | |
| AVCaptureDevice.requestAccess(for: .video) { (granted) in | |
| completion(self.status) | |
| } |
This file contains hidden or 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 MicrophonePermission: Permission { | |
| var status: AVAudioSession.RecordPermission { | |
| AVAudioSession.sharedInstance().recordPermission | |
| } | |
| func request(completion: @escaping (AVAudioSession.RecordPermission) -> ()) { | |
| AVAudioSession.sharedInstance().requestRecordPermission { _ in | |
| completion(self.status) | |
| } |
This file contains hidden or 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
| protocol Permission { | |
| associatedtype PermissionType | |
| var status: PermissionType { get } | |
| func request(completion: @escaping (PermissionType) -> ()) | |
| } |
This file contains hidden or 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 | |
| final class Slider: UISlider { | |
| private let baseLayer = CALayer() // Step 3 | |
| private let trackLayer = CAGradientLayer() // Step 7 | |
| override func draw(_ rect: CGRect) { | |
| super.draw(rect) | |
| setup() |
This file contains hidden or 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
| @objc private func valueChanged(_ sender: Slider) { | |
| // Step 9 | |
| CATransaction.begin() | |
| CATransaction.setDisableActions(true) | |
| let thumbRectA = thumbRect(forBounds: bounds, | |
| trackRect: trackRect(forBounds: bounds), | |
| value: value) | |
| trackLayer.frame = .init(x: 0, | |
| y: frame.height / 4, | |
| width: thumbRectA.midX, |
This file contains hidden or 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
| private func setup() { | |
| clear() | |
| createBaseLayer() // Step 3 | |
| createThumbImageView() // Step 5 | |
| configureTrackLayer() // Step 7 | |
| addTarget(self, action: #selector(valueChanged(_:)), for: .valueChanged) // Step 8 | |
| } | |
| // Step 8 | |
| @objc private func valueChanged(_ sender: Slider) { |
This file contains hidden or 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
| private let trackLayer = CAGradientLayer() // Step 7 | |
| // Step 7 | |
| private func configureTrackLayer() { | |
| let firstColor = UIColor(red: 210/255, green: 152/255, blue: 238/255, alpha: 1).cgColor | |
| let secondColor = UIColor(red: 166/255, green: 20/255, blue: 217/255, alpha: 1).cgColor | |
| trackLayer.colors = [firstColor, secondColor] | |
| trackLayer.startPoint = .init(x: 0, y: 0.5) | |
| trackLayer.endPoint = .init(x: 1, y: 0.5) | |
| trackLayer.frame = .init(x: 0, |
This file contains hidden or 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
| // Step 5 | |
| private func createThumbImageView() { | |
| let thumbSize = (3 * frame.height) / 4 | |
| let thumbView = ThumbView(frame: .init(x: 0, | |
| y: 0, | |
| width: thumbSize, | |
| height: thumbSize)) | |
| thumbView.layer.cornerRadius = thumbSize / 2 | |
| let thumbSnapshot = thumbView.snapshot | |
| setThumbImage(thumbSnapshot, for: .normal) |
This file contains hidden or 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
| // Step 5 | |
| private func createThumbImageView() { | |
| let thumbSize = (3 * frame.height) / 4 | |
| let thumbView = ThumbView(frame: .init(x: 0, | |
| y: 0, | |
| width: thumbSize, | |
| height: thumbSize)) | |
| thumbView.layer.cornerRadius = thumbSize / 2 | |
| let thumbSnapshot = thumbView.snapshot | |
| setThumbImage(thumbSnapshot, for: .normal) |