Skip to content

Instantly share code, notes, and snippets.

View amhinson's full-sized avatar

Alex Hinson amhinson

View GitHub Profile
import { transform, isEqual, isObject } from "lodash";
import Reactotron from "reactotron-react-native";
export const stateChanges = (object: any, base: any): Object => {
return transform(object, (result, value, key) => {
if (!isEqual(value, base[key])) {
// @ts-ignore
result[key] =
isObject(value) && isObject(base[key])
? stateChanges(value, base[key])
@amhinson
amhinson / Screen.js
Created June 24, 2019 16:04
React Native - Enable scrolling only when content is larger than screen
const DEVICE_HEIGHT = Dimensions.get("window").height;
const Screen = () => {
const [screenHeight, setScreenHeight] = useState(0);
function onContentSizeChange(contentWidth, contentHeight) {
setScreenHeight(contentHeight);
}
const scrollEnabled = screenHeight > DEVICE_HEIGHT;
@amhinson
amhinson / MyComponent.tsx
Created January 18, 2019 19:13
Unstated HOC
import { ContainerOne, ContainerTwo } from './containers';
// ...
withUnstated(MyComponent, {
one: ContainerOne,
two: ContainerTwo
})
@amhinson
amhinson / usage.js
Last active December 14, 2018 17:35
Yup - valid image url/source
yup.object().shape({
imageUrl: yup
.string()
.test('valid-image-url', 'Must use valid image URL', value =>
testImage(value, 1000).then(status => status === 'success')
)
})
@amhinson
amhinson / gist:79799400801f0623c6f9fe19bdb3dc21
Last active November 28, 2018 17:18
Yup Phone Validation
import libphonenumber from 'google-libphonenumber';
const phoneUtil = libphonenumber.PhoneNumberUtil.getInstance();
export const validPasswordRegex = /^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$/;
export const phoneValidation = function(message: string) {
return this.test({
name: 'phone',
exclusive: true,