Skip to content

Instantly share code, notes, and snippets.

View Aakashcs's full-sized avatar
🎯
Focusing

Aakash Aakashcs

🎯
Focusing
View GitHub Profile
@Aakashcs
Aakashcs / SwiftUIGifLoadingView.swift
Created July 16, 2020 00:16
Gif Loading View in Swift UI
struct LoadingView: UIViewRepresentable {
@Environment(\.colorScheme) var colorScheme
func makeUIView(context: Context) -> GIFImageView {
let gifImageView = GIFImageView()
gifImageView.animate(withGIFNamed: colorScheme == .light ? "loader-black" : "loader-white") {
print("It's animating!")
}
return gifImageView
@Aakashcs
Aakashcs / SwitchToDarkMode
Created July 16, 2020 00:18
Switch to dark mode in Swift
UIApplication.shared.windows.first?.overrideUserInterfaceStyle = .dark // for Light mode: .light
@Aakashcs
Aakashcs / SearchView.swift
Created July 16, 2020 00:20
Search View with list in Swift UI
//
// SearchView.swift
// Branddose
//
// Created by Aakash on 10/07/2020.
// Copyright © 2020 Minhasoft. All rights reserved.
//
import SwiftUI
@Aakashcs
Aakashcs / Extension.swift
Created July 16, 2020 00:22
Resigning the keyboard on drag in the list can be realised using a method on UIApplication window. For easier handling I created an extension on UIApplication and view modifier for this extension and finally an extension to View
extension UIApplication {
func endEditing(_ force: Bool) {
self.windows
.filter{$0.isKeyWindow}
.first?
.endEditing(force)
}
}
struct ResignKeyboardOnDragGesture: ViewModifier {
@Aakashcs
Aakashcs / Extension.swift
Created July 16, 2020 00:23
SwiftUI Color from Hex
extension Color {
init(hex: String) {
let scanner = Scanner(string: hex)
var rgbValue: UInt64 = 0
scanner.scanHexInt64(&rgbValue)
let r = (rgbValue & 0xff0000) >> 16
let g = (rgbValue & 0xff00) >> 8
let b = rgbValue & 0xff
@Aakashcs
Aakashcs / Array.swift
Last active July 16, 2020 00:24
Making 2D arrays for swiftUI multiple column list
extension Array{
func collection(into size :Int) -> [[Element]]{
return stride(from: 0, to: count, by:size).map{
Array(self[$0 ..< Swift.min($0 + size, count)])
}
}
}
@Aakashcs
Aakashcs / Extension.swift
Created July 16, 2020 00:25
NavigateModifier for navigating in swiftUI
extension View {
/// Navigate to a new view.
/// - Parameters:
/// - view: View to navigate to.
/// - binding: Only navigates when this condition is `true`.
func navigate<SomeView: View>(to view: SomeView, when binding: Binding<Bool>) -> some View {
modifier(NavigateModifier(destination: view, binding: binding))
}
@Aakashcs
Aakashcs / BaseStation.java
Created September 4, 2020 10:59
An example to get cell towers info on Android
package com.mirrordust.gpscellinfodemo;
public class BaseStation {
private int mcc; // Mobile Country Code
private int mnc; // Mobile Network Code
private int lac; // Location Area Code or TAC(Tracking Area Code) for LTE