Flash Card animation working
This commit is contained in:
parent
ffa1094722
commit
32456552a1
@ -46,10 +46,10 @@
|
|||||||
filePath = "Toki Trainer/Views/FlashCardView.swift"
|
filePath = "Toki Trainer/Views/FlashCardView.swift"
|
||||||
startingColumnNumber = "9223372036854775807"
|
startingColumnNumber = "9223372036854775807"
|
||||||
endingColumnNumber = "9223372036854775807"
|
endingColumnNumber = "9223372036854775807"
|
||||||
startingLineNumber = "94"
|
startingLineNumber = "145"
|
||||||
endingLineNumber = "94"
|
endingLineNumber = "145"
|
||||||
landmarkName = "body"
|
landmarkName = "init(isFaceDown:frontText:backText:)"
|
||||||
landmarkType = "24">
|
landmarkType = "7">
|
||||||
</BreakpointContent>
|
</BreakpointContent>
|
||||||
</BreakpointProxy>
|
</BreakpointProxy>
|
||||||
</Breakpoints>
|
</Breakpoints>
|
||||||
|
@ -22,37 +22,46 @@ struct FlashCardView: View {
|
|||||||
|
|
||||||
struct FlashCardStack: View {
|
struct FlashCardStack: View {
|
||||||
|
|
||||||
@State var dictionary: [TokiDictEntry]
|
var dictionary: [TokiDictEntry]
|
||||||
@State private var flashCards: [FlashCard] = []
|
@State private var flashCards: [FlashCard] = []
|
||||||
|
@State private var topFlashCard: FlashCard? = nil
|
||||||
|
@State private var flashCardStack: [FlashCard] = []
|
||||||
@State private var flashCardsCanBeFlipped: [Bool] = []
|
@State private var flashCardsCanBeFlipped: [Bool] = []
|
||||||
|
@State private var flashCardsVertOffset: [CGFloat] = []
|
||||||
|
|
||||||
|
@State private var currentFlashCard = 0
|
||||||
|
|
||||||
|
let timer = Timer.publish(every: 1, tolerance: 0.1, on: .main, in: .common, options: nil).autoconnect()
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack {
|
VStack {
|
||||||
ZStack {
|
ZStack {
|
||||||
ForEach(flashCards.indices, id: \.self) { i in
|
if(flashCards.count > 0) {
|
||||||
if i == 0 {
|
ForEach(flashCards.indices, id: \.self) { index in
|
||||||
flashCards[0]
|
flashCards[index]
|
||||||
.offset(x: 0, y: -300)
|
.offset(x: 0, y: flashCardsVertOffset[index])
|
||||||
.zIndex(0)
|
|
||||||
|
|
||||||
} else if i < 10 {
|
|
||||||
flashCards[i]
|
|
||||||
.offset(x: 0, y: 30 * CGFloat(i))
|
|
||||||
.zIndex(Double(-i))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// if(flashCards.count > 1) {
|
||||||
|
// flashCards[currentFlashCard]
|
||||||
|
// .offset(x: 0, y: flashCardsVertOffset[currentFlashCard])
|
||||||
|
// .animation(.default)
|
||||||
|
// flashCards[currentFlashCard + 1]
|
||||||
|
// .offset(x: 0, y: flashCardsVertOffset[currentFlashCard + 1])
|
||||||
|
// .animation(.default)
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
.onAppear {
|
Spacer()
|
||||||
initFlashCardsArray()
|
|
||||||
flashCards[0].setCanBeFlipped(true)
|
|
||||||
}
|
|
||||||
Button {
|
Button {
|
||||||
self.popFromDictionary()
|
//self.currentFlashCard += 1
|
||||||
|
nextFlashCard()
|
||||||
} label: {
|
} label: {
|
||||||
Text("Next Card")
|
Text("Next Card")
|
||||||
}
|
}
|
||||||
.background(.white)
|
.background(.white)
|
||||||
.animation(.default)
|
}
|
||||||
|
.onAppear {
|
||||||
|
initFlashCardsArray()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,12 +70,26 @@ struct FlashCardStack: View {
|
|||||||
for index in dictionary.indices {
|
for index in dictionary.indices {
|
||||||
flashCardsCanBeFlipped.append(false)
|
flashCardsCanBeFlipped.append(false)
|
||||||
flashCards.append(FlashCard(canBeFlipped: $flashCardsCanBeFlipped[index], dictionaryEntry: dictionary[index]))
|
flashCards.append(FlashCard(canBeFlipped: $flashCardsCanBeFlipped[index], dictionaryEntry: dictionary[index]))
|
||||||
|
flashCardsVertOffset.append(800)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func popFromDictionary() {
|
func nextFlashCard() {
|
||||||
dictionary.removeFirst()
|
if(currentFlashCard > 0 ) {
|
||||||
initFlashCardsArray()
|
flashCardsVertOffset[currentFlashCard - 1] = -1000
|
||||||
|
}
|
||||||
|
flashCardsVertOffset[currentFlashCard] = 300
|
||||||
|
flashCards[currentFlashCard].setCanBeFlipped(true)
|
||||||
|
currentFlashCard += 1
|
||||||
|
//flashCardsVertOffset[currentFlashCard + 1] = 300
|
||||||
|
}
|
||||||
|
|
||||||
|
func setTopFlashCard(card: FlashCard?) {
|
||||||
|
if let safeCard = card {
|
||||||
|
self.topFlashCard?.canBeFlipped = false
|
||||||
|
self.topFlashCard = safeCard
|
||||||
|
self.topFlashCard?.canBeFlipped = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user