Skip to content

Instantly share code, notes, and snippets.

View giovani-pereira-ifood's full-sized avatar

Giovani Nascimento Pereira giovani-pereira-ifood

View GitHub Profile
@giovani-pereira-ifood
giovani-pereira-ifood / accessibility-custom-actions.swift
Last active April 29, 2021 11:56
How to add custom accessibility actions to a view
func configureAccessibility() {
isAccessibilityElement = true
let deleteAction = UIAccessibilityCustomAction(
name: "delete",
target: self,
selector: #selector(didTouchDeleteListAction)
)
let selectAction = UIAccessibilityCustomAction(
name: "select",
target: self,
final class IconsDataTests: XCTestCase {
func test_icons_shouldHaveExpectedHash() {
guard recordMode == false else {
recordReferenceHashes()
return
}
let storedObjects = storage.toredIconsHashes() // [IconData]
Icon.allCases.forEach { icon in
func record(file: [IconData]) throws {
// Create the JSON
let data = try JSONEncoder().encode(file)
let json = try convertToFormattedJSON(data: data)
// Get the file path
let referenceFileURL = try getReferenceFilePath()
// Write file
try json.write(to: referenceFileURL, atomically: false, encoding: .utf8)
private func getReferenceFilePath() throws -> URL {
let fileURL = URL(fileURLWithPath: #file, isDirectory: false)
let referenceFileDirectotyURL = fileURL
.deletingLastPathComponent().deletingLastPathComponent()
.appendingPathComponent("ReferenceFolder")
let referenceFileURL = referenceFileDirectotyURL
.appendingPathComponent("referenceFile")
.appendingPathExtension("json")
struct ItemData: Codable {
let name: String
let hash: String
}
func createHash(from image: UIImage) -> String {
let data = image.pngData()
let hash = SHA256.createHashString(data: data)
return hash
}
func createSnapshot(from icon: Icon) -> UIImage {
// Create view and add as subview on the window
let window: UIWindow = UIApplication.shared.keyWindow ?? UIWindow()
let iconView = IconView(icon: icon)
window.addSubview(iconView)
// Set a default size for all the snapshots
iconView.frame = CGRect(origin: .zero, size: dataImageStorageSize)
// Take a snapshot
@giovani-pereira-ifood
giovani-pereira-ifood / animation-download,json
Last active December 18, 2020 11:40
animation download json
[{
"startDate": "YYYY-MM-dd",
"endDate": "YYYY-MM-dd",
"animation": { ... }
},
{
"startDate": "YYYY-MM-dd",
"endDate": "YYYY-MM-dd",
"animation": { ... }
}]
@giovani-pereira-ifood
giovani-pereira-ifood / loadLottieAnimationFromJSON.swift
Created December 17, 2020 19:26
load Lottie animation from JSON
guard let jsonString = UserDefaults.shared.string(forKey: .splashAnimation),
  let data = jsonString.data(using: .utf8),
  let animation = try? JSONDecoder().decode(Animation.self, from: data) else { return }
animationView = AnimationView(animation: animation)
class IconView: UIView {
private func setupAccessibility() {
label.isAccessibilityElement = false
isAccessibilityElement = false
shouldGroupAccessibilityChildren = true
}
}