piemonte / Twinkle

:sparkles: Twinkle interface elements in Swift
MIT License
612 stars 69 forks source link

SwiftUI Update #17

Open RMottram opened 4 years ago

RMottram commented 4 years ago

Make a version for SwiftUI Framework

Fred10932 commented 2 years ago

For folks looking how to use this in SwiftUI:

struct TwinkleView: UIViewRepresentable {
    @State var rect: CGRect

    func makeUIView(context: Context) -> UIView {        
         let view = UIView(frame: rect) 
         view.clipsToBounds = false         
         view.twinkle()         
         return view
     }     
     func updateUIView(_ uiView: UIView, context: Context) {
     }
}

//Use like this: 

SomeSwiftUIView()
   .overlay(
        GeometryReader { geometry in       //It currently doesn't work without explicitly passing the frame like this
             TwinkleView(rect: CGRect(x: 0, y: 0, width: geometry.size.width, height: geometry.size.height))
         }      
   )