Skip to content

Instantly share code, notes, and snippets.

View ashwin1014's full-sized avatar
🎯
Focusing

Ashwin Bordoloi ashwin1014

🎯
Focusing
View GitHub Profile
@ashwin1014
ashwin1014 / Space.js
Created May 20, 2021 13:43
Space component in React Native. (Inspired by Ant Design's "Space" component)
/* eslint-disable react/no-array-index-key */
import React, { memo } from "react";
import { View, StyleSheet } from "react-native";
import PropTypes from "prop-types";
/**
* @param direction -> horizontal, vertical
* @param size -> "xs", "sm", "md", "lg", "xl"
*/
@ashwin1014
ashwin1014 / RadioGroup.js
Last active May 20, 2021 15:13
Radio Button Group React Native
import React, { memo, useCallback } from "react";
import { View, Pressable, Text, StyleSheet } from "react-native";
import PropTypes from "prop-types";
import Space from "./Space/Space";
/**
* @param items = [{ name: "Good Morning", value: "greet_morning" }, { name: "Good Evening", value: "greet_evening" }]
*/
@ashwin1014
ashwin1014 / utils.js
Last active March 22, 2024 05:20
Some handy javascript utility functions to use in a project
export const isEmpty = (obj) => [Object, Array].includes((obj || {}).constructor) && !Object.entries(obj || {}).length;
export const uid = () => Date.now().toString(36) + Math.random().toString(36).substr(2, 5);
export const uniqueObjArray = (arr, prop) => {
return Array.from(new Set(arr.map((a) => a[prop]))).map((item) => {
return arr.find((a) => a[prop] === item);
});
};
@ashwin1014
ashwin1014 / useRnKeyboardHeight.ts
Created May 24, 2023 14:43
Hook to get keyboard height in react native
import { useEffect, useState } from 'react';
import { Keyboard, KeyboardEvent } from 'react-native';
/**
* Shows height of keyboard when shown
*/
function useKeyboardHeight() {
const [keyboardHeight, setKeyboardHeight] = useState(0);
@ashwin1014
ashwin1014 / dynamicNode.txt
Created February 28, 2024 06:13
react-native android dynamic node_modules discovery when hoisted in mono-repo
When using a react-native inside a mono-repo, builds dont work when node_modules are hoisted. To fix this, we make a few changes in gradle files.
"apps/mobile-app/android/app/build.gradle" -> update with below changes
reactNativeDir = new File(["node", "--print", "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim()).getParentFile().getAbsoluteFile()
codegenDir = new File(["node", "--print", "require.resolve('@react-native/codegen/package.json')"].execute(null, rootDir).text.trim()).getParentFile().getAbsoluteFile()
cliFile = new File(["node", "--print", "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim(), "../cli.js").getAbsoluteFile()
@ashwin1014
ashwin1014 / navigationTypesExample.ts
Created February 28, 2024 12:55
Organizing navigation types for react-native
type CreateNavigationParams<
ScreenEnum extends string,
ExtensionType extends Partial<Record<ScreenEnum, unknown>>,
> = {
[K in ScreenEnum | keyof ExtensionType]: K extends keyof ExtensionType
? ExtensionType[K]
: undefined;
};
// Usage: