Skip to content

Commit

Permalink
feat typing effect #18
Browse files Browse the repository at this point in the history
  • Loading branch information
LIM-YUSANG committed Mar 30, 2023
1 parent fe44e27 commit 92689a3
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 5 deletions.
Binary file not shown.
3 changes: 2 additions & 1 deletion Utils/Scene/handleSequenceOne.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ func handleSequenceOne(globalStore: GlobalStore){
globalStore.turnOffIsFaceViewActive()
globalStore.turnOnIsQuizSequence()
globalStore.turnOffIsTapAble()
// case 7: handleSequenceQuizOne() 실행될 것

//case 7: handleSequenceQuizOne() //실행될 것
default:
print("sequence one is Ready")
}
Expand Down
11 changes: 11 additions & 0 deletions View/CustomView/CustomText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,25 @@
import SwiftUI

struct CustomText: View {

var value = ""
var fontSize = 32
var color = CustomColor.scriptColor

// @Binding var isStart: Bool

var body: some View {
Text(value)
.font(Font.custom("morris9", size: CGFloat(fontSize)))
.lineSpacing(8)
.foregroundColor(color)

// TypeWriterTextView(
// value,
// speed: 0.1,
// isStart: $isStart
// ).font(Font.custom("morris9", size: CGFloat(fontSize))).lineSpacing(8).foregroundColor(color)

}

}
1 change: 1 addition & 0 deletions View/QuizModalView/AnswerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ struct AnswerView: View {
var globalStore: GlobalStore
// QuizData에 있는 question값을 가져와서 String으로 형 변환해준다

// @Binding var isStart: Bool
let answer: String = QUESTION_TWO["answer"] as? String ?? ""
let answer1: String = QUESTION_TWO["answer1"] as? String ?? ""

Expand Down
2 changes: 2 additions & 0 deletions View/QuizModalView/QuestionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import SwiftUI
struct QuestionView: View {
@EnvironmentObject
var globalStore: GlobalStore

// @Binding var isStart: Bool

let q = QUESTION_TWO["question"] as? String ?? ""
let q1 = QUESTION_TWO["question1"] as? String ?? ""
Expand Down
5 changes: 5 additions & 0 deletions View/QuizModalView/QuizButtonView1.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
import SwiftUI

struct QuizButtonView1: View {

@EnvironmentObject
var globalStore: GlobalStore

@Environment(\.presentationMode) var presentation
@Binding var isShowingModal: Bool
@Binding var quizFalse: Bool
Expand All @@ -18,6 +22,7 @@ struct QuizButtonView1: View {
LazyVGrid(columns: [GridItem(.flexible()), GridItem(.flexible())]) {
Button{
isShowingModal = false
handleSequenceQuizOne(globalStore: globalStore)
} label: {
CustomText(value: "A", fontSize: 18, color: Color.black)
.frame(width: 180, height: 70)
Expand Down
6 changes: 3 additions & 3 deletions View/QuizModalView/QuizModalView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ struct QuizModalView: View {
}
*/

if globalStore.currentScene == EnumScene.sequence1 {
QuizButtonView1(isShowingModal: $isShowingModal, quizFalse: $quizFalse){

}
}
}

else {
QuizButtonView(isShowingModal: $isShowingModal, quizFalse: $quizFalse){

}
}
// QuizButtonView(isShowingModal: $isShowingModal, quizFalse: $quizFalse){
Expand Down
8 changes: 7 additions & 1 deletion View/ScriptBoxView/ScriptBoxView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import SwiftUI


/**
필요한 기능
1. 탭 클릭 시 스크립트가 변경된다.
Expand All @@ -23,9 +22,15 @@ struct ScriptBoxView: View {
@State
var currentSceneCount: Int = 0

//@Binding var isStart: Bool
//@State var isStart: Bool = false

var script: Script
var width: CGFloat


//weak var titleLabel: UILabel!

private let SCRIPT_BOX_VIEW_BACKGROUND_IMAGE = "Background_Text"

private func updateCurrentSequence() {
Expand Down Expand Up @@ -88,6 +93,7 @@ struct ScriptBoxView: View {
.background(CustomColor.scriptBox)
.onTapGesture {
updateCurrentSequence()
// isStart = true
}
}
}
Expand Down
42 changes: 42 additions & 0 deletions View/ScriptBoxView/TypeWriterTextView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// File.swift
//
//
// Created by yusang on 2023/03/30.
//

import Foundation

import SwiftUI

struct TypeWriterTextView: View {
private let text: String

private let speed: TimeInterval

@Binding var isStart: Bool

@State private var textArray: String = ""

init(_ text: String, speed: TimeInterval = 0.1, isStart: Binding<Bool>) {
self.text = text
self.speed = speed
self._isStart = isStart
}

var body: some View {
Text(textArray)
.onChange(of: isStart) { _ in
startAnimation()
}
}

private func startAnimation() {
DispatchQueue.global().async {
let _ = text.map {
Thread.sleep(forTimeInterval: speed)
textArray += $0.description
}
}
}
}

0 comments on commit 92689a3

Please sign in to comment.