Skip to content

Instantly share code, notes, and snippets.

View navsing's full-sized avatar
🏠
Working from home

Navdeep Singh navsing

🏠
Working from home
View GitHub Profile
@navsing
navsing / TextShimmerSample.swift
Created January 5, 2023 23:48
Text Shimmer Sample
struct TextShimmer : View {
@State var show = false
var body : some View{
ZStack{
Text("Shimmer").fontWeight(.heavy).font(.largeTitle).foregroundColor(Color(UIColor.systemOrange)).redacted(reason: .placeholder)
Text("Shimmer").fontWeight(.heavy).font(.largeTitle).foregroundColor(.white)
.mask(
Capsule()
.fill(LinearGradient(gradient: .init(colors: [.clear,.white,.clear]), startPoint: .top, endPoint: .bottom))
.rotationEffect(.init(degrees: 60)) //just to tilt the shimmer a little to prettify it
@navsing
navsing / CardShimmerSample.swift
Created January 5, 2023 23:50
Card Shimmer Sample
struct CardShimmer : View {
@State var show = false
var center = (UIScreen.main.bounds.width / 2) + 110 //removing padding with this hack
var body : some View{
ZStack{
Color.black.opacity(0.08)
.frame(height: 250)
.cornerRadius(20)
Color.white
.frame(height: 250)
@navsing
navsing / ShimmerEffect.swift
Created January 5, 2023 23:51
Shimmer Effect Sample
import SwiftUI
struct Shimmer: View {
@State var loading = true
var body: some View {
Group {
if self.loading {
ScrollView(.vertical, showsIndicators: false) {
VStack{
HStack {
@navsing
navsing / network.swift
Created January 6, 2023 18:48
Network Layer
import Foundation
import Apollo
class Network {
static let shared = Network()
let apollo: ApolloClient = {
let configuration = URLSessionConfiguration.default
configuration.httpAdditionalHeaders = [
"x-api-key": "<YOUR-API-KEY>"
]
Network.shared.apollo.fetch(query: ListPersonQuery) { result in
switch result {
case .success(let graphQLResult):
if let items = graphQLResult.data?.listPerson?.items {
for conf in items {
if let curPerson = conf {
//Do whatever here with your Graphql Result
print(curPerson)
}
}
Network.shared.apollo.perform(mutation: CreatePersonMutation(input: personInput)) { result in
switch result {
case .success(let graphQLResult):
print(graphQLResult)
case .failure(let error):
print("Failure! Error: \(error)")
}
}
ZStack {
Color("bg").edgesIgnoringSafeArea(.all) //give the entire app the same background as the component's background
RoundedRectangle(cornerRadius: 20)
.fill(Color("bg")) //same background as the app
.frame(width: 280, height: 280)
.shadow(color: Color("dark"), radius: 5, x: -10, y: -10) //shadow left and top
.shadow(color: Color("light"), radius: 5, x: 10, y: 10).padding(.top, 32) //shadow right and bottom
.blur(radius: 5) //to show smooth transition
}
Button(action: {}) {
Circle()
.fill(Color("bg"))
.frame(width: 96, height: 96)
.shadow(color: Color("dark"), radius: 5, x: -10, y: -10)
.shadow(color: Color("light"), radius: 5, x: 10, y: 10)
.blur(radius: 5)
.overlay(
Image(systemName: "play.fill")
.resizable()
ZStack(alignment: Alignment(horizontal: .leading, vertical: .center), content: {
Capsule()
.fill(Color.gray.opacity(0.2))
.frame(height: 6)
ZStack(alignment: Alignment(horizontal: .trailing, vertical: .center)) {
Capsule()
.fill(Color("dark").opacity(0.6))
.frame(width: value,height: 6) //value is the current volume percentage
Circle()
.fill(Color("dark"))
import SwiftUI
import Lottie
struct LottieView: UIViewRepresentable {
let animationView = AnimationView()
var lottieFile = ""
func makeUIView(context: UIViewRepresentableContext<LottieView>) -> UIView {
let view = UIView()
let animation = Animation.named(filename)