improve carplay apply button ui

This commit is contained in:
leminlimez committed 2025-06-21 14:04:45 -04:00
1 parent 759597dfb2
commit f9ba2dee0d
7 files changed
+126 -48

No files matched your search

@@ -0,0 +1,39 @@
//
// OpaqueButton.swift
// Pocket Poster
//
// Created by lemin on 6/21/25.
//
import SwiftUI
struct OpaqueButton: ButtonStyle {
var color: Color
var textColor: Color
var fullwidth: Bool = false
func makeBody(configuration: Configuration) -> some View {
ZStack {
if fullwidth {
configuration.label
.padding(15)
.frame(maxWidth: .infinity)
.background(color)
.cornerRadius(8)
.foregroundColor(textColor)
} else {
configuration.label
.padding(15)
.background(color)
.cornerRadius(8)
.foregroundColor(textColor)
}
}
}
init(color: Color = .blue, textColor: Color = .primary, fullwidth: Bool = false) {
self.color = color
self.textColor = textColor
self.fullwidth = fullwidth
}
}
@@ -0,0 +1,56 @@
//
// TintedButton.swift
// Pocket Poster
//
// Created by lemin on 5/31/25.
//
import SwiftUI
struct TintedButton: ButtonStyle {
var color: Color
var material: UIBlurEffect.Style?
var fullwidth: Bool = false
func makeBody(configuration: Configuration) -> some View {
ZStack {
if fullwidth {
configuration.label
.padding(15)
.frame(maxWidth: .infinity)
.background(material == nil ? AnyView(color.opacity(0.2)) : AnyView(MaterialView(material!)))
.cornerRadius(8)
.foregroundColor(color)
} else {
configuration.label
.padding(15)
.background(material == nil ? AnyView(color.opacity(0.2)) : AnyView(MaterialView(material!)))
.cornerRadius(8)
.foregroundColor(color)
}
}
}
init(color: Color = .blue, fullwidth: Bool = false) {
self.color = color
self.fullwidth = fullwidth
}
init(color: Color = .blue, material: UIBlurEffect.Style, fullwidth: Bool = false) {
self.color = color
self.material = material
self.fullwidth = fullwidth
}
}
#if DEBUG
struct FullwidthTintedButton_Previews: PreviewProvider {
static var previews: some View {
Button("Exaple") {
}
.buttonStyle(TintedButton(color: .red, fullwidth: true))
.padding()
}
}
#endif
@@ -0,0 +1,41 @@
//
// LoopingPlayerUIView.swift
// Pocket Poster
//
// Created by lemin on 6/11/25.
//
import UIKit
import AVFoundation
class LoopingPlayerUIView: UIView {
private var playerLayer = AVPlayerLayer()
private var playerLooper: AVPlayerLooper?
private var player = AVQueuePlayer()
init(videoURL: URL){
let asset = AVAsset(url: videoURL)
let item = AVPlayerItem(asset: asset)
super.init(frame: .zero)
// Setup the player
playerLayer.player = player
playerLayer.videoGravity = .resizeAspectFill
layer.addSublayer(playerLayer)
// Create a new player looper with the queue player and template item
playerLooper = AVPlayerLooper(player: player, templateItem: item)
player.play()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func layoutSubviews() {
super.layoutSubviews()
playerLayer.frame = bounds
}
}
@@ -0,0 +1,24 @@
//
// MaterialView.swift
// Pocket Poster
//
// Created by lemin on 5/31/25.
//
import SwiftUI
struct MaterialView: UIViewRepresentable {
let material: UIBlurEffect.Style
init(_ material: UIBlurEffect.Style) {
self.material = material
}
func makeUIView(context: Context) -> UIVisualEffectView {
UIVisualEffectView(effect: UIBlurEffect(style: material))
}
func updateUIView(_ uiView: UIVisualEffectView, context: Context) {
uiView.effect = UIBlurEffect(style: material)
}
}
@@ -0,0 +1,23 @@
//
// PlayerView.swift
// Pocket Poster
//
// Created by lemin on 6/11/25.
//
import SwiftUI
struct PlayerView: UIViewRepresentable {
var videoURL: URL
init(videoURL: URL) {
self.videoURL = videoURL
}
func updateUIView(_ uiView: UIView, context: UIViewRepresentableContext<PlayerView>) {
}
func makeUIView(context: Context) -> UIView {
return LoopingPlayerUIView(videoURL: videoURL)
}
}