26 lines
598 B
Swift
26 lines
598 B
Swift
import Foundation
|
|
|
|
struct MyPageNoticeRoller {
|
|
private var items: [NoticeItem] = []
|
|
private(set) var index = 0
|
|
|
|
var current: NoticeItem? {
|
|
items.isEmpty ? nil : items[index]
|
|
}
|
|
|
|
mutating func update(_ items: [NoticeItem]) {
|
|
guard self.items != items else { return }
|
|
self.items = items
|
|
index = 0
|
|
}
|
|
|
|
mutating func advance() {
|
|
guard items.count > 1 else { return }
|
|
index = (index + 1) % items.count
|
|
}
|
|
|
|
func shouldRoll(isVisible: Bool, isActive: Bool) -> Bool {
|
|
items.count > 1 && isVisible && isActive
|
|
}
|
|
}
|