Skip to content

Commit

Permalink
test: custom font typing effect #14
Browse files Browse the repository at this point in the history
  • Loading branch information
yuncoffee committed Mar 30, 2023
1 parent e2553bd commit 13c6971
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion View/CustomView/CustomText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,41 @@ import SwiftUI

struct CustomText: View {

@EnvironmentObject
var globalStore: GlobalStore

var value = ""


var fontSize = 32
var color = CustomColor.scriptColor

@State
var tmpText: String = ""
// @Binding var isStart: Bool

func typeWriter(at position: Int = 0) {
if position == 0 {
tmpText = ""
}
if position < value.count {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
tmpText.append(value[position])
typeWriter(at: position + 1)
}
}
}

var body: some View {
Text(value)
Text(tmpText)
.font(Font.custom("morris9", size: CGFloat(fontSize)))
.lineSpacing(8)
.foregroundColor(color)
.onReceive(globalStore.$scriptCount, perform: {
currentCount in
print("나는 지금 불렸어")
typeWriter()
})

// TypeWriterTextView(
// value,
Expand All @@ -30,3 +54,9 @@ struct CustomText: View {
}

}

extension String {
subscript(offset: Int) -> Character {
self[index(startIndex, offsetBy: offset)]
}
}

0 comments on commit 13c6971

Please sign in to comment.