Skip to content

Instantly share code, notes, and snippets.

View caiobzen's full-sized avatar
:octocat:

Carlos Corrêa da Silva caiobzen

:octocat:
View GitHub Profile
@caiobzen
caiobzen / RepearingAnimation.swift
Created September 25, 2019 01:06
Repeating EaseInOut Animation
private var repeatingAnimation: Animation {
Animation
.easeInOut
.speed(0.15)
.repeatForever()
}
WavingBackground(fill: 10) {
Text("Hey!")
}
ZStack {
WavingBackground(fill: 10)
Text("Hey!")
}
@caiobzen
caiobzen / WavingBackground.swift
Created September 25, 2019 00:15
Waving Wrapper view
import SwiftUI
struct WavingBackground <Content: View>: View {
private let content: Content
private var fill: CGFloat
public init(fill: CGFloat = .zero, @ViewBuilder content: () -> Content) {
self.fill = fill
self.content = content()
}
@caiobzen
caiobzen / DrinkButton.swift
Created September 24, 2019 20:32
Drink Button
import SwiftUI
struct DrinkButton: View {
var text: String
var action: () -> Void
var body: some View {
Button(action: {
withAnimation { self.action() }
}) {
HStack(spacing: 20) {
@caiobzen
caiobzen / DigitalCrownSetup.swift
Created September 24, 2019 20:14
DigitalCrown setup
MyView()
.digitalCrownRotation($viewModel.drinkingAmount,
from: viewModel.minimumInterval,
through: viewModel.drinkingTarget,
by: 50,
sensitivity: .low)
@caiobzen
caiobzen / Wave.swift
Created September 24, 2019 15:55
Wave view SwiftUI
import SwiftUI
struct Wave: Shape {
let graphWidth: CGFloat
let amplitude: CGFloat
func path(in rect: CGRect) -> Path {
let width = rect.width
let height = rect.height
@caiobzen
caiobzen / UsingSwipe.swift
Created September 18, 2019 11:37
Using Swipe Class
private func setupGestures() {
view.addGestureRecognizer(Swipe(.left) { [weak self] in
self?.viewModel?.push(.left)
})
view.addGestureRecognizer(Swipe(.right) { [weak self] in
self?.viewModel?.push(.right)
})
view.addGestureRecognizer(Swipe(.up) { [weak self] in
self?.viewModel?.push(.up)
})
@caiobzen
caiobzen / GameRobotTest.swift
Created September 17, 2019 23:20
Game Robot test sample
func test_when_scored_on_new_game_reset_score() {
robot
.swipeLeft()
.swipeRight()
.swipeUp()
.swipeDown()
.tapMenu()
.tapNewGame()
.assertScoreIs(0)
}
@caiobzen
caiobzen / DiscardableFunc.swift
Created September 17, 2019 23:19
Discardable Result Function
@discardableResult
func tapNewGame() -> Self {
newGameButton?.tap()
return self
}