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 / 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 / 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);
#import "DarkMode.h"
#import <React/RCTLog.h>
@implementation DarkMode
RCT_EXPORT_MODULE();
@end
#import <React/RCTBridgeModule.h>
@interface DarkMode : NSObject <RCTBridgeModule>
@end
@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" });
@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);
const counterValue = 0;
const initialCounterValue = useInitialValue(selectedBrands);
const hasCounterChanged = counterValue !== initialCounterValue;
@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
};
@lukebrandonfarrell
lukebrandonfarrell / ActionReducer.js
Last active March 4, 2023 12:57
A hook to listen to Redux actions in your component.
const initialState = {
type: null,
payload: null,
meta: null,
error: false
};
export default (state = initialState, action) => {
return {
...state,
@lukebrandonfarrell
lukebrandonfarrell / funnels.ts
Created August 13, 2019 08:14
Funnels TypeScript implementation for RMN
/**
* @author Luke Brandon Farrell
* @description Funnels allow us to re-use screens with react-native-navigation
* and build more complex patterns. In the context of this utility a stack
* refers to a single screen, where as a funnel refres to a collection of screens.
*/
import { Platform } from "react-native";
import { Navigation, Layout, Options } from "react-native-navigation";
import * as NavigationLayouts from "react-native-navigation-layouts";