2023-02-27 14:27:15 -08:00
//
// C o n t e n t V i e w . s w i f t
// g l o s s
//
// C r e a t e d b y S a i n t o n 1 0 / 2 3 / 2 2 .
//
import GRDB
import GRDBQuery
2024-05-15 08:57:41 -07:00
import SwiftUIIntrospect
2023-02-27 14:27:15 -08:00
import os
2024-05-15 08:57:41 -07:00
import SwiftUI
import WrappingHStack
2023-02-27 14:27:15 -08:00
let logger = Logger ( subsystem : Bundle . main . bundleIdentifier ! , category : " network " )
2024-05-15 08:57:41 -07:00
var currentId : String ?
var currentOffset : CGFloat ?
2023-04-23 20:41:17 -07:00
var gTracker : VisibilityTracker < String > ?
2023-06-01 12:45:36 -07:00
var printCount : Int64 = 0
2023-04-23 20:41:17 -07:00
2023-08-16 12:19:14 -07:00
var disableDrop = false
2023-02-27 14:27:15 -08:00
// v a r c u r B o o k = " J o h n "
2024-05-15 08:57:41 -07:00
public extension UserDefaults {
func optionalInt ( forKey defaultName : String ) -> Int ? {
2023-02-28 14:03:58 -08:00
let defaults = self
if let value = defaults . value ( forKey : defaultName ) {
return value as ? Int
}
2024-05-15 08:57:41 -07:00
return nil
2023-02-28 14:03:58 -08:00
}
2024-05-15 08:57:41 -07:00
func optionalBool ( forKey defaultName : String ) -> Bool ? {
2023-02-28 14:03:58 -08:00
let defaults = self
if let value = defaults . value ( forKey : defaultName ) {
return value as ? Bool
}
return nil
}
}
2023-11-14 13:39:46 -08:00
func goToRibbon ( selectedRibbon : Ribbon ,
destRibbon : Ribbon ,
2023-05-31 13:57:17 -07:00
scrollId : Binding < String ? > ,
scrollOffset : Binding < CGFloat ? > ,
refresh : Binding < Bool > ,
2023-06-27 16:04:24 -07:00
showOverlay : Binding < Bool > ,
2023-06-01 12:45:36 -07:00
appDatabase : AppDatabase ,
2024-05-15 08:57:41 -07:00
loading : Bool )
2023-06-01 12:45:36 -07:00
{
Task {
2023-11-14 13:39:46 -08:00
// p r i n t ( " S E L E C T E D R I B B O N " , s e l e c t e d R i b b o n )
2023-05-31 13:57:17 -07:00
var scrollOffsetToSave = currentOffset
var scrollIdToSave = currentId
var updatedRibbon = selectedRibbon
2024-05-15 08:57:41 -07:00
if selectedRibbon . id != destRibbon . id ! || loading {
2023-05-31 16:42:11 -07:00
print ( " switching ribbons " )
2023-11-14 13:39:46 -08:00
2023-06-27 16:04:24 -07:00
// w i t h A n i m a t i o n ( . s p r i n g ( r e s p o n s e : 0 . 0 5 ) ) {
2024-05-15 08:57:41 -07:00
// s h o w O v e r l a y . w r a p p e d V a l u e = t r u e
showOverlay . wrappedValue = true
2023-06-27 16:04:24 -07:00
// }
2023-05-31 13:57:17 -07:00
2024-05-15 08:57:41 -07:00
if loading {
2023-06-01 12:45:36 -07:00
currentId = destRibbon . scrollId
// c u r r e n t O f f s e t = C G F l o a t ( d e s t R i b b o n . s c r o l l O f f s e t )
}
2023-05-31 13:57:17 -07:00
scrollId . wrappedValue = destRibbon . scrollId
2023-05-31 16:42:11 -07:00
// p r i n t ( " s e t t i n g s c r o l l o f f s e t " )
2023-05-31 13:57:17 -07:00
scrollOffset . wrappedValue = CGFloat ( destRibbon . scrollOffset )
2023-05-31 16:42:11 -07:00
// p r i n t ( s c r o l l O f f s e t . w r a p p e d V a l u e )
// p r i n t ( " e n d s e t t i n g s c r o l l o f f s e t " )
2023-05-31 13:57:17 -07:00
refresh . wrappedValue . toggle ( )
var updateSelectRibbon = SelectedRibbon ( id : Int64 ( 1 ) , ribbonId : destRibbon . id ! )
2023-05-31 16:42:11 -07:00
// p r i n t ( " S a v i n g s e l e c t e d r i b b o n " )
// p r i n t ( u p d a t e S e l e c t R i b b o n )
2023-05-31 13:57:17 -07:00
do {
_ = try await appDatabase . saveSelectedRibbon ( & updateSelectRibbon )
2024-05-15 08:57:41 -07:00
} catch {
2023-05-31 13:57:17 -07:00
// P r i n t ( " s o m e t h i n g w r o n g " )
}
}
2024-05-15 08:57:41 -07:00
if ! loading {
2023-06-01 12:45:36 -07:00
print ( " not loading " )
2023-06-27 16:04:24 -07:00
updatedRibbon . scrollOffset = Int ( floor ( scrollOffsetToSave ! ) )
2023-06-01 12:45:36 -07:00
updatedRibbon . scrollId = scrollIdToSave !
2023-05-31 13:57:17 -07:00
2023-06-01 12:45:36 -07:00
_ = try await appDatabase . saveRibbon ( & updatedRibbon )
// p r i n t ( " s a v e d u p d a t e d R i b b o n " , u p d a t e d R i b b o n )
2023-05-31 13:57:17 -07:00
2023-06-01 12:45:36 -07:00
// p r i n t ( " U P D A T E D " )
// s c r o l l O f f s e t T o S a v e = u s e r D e f a u l t s . o b j e c t ( f o r K e y : " c u r r e n t O f f s e t " ) a s ? C G F l o a t
// s c r o l l I d T o S a v e = u s e r D e f a u l t s . o b j e c t ( f o r K e y : " c u r r e n t I d " ) a s ? S t r i n g
} else {
print ( " loading " )
}
2023-05-31 13:57:17 -07:00
2023-05-31 16:42:11 -07:00
// p r i n t ( " s c r o l l O f f s e t T o S a v e : " , s c r o l l O f f s e t T o S a v e )
// p r i n t ( " s c r o l l I d T o S a v e : " , s c r o l l I d T o S a v e )
2023-05-31 13:57:17 -07:00
}
}
2023-11-14 13:39:46 -08:00
2023-08-03 12:40:12 -07:00
extension View {
@ ViewBuilder
func ` if ` < Transform : View > ( _ condition : Bool , transform : ( Self ) -> Transform ) -> some View {
if condition { transform ( self ) }
else { self }
}
}
2023-05-31 13:57:17 -07:00
2024-05-15 08:57:41 -07:00
struct RibbonCrown : View {
2023-03-01 10:47:34 -08:00
var ribbon : Ribbon
2024-05-15 08:57:41 -07:00
@ Binding var scrollId : String ?
@ Binding var scrollOffset : CGFloat ?
@ Binding var showOverlay : Bool
@ Binding var refresh : Bool
var draggedRibbon : Ribbon ?
var isDragging : Bool
2023-02-28 14:03:58 -08:00
2023-08-02 16:26:17 -07:00
var height = CGFloat ( 45 )
2023-07-21 17:19:30 -07:00
var xOffset = CGFloat ( 25 )
var scale = 0.65
2023-02-28 14:03:58 -08:00
@ Environment ( \ . appDatabase ) private var appDatabase
2023-02-27 14:27:15 -08:00
2023-03-01 10:47:34 -08:00
@ Query ( SelectedRibbonRequest ( ) ) private var sr : [ Ribbon ]
2023-02-28 14:03:58 -08:00
@ State var saveOffset = CGFloat ( )
2023-02-27 14:27:15 -08:00
var body : some View {
2023-08-02 16:26:17 -07:00
ZStack {
2023-11-14 13:39:46 -08:00
MyIcon ( ) . frame (
width : CGFloat ( 100 * 1.66 * scale ) ,
height : CGFloat ( 100 * scale ) ,
alignment : . center
2024-05-15 08:57:41 -07:00
) . foregroundColor ( Color ( UIColor ( red : 0.30 , green : 0.30 , blue : 0.30 , alpha : 0.4 ) ) )
2023-11-14 13:39:46 -08:00
. if ( draggedRibbon != nil && draggedRibbon ! . id = = ribbon . id && isDragging ) { $0 . overlay ( Color ( red : 0.1 , green : 0.1 , blue : 0.1 ) ) }
2023-08-02 16:26:17 -07:00
2024-05-15 08:57:41 -07:00
// . o f f s e t ( x : 1 0 )
2023-08-03 12:40:12 -07:00
2023-11-14 13:39:46 -08:00
Text ( ribbon . title )
. foregroundColor ( Color ( UIColor ( red : 0.76 , green : 0.76 , blue : 0.76 , alpha : 1.00 ) ) )
// . f o r e g r o u n d C o l o r ( . w h i t e ) )
// . f o r e g r o u n d C o l o r ( . b l a c k )
. frame ( minWidth : CGFloat ( 70 ) ,
2024-05-15 08:57:41 -07:00
maxWidth : CGFloat ( 70 ) ,
minHeight : height ,
maxHeight : height ,
alignment : . center )
2023-08-03 12:40:12 -07:00
2023-11-14 13:39:46 -08:00
. if ( draggedRibbon != nil && draggedRibbon ! . id = = ribbon . id && isDragging ) { $0 . overlay ( Color ( red : 0.1 , green : 0.1 , blue : 0.1 ) ) }
2023-08-03 12:40:12 -07:00
2023-11-14 13:39:46 -08:00
// . i f ( ! i s D r a g g i n g | | d r a g g e d R i b b o n = = n i l | | d r a g g e d R i b b o n ! . i d ! = r i b b o n . i d ) { $ 0 . b a c k g r o u n d ( C o l o r ( r e d : 0 . 1 , g r e e n : 0 . 1 , b l u e : 0 . 1 ) ) }
// . i f ( d r a g g e d R i b b o n ! = n i l & & d r a g g e d R i b b o n ! . i d = = r i b b o n . i d ) { $ 0 . b a c k g r o u n d ( . r e d ) }
. background ( Color ( red : 0.1 , green : 0.1 , blue : 0.1 ) )
// . o f f s e t ( x : 1 0 )
// . b a c k g r o u n d ( C o l o r ( r e d : 0 . 1 , g r e e n : 0 . 1 , b l u e : 0 . 1 ) )
// . b a c k g r o u n d ( . r e d )
// . b a c k g r o u n d ( . y e l l o w )
. multilineTextAlignment ( . center )
// . m i n i m u m S c a l e F a c t o r ( 0 . 5 )
// . p a d d i n g ( [ . t o p , . b o t t o m ] , 1 0 )
. font ( Font . custom ( " AveriaSerifLibre-Regular " , size : CGFloat ( 10 ) ) )
2023-08-02 16:26:17 -07:00
}
2024-05-15 08:57:41 -07:00
. frame ( width : CGFloat ( 100 * 1.66 * scale + 10 ) , height : CGFloat ( 100 * scale + 5 ) )
2023-03-01 10:47:34 -08:00
}
}
2023-02-28 14:03:58 -08:00
2023-03-11 20:31:48 -08:00
class Verse : NSObject , Codable {
var body : String
var verse : Int
}
func makeVerseView ( seg : SegDenorm ) -> some View {
var retView = Text ( " " )
var segSplit = seg . body . components ( separatedBy : " ;; " )
let decoder = JSONDecoder ( )
2024-05-15 08:57:41 -07:00
for ( index , item ) in segSplit . enumerated ( ) {
2023-03-11 20:31:48 -08:00
let verse = try ! decoder . decode ( Verse . self , from : item . data ( using : . utf8 ) ! )
retView = retView + Text ( String ( verse . verse ) )
2024-05-15 08:57:41 -07:00
. font ( Font . custom ( " AveriaSerifLibre-Regular " , size : 6 ) )
. baselineOffset ( 6.0 )
. foregroundColor ( Color . white )
2023-03-11 20:31:48 -08:00
retView = retView + Text ( verse . body )
2024-05-15 08:57:41 -07:00
. foregroundColor ( Color . white )
. font ( Font . custom ( " AveriaSerifLibre-Regular " , size : 15 ) )
}
2023-03-11 20:31:48 -08:00
return retView
}
2023-03-01 10:47:34 -08:00
2023-03-11 20:31:48 -08:00
private struct SegRow : View {
var seg : SegDenorm
2023-06-01 12:45:36 -07:00
var ribbonId : Int64
2023-03-01 10:47:34 -08:00
2023-03-11 20:31:48 -08:00
var body : some View {
var retView = Text ( " " )
2024-05-15 08:57:41 -07:00
// . o n T a p G e s t u r e {
// / / s e l e c t e d L i n e = s e g . i d
// / / P r i n t ( s e l e c t e d L i n e )
// P r i n t ( " m e o w " )
// / / P r i n t ( v e r s e . b o d y )
// }
2023-03-11 20:31:48 -08:00
var segSplit = seg . body . components ( separatedBy : " ;; " )
let decoder = JSONDecoder ( )
// T e x t ( s e g S p l i t [ 0 ] . b o d y )
// . i d ( s e g . i d )
// V S t a c k {
2024-05-15 08:57:41 -07:00
// F o r E a c h ( s e g S p l i t . i n d i c e s ) { i i n
segSplit . enumerated ( ) . forEach { _ , item in
let verse = try ! decoder . decode ( Verse . self , from : item . data ( using : . utf8 ) ! )
var attributedString : AttributedString {
// v a r r e s u l t = A t t r i b u t e d S t r i n g ( " H e l l o W o r l d ! " )
var result = AttributedString ( verse . body )
// r e s u l t . u n d e r l i n e S t y l e = T e x t . L i n e S t y l e (
// p a t t e r n : . d o t , c o l o r : . w h i t e )
return result
}
2023-05-31 13:57:17 -07:00
2024-05-15 08:57:41 -07:00
retView = retView + Text ( String ( ribbonId ) )
// r e t V i e w = r e t V i e w + T e x t ( a t t r i b u t e d S t r i n g )
2023-03-11 20:31:48 -08:00
// T e x t ( s e g . b o d y )
// . c o n t e n t S h a p e ( R e c t a n g l e ( ) )
2023-04-23 20:41:17 -07:00
. font ( Font . custom ( " AveriaSerifLibre-Regular " , size : 10 ) )
2023-03-11 20:31:48 -08:00
. baselineOffset ( 6.0 )
2023-05-31 13:57:17 -07:00
. foregroundColor ( Color ( UIColor ( red : 0.76 , green : 0.76 , blue : 0.76 , alpha : 1.00 ) ) )
2023-03-11 20:31:48 -08:00
2024-05-15 08:57:41 -07:00
retView = retView +
Text ( attributedString )
2023-05-31 13:57:17 -07:00
. foregroundColor ( Color ( UIColor ( red : 0.76 , green : 0.76 , blue : 0.76 , alpha : 1.00 ) ) )
2023-04-23 20:41:17 -07:00
. font ( Font . custom ( " AveriaSerifLibre-Regular " , size : 20 ) )
2024-05-15 08:57:41 -07:00
// . f r a m e ( m a x W i d t h : . i n f i n i t y , a l i g n m e n t : . l e a d i n g )
// . c o n t e n t S h a p e ( R e c t a n g l e ( ) )
2023-03-01 10:47:34 -08:00
2024-05-15 08:57:41 -07:00
// . l i s t R o w B a c k g r o u n d ( C o l o r ( r e d : 0 . 2 , g r e e n : 0 . 8 , b l u e : 0 . 2 ) )
// . l i s t R o w I n s e t s ( E d g e I n s e t s ( ) )
// . p a d d i n g ( E d g e I n s e t s ( t o p : 1 0 , l e a d i n g : 2 0 , b o t t o m : 4 0 , t r a i l i n g : 2 0 ) )
// . l i s t R o w S e p a r a t o r ( . h i d d e n )
// . i d ( S t r i n g ( s e g . i d ) + " b o d y " + S t r i n g ( i ) )
// . i d ( s e g . i d )
// . l i s t R o w B a c k g r o u n d ( C o l o r ( r e d : 0 . 2 , g r e e n : 0 . 8 , b l u e : 0 . 2 ) )
// . l i s t R o w I n s e t s ( E d g e I n s e t s ( ) )
// . p a d d i n g ( E d g e I n s e t s ( t o p : 1 0 , l e a d i n g : 2 0 , b o t t o m : 4 0 , t r a i l i n g : 2 0 ) )
// . l i s t R o w S e p a r a t o r ( . h i d d e n )
// . i d ( S t r i n g ( s e g . i d ) + " v e r s e " + S t r i n g ( i ) )
// . i d ( s e g . i d )
// . o n T a p G e s t u r e {
// s e l e c t e d L i n e = s e g . i d
// P r i n t ( s e l e c t e d L i n e )
// }
}
// }
2023-02-27 14:27:15 -08:00
2024-05-15 08:57:41 -07:00
let myText = " There was a man sent from God, whose name was John. This man came for a witness, to give testimony of the light, that all men might believe through him. He was not the light, but was to give testimony of the light. That was the true light, which enlighteneth every man that cometh into this world. He was in the world, and the world was made by him, and the world knew him not. "
let arrayOfText = myText . components ( separatedBy : " " )
var wordSelected = " "
var newView = WrappingHStack ( alignment : . leading , horizontalSpacing : 3.5 ) {
ForEach ( 0. . < arrayOfText . count , id : \ . self ) { index in
Text ( arrayOfText [ index ] )
. foregroundColor ( Color ( UIColor ( red : 0.76 , green : 0.76 , blue : 0.76 , alpha : 1.00 ) ) )
. font ( Font . custom ( " AveriaSerifLibre-Regular " , size : 20 ) )
. foregroundColor ( Color . white )
// . b a c k g r o u n d ( C o l o r . b l a c k )
. padding ( . horizontal , 0 )
. onTapGesture {
Print ( arrayOfText [ index ] )
Print ( index )
}
}
}
// r e t u r n r e t V i e w
return newView } }
struct ContentView : View {
2023-02-27 14:27:15 -08:00
@ State var viewState = CGSize . zero
@ State var pulledOut = CGSize . zero
2024-05-15 08:57:41 -07:00
@ State var taskTitle : String = " FIRST DOGGG "
@ State var curBook : String = " Matthew "
@ State var selectedLine : Int64 ?
2023-02-28 14:03:58 -08:00
2024-05-15 08:57:41 -07:00
@ State var thisScrollView : UIScrollView ?
2023-03-11 20:31:48 -08:00
@ State var scrollUpdate = false
2023-03-01 10:47:34 -08:00
@ State var initLoad = false
2023-04-21 17:06:30 -07:00
// s e t t h i s t o s c r o l l t o a r e a
2024-05-15 08:57:41 -07:00
@ State var scrollId : String ?
@ State var scrollOffset : CGFloat ?
2023-04-21 17:06:30 -07:00
2024-05-15 08:57:41 -07:00
@ State var setScrollOffset : CGFloat ?
@ State var showOverlay : Bool = false
2023-04-22 01:01:09 -07:00
2023-07-21 17:19:30 -07:00
@ State var vertSep = CGFloat ( 20 )
2023-06-01 12:45:36 -07:00
@ Environment ( \ . appDatabase ) private var appDatabase
2023-03-11 20:31:48 -08:00
@ Query ( SegDenormRequest ( book : " bible.mark " ) ) private var segs : [ SegDenorm ]
2023-04-21 17:06:30 -07:00
// @ S t a t e v a r s c r o l l D e l e g a t e : S c r o l l V i e w H a n d l e r
2023-03-11 20:31:48 -08:00
// @ S t a t e v a r s c r o l l D e l e g a t e = S c r o l l V i e w H a n d l e r ( )
2023-03-01 10:47:34 -08:00
2023-02-28 14:03:58 -08:00
// @ S t a t e v a r s e l e c t e d R i b b o n I d = I n t 6 4 ( U s e r D e f a u l t s . s t a n d a r d . o p t i o n a l I n t ( f o r K e y : " s e l e c t e d R i b b o n I d " ) ? ? 1 )
2023-03-01 10:47:34 -08:00
// r i b b o n
2023-06-01 12:45:36 -07:00
// @ Q u e r y ( S e l e c t e d R i b b o n R e q u e s t ( ) ) p r i v a t e v a r s e l e c t e d R i b b o n : [ R i b b o n ]
2023-02-28 14:03:58 -08:00
@ State var endedDrag = true
@ State var readOffset = CGPoint ( )
2023-07-21 17:19:30 -07:00
@ State var dragOffset = CGFloat ( )
2023-11-14 13:39:46 -08:00
2023-03-11 20:31:48 -08:00
@ State var refresh : Bool = false
2023-06-01 12:45:36 -07:00
2023-04-22 01:01:09 -07:00
@ State var refresh2 : Bool = false
2023-11-14 13:39:46 -08:00
2023-08-02 16:26:17 -07:00
@ State var draggedRibbon : Ribbon ?
2023-08-03 12:40:12 -07:00
@ State var isDragging = false
2023-11-14 13:39:46 -08:00
2023-08-02 16:26:17 -07:00
@ State var reorder = true
2023-02-27 14:27:15 -08:00
@ Query ( RibbonRequest ( ) ) private var ribbons : [ Ribbon ]
2023-06-01 12:45:36 -07:00
@ Query < SelectedRibbonRequest > var selectedRibbon : [ Ribbon ]
2023-02-27 14:27:15 -08:00
2023-02-28 14:03:58 -08:00
// @ Q u e r y ( R i b b o n R e q u e s t ( i d : I n t 6 4 ( U s e r D e f a u l t s . s t a n d a r d . o p t i o n a l I n t ( f o r K e y : " l a s t R i b b o n I d " ) ? ? 1 ) ) ) p r i v a t e v a r s e l e c t e d R i b b o n : [ R i b b o n ]
2023-11-14 13:39:46 -08:00
2023-02-27 14:27:15 -08:00
init ( ) {
UITableView . appearance ( ) . backgroundColor = UIColor ( Color ( red : 0.2 , green : 0.2 , blue : 0.2 ) )
2024-05-15 08:57:41 -07:00
_selectedRibbon = Query ( SelectedRibbonRequest ( ) )
2023-06-01 12:45:36 -07:00
2023-04-21 17:06:30 -07:00
// s e l f . _ s c r o l l D e l e g a t e = S t a t e ( i n i t i a l V a l u e : S c r o l l V i e w H a n d l e r ( ) )
2023-02-27 14:27:15 -08:00
}
2023-11-14 13:39:46 -08:00
2023-02-27 14:27:15 -08:00
var body : some View {
2023-04-24 07:08:02 -07:00
// P r i n t ( " r e n d e r i n g " )
2023-03-11 20:31:48 -08:00
2023-06-30 16:47:39 -07:00
var size1 = CGFloat ( 11 )
var size2 = CGFloat ( 100 )
var fontSize = CGFloat ( 15 )
var scale = 0.65
var height = CGFloat ( 50 )
var xOffset = CGFloat ( 25 )
2023-07-21 17:19:30 -07:00
2023-07-31 10:54:42 -07:00
var width = CGFloat ( 100 * 1.66 * scale )
2023-08-02 16:26:17 -07:00
// F o r E a c h ( r i b b o n s ) { r i b b o n i n
// d a t a . a p p e n d ( r i b b o n )
// }
2023-07-31 10:54:42 -07:00
2023-02-27 14:27:15 -08:00
GeometryReader { geometry in
2024-05-15 08:57:41 -07:00
ZStack ( alignment : . top ) {
VStack ( alignment : . leading ) {
2023-07-21 17:19:30 -07:00
VStack {
2023-08-02 16:26:17 -07:00
// R e o r d e r a b l e F o r E a c h ( $ d a t a , a l l o w R e o r d e r i n g : $ r e o r d e r ) { i t e m , i s D r a g g e d i n
ForEach ( ribbons ) { ribbon in
RibbonCrown ( ribbon : ribbon ,
2024-05-15 08:57:41 -07:00
scrollId : $ scrollId ,
scrollOffset : $ scrollOffset ,
2023-08-02 16:26:17 -07:00
showOverlay : $ showOverlay ,
2024-05-15 08:57:41 -07:00
refresh : $ refresh ,
2023-08-03 12:40:12 -07:00
draggedRibbon : draggedRibbon ,
2024-05-15 08:57:41 -07:00
isDragging : isDragging )
. onDrag {
self . draggedRibbon = ribbon
return NSItemProvider ( )
}
. onDrop ( of : [ . item ] ,
delegate : DropViewDelegate ( destinationItem : ribbon ,
draggedItem : $ draggedRibbon ,
isDragging : $ isDragging ,
appDatabase : appDatabase ) )
. offset ( x : 6 , y : 6 )
2023-07-31 10:54:42 -07:00
}
2023-07-21 17:19:30 -07:00
2023-07-31 10:54:42 -07:00
// . f o r e g r o u n d C o l o r ( C o l o r ( U I C o l o r ( r e d : 0 . 7 6 , g r e e n : 0 . 7 6 , b l u e : 0 . 7 6 , a l p h a : 1 . 0 0 ) ) )
2023-07-21 17:19:30 -07:00
}
. frame ( width : geometry . size . width , height : geometry . size . height - 100 , alignment : . topLeading )
. background ( Color ( red : 0.1 , green : 0.1 , blue : 0.1 ) )
. zIndex ( 0 )
2023-08-02 16:26:17 -07:00
. animation ( . default , value : ribbons )
2023-08-03 15:22:18 -07:00
. onDrop ( of : [ . item ] ,
2024-05-15 08:57:41 -07:00
delegate : DropViewDelegate2 ( isDragging : $ isDragging ) )
2023-08-03 15:22:18 -07:00
2023-07-21 17:19:30 -07:00
// S p a c e r ( )
2023-03-11 20:31:48 -08:00
2023-08-02 16:26:17 -07:00
// F o r E a c h ( r i b b o n s ) { r i b b o n i n
// R i b b o n C r o w n ( r i b b o n : r i b b o n ,
// s c r o l l I d : $ s c r o l l I d ,
// s c r o l l O f f s e t : $ s c r o l l O f f s e t ,
// s h o w O v e r l a y : $ s h o w O v e r l a y ,
// r e f r e s h : $ r e f r e s h
// )
// / / . b u t t o n S t y l e ( B l u e B u t t o n S t y l e ( ) )
// / / . f r a m e ( a l i g n m e n t : . t o p L e a d i n g )
// / / . b a c k g r o u n d ( C o l o r ( r e d : 0 . 4 , g r e e n : 0 . 4 , b l u e : 0 . 1 ) )
// . a n i m a t i o n ( n i l )
// }
2023-02-27 14:27:15 -08:00
}
2023-03-11 20:31:48 -08:00
. background ( Color ( red : 0.1 , green : 0.1 , blue : 0.1 ) )
2023-07-21 17:19:30 -07:00
. frame ( alignment : . topLeading )
2024-05-15 08:57:41 -07:00
// . a n i m a t i o n ( n i l )
2023-07-21 17:19:30 -07:00
VStack {
ScrollViewReader { proxy in
VisibilityTrackingScrollView ( action : handleVisibilityChanged ) {
// S c r o l l V i e w {
LazyVStack {
ForEach ( segs ) { seg in
SegRow ( seg : seg ,
2024-05-15 08:57:41 -07:00
ribbonId : selectedRibbon [ 0 ] . id ! )
. id ( " \( seg . id ) " )
. offset ( x : - dragOffset )
// . o f f s e t ( x : p u l l e d O u t . w i d t h )
2023-07-21 17:19:30 -07:00
2024-05-15 08:57:41 -07:00
. padding ( EdgeInsets ( top : 10 , leading : 20 , bottom : 40 , trailing : 20 ) )
. trackVisibility ( id : " \( seg . id ) " )
2023-07-21 17:19:30 -07:00
// . o n C h a n g e ( o f : g e o m e t r y . f r a m e ( i n : . n a m e d ( " s c r o l l V i e w " ) ) ) { i m a g e R e c t i n
2024-05-15 08:57:41 -07:00
// P r i n t ( i m a g e R e c t )
// P r i n t ( o u t e r P r o x y )
2023-07-21 17:19:30 -07:00
// i f i s I n V i e w ( i n n e r R e c t : i m a g e R e c t , i s I n : o u t e r P r o x y ) {
// v i s i b l e I n d e x . i n s e r t ( i t e m )
2024-05-15 08:57:41 -07:00
// } e l s e {
2023-07-21 17:19:30 -07:00
// v i s i b l e I n d e x . r e m o v e ( i t e m )
// }
// }
}
2023-06-27 16:04:24 -07:00
}
2023-07-21 17:19:30 -07:00
. background ( Color ( red : 0.18 , green : 0.18 , blue : 0.18 ) )
2023-02-27 14:27:15 -08:00
}
2023-06-01 12:45:36 -07:00
2024-05-15 08:57:41 -07:00
. onAppear {
2023-07-21 17:19:30 -07:00
Print ( " APPEAR " )
// P r i n t ( s e l e c t e d R i b b o n [ 0 ] )
// s c r o l l I d = " 3 "
// s c r o l l O f f s e t = 1 0 3
// r e f r e s h . t o g g l e ( )
goToRibbon ( selectedRibbon : selectedRibbon [ 0 ] ,
destRibbon : selectedRibbon [ 0 ] ,
scrollId : $ scrollId ,
scrollOffset : $ scrollOffset ,
refresh : $ refresh ,
showOverlay : $ showOverlay ,
appDatabase : appDatabase ,
loading : true )
}
2024-05-15 08:57:41 -07:00
. onChange ( of : refresh ) { _ in
// i f l e t t a r g e t = t a r g e t {
// g T r a c k e r ! . v i s i b l e V i e w s [ " 1 2 3 1 2 3 " ] = C G F l o a t ( 1 0 0 )
2023-07-21 17:19:30 -07:00
// P r i n t ( " O N C H A N G E " , g T r a c k e r ! . v i s i b l e V i e w s )
// P r i n t ( " r e m o v i n g " , g T r a c k e r ! . v i s i b l e V i e w s . r e m o v e A l l ( ) )
2023-06-01 12:45:36 -07:00
2023-07-21 17:19:30 -07:00
Task {
DispatchQueue . main . async {
Print ( " scroll Id target: \( scrollId ) " )
2024-05-15 08:57:41 -07:00
proxy . scrollTo ( scrollId ! , anchor : . top )
2023-07-21 17:19:30 -07:00
// p r o x y . s c r o l l T o ( S t r i n g ( I n t ( s c r o l l I d ! ) ! + 1 ) )
// c u r r e n t I d = s c r o l l I d !
// i f ( c u r r e n t I d ! = s c r o l l I d ! ) {
2023-06-02 14:25:20 -07:00
2023-07-21 17:19:30 -07:00
DispatchQueue . main . asyncAfter ( deadline : . now ( ) + 0.5 ) {
Print ( " scroll id target " , scrollId )
Print ( " current id " , currentId )
Print ( gTracker ! . sortedViewIDs )
2024-05-15 08:57:41 -07:00
if currentId ! != scrollId ! {
2023-07-21 17:19:30 -07:00
Print ( " NO MATCH " )
}
2023-06-02 14:25:20 -07:00
2023-07-21 17:19:30 -07:00
// P r i n t ( " s c r o l l o f f s e t t a r g e t " , s c r o l l O f f s e t )
Print ( " current offset " , gTracker ! . visibleViews [ scrollId ! ] )
var curOffset = gTracker ! . visibleViews [ scrollId ! ]
Print ( " stats " , gTracker ! . visibleViews )
// / / s e t S c r o l l O f f s e t = C G F l o a t ( I n t ( c u r r e n t O f f s e t ! ) * - 1 + I n t ( s c r o l l O f f s e t ! ) )
2024-05-15 08:57:41 -07:00
if curOffset != nil {
2023-07-21 17:19:30 -07:00
setScrollOffset = CGFloat ( Int ( scrollOffset ! ) - Int ( curOffset ! ) )
Print ( " applying scroll offset \( setScrollOffset ) " )
// / / s e t S c r o l l O f f s e t = C G F l o a t ( I n t ( s c r o l l O f f s e t ! ) )
// P r i n t ( " s e t t i n g s c r o l l o f f s e t " , s e t S c r o l l O f f s e t )
refresh2 . toggle ( )
} else {
var adjust = ( Int ( scrollId ! ) ! - Int ( currentId ! ) ! ) * 200
Print ( " adjusting \( adjust ) " )
2023-06-02 14:25:20 -07:00
2023-07-21 17:19:30 -07:00
setScrollOffset = CGFloat ( adjust )
refresh . toggle ( )
}
// / / c u r r e n t I d = s c r o l l I d !
2023-06-02 14:25:20 -07:00
2023-07-21 17:19:30 -07:00
// D i s p a t c h Q u e u e . m a i n . a s y n c {
2023-06-02 14:25:20 -07:00
2023-07-21 17:19:30 -07:00
// c u r r e n t O f f s e t = s c r o l l O f f s e t !
// c u r r e n t I d = s c r o l l I d !
// }
}
2023-06-27 16:04:24 -07:00
}
2023-06-02 14:25:20 -07:00
}
2023-04-21 17:06:30 -07:00
}
2024-05-15 08:57:41 -07:00
. introspect ( . scrollView , on : . iOS ( . v13 , . v14 , . v15 , . v16 , . v17 ) ) { scrollView in Print ( " introspect " )
// P r i n t ( " S c r o l l d e l e g a t e o f f s e t " , s c r o l l D e l e g a t e . s c r o l l O f f s e t )
2023-07-21 17:19:30 -07:00
2024-05-15 08:57:41 -07:00
if setScrollOffset != nil {
2023-07-21 17:19:30 -07:00
// P r i n t ( " S e t t i n g s c r o l l o f f s e t i n i n t r o s p e c t " , s e t S c r o l l O f f s e t )
2023-11-14 13:39:46 -08:00
DispatchQueue . main . async {
2023-07-21 17:19:30 -07:00
scrollView . contentOffset . y = scrollView . contentOffset . y + setScrollOffset !
setScrollOffset = nil
2024-05-15 08:57:41 -07:00
// s e l f . s h o w O v e r l a y = f a l s e
2023-07-21 17:19:30 -07:00
withAnimation {
showOverlay = false
}
}
}
// i f ( t h i s S c r o l l V i e w = = n i l ) {
// P r i n t ( " i n i t s c r o l l " )
// t h i s S c r o l l V i e w = s c r o l l V i e w
// s c r o l l V i e w . c o n t e n t O f f s e t . y = C G F l o a t ( s e l e c t e d R i b b o n [ 0 ] . s c r o l l O f f s e t )
// }
Print ( " end introspect " )
}
. listStyle ( PlainListStyle ( ) )
2023-06-02 14:25:20 -07:00
}
2023-07-21 17:19:30 -07:00
. zIndex ( 1 )
. background ( Color ( red : 0.2 , green : 0.2 , blue : 0.2 ) )
2023-11-14 13:39:46 -08:00
. frame ( width : geometry . size . width - 50 , height : geometry . size . height / 2 - vertSep )
2024-05-15 08:57:41 -07:00
. offset ( x : 30 , y : 0 )
2023-07-21 17:19:30 -07:00
. offset ( x : pulledOut . width )
. offset ( x : viewState . width , y : viewState . height )
. gesture (
DragGesture ( )
2024-05-15 08:57:41 -07:00
. onChanged { gesture in
2023-07-21 17:19:30 -07:00
2024-05-15 08:57:41 -07:00
if endedDrag {
endedDrag = false
scrollOffset = readOffset . y - 20
// _ = P r i n t ( " m e o w " )
2023-06-27 16:04:24 -07:00
}
2024-05-15 08:57:41 -07:00
// l o g g e r . e r r o r ( " h e l l o 2 2 2 " )
// N S L o g ( " h e l l o o o " )
Print ( viewState . width )
if abs ( gesture . translation . width ) > 20 {
viewState . width = gesture . translation . width
if gesture . translation . width < - 50 , pulledOut . width = = CGFloat ( 0 ) {
dragOffset = gesture . translation . width + 50
}
}
// o f f s e t . y = g e s t u r e . t r a n s l a t i o n . w i d t h
// l o g g e r . l o g ( " h e l l o " )
2023-06-27 16:04:24 -07:00
}
2024-05-15 08:57:41 -07:00
. onEnded { _ in
endedDrag = true
var pulledOutWidth = CGFloat ( 0 )
if viewState . width < 0 {
pulledOutWidth = CGFloat ( 0 )
} else if abs ( viewState . width + pulledOut . width ) > 30 {
pulledOutWidth = CGFloat ( 200 )
}
2023-06-02 14:25:20 -07:00
2024-05-15 08:57:41 -07:00
withAnimation ( . spring ( response : 0.2 ) ) {
pulledOut . width = pulledOutWidth
viewState = . zero
dragOffset = . zero
}
2023-07-21 17:19:30 -07:00
}
)
2024-05-15 08:57:41 -07:00
Text ( " separator " ) . foregroundColor ( Color ( UIColor ( red : 0.76 , green : 0.76 , blue : 0.76 , alpha : 1.00 ) ) )
. gesture (
DragGesture ( )
. onChanged { gesture in
2023-07-21 17:19:30 -07:00
2024-05-15 08:57:41 -07:00
vertSep = vertSep - gesture . translation . height
Print ( gesture . translation . width )
Print ( gesture . translation . height )
Print ( " drag " )
// i f ( e n d e d D r a g ) {
// e n d e d D r a g = f a l s e
// s c r o l l O f f s e t = r e a d O f f s e t . y - 2 0
// / / _ = P r i n t ( " m e o w " )
// }
// / / l o g g e r . e r r o r ( " h e l l o 2 2 2 " )
// / / N S L o g ( " h e l l o o o " )
// P r i n t ( v i e w S t a t e . w i d t h )
// i f ( a b s ( g e s t u r e . t r a n s l a t i o n . w i d t h ) > 2 0 ) {
// v i e w S t a t e . w i d t h = g e s t u r e . t r a n s l a t i o n . w i d t h
// }
// / / o f f s e t . y = g e s t u r e . t r a n s l a t i o n . w i d t h
// / / l o g g e r . l o g ( " h e l l o " )
}
// . o n E n d e d { _ i n
// e n d e d D r a g = t r u e
// v a r p u l l e d O u t W i d t h = C G F l o a t ( 0 )
// i f ( v i e w S t a t e . w i d t h < 0 ) {
// p u l l e d O u t W i d t h = C G F l o a t ( 0 )
// }
// e l s e i f a b s ( v i e w S t a t e . w i d t h + p u l l e d O u t . w i d t h ) > 3 0 {
// p u l l e d O u t W i d t h = C G F l o a t ( 2 0 0 )
// }
// w i t h A n i m a t i o n ( . s p r i n g ( r e s p o n s e : 0 . 2 ) ) {
// p u l l e d O u t . w i d t h = p u l l e d O u t W i d t h
// v i e w S t a t e = . z e r o
// }
// }
)
ScrollViewReader { _ in
2023-07-21 17:19:30 -07:00
VisibilityTrackingScrollView ( action : handleVisibilityChanged2 ) {
// S c r o l l V i e w {
LazyVStack {
ForEach ( segs ) { seg in
SegRow ( seg : seg ,
2024-05-15 08:57:41 -07:00
ribbonId : selectedRibbon [ 0 ] . id ! )
. id ( " \( seg . id ) " )
. padding ( EdgeInsets ( top : 10 , leading : 20 , bottom : 40 , trailing : 20 ) )
. trackVisibility ( id : " \( seg . id ) " )
2023-07-21 17:19:30 -07:00
// . o n C h a n g e ( o f : g e o m e t r y . f r a m e ( i n : . n a m e d ( " s c r o l l V i e w " ) ) ) { i m a g e R e c t i n
2024-05-15 08:57:41 -07:00
// P r i n t ( i m a g e R e c t )
// P r i n t ( o u t e r P r o x y )
2023-07-21 17:19:30 -07:00
// i f i s I n V i e w ( i n n e r R e c t : i m a g e R e c t , i s I n : o u t e r P r o x y ) {
// v i s i b l e I n d e x . i n s e r t ( i t e m )
2024-05-15 08:57:41 -07:00
// } e l s e {
2023-07-21 17:19:30 -07:00
// v i s i b l e I n d e x . r e m o v e ( i t e m )
// }
// }
}
}
. background ( Color ( red : 0.18 , green : 0.18 , blue : 0.18 ) )
}
2023-06-27 16:04:24 -07:00
2024-05-15 08:57:41 -07:00
. onAppear {
2023-07-21 17:19:30 -07:00
Print ( " APPEAR " )
// P r i n t ( s e l e c t e d R i b b o n [ 0 ] )
// s c r o l l I d = " 3 "
// s c r o l l O f f s e t = 1 0 3
// r e f r e s h . t o g g l e ( )
// g o T o R i b b o n ( s e l e c t e d R i b b o n : s e l e c t e d R i b b o n [ 0 ] ,
// d e s t R i b b o n : s e l e c t e d R i b b o n [ 0 ] ,
// s c r o l l I d : $ s c r o l l I d ,
// s c r o l l O f f s e t : $ s c r o l l O f f s e t ,
// r e f r e s h : $ r e f r e s h ,
// s h o w O v e r l a y : $ s h o w O v e r l a y ,
// a p p D a t a b a s e : a p p D a t a b a s e ,
// l o a d i n g : t r u e )
2023-02-28 14:03:58 -08:00
}
2024-05-15 08:57:41 -07:00
// . o n C h a n g e ( o f : r e f r e s h ) { t a r g e t i n
2023-07-21 17:19:30 -07:00
// / / i f l e t t a r g e t = t a r g e t {
// / / g T r a c k e r ! . v i s i b l e V i e w s [ " 1 2 3 1 2 3 " ] = C G F l o a t ( 1 0 0 )
// / / P r i n t ( " O N C H A N G E " , g T r a c k e r ! . v i s i b l e V i e w s )
// / / P r i n t ( " r e m o v i n g " , g T r a c k e r ! . v i s i b l e V i e w s . r e m o v e A l l ( ) )
// T a s k {
// D i s p a t c h Q u e u e . m a i n . a s y n c {
// P r i n t ( " s c r o l l I d t a r g e t : \ ( s c r o l l I d ) " )
// p r o x y . s c r o l l T o ( s c r o l l I d ! , a n c h o r : . t o p )
// / / p r o x y . s c r o l l T o ( S t r i n g ( I n t ( s c r o l l I d ! ) ! + 1 ) )
// / / c u r r e n t I d = s c r o l l I d !
// / / i f ( c u r r e n t I d ! = s c r o l l I d ! ) {
// D i s p a t c h Q u e u e . m a i n . a s y n c A f t e r ( d e a d l i n e : . n o w ( ) + 0 . 5 ) {
// P r i n t ( " s c r o l l i d t a r g e t " , s c r o l l I d )
// P r i n t ( " c u r r e n t i d " , c u r r e n t I d )
// P r i n t ( g T r a c k e r ! . s o r t e d V i e w I D s )
// i f ( c u r r e n t I d ! ! = s c r o l l I d ! ) {
// P r i n t ( " N O M A T C H " )
// }
// / / P r i n t ( " s c r o l l o f f s e t t a r g e t " , s c r o l l O f f s e t )
// P r i n t ( " c u r r e n t o f f s e t " , g T r a c k e r ! . v i s i b l e V i e w s [ s c r o l l I d ! ] )
// v a r c u r O f f s e t = g T r a c k e r ! . v i s i b l e V i e w s [ s c r o l l I d ! ]
// P r i n t ( " s t a t s " , g T r a c k e r ! . v i s i b l e V i e w s )
// / / / / s e t S c r o l l O f f s e t = C G F l o a t ( I n t ( c u r r e n t O f f s e t ! ) * - 1 + I n t ( s c r o l l O f f s e t ! ) )
// i f ( c u r O f f s e t ! = n i l ) {
// s e t S c r o l l O f f s e t = C G F l o a t ( I n t ( s c r o l l O f f s e t ! ) - I n t ( c u r O f f s e t ! ) )
// P r i n t ( " a p p l y i n g s c r o l l o f f s e t \ ( s e t S c r o l l O f f s e t ) " )
// / / / / s e t S c r o l l O f f s e t = C G F l o a t ( I n t ( s c r o l l O f f s e t ! ) )
// / / P r i n t ( " s e t t i n g s c r o l l o f f s e t " , s e t S c r o l l O f f s e t )
// r e f r e s h 2 . t o g g l e ( )
// } e l s e {
// v a r a d j u s t = ( I n t ( s c r o l l I d ! ) ! - I n t ( c u r r e n t I d ! ) ! ) * 2 0 0
// P r i n t ( " a d j u s t i n g \ ( a d j u s t ) " )
// s e t S c r o l l O f f s e t = C G F l o a t ( a d j u s t )
// r e f r e s h . t o g g l e ( )
// }
// / / / / c u r r e n t I d = s c r o l l I d !
// / / D i s p a t c h Q u e u e . m a i n . a s y n c {
// / / c u r r e n t O f f s e t = s c r o l l O f f s e t !
// / / c u r r e n t I d = s c r o l l I d !
// / / }
// }
// }
// }
2024-05-15 08:57:41 -07:00
// }
// . i n t r o s p e c t S c r o l l V i e w { s c r o l l V i e w i n
2023-07-21 17:19:30 -07:00
// P r i n t ( " i n t r o s p e c t " )
// / / s c r o l l V i e w . d e l e g a t e = s c r o l l D e l e g a t e
// / / P r i n t ( " S c r o l l d e l e g a t e o f f s e t " , s c r o l l D e l e g a t e . s c r o l l O f f s e t )
// i f ( s e t S c r o l l O f f s e t ! = n i l ) {
// / / P r i n t ( " S e t t i n g s c r o l l o f f s e t i n i n t r o s p e c t " , s e t S c r o l l O f f s e t )
2023-11-14 13:39:46 -08:00
// D i s p a t c h Q u e u e . m a i n . a s y n c {
2023-07-21 17:19:30 -07:00
// s c r o l l V i e w . c o n t e n t O f f s e t . y = s c r o l l V i e w . c o n t e n t O f f s e t . y + s e t S c r o l l O f f s e t !
// s e t S c r o l l O f f s e t = n i l
// w i t h A n i m a t i o n {
// s h o w O v e r l a y = f a l s e
// }
// }
// }
// / / i f ( t h i s S c r o l l V i e w = = n i l ) {
// / / P r i n t ( " i n i t s c r o l l " )
// / / t h i s S c r o l l V i e w = s c r o l l V i e w
// / / s c r o l l V i e w . c o n t e n t O f f s e t . y = C G F l o a t ( s e l e c t e d R i b b o n [ 0 ] . s c r o l l O f f s e t )
// / / }
// P r i n t ( " e n d i n s t r o s p e c t " )
2024-05-15 08:57:41 -07:00
// }
2023-07-21 17:19:30 -07:00
. listStyle ( PlainListStyle ( ) )
2023-02-27 14:27:15 -08:00
}
2023-07-21 17:19:30 -07:00
. zIndex ( 1 )
. background ( Color ( red : 0.2 , green : 0.2 , blue : 0.2 ) )
. frame ( width : geometry . size . width - 50 )
2024-05-15 08:57:41 -07:00
. offset ( x : 30 , y : 0 )
2023-07-21 17:19:30 -07:00
. offset ( x : pulledOut . width )
. offset ( x : viewState . width , y : viewState . height )
. gesture (
DragGesture ( )
2024-05-15 08:57:41 -07:00
. onChanged { gesture in
2023-07-21 17:19:30 -07:00
2024-05-15 08:57:41 -07:00
if endedDrag {
endedDrag = false
scrollOffset = readOffset . y - 20
// _ = P r i n t ( " m e o w " )
}
// l o g g e r . e r r o r ( " h e l l o 2 2 2 " )
// N S L o g ( " h e l l o o o " )
Print ( viewState . width )
if abs ( gesture . translation . width ) > 20 {
viewState . width = gesture . translation . width
}
// o f f s e t . y = g e s t u r e . t r a n s l a t i o n . w i d t h
// l o g g e r . l o g ( " h e l l o " )
2023-07-21 17:19:30 -07:00
}
2024-05-15 08:57:41 -07:00
. onEnded { _ in
endedDrag = true
var pulledOutWidth = CGFloat ( 0 )
if viewState . width < 0 {
pulledOutWidth = CGFloat ( 0 )
} else if abs ( viewState . width + pulledOut . width ) > 30 {
pulledOutWidth = CGFloat ( 200 )
}
2023-02-27 14:27:15 -08:00
2024-05-15 08:57:41 -07:00
withAnimation ( . spring ( response : 0.2 ) ) {
pulledOut . width = pulledOutWidth
viewState = . zero
}
2023-07-21 17:19:30 -07:00
}
)
}
2023-06-27 16:04:24 -07:00
2024-05-15 08:57:41 -07:00
if showOverlay {
2023-06-27 16:04:24 -07:00
Rectangle ( )
2023-11-14 13:39:46 -08:00
. frame ( width : geometry . size . width - 50 , height : geometry . size . height + 200 )
. background ( . ultraThinMaterial )
2023-06-27 16:04:24 -07:00
2024-05-15 08:57:41 -07:00
// . b l u r ( r a d i u s : 0 . 8 )
. offset ( x : 30 , y : - 100 )
2023-11-14 13:39:46 -08:00
. opacity ( 0.98 )
. transition ( . opacity )
2023-06-27 16:04:24 -07:00
2023-11-14 13:39:46 -08:00
// . f r a m e ( w i d t h : g e o m e t r y . s i z e . w i d t h - 5 0 )
. offset ( x : pulledOut . width )
. offset ( x : viewState . width , y : viewState . height )
. zIndex ( 2 )
2023-06-27 16:04:24 -07:00
}
2023-02-27 14:27:15 -08:00
}
}
}
2024-05-15 08:57:41 -07:00
func handleVisibilityChanged2 ( _ : String , change _ : VisibilityChange , tracker _ : VisibilityTracker < String > ) { }
2023-08-02 16:26:17 -07:00
2024-05-15 08:57:41 -07:00
func handleVisibilityChanged ( _ : String , change _ : VisibilityChange , tracker : VisibilityTracker < String > ) {
2023-06-02 14:25:20 -07:00
// v a r p r i n t R a t e : I n t 6 4 = 1 0
2023-06-01 12:45:36 -07:00
gTracker = tracker
2023-04-21 17:06:30 -07:00
// @ E n v i r o n m e n t ( \ . a p p D a t a b a s e ) v a r a p p D a t a b a s e
2023-05-31 16:42:11 -07:00
// s w i t c h c h a n g e {
// c a s e . s h o w n : p r i n t ( " \ ( i d ) s h o w n " )
// c a s e . h i d d e n : p r i n t ( " \ ( i d ) h i d d e n " )
// }
2023-06-02 14:25:20 -07:00
// i f ( p r i n t C o u n t % p r i n t R a t e = = 0 ) {
// p r i n t ( " V I S I B I L I T Y C H A N G E D S T A R T E D " )
// p r i n t ( t r a c k e r . v i s i b l e V i e w s )
// p r i n t ( t r a c k e r . s o r t e d V i e w I D s )
// p r i n t ( " V I S I B I L I T Y C H A N G E D E N D E D " )
// }
// p r i n t C o u n t + = 1
2023-06-01 12:45:36 -07:00
2023-11-14 13:39:46 -08:00
// i f ( c u r r e n t I d ! = n i l ) {
2023-04-21 17:06:30 -07:00
// c u r r e n t O f f s e t = t r a c k e r . v i s i b l e V i e w s [ c u r r e n t I d ! ] !
// }
2023-04-23 20:41:17 -07:00
let visibleViews2 = Array ( tracker . visibleViews . keys )
2024-05-15 08:57:41 -07:00
if visibleViews2 . count = = 0 {
2023-04-22 01:01:09 -07:00
return
}
2023-06-02 16:20:04 -07:00
// c u r r e n t I d = t r a c k e r . s o r t e d V i e w I D s [ t r a c k e r . s o r t e d V i e w I D s . c o u n t - 1 ]
currentId = tracker . sortedViewIDs [ 0 ]
2023-06-02 14:25:20 -07:00
currentOffset = tracker . visibleViews [ currentId ! ] !
2023-06-02 16:20:04 -07:00
// i f ( I n t ( c u r r e n t O f f s e t ! ) ! = - 1 & & I n t ( c u r r e n t O f f s e t ! ) < 0 ) {
// i f ( t r a c k e r . s o r t e d V i e w I D s . c o u n t > 1 ) {
// c u r r e n t I d = t r a c k e r . s o r t e d V i e w I D s [ 1 ]
// c u r r e n t O f f s e t = t r a c k e r . v i s i b l e V i e w s [ c u r r e n t I d ! ] !
// }
// }
2024-05-15 08:57:41 -07:00
// i f ( c u r r e n t I d ! = n i l ) {
// / / i f ( p r i n t C o u n t % p r i n t R a t e = = 0 ) {
// / / p r i n t ( p r i n t C o u n t )
// / / p r i n t ( " c a t c u r r e n t I D : " , c u r r e n t I d )
// / / }
// / / p r i n t ( " g o t h e r e " )
// c u r r e n t O f f s e t = t r a c k e r . v i s i b l e V i e w s [ c u r r e n t I d ! ] !
// }
2023-02-27 14:27:15 -08:00
}
}
private let itemFormatter : DateFormatter = {
let formatter = DateFormatter ( )
formatter . dateStyle = . short
formatter . timeStyle = . medium
return formatter
} ( )
2023-08-03 15:22:18 -07:00
struct DropViewDelegate2 : DropDelegate {
@ Binding var isDragging : Bool
2024-05-15 08:57:41 -07:00
func dropUpdated ( info _ : DropInfo ) -> DropProposal ? {
2023-08-03 15:22:18 -07:00
return DropProposal ( operation : . move )
}
2024-05-15 08:57:41 -07:00
func performDrop ( info _ : DropInfo ) -> Bool {
2023-08-04 12:02:22 -07:00
isDragging = false
2023-08-03 15:22:18 -07:00
return true
}
2024-05-15 08:57:41 -07:00
func dropEntered ( info _ : DropInfo ) {
2023-08-03 15:22:18 -07:00
isDragging = true
print ( " SECOND DROPPPOOO " )
}
}
2023-08-02 16:26:17 -07:00
struct DropViewDelegate : DropDelegate {
let destinationItem : Ribbon
// @ B i n d i n g v a r c o l o r s : [ C o l o r ]
@ Binding var draggedItem : Ribbon ?
2023-08-03 12:40:12 -07:00
@ Binding var isDragging : Bool
2023-08-02 16:26:17 -07:00
let appDatabase : AppDatabase
2023-11-14 13:39:46 -08:00
2024-05-15 08:57:41 -07:00
func dropUpdated ( info _ : DropInfo ) -> DropProposal ? {
2023-08-02 16:26:17 -07:00
return DropProposal ( operation : . move )
}
2024-05-15 08:57:41 -07:00
func dropExited ( info _ : DropInfo ) {
2023-08-03 12:40:12 -07:00
print ( " EXITED " )
isDragging = false
}
2024-05-15 08:57:41 -07:00
func dropEntered ( info _ : DropInfo ) {
2023-08-02 16:26:17 -07:00
Task {
2023-08-03 12:40:12 -07:00
isDragging = true
2024-05-15 08:57:41 -07:00
if draggedItem = = nil {
2023-08-03 12:40:12 -07:00
return
}
2023-11-14 13:39:46 -08:00
if disableDrop {
2024-05-15 08:57:41 -07:00
return
2023-11-14 13:39:46 -08:00
}
2023-08-16 12:19:14 -07:00
2023-11-14 13:39:46 -08:00
var newRibbon = draggedItem !
2023-08-02 16:26:17 -07:00
var newDest = destinationItem
var oldPos = draggedItem ! . pos
var newPos = destinationItem . pos
print ( " dragged item " )
print ( draggedItem )
print ( " dest item " )
print ( destinationItem )
2024-05-15 08:57:41 -07:00
if draggedItem ! . id ! = = destinationItem . id ! {
2023-08-02 16:26:17 -07:00
return
}
newRibbon . pos = destinationItem . pos
2024-05-15 08:57:41 -07:00
_ = try await appDatabase . updateRibbonPosition ( & newRibbon , oldPos , newPos )
2023-08-16 12:19:14 -07:00
disableDrop = true
DispatchQueue . main . asyncAfter ( deadline : . now ( ) + 0.5 ) {
disableDrop = false
}
2023-08-03 12:40:12 -07:00
draggedItem ! . pos = newPos
2023-08-02 16:26:17 -07:00
2023-08-03 12:40:12 -07:00
// d r a g g e d I t e m = n i l
2023-08-02 16:26:17 -07:00
}
}
2023-11-14 13:39:46 -08:00
2024-05-15 08:57:41 -07:00
func performDrop ( info _ : DropInfo ) -> Bool {
2023-08-03 12:40:12 -07:00
print ( " PERFORMED DROPPPP " )
2023-08-02 16:26:17 -07:00
draggedItem = nil
2023-08-03 12:40:12 -07:00
isDragging = false
2023-08-02 16:26:17 -07:00
return true
}
}
2023-02-27 14:27:15 -08:00
struct ContentView_Previews : PreviewProvider {
static var previews : some View {
ContentView ( )
ContentView ( ) . environment ( \ . appDatabase , . random ( ) )
}
}
extension View {
func Print ( _ vars : Any . . . ) -> some View {
2024-05-15 08:57:41 -07:00
for v in vars {
print ( v )
}
2023-02-27 14:27:15 -08:00
return EmptyView ( )
}
}