Skip to content

Instantly share code, notes, and snippets.

View DigitalZebra's full-sized avatar
🦓

Drew DigitalZebra

🦓
View GitHub Profile
@KrisRJack
KrisRJack / Array+Extension.swift
Last active July 24, 2022 20:13
Helpful Swift Extensions
import UIKit
extension Array where Element == NSLayoutConstraint {
/// Activates each constraint in an array of `NSLayoutConstraint`.
///
/// Example usage: `[view.heightAnchor.constraint(equalToConstant: 30), view.widthAnchor.constraint(equalToConstant: 30)].activate()`
func activate() {
NSLayoutConstraint.activate(self)
}
import React from 'react';
import {View, SafeAreaView, StyleSheet, ScrollView} from 'react-native';
import Svg, {Defs, LinearGradient, Stop, Rect} from 'react-native-svg';
import {MotiView} from 'moti';
const Gradient = () => (
<Svg viewBox="0 0 100 100">
<Defs>
<LinearGradient id={'gradient'} x1={'0%'} y1={'0%'} x2={'100%'} y2={'0%'}>
<Stop stopOpacity={0} stopColor={'rgb(225, 225, 225)'} offset={'0%'} />
import React, {useState, useEffect} from 'react';
import {
SafeAreaView,
Text,
View,
TextInput,
StatusBar,
ActivityIndicator,
} from 'react-native';
import Svg, {Circle} from 'react-native-svg';
@intergalacticspacehighway
intergalacticspacehighway / viewability-tracker-flatlist.tsx
Last active January 23, 2024 03:38
Viewability tracker with shared values
import { createContext, forwardRef, useCallback, useMemo } from "react";
import { FlatList, FlatListProps, ViewToken } from "react-native";
import Animated, { useSharedValue } from "react-native-reanimated";
const MAX_VIEWABLE_ITEMS = 4;
type ViewabilityItemsContextType = string[];
export const ViewabilityItemsContext = createContext<
Animated.SharedValue<ViewabilityItemsContextType>
extension Error {
var code: Int { return (self as NSError).code }
var domain: String { return (self as NSError).domain }
var userInfo: [String:Any] { return (self as NSError).userInfo }
func timeAfterWhichToRetry(retryCount: Int) -> TimeInterval? {
// CloudKit suggests us retry too often, so slow us down as we retry a lot, up to 5 minutes
if let suggestedTimeout = suggestedTimeAfterWhichToRetry {
if suggestedTimeAfterWhichToRetry == 0 {
return 0
//
// YeetJSIUTils.h
// yeet
//
// Created by Jarred WSumner on 1/30/20.
// Copyright © 2020 Facebook. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <jsi/jsi.h>
@louy
louy / AccessibilityWrapper.tsx
Last active November 30, 2023 10:23
RN Accessibility Wrapper, a custom view that allows you to control the accessibility behaviour of a React Native component tree
/**
* @author Louay Alakkad (github.com/louy)
* @license MIT https://opensource.org/licenses/MIT
*/
import React from 'react'
import PropTypes from 'prop-types'
import {
NativeModules,
ViewProps,
ViewPropTypes,
@grrrlikestaquitos
grrrlikestaquitos / swiftui-higher-order-component.swift
Last active September 24, 2022 17:09
SwiftUI: Higher Order Component Syntax
// Declaring ContainerView as a HOC
struct ContainerView<C: View> : View {
let childView: C
init(_ childView: () -> (C)) {
self.childView = childView()
}
var body: some View {
childView
@josephlord
josephlord / FetchedResultsControllerPublisher.swift
Created June 10, 2019 23:08
Making a Combine publisher from a FetchedResultsController
//
// FetchedResultsControllerPublisher.swift
// ListsModel
//
// Created by Joseph Lord on 09/06/2019.
// Copyright © 2019 Joseph Lord. All rights reserved.
//
import Foundation
import Combine
@victorchee
victorchee / Fireworks.swift
Created December 29, 2018 06:11
Fireworks effect by emitter.
let emitterLayer = CAEmitterLayer()
emitterLayer.frame = navigationView.bounds
emitterLayer.renderMode = .additive
emitterLayer.emitterMode = .outline
emitterLayer.emitterShape = .line
emitterLayer.emitterSize = CGSize(width: 50, height: 0)
emitterLayer.emitterPosition = CGPoint(x: navigationView.bounds.width / 2, y: navigationView.bounds.height)
emitterLayer.velocity = 1
emitterLayer.seed = (arc4random() % 100) + 1
navigationView.layer.insertSublayer(emitterLayer, at: 0)