Skip to content

Instantly share code, notes, and snippets.

private func updateAccessibility() {
isAccessibilityElement = true
if let text = text {
accessibilityLabel = text
} else if let attributedText = attributedText {
accessibilityLabel = attributedText.string
}
accessibilityTraits = .staticText
}
private func generateTextMask() -> CGImage? {
guard frame.size.width != 0.0,
frame.size.height != 0.0,
let attributedString = maskAttributedText() else {
return nil
}
let bitmap = Bitmap(width: frame.size.width, height: frame.size.height)
bitmap.context.clear(bitmap.bounds)
private func setupBackgroundVideoIfNeeded() {
guard playerLayer == nil, let url = url else {
return
}
let player = AVPlayer(url: url)
if let playerItem = player.currentItem {
NotificationCenter.default.addObserver(forName: .AVPlayerItemDidPlayToEndTime, object: playerItem, queue: nil) { [weak self] notification in
let currentItem = notification.object as? AVPlayerItem
override func layoutSubviews() {
super.layoutSubviews()
setupBackgroundVideoIfNeeded()
updateVideoMask()
}
// This initilizer will use the UIFont.preferredFont(forTextStyle: .largeTitle)
init(text: String, url: URL) {
self.text = text
self.url = url
super.init(frame: .zero)
}
// This initilizer will the use the font attribute of the text,
// otherwise it will revert to UIFont.preferredFont(forTextStyle: .largeTitle)
var body: some View {
ZStack {
Group {
RoundArrowBackground()
.fill()
.opacity(backgroundOpacity)
RoundArrow()
.stroke(lineWidth: 3)
RoundArrowHead()
.fill()
private func popAnimation() {
let delay = DispatchTime.now() + 0.8
DispatchQueue.main.asyncAfter(deadline: delay) {
self.numberOfAnimations -= 1
if self.numberOfAnimations == 0 {
withAnimation(Animation.easeInOut(duration: 0.15)) {
self.durationLabelOpacity = 1.0
}
}
private func incrementSeekValue() -> String {
var valueString = accumulationString
valueString.removeFirst()
if var value = Int(valueString) {
value += interval
return "+" + String(value)
}
return accumulationString
@State private var rotation: Angle = .zero
@State private var backgroundOpacity: Double = 0.0
@State private var durationLabelOpacity: Double = 1.0
@State private var xOffset: CGFloat = 0.0
@State private var accumulationLabelOpacity: Double = 0.0
@State private var numberOfAnimations: Int = 0
@State private var accumulationString: String = ""
var body: some View {
ZStack {
private func animateAccumulationLabel() {
// Reset the labels animation values
accumulationLabelOpacity = 0
xOffset = 0.0
// Fade in
withAnimation(.easeInOut(duration: 0.1)) {
accumulationLabelOpacity = 1.0
}