builds and offset drag
parent
8c1a284151
commit
6f7eed1e81
|
@ -88,7 +88,7 @@ struct Pane: View {
|
|||
@State var width: CGFloat
|
||||
@State var height: CGFloat
|
||||
|
||||
@State var dragOffset = CGFloat()
|
||||
var dragOffset = CGFloat()
|
||||
|
||||
@State var refresh: Bool = false
|
||||
|
||||
|
@ -119,8 +119,7 @@ struct Pane: View {
|
|||
destRibbon: selectedRibbon[0],
|
||||
appDatabase: appDatabase,
|
||||
paneConnector: paneConnector,
|
||||
loading: true,
|
||||
bump: false)
|
||||
loading: true)
|
||||
}
|
||||
.onChange(of: paneConnector.refresh) { _ in
|
||||
print("inside change")
|
||||
|
@ -178,8 +177,8 @@ struct Pane: View {
|
|||
// let reactive = self.paneConnector
|
||||
// }
|
||||
|
||||
if paneConnector.setScrollOffset != nil {
|
||||
DispatchQueue.main.async {
|
||||
if paneConnector.setScrollOffset != nil {
|
||||
scrollView.contentOffset.y = scrollView.contentOffset.y + paneConnector.setScrollOffset!
|
||||
paneConnector.setScrollOffset = nil
|
||||
|
||||
|
@ -236,7 +235,10 @@ struct Pane: View {
|
|||
currentId = tracker.sortedViewIDs[0]
|
||||
currentOffset = tracker.visibleViews[currentId!]!
|
||||
|
||||
if self.paneConnector.currentId != tracker.sortedViewIDs[0] {
|
||||
self.paneConnector.currentId = tracker.sortedViewIDs[0]
|
||||
}
|
||||
|
||||
self.paneConnector.currentOffset = tracker.visibleViews[currentId!]!
|
||||
|
||||
if self.paneConnector.currentId == self.paneConnector.scrollId
|
||||
|
|
|
@ -8,9 +8,6 @@ struct NaviBar: View {
|
|||
@ObservedObject var paneConnector: PaneConnector
|
||||
|
||||
@Query(RibbonRequest(dir: .prev, groupId: 1)) private var backRibbon: [Ribbon]
|
||||
|
||||
// @Query(RibbonRequest(dir: .current, groupId: 1)) private var currentRibbon: [Ribbon]
|
||||
|
||||
@Query(RibbonRequest(dir: .next, groupId: 1)) private var nextRibbon: [Ribbon]
|
||||
|
||||
@Query(SelectedRibbonRequest()) private var selectedRibbon: [Ribbon]
|
||||
|
@ -32,16 +29,12 @@ struct NaviBar: View {
|
|||
.if(!paneConnector.hasMoved) { $0.foregroundColor(Color(UIColor(red: 0.30, green: 0.30, blue: 0.30, alpha: 0.4))) }
|
||||
.onTapGesture {
|
||||
Task {
|
||||
if backRibbon.count == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
var br = backRibbon[0]
|
||||
var sr = selectedRibbon[0]
|
||||
|
||||
do {
|
||||
if paneConnector.hasMoved {
|
||||
// if true {
|
||||
print("has moved")
|
||||
|
||||
let updatedRibbon = try await createUndoState(selectedRibbon: sr,
|
||||
appDatabase: appDatabase,
|
||||
|
@ -50,49 +43,23 @@ struct NaviBar: View {
|
|||
destRibbon: sr,
|
||||
appDatabase: appDatabase,
|
||||
paneConnector: paneConnector,
|
||||
loading: false,
|
||||
bump: true)
|
||||
loading: false)
|
||||
} else {
|
||||
if backRibbon.count == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
try await appDatabase.undoRibbon(&sr)
|
||||
|
||||
goToRibbon(selectedRibbon: sr,
|
||||
destRibbon: br,
|
||||
appDatabase: appDatabase,
|
||||
paneConnector: paneConnector,
|
||||
loading: false,
|
||||
bump: true)
|
||||
|
||||
loading: false)
|
||||
}
|
||||
|
||||
// var sr = try await appDatabase.getSelectedRibbon()
|
||||
// print("meow first sr:\(sr)")
|
||||
// print("meow first selectedRibbon:\(selectedRibbon[0])")
|
||||
|
||||
// try await appDatabase.dbWriter.write { db in
|
||||
// var ribs = RibbonRequest().fetchValue(db)
|
||||
// }
|
||||
|
||||
// try await updateRibbon(selectedRibbon: selectedRibbon[0],
|
||||
// appDatabase: appDatabase,
|
||||
// paneConnector: paneConnector)
|
||||
|
||||
// print("meow back from update in main")
|
||||
// sr = try await appDatabase.getSelectedRibbon()
|
||||
// print("meow second sr:\(sr)")
|
||||
// print("meow backribbon br:\(br)")
|
||||
|
||||
// _ = try await appDatabase.undoRibbon(&sr[0])
|
||||
|
||||
// goToRibbon(selectedRibbon: sr[0],
|
||||
// destRibbon: br,
|
||||
// appDatabase: appDatabase,
|
||||
// paneConnector: paneConnector,
|
||||
// loading: false,
|
||||
// bump:false)
|
||||
|
||||
} catch {
|
||||
print("back 2 error")
|
||||
print("Error info: \(error)")
|
||||
print("Back Arrow Error info: \(error)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -101,6 +68,23 @@ struct NaviBar: View {
|
|||
.frame(width: CGFloat(30), height: CGFloat(30))
|
||||
.background(Color(red: 0.1, green: 0.1, blue: 0.1))
|
||||
.foregroundColor(Color(UIColor(red: 0.30, green: 0.30, blue: 0.30, alpha: 0.4)))
|
||||
.onTapGesture {
|
||||
if nextRibbon.count == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
Task {
|
||||
var sr = selectedRibbon[0]
|
||||
var nr = nextRibbon[0]
|
||||
try await appDatabase.redoRibbon(&sr)
|
||||
|
||||
goToRibbon(selectedRibbon: sr,
|
||||
destRibbon: nr,
|
||||
appDatabase: appDatabase,
|
||||
paneConnector: paneConnector,
|
||||
loading: false)
|
||||
}
|
||||
}
|
||||
}
|
||||
.cornerRadius(5)
|
||||
}
|
||||
|
|
|
@ -218,6 +218,31 @@ extension AppDatabase {
|
|||
}
|
||||
}
|
||||
|
||||
func redoRibbon(_ ribbon: inout Ribbon) async throws {
|
||||
let currentLevel = ribbon.currentLevel
|
||||
let minLevel = ribbon.maxLevel
|
||||
|
||||
if currentLevel == minLevel {
|
||||
print("no where to redo")
|
||||
return
|
||||
}
|
||||
|
||||
let newCurrent = (ribbon.currentLevel + 1) %% totalLevels
|
||||
|
||||
do {
|
||||
try await dbWriter.write { [ribbon] db in
|
||||
try db.execute(sql: """
|
||||
UPDATE Ribbon \
|
||||
SET currentLevel = ? WHERE groupId = ?
|
||||
""", arguments: [newCurrent, ribbon.groupId])
|
||||
}
|
||||
|
||||
} catch {
|
||||
print("Redo Ribbon Error info: \(error)")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// this sets the current undoLevel to the previous value
|
||||
// if you can go back
|
||||
func undoRibbon(_ ribbon: inout Ribbon) async throws {
|
||||
|
@ -237,12 +262,6 @@ extension AppDatabase {
|
|||
UPDATE Ribbon \
|
||||
SET currentLevel = ? WHERE groupId = ?
|
||||
""", arguments: [newCurrent, ribbon.groupId])
|
||||
|
||||
var ret3 = try Ribbon.fetchAll(db, sql: """
|
||||
SELECT * from Ribbon \
|
||||
WHERE groupId = ?
|
||||
""", arguments: [ribbon.groupId])
|
||||
|
||||
}
|
||||
|
||||
} catch {
|
||||
|
|
|
@ -72,8 +72,7 @@ func goToRibbon(selectedRibbon: Ribbon,
|
|||
destRibbon: Ribbon,
|
||||
appDatabase: AppDatabase,
|
||||
paneConnector: PaneConnector,
|
||||
loading: Bool,
|
||||
bump: Bool)
|
||||
loading: Bool)
|
||||
{
|
||||
print("meow goto ribbon - selected ribbon: \(selectedRibbon), dest ribbon: \(destRibbon) ")
|
||||
|
||||
|
@ -112,26 +111,6 @@ func goToRibbon(selectedRibbon: Ribbon,
|
|||
}
|
||||
}
|
||||
|
||||
// // this gets run regardless of if we switch ribbons or not
|
||||
// // so if you click the same ribbon or a different ribbon
|
||||
// if !loading || bump {
|
||||
// print("not loading")
|
||||
|
||||
|
||||
// print("saving ribbon")
|
||||
// // updating the ribbon location
|
||||
// updatedRibbon.scrollOffset = Int(floor(scrollOffsetToSave))
|
||||
// updatedRibbon.scrollId = scrollIdToSave
|
||||
// // updatedRibbon.undoLevel = updatedRibbon.undoLevel + 1
|
||||
// // updatedRibbon.currentLevel = updatedRibbon.currentLevel + 1
|
||||
|
||||
// if bump {
|
||||
// _ = try await appDatabase.bumpRibbon(&updatedRibbon)
|
||||
// }
|
||||
|
||||
// } else {
|
||||
// print("loading")
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -202,8 +181,7 @@ struct RibbonCrown: View {
|
|||
destRibbon: ribbon,
|
||||
appDatabase: appDatabase,
|
||||
paneConnector: paneConnector,
|
||||
loading: false,
|
||||
bump: true)
|
||||
loading: false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -271,6 +249,8 @@ struct ContentView: View {
|
|||
@State var draggedRibbon: Ribbon?
|
||||
@State var isDragging = false
|
||||
|
||||
@State var dragOffset = CGFloat(0)
|
||||
|
||||
@Environment(\.appDatabase) private var appDatabase
|
||||
|
||||
@Query(RibbonRequest()) private var ribbons: [Ribbon]
|
||||
|
@ -331,10 +311,15 @@ struct ContentView: View {
|
|||
|
||||
VStack {
|
||||
// Top pane
|
||||
|
||||
// if viewState.width > -50 {
|
||||
// dragOffset = viewState.width + pulledOut.width + 50
|
||||
// }
|
||||
Pane(paneConnector: paneConnector,
|
||||
selectedRibbon: selectedRibbon,
|
||||
width: geometry.size.width - 50,
|
||||
height: geometry.size.height / 2)
|
||||
height: geometry.size.height / 2,
|
||||
dragOffset: dragOffset)
|
||||
//////
|
||||
|
||||
Text("separator").foregroundColor(Color(UIColor(red: 0.76, green: 0.76, blue: 0.76, alpha: 1.00)))
|
||||
|
@ -392,7 +377,7 @@ struct ContentView: View {
|
|||
DragGesture()
|
||||
.onChanged { gesture in
|
||||
|
||||
print(viewState.width)
|
||||
print("mao viewState :\(viewState.width)")
|
||||
print(pulledOut.width)
|
||||
// threshold of how much to swipe before the view drags
|
||||
if abs(gesture.translation.width) > 10 {
|
||||
|
@ -400,9 +385,18 @@ struct ContentView: View {
|
|||
// if gesture.translation.width < -50, pulledOut.width == CGFloat(0) {
|
||||
// }
|
||||
}
|
||||
if viewState.width < -50 {
|
||||
dragOffset = CGFloat(50) + viewState.width + pulledOut.width
|
||||
}
|
||||
|
||||
|
||||
if viewState.width > 0 {
|
||||
dragOffset = CGFloat(50) + viewState.width + pulledOut.width
|
||||
}
|
||||
}
|
||||
.onEnded { _ in
|
||||
var setPulledOutWith = CGFloat(0)
|
||||
var setDragOffset = CGFloat(0)
|
||||
if viewState.width < 0 && pulledOut.width > 0 {
|
||||
setPulledOutWith = CGFloat(0)
|
||||
} else if viewState.width > 0 && pulledOut.width < 0 {
|
||||
|
@ -413,8 +407,18 @@ struct ContentView: View {
|
|||
setPulledOutWith = CGFloat(200)
|
||||
}
|
||||
|
||||
if setPulledOutWith < 0 {
|
||||
setDragOffset = CGFloat(50) + setPulledOutWith
|
||||
} else if setPulledOutWith > 0 {
|
||||
setDragOffset = setPulledOutWith
|
||||
} else {
|
||||
setDragOffset = .zero
|
||||
}
|
||||
|
||||
print("mao setPulledOutWith \(setPulledOutWith)")
|
||||
withAnimation(.spring(response: 0.2)) {
|
||||
pulledOut.width = setPulledOutWith
|
||||
dragOffset = setDragOffset
|
||||
viewState = .zero
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue