Skip to content

Instantly share code, notes, and snippets.

View lukebrandonfarrell's full-sized avatar
✌️
fixing bugs since 1996

Luke Brandon Farrell lukebrandonfarrell

✌️
fixing bugs since 1996
View GitHub Profile
@lukebrandonfarrell
lukebrandonfarrell / react-native.config.js
Last active April 10, 2020 14:38
React Native Config 0.60+
module.exports = {
project: {
ios: {},
android: {}, // grouped into "project"
},
assets: ['./path-to-assets'], // stays the same
};
const counterValue = 0;
const initialCounterValue = useInitialValue(selectedBrands);
const hasCounterChanged = counterValue !== initialCounterValue;
@lukebrandonfarrell
lukebrandonfarrell / useEffectAfterMount.js
Last active June 12, 2020 14:43
Use an effect after the component has been mounted.
/**
* Use effect after component mount
*
* @param effect
* @param deps
*
* @return {*}
*/
export function useEffectAfterMount(effect, deps) {
const isFirstRun = useRef(true);
@lukebrandonfarrell
lukebrandonfarrell / example.js
Created October 3, 2019 13:50
Sets an array of errors for a formik form
/*
* The first arguement is an object of errors e.g. { email: "Email has been taken" }
* The seound arguement is a refrence to your formik form (e.g. useRef)
* The third arguement is an optional mapping
*/
useSetFormikErrors(errors, formikRef, { dob: "birthday" });
#import <React/RCTBridgeModule.h>
@interface DarkMode : NSObject <RCTBridgeModule>
@end
#import "DarkMode.h"
#import <React/RCTLog.h>
@implementation DarkMode
RCT_EXPORT_MODULE();
@end
@lukebrandonfarrell
lukebrandonfarrell / useKeyboardStatus.js
Created October 11, 2019 11:27
Hook to return if the react-native keyboard is open / closed
import React, { useState, useRef } from "react";
import { Keyboard } from "react-native";
/**
* Returns if the keyboard is open / closed
*
* @return {bool} isOpen
*/
export function useKeyboardStatus(){
const [isOpen, setIsOpen] = useState(false);
@lukebrandonfarrell
lukebrandonfarrell / collapsable.js
Last active January 29, 2024 14:49
Collapsable header in React Native
import React, { useRef } from "react";
import { View, Animated, Image, ScrollView, Text } from "react-native";
const H_MAX_HEIGHT = 150;
const H_MIN_HEIGHT = 52;
const H_SCROLL_DISTANCE = H_MAX_HEIGHT - H_MIN_HEIGHT;
const CollapsibleHeader = () => {
const scrollOffsetY = useRef(new Animated.Value(0)).current;
const headerScrollHeight = scrollOffsetY.interpolate({
@lukebrandonfarrell
lukebrandonfarrell / handleBackPress.js
Last active August 20, 2020 14:10
Hook to handle back press on Android in React Native with an exit alert.
import { Alert, BackHandler } from "react-native";
/*
* If we are using React Native Navigation
* the BackHandler.exitApp() will in some
* cases invoke a pop instead of exiting
* the application. Using the following
* library solves this issue:
*
* import RNExitApp from "react-native-exit-app";
const { data: userData, isLoading: isUserLoading, error: isUserError } = ...;
const { data: referralData, isLoading: isReferralsLoading, error: isReferralsError } = ...;
const isUserReferralEmpty = _isNil(referralUrl);
const isReferralsEmpty = _isEmpty(referrals);
const isReferralsAvailable = !_isEmpty(referrals) && !isReferralsError;