reordering works with hiding view
parent
5294ee7c4d
commit
ecb13c384c
|
@ -130,6 +130,9 @@ extension AppDatabase {
|
||||||
// BEGIN TRANSACTION;
|
// BEGIN TRANSACTION;
|
||||||
// """)
|
// """)
|
||||||
do {
|
do {
|
||||||
|
|
||||||
|
if (newPos < oldPos) {
|
||||||
|
|
||||||
try db.execute(sql: """
|
try db.execute(sql: """
|
||||||
UPDATE Ribbon
|
UPDATE Ribbon
|
||||||
SET pos =
|
SET pos =
|
||||||
|
@ -140,6 +143,22 @@ extension AppDatabase {
|
||||||
END
|
END
|
||||||
WHERE (pos >= ? AND pos <= ?)
|
WHERE (pos >= ? AND pos <= ?)
|
||||||
""", arguments: [oldPos, newPos, newPos, oldPos])
|
""", arguments: [oldPos, newPos, newPos, oldPos])
|
||||||
|
} else {
|
||||||
|
|
||||||
|
print("DIFFFFF")
|
||||||
|
|
||||||
|
try db.execute(sql: """
|
||||||
|
UPDATE Ribbon
|
||||||
|
SET pos =
|
||||||
|
CASE
|
||||||
|
WHEN pos = ? THEN ?
|
||||||
|
ELSE
|
||||||
|
pos - 1
|
||||||
|
END
|
||||||
|
WHERE (pos >= ? AND pos <= ?)
|
||||||
|
""", arguments: [oldPos, newPos, oldPos, newPos])
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// try db.execute(sql: """
|
// try db.execute(sql: """
|
||||||
// UPDATE Ribbon
|
// UPDATE Ribbon
|
||||||
|
|
|
@ -119,6 +119,13 @@ func goToRibbon(selectedRibbon: Ribbon,
|
||||||
// print("scrollIdToSave: ", scrollIdToSave)
|
// print("scrollIdToSave: ", scrollIdToSave)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
extension View {
|
||||||
|
@ViewBuilder
|
||||||
|
func `if`<Transform: View>(_ condition: Bool, transform: (Self) -> Transform) -> some View {
|
||||||
|
if condition { transform(self) }
|
||||||
|
else { self }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct RibbonCrown : View {
|
struct RibbonCrown : View {
|
||||||
var ribbon: Ribbon
|
var ribbon: Ribbon
|
||||||
|
@ -126,6 +133,8 @@ struct RibbonCrown : View {
|
||||||
@Binding var scrollOffset : CGFloat?
|
@Binding var scrollOffset : CGFloat?
|
||||||
@Binding var showOverlay : Bool
|
@Binding var showOverlay : Bool
|
||||||
@Binding var refresh : Bool
|
@Binding var refresh : Bool
|
||||||
|
var draggedRibbon : Ribbon?
|
||||||
|
var isDragging : Bool
|
||||||
|
|
||||||
var height = CGFloat(45)
|
var height = CGFloat(45)
|
||||||
var xOffset = CGFloat(25)
|
var xOffset = CGFloat(25)
|
||||||
|
@ -142,12 +151,20 @@ struct RibbonCrown : View {
|
||||||
ZStack {
|
ZStack {
|
||||||
MyIcon().frame(width: CGFloat(100 * 1.66 * scale), height: CGFloat(100 * scale), alignment: .center) .foregroundColor(Color(UIColor(red: 0.30, green: 0.30, blue: 0.30, alpha: 0.4)))
|
MyIcon().frame(width: CGFloat(100 * 1.66 * scale), height: CGFloat(100 * scale), alignment: .center) .foregroundColor(Color(UIColor(red: 0.30, green: 0.30, blue: 0.30, alpha: 0.4)))
|
||||||
|
|
||||||
|
.if(draggedRibbon != nil && draggedRibbon!.id == ribbon.id && isDragging) { $0.overlay(Color(red: 0.1, green: 0.1, blue: 0.1)) }
|
||||||
|
|
||||||
Text(ribbon.title)
|
Text(ribbon.title)
|
||||||
.foregroundColor(Color(UIColor(red: 0.76, green: 0.76, blue: 0.76, alpha: 1.00)))
|
.foregroundColor(Color(UIColor(red: 0.76, green: 0.76, blue: 0.76, alpha: 1.00)))
|
||||||
// .foregroundColor(.white))
|
// .foregroundColor(.white))
|
||||||
// .foregroundColor(.black)
|
// .foregroundColor(.black)
|
||||||
.frame(minWidth: CGFloat(70), maxWidth: CGFloat(70), minHeight: height, maxHeight: height, alignment: .center)
|
.frame(minWidth: CGFloat(70), maxWidth: CGFloat(70), minHeight: height, maxHeight: height, alignment: .center)
|
||||||
|
|
||||||
|
.if(draggedRibbon != nil && draggedRibbon!.id == ribbon.id && isDragging) { $0.overlay(Color(red: 0.1, green: 0.1, blue: 0.1)) }
|
||||||
|
|
||||||
|
// .if(!isDragging || draggedRibbon == nil || draggedRibbon!.id != ribbon.id) { $0.background(Color(red: 0.1, green: 0.1, blue: 0.1)) }
|
||||||
|
// .if(draggedRibbon != nil && draggedRibbon!.id == ribbon.id) { $0.background(.red) }
|
||||||
.background(Color(red: 0.1, green: 0.1, blue: 0.1))
|
.background(Color(red: 0.1, green: 0.1, blue: 0.1))
|
||||||
|
// .background(Color(red: 0.1, green: 0.1, blue: 0.1))
|
||||||
// .background(.red)
|
// .background(.red)
|
||||||
// .background(.yellow)
|
// .background(.yellow)
|
||||||
.multilineTextAlignment(.center)
|
.multilineTextAlignment(.center)
|
||||||
|
@ -332,6 +349,7 @@ struct ContentView: View {
|
||||||
@State var refresh2: Bool = false
|
@State var refresh2: Bool = false
|
||||||
|
|
||||||
@State var draggedRibbon: Ribbon?
|
@State var draggedRibbon: Ribbon?
|
||||||
|
@State var isDragging = false
|
||||||
|
|
||||||
@State var reorder = true
|
@State var reorder = true
|
||||||
|
|
||||||
|
@ -375,14 +393,19 @@ struct ContentView: View {
|
||||||
scrollId:$scrollId,
|
scrollId:$scrollId,
|
||||||
scrollOffset:$scrollOffset,
|
scrollOffset:$scrollOffset,
|
||||||
showOverlay: $showOverlay,
|
showOverlay: $showOverlay,
|
||||||
refresh:$refresh
|
refresh:$refresh,
|
||||||
|
draggedRibbon: draggedRibbon,
|
||||||
|
isDragging: isDragging
|
||||||
)
|
)
|
||||||
.onDrag {
|
.onDrag {
|
||||||
self.draggedRibbon = ribbon
|
self.draggedRibbon = ribbon
|
||||||
return NSItemProvider()
|
return NSItemProvider()
|
||||||
}
|
}
|
||||||
.onDrop(of: [.text],
|
.onDrop(of: [.item],
|
||||||
delegate: DropViewDelegate(destinationItem: ribbon, draggedItem: $draggedRibbon, appDatabase: appDatabase)
|
delegate: DropViewDelegate(destinationItem: ribbon,
|
||||||
|
draggedItem: $draggedRibbon,
|
||||||
|
isDragging: $isDragging,
|
||||||
|
appDatabase: appDatabase)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -896,15 +919,26 @@ struct DropViewDelegate: DropDelegate {
|
||||||
let destinationItem: Ribbon
|
let destinationItem: Ribbon
|
||||||
// @Binding var colors: [Color]
|
// @Binding var colors: [Color]
|
||||||
@Binding var draggedItem: Ribbon?
|
@Binding var draggedItem: Ribbon?
|
||||||
|
@Binding var isDragging: Bool
|
||||||
let appDatabase: AppDatabase
|
let appDatabase: AppDatabase
|
||||||
|
|
||||||
func dropUpdated(info: DropInfo) -> DropProposal? {
|
func dropUpdated(info: DropInfo) -> DropProposal? {
|
||||||
return DropProposal(operation: .move)
|
return DropProposal(operation: .move)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func dropExited(info: DropInfo) {
|
||||||
|
print("EXITED")
|
||||||
|
isDragging = false
|
||||||
|
}
|
||||||
|
|
||||||
func dropEntered(info: DropInfo) {
|
func dropEntered(info: DropInfo) {
|
||||||
|
|
||||||
Task {
|
Task {
|
||||||
|
isDragging = true
|
||||||
|
if (draggedItem == nil) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
var newRibbon = draggedItem!
|
var newRibbon = draggedItem!
|
||||||
var newDest = destinationItem
|
var newDest = destinationItem
|
||||||
|
@ -925,12 +959,16 @@ struct DropViewDelegate: DropDelegate {
|
||||||
newRibbon.pos = destinationItem.pos
|
newRibbon.pos = destinationItem.pos
|
||||||
|
|
||||||
_ = try await appDatabase.updateRibbonPosition(&newRibbon, oldPos, newPos )
|
_ = try await appDatabase.updateRibbonPosition(&newRibbon, oldPos, newPos )
|
||||||
|
draggedItem!.pos = newPos
|
||||||
|
|
||||||
|
// draggedItem = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func performDrop(info: DropInfo) -> Bool {
|
func performDrop(info: DropInfo) -> Bool {
|
||||||
|
print("PERFORMED DROPPPP")
|
||||||
draggedItem = nil
|
draggedItem = nil
|
||||||
|
isDragging = false
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue