Skip to content

Instantly share code, notes, and snippets.

View juanchoperezj's full-sized avatar
🇻🇪

Juan Simón juanchoperezj

🇻🇪
View GitHub Profile
@juanchoperezj
juanchoperezj / Alert.tsx
Created August 11, 2023 20:30
Alert component using react-native-bottom-sheet and event emmitter
import { EventEmitter } from 'eventemitter3';
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { Text, View } from 'react-native';
import { BottomSheetModal, BottomSheetModalProvider } from '@gorhom/bottom-sheet';
import { useNavigation } from '@react-navigation/native';
import { AuthStackScreens } from 'navigation/stacks/auth';
import Button from 'common/Button';
@juanchoperezj
juanchoperezj / CustomToast.tsx
Created August 11, 2023 20:10
Custom Toast implemented with Reanimated and Gesture Handler
import React, { forwardRef, useCallback, useImperativeHandle } from 'react';
import { PanGestureHandler } from 'react-native-gesture-handler';
import Animated, {
runOnJS,
useAnimatedGestureHandler,
useAnimatedStyle,
useSharedValue,
withDelay,
withSequence,
withSpring,
@juanchoperezj
juanchoperezj / validate_env.ts
Created August 10, 2023 17:02
Validate env complete implementation reading the env file variables a compare them against the zod object
import fs from 'fs';
import path from 'path';
import Environment from '../src/@types/env';
const APP_ENV = process.env.APP_ENV ?? 'dev';
const isDev = APP_ENV === 'dev';
const envFile = path.join(__dirname, isDev ? '../.env' : `../.env.${APP_ENV}`);
(() => {
@juanchoperezj
juanchoperezj / package.json
Created August 8, 2023 22:02
Package.json scripts example
"scripts": {
"ios:staging": "APP_ENV=staging ts-node scripts/validate-env.ts && react-native run-ios --scheme MyReactNativeApp-Staging",
"ios:prod": "APP_ENV=prod ts-node scripts/validate-env.ts && react-native run-ios --scheme MyReactNativeApp",
"android:dev": "APP_ENV=dev ts-node scripts/validate-env.ts && react-native run-android --variant=devDebug --appIdSuffix=dev",
"android:qa": "APP_ENV=qa ts-node scripts/validate-env.ts && react-native run-android --variant=qaDebug --appIdSuffix=qa",
// ... other scripts
}
@juanchoperezj
juanchoperezj / env.ts
Created August 8, 2023 22:01
ENV zod object
import z from 'zod';
const NativeConfig = z.object({
API_URL: z.string(),
BASE_URL: z.string(),
});
export type NativeConfigType = z.infer<typeof NativeConfig>;
export default NativeConfig;
@juanchoperezj
juanchoperezj / react_native_config.d.ts
Last active August 10, 2023 16:58
React Native Config Interface Example
import { NativeConfigType } from './env';
declare module 'react-native-config' {
export interface NativeConfig extends NativeConfigType {}
export const Config: NativeConfig;
export default Config;
}
@juanchoperezj
juanchoperezj / ts_node.sh
Last active August 10, 2023 16:58
ts-node dev dependency
yarn add -D ts-node
npm install ts-node --save-dev
@juanchoperezj
juanchoperezj / install_dependencies.sh
Last active August 10, 2023 16:58
Dependencies needed to validate environment variables
yarn add react-native-config zod
npm i react-native-config zod
@juanchoperezj
juanchoperezj / Postgres Notify Firebase
Created October 3, 2018 12:53
Trigger that notifies the javascript thread of a change occurred and sends push notifications using postgres and firebase
const admin = require('firebase-admin')
const request = require('request')
const config = require('../config')
const {JWT} = require('google-auth-library')
const dbConfig = config.database
const pg = require('pg')
/**
* @type {string}
import { AsyncStorage, Alert, Platform } from 'react-native';
import firebase from 'react-native-firebase';
const displayNotificationFromCustomData = message => {
if (message.data && message.data.title) {
let notification = new firebase.notifications.Notification();
notification = notification
.setTitle(message.data.title)
.setBody(message.data.body)
.setData(message.data);