feat: add dotted background pattern

This commit is contained in:
2024-07-29 15:49:13 +01:00
parent 6db6a8375c
commit 39bf43204d
3 changed files with 78 additions and 19 deletions

View File

@@ -12,6 +12,7 @@
F12B73492C55C0C40064A230 /* .gitignore in Resources */ = {isa = PBXBuildFile; fileRef = F12B73482C55C0C40064A230 /* .gitignore */; };
F12B734B2C56AEB00064A230 /* LiveStatusManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = F12B734A2C56AEB00064A230 /* LiveStatusManager.swift */; };
F12B734D2C5702EC0064A230 /* LiveListenerCounter.swift in Sources */ = {isa = PBXBuildFile; fileRef = F12B734C2C5702EC0064A230 /* LiveListenerCounter.swift */; };
F12B73502C57BDD90064A230 /* DottedBackground.swift in Sources */ = {isa = PBXBuildFile; fileRef = F12B734F2C57BDD90064A230 /* DottedBackground.swift */; };
F13839702C51BABD00B4814F /* InfinifiIOSApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = F138396F2C51BABD00B4814F /* InfinifiIOSApp.swift */; };
F13839722C51BABD00B4814F /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F13839712C51BABD00B4814F /* ContentView.swift */; };
F13839742C51BABE00B4814F /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F13839732C51BABE00B4814F /* Assets.xcassets */; };
@@ -25,6 +26,7 @@
F12B734A2C56AEB00064A230 /* LiveStatusManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LiveStatusManager.swift; sourceTree = "<group>"; };
F12B734C2C5702EC0064A230 /* LiveListenerCounter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LiveListenerCounter.swift; sourceTree = "<group>"; };
F12B734E2C57B0230064A230 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
F12B734F2C57BDD90064A230 /* DottedBackground.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DottedBackground.swift; sourceTree = "<group>"; };
F138396C2C51BABD00B4814F /* InfinifiIOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = InfinifiIOS.app; sourceTree = BUILT_PRODUCTS_DIR; };
F138396F2C51BABD00B4814F /* InfinifiIOSApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfinifiIOSApp.swift; sourceTree = "<group>"; };
F13839712C51BABD00B4814F /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
@@ -72,6 +74,7 @@
F12B73482C55C0C40064A230 /* .gitignore */,
F12B734A2C56AEB00064A230 /* LiveStatusManager.swift */,
F12B734C2C5702EC0064A230 /* LiveListenerCounter.swift */,
F12B734F2C57BDD90064A230 /* DottedBackground.swift */,
);
path = InfinifiIOS;
sourceTree = "<group>";
@@ -160,6 +163,7 @@
F12B734D2C5702EC0064A230 /* LiveListenerCounter.swift in Sources */,
F13839722C51BABD00B4814F /* ContentView.swift in Sources */,
F12B73472C55AC6B0064A230 /* PlaybackManager.swift in Sources */,
F12B73502C57BDD90064A230 /* DottedBackground.swift in Sources */,
F13839702C51BABD00B4814F /* InfinifiIOSApp.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;

View File

@@ -1,4 +1,3 @@
import AVKit
import SwiftUI
struct ContentView: View {
@@ -29,28 +28,41 @@ struct ContentView: View {
default: ""
}
VStack(alignment: .center) {
Text("infinifi")
.font(.system(.title3, design: .monospaced))
.fontWeight(.bold)
.padding()
ZStack {
DottedBackground()
.frame(
maxWidth: .infinity,
maxHeight: .infinity
)
.ignoresSafeArea()
Spacer()
VStack(alignment: .center) {
Text("infinifi")
.font(.system(.title3, design: .monospaced))
.fontWeight(.bold)
.padding()
if playbackManager.playbackState != .initializing {
NeuButton(action: {
toggleAudioPlayback()
}) {
Image(systemName: buttonImageName)
.font(.system(size: 24))
.tint(.text)
Spacer()
if playbackManager.playbackState != .initializing {
NeuButton(action: {
toggleAudioPlayback()
}) {
Image(systemName: buttonImageName)
.font(.system(size: 24))
.tint(.text)
}
}
Spacer()
LiveListenerCounter(
playbackManager: playbackManager
)
}
Spacer()
LiveListenerCounter(
playbackManager: playbackManager
.frame(
maxWidth: .infinity,
maxHeight: .infinity
)
}
.frame(

View File

@@ -0,0 +1,43 @@
import Foundation
import SwiftUI
let effectRadius = 100
let minDotRadius = 1
struct DottedBackground: View {
@State private var isDragging = false
@State private var touchX: Float = 0
@State private var touchY: Float = 0
var body: some View {
let dragGesture = DragGesture(minimumDistance: 0)
.onChanged { value in
isDragging = true
touchX = Float(value.location.x)
touchY = Float(value.location.y)
}
.onEnded { _ in
isDragging = false
}
Canvas { ctx, size in
for y in stride(from: 0, to: Int(size.height), by: 10) {
for x in stride(from: 0, to: Int(size.width), by: 10) {
let radius: Int
if isDragging {
let distanceFromTouch = Int(sqrt(pow(Float(x) - touchX, 2) + pow(Float(y) - touchY, 2)))
radius = minDotRadius + minDotRadius * 4 * (effectRadius - min(effectRadius, distanceFromTouch)) / 100
} else {
radius = minDotRadius
}
ctx.fill(
Path(ellipseIn: CGRect(x: x, y: y, width: radius * 2, height: radius * 2)),
with: .color(.surface1)
)
}
}
}
.gesture(dragGesture)
}
}