feat(mypage): 최신 공지 배열과 제목 롤링을 적용한다
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user