Skip to content

Commit

Permalink
πŸ”— :: (#239) Tap λ²”μœ„ μˆ˜μ •
Browse files Browse the repository at this point in the history
  • Loading branch information
HongSJae authored Apr 3, 2024
2 parents 1abc27f + 3ff9e0b commit 9c6d60b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 41 deletions.
2 changes: 1 addition & 1 deletion Projects/Flow/Sources/Home/HomeFlow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private extension HomeFlow {
let easterEggFlow = EasterEggFlow(container: container)

Flows.use(easterEggFlow, when: .created) { root in
self.rootViewController.present(
self.rootViewController.pushViewController(
root, animated: true
)
}
Expand Down
68 changes: 29 additions & 39 deletions Projects/Presentation/Sources/EasterEgg/EasterEggView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,25 @@ import DesignSystem

struct EasterEggView: View {
@State private var count = 0
var body: some View {
ZStack(alignment: .bottom) {
Button("") {}
.buttonStyle(CatButtonStyle(count: $count))

Text("\(count)")
.padding(.top, 50)
}
}
}

struct CatButtonStyle: ButtonStyle {
@Binding var count: Int
@State private var angle = 0
@State private var index = 0

init(count: Binding<Int>) {
_count = count
}
private var colors: [Color] = [
.yellow,
.red,
Expand All @@ -15,46 +32,19 @@ struct EasterEggView: View {
.mint,
.white
]
var body: some View {
VStack {
Button("", action: addAction)
.buttonStyle(CatButtonStyle())
.rotationEffect(.degrees(Double(angle)))

Text("\(count)")
.padding(.top, 50)
}
func makeBody(configuration: Configuration) -> some View {
(configuration.isPressed ? DesignSystemAsset.Images.EasterEgg.open.swiftUIImage:
DesignSystemAsset.Images.EasterEgg.close.swiftUIImage)
.rotationEffect(.degrees(Double(angle)))
.frame(maxWidth: .infinity, maxHeight: .infinity)
.padding()
.background(colors[index])
}

private func addAction() {
count += 1
angle = (angle + 45) % 360
index = Int.random(in: 0..<colors.count)
HapticManager.instance.impact(style: .heavy)
}
}

private struct CatButtonStyle: ButtonStyle {
func makeBody(configuration: Configuration) -> some View {
configuration.isPressed ? DesignSystemAsset.Images.EasterEgg.open.swiftUIImage:
DesignSystemAsset.Images.EasterEgg.close.swiftUIImage
}
}

final private class HapticManager {
static let instance = HapticManager()

func notification(type: UINotificationFeedbackGenerator.FeedbackType) {

let generator = UINotificationFeedbackGenerator()
generator.notificationOccurred(type)
}

func impact(style: UIImpactFeedbackGenerator.FeedbackStyle) {
let generator = UIImpactFeedbackGenerator(style: style)
generator.impactOccurred()
.onChange(of: configuration.isPressed) {
if $0 {
angle = (angle + 45) % 360
index = Int.random(in: 0..<colors.count)
count += 1
UIImpactFeedbackGenerator(style: .heavy).impactOccurred()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class RxFlowViewController: UIViewController, RxFlow.Stepper {

open override func viewDidLoad() {
super.viewDidLoad()

addChild(contentViewController)
view.addSubview(contentViewController.view)
setupConstraints()
Expand Down

0 comments on commit 9c6d60b

Please sign in to comment.