closed #56
This commit is contained in:
@@ -11,11 +11,24 @@ import CoreData
|
|||||||
class ContentModeViewModel: ObservableObject {
|
class ContentModeViewModel: ObservableObject {
|
||||||
@Published var grouped = [Int: [Int: [MoodEntry]]]()
|
@Published var grouped = [Int: [Int: [MoodEntry]]]()
|
||||||
@Published public private(set) var savedOnboardingData = UserDefaultsStore.getOnboarding()
|
@Published public private(set) var savedOnboardingData = UserDefaultsStore.getOnboarding()
|
||||||
|
@Published var numberOfItems = 0
|
||||||
|
|
||||||
var hasNoData: Bool {
|
var hasNoData: Bool {
|
||||||
grouped.isEmpty
|
grouped.isEmpty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var numberOfEntries: Int {
|
||||||
|
var num = 0
|
||||||
|
grouped.keys.forEach({
|
||||||
|
let year = grouped[$0]
|
||||||
|
let monthKeys = year?.keys
|
||||||
|
monthKeys?.forEach({
|
||||||
|
num += year![$0]!.count
|
||||||
|
})
|
||||||
|
})
|
||||||
|
return num
|
||||||
|
}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
PersistenceController.shared.switchContainerListeners.append {
|
PersistenceController.shared.switchContainerListeners.append {
|
||||||
self.getGroupedData()
|
self.getGroupedData()
|
||||||
@@ -26,6 +39,7 @@ class ContentModeViewModel: ObservableObject {
|
|||||||
|
|
||||||
private func getGroupedData() {
|
private func getGroupedData() {
|
||||||
grouped = PersistenceController.shared.splitIntoYearMonth()
|
grouped = PersistenceController.shared.splitIntoYearMonth()
|
||||||
|
numberOfItems = numberOfEntries
|
||||||
}
|
}
|
||||||
|
|
||||||
public func shouldShowVotingHeader() -> Bool {
|
public func shouldShowVotingHeader() -> Bool {
|
||||||
|
|||||||
@@ -134,9 +134,9 @@ struct ContentView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func calculateHeight(minHeight: CGFloat, maxHeight: CGFloat, yOffset: CGFloat) {
|
func calculateHeight(minHeight: CGFloat, maxHeight: CGFloat, yOffset: CGFloat) {
|
||||||
calcuateViewAlpha()
|
|
||||||
|
|
||||||
let newValue = maxHeight + yOffset
|
let newValue = maxHeight + yOffset
|
||||||
|
|
||||||
|
calcuateViewAlpha()
|
||||||
// If scrolling up, yOffset will be a negative number
|
// If scrolling up, yOffset will be a negative number
|
||||||
if newValue < minHeight {
|
if newValue < minHeight {
|
||||||
// SCROLLING UP
|
// SCROLLING UP
|
||||||
@@ -184,7 +184,11 @@ struct ContentView: View {
|
|||||||
)
|
)
|
||||||
.coordinateSpace(name: "scroll")
|
.coordinateSpace(name: "scroll")
|
||||||
.onPreferenceChange(ViewOffsetKey.self) { value in
|
.onPreferenceChange(ViewOffsetKey.self) { value in
|
||||||
calculateHeight(minHeight: ContentViewConstants.minHeaderHeight, maxHeight: ContentViewConstants.maxHeaderHeight, yOffset: value)
|
if viewModel.numberOfItems > 10 {
|
||||||
|
calculateHeight(minHeight: ContentViewConstants.minHeaderHeight,
|
||||||
|
maxHeight: ContentViewConstants.maxHeaderHeight,
|
||||||
|
yOffset: value)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.clipShape(RoundedRectangle(cornerRadius: 25, style: .continuous))
|
.clipShape(RoundedRectangle(cornerRadius: 25, style: .continuous))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user