Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔗 :: (#239) Tap 범위 수정 #240

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading