builds and offset drag
parent
8c1a284151
commit
6f7eed1e81
|
@ -88,7 +88,7 @@ struct Pane: View {
|
||||||
@State var width: CGFloat
|
@State var width: CGFloat
|
||||||
@State var height: CGFloat
|
@State var height: CGFloat
|
||||||
|
|
||||||
@State var dragOffset = CGFloat()
|
var dragOffset = CGFloat()
|
||||||
|
|
||||||
@State var refresh: Bool = false
|
@State var refresh: Bool = false
|
||||||
|
|
||||||
|
@ -119,8 +119,7 @@ struct Pane: View {
|
||||||
destRibbon: selectedRibbon[0],
|
destRibbon: selectedRibbon[0],
|
||||||
appDatabase: appDatabase,
|
appDatabase: appDatabase,
|
||||||
paneConnector: paneConnector,
|
paneConnector: paneConnector,
|
||||||
loading: true,
|
loading: true)
|
||||||
bump: false)
|
|
||||||
}
|
}
|
||||||
.onChange(of: paneConnector.refresh) { _ in
|
.onChange(of: paneConnector.refresh) { _ in
|
||||||
print("inside change")
|
print("inside change")
|
||||||
|
@ -178,8 +177,8 @@ struct Pane: View {
|
||||||
// let reactive = self.paneConnector
|
// let reactive = self.paneConnector
|
||||||
// }
|
// }
|
||||||
|
|
||||||
if paneConnector.setScrollOffset != nil {
|
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
|
if paneConnector.setScrollOffset != nil {
|
||||||
scrollView.contentOffset.y = scrollView.contentOffset.y + paneConnector.setScrollOffset!
|
scrollView.contentOffset.y = scrollView.contentOffset.y + paneConnector.setScrollOffset!
|
||||||
paneConnector.setScrollOffset = nil
|
paneConnector.setScrollOffset = nil
|
||||||
|
|
||||||
|
@ -236,7 +235,10 @@ struct Pane: View {
|
||||||
currentId = tracker.sortedViewIDs[0]
|
currentId = tracker.sortedViewIDs[0]
|
||||||
currentOffset = tracker.visibleViews[currentId!]!
|
currentOffset = tracker.visibleViews[currentId!]!
|
||||||
|
|
||||||
|
if self.paneConnector.currentId != tracker.sortedViewIDs[0] {
|
||||||
self.paneConnector.currentId = tracker.sortedViewIDs[0]
|
self.paneConnector.currentId = tracker.sortedViewIDs[0]
|
||||||
|
}
|
||||||
|
|
||||||
self.paneConnector.currentOffset = tracker.visibleViews[currentId!]!
|
self.paneConnector.currentOffset = tracker.visibleViews[currentId!]!
|
||||||
|
|
||||||
if self.paneConnector.currentId == self.paneConnector.scrollId
|
if self.paneConnector.currentId == self.paneConnector.scrollId
|
||||||
|
|
|
@ -8,9 +8,6 @@ struct NaviBar: View {
|
||||||
@ObservedObject var paneConnector: PaneConnector
|
@ObservedObject var paneConnector: PaneConnector
|
||||||
|
|
||||||
@Query(RibbonRequest(dir: .prev, groupId: 1)) private var backRibbon: [Ribbon]
|
@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(RibbonRequest(dir: .next, groupId: 1)) private var nextRibbon: [Ribbon]
|
||||||
|
|
||||||
@Query(SelectedRibbonRequest()) private var selectedRibbon: [Ribbon]
|
@Query(SelectedRibbonRequest()) private var selectedRibbon: [Ribbon]
|
||||||
|
@ -20,7 +17,7 @@ struct NaviBar: View {
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack {
|
VStack {
|
||||||
HStack {
|
HStack {
|
||||||
//Print("meow navi reloaded back ribbon: \(backRibbon[0])")
|
// Print("meow navi reloaded back ribbon: \(backRibbon[0])")
|
||||||
|
|
||||||
Print("rendering navi")
|
Print("rendering navi")
|
||||||
Print("dog backRibbon: \(backRibbon)")
|
Print("dog backRibbon: \(backRibbon)")
|
||||||
|
@ -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))) }
|
.if(!paneConnector.hasMoved) { $0.foregroundColor(Color(UIColor(red: 0.30, green: 0.30, blue: 0.30, alpha: 0.4))) }
|
||||||
.onTapGesture {
|
.onTapGesture {
|
||||||
Task {
|
Task {
|
||||||
if backRibbon.count == 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var br = backRibbon[0]
|
var br = backRibbon[0]
|
||||||
var sr = selectedRibbon[0]
|
var sr = selectedRibbon[0]
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if paneConnector.hasMoved {
|
if paneConnector.hasMoved {
|
||||||
// if true {
|
print("has moved")
|
||||||
|
|
||||||
let updatedRibbon = try await createUndoState(selectedRibbon: sr,
|
let updatedRibbon = try await createUndoState(selectedRibbon: sr,
|
||||||
appDatabase: appDatabase,
|
appDatabase: appDatabase,
|
||||||
|
@ -50,49 +43,23 @@ struct NaviBar: View {
|
||||||
destRibbon: sr,
|
destRibbon: sr,
|
||||||
appDatabase: appDatabase,
|
appDatabase: appDatabase,
|
||||||
paneConnector: paneConnector,
|
paneConnector: paneConnector,
|
||||||
loading: false,
|
loading: false)
|
||||||
bump: true)
|
|
||||||
} else {
|
} else {
|
||||||
|
if backRibbon.count == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
try await appDatabase.undoRibbon(&sr)
|
try await appDatabase.undoRibbon(&sr)
|
||||||
|
|
||||||
goToRibbon(selectedRibbon: sr,
|
goToRibbon(selectedRibbon: sr,
|
||||||
destRibbon: br,
|
destRibbon: br,
|
||||||
appDatabase: appDatabase,
|
appDatabase: appDatabase,
|
||||||
paneConnector: paneConnector,
|
paneConnector: paneConnector,
|
||||||
loading: false,
|
loading: false)
|
||||||
bump: true)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 {
|
} catch {
|
||||||
print("back 2 error")
|
print("Back Arrow Error info: \(error)")
|
||||||
print("Error info: \(error)")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -101,6 +68,23 @@ struct NaviBar: View {
|
||||||
.frame(width: CGFloat(30), height: CGFloat(30))
|
.frame(width: CGFloat(30), height: CGFloat(30))
|
||||||
.background(Color(red: 0.1, green: 0.1, blue: 0.1))
|
.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)))
|
.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)
|
.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
|
// this sets the current undoLevel to the previous value
|
||||||
// if you can go back
|
// if you can go back
|
||||||
func undoRibbon(_ ribbon: inout Ribbon) async throws {
|
func undoRibbon(_ ribbon: inout Ribbon) async throws {
|
||||||
|
@ -237,12 +262,6 @@ extension AppDatabase {
|
||||||
UPDATE Ribbon \
|
UPDATE Ribbon \
|
||||||
SET currentLevel = ? WHERE groupId = ?
|
SET currentLevel = ? WHERE groupId = ?
|
||||||
""", arguments: [newCurrent, ribbon.groupId])
|
""", arguments: [newCurrent, ribbon.groupId])
|
||||||
|
|
||||||
var ret3 = try Ribbon.fetchAll(db, sql: """
|
|
||||||
SELECT * from Ribbon \
|
|
||||||
WHERE groupId = ?
|
|
||||||
""", arguments: [ribbon.groupId])
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch {
|
} catch {
|
||||||
|
|
|
@ -72,8 +72,7 @@ func goToRibbon(selectedRibbon: Ribbon,
|
||||||
destRibbon: Ribbon,
|
destRibbon: Ribbon,
|
||||||
appDatabase: AppDatabase,
|
appDatabase: AppDatabase,
|
||||||
paneConnector: PaneConnector,
|
paneConnector: PaneConnector,
|
||||||
loading: Bool,
|
loading: Bool)
|
||||||
bump: Bool)
|
|
||||||
{
|
{
|
||||||
print("meow goto ribbon - selected ribbon: \(selectedRibbon), dest ribbon: \(destRibbon) ")
|
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,
|
destRibbon: ribbon,
|
||||||
appDatabase: appDatabase,
|
appDatabase: appDatabase,
|
||||||
paneConnector: paneConnector,
|
paneConnector: paneConnector,
|
||||||
loading: false,
|
loading: false)
|
||||||
bump: true)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -271,6 +249,8 @@ struct ContentView: View {
|
||||||
@State var draggedRibbon: Ribbon?
|
@State var draggedRibbon: Ribbon?
|
||||||
@State var isDragging = false
|
@State var isDragging = false
|
||||||
|
|
||||||
|
@State var dragOffset = CGFloat(0)
|
||||||
|
|
||||||
@Environment(\.appDatabase) private var appDatabase
|
@Environment(\.appDatabase) private var appDatabase
|
||||||
|
|
||||||
@Query(RibbonRequest()) private var ribbons: [Ribbon]
|
@Query(RibbonRequest()) private var ribbons: [Ribbon]
|
||||||
|
@ -331,10 +311,15 @@ struct ContentView: View {
|
||||||
|
|
||||||
VStack {
|
VStack {
|
||||||
// Top pane
|
// Top pane
|
||||||
|
|
||||||
|
// if viewState.width > -50 {
|
||||||
|
// dragOffset = viewState.width + pulledOut.width + 50
|
||||||
|
// }
|
||||||
Pane(paneConnector: paneConnector,
|
Pane(paneConnector: paneConnector,
|
||||||
selectedRibbon: selectedRibbon,
|
selectedRibbon: selectedRibbon,
|
||||||
width: geometry.size.width - 50,
|
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)))
|
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()
|
DragGesture()
|
||||||
.onChanged { gesture in
|
.onChanged { gesture in
|
||||||
|
|
||||||
print(viewState.width)
|
print("mao viewState :\(viewState.width)")
|
||||||
print(pulledOut.width)
|
print(pulledOut.width)
|
||||||
// threshold of how much to swipe before the view drags
|
// threshold of how much to swipe before the view drags
|
||||||
if abs(gesture.translation.width) > 10 {
|
if abs(gesture.translation.width) > 10 {
|
||||||
|
@ -400,9 +385,18 @@ struct ContentView: View {
|
||||||
// if gesture.translation.width < -50, pulledOut.width == CGFloat(0) {
|
// 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
|
.onEnded { _ in
|
||||||
var setPulledOutWith = CGFloat(0)
|
var setPulledOutWith = CGFloat(0)
|
||||||
|
var setDragOffset = CGFloat(0)
|
||||||
if viewState.width < 0 && pulledOut.width > 0 {
|
if viewState.width < 0 && pulledOut.width > 0 {
|
||||||
setPulledOutWith = CGFloat(0)
|
setPulledOutWith = CGFloat(0)
|
||||||
} else if viewState.width > 0 && pulledOut.width < 0 {
|
} else if viewState.width > 0 && pulledOut.width < 0 {
|
||||||
|
@ -413,8 +407,18 @@ struct ContentView: View {
|
||||||
setPulledOutWith = CGFloat(200)
|
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)) {
|
withAnimation(.spring(response: 0.2)) {
|
||||||
pulledOut.width = setPulledOutWith
|
pulledOut.width = setPulledOutWith
|
||||||
|
dragOffset = setDragOffset
|
||||||
viewState = .zero
|
viewState = .zero
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue