Skip to content

Instantly share code, notes, and snippets.

View hirbod's full-sized avatar

Hirbod hirbod

View GitHub Profile
import { BottomSheetModal, BottomSheetModalProps } from '@gorhom/bottom-sheet';
import { useCallback, useRef } from 'react';
import { BackHandler, NativeEventSubscription } from 'react-native';
/**
* hook that dismisses the bottom sheet on the hardware back button press if it is visible
* @param bottomSheetRef ref to the bottom sheet which is going to be closed/dismissed on the back press
*/
export const useBottomSheetBackHandler = (
bottomSheetRef: React.RefObject<BottomSheetModal | null>,
@hirbod
hirbod / instagram-like-button.jsx
Created October 20, 2022 17:26 — forked from vcapretz/instagram-like-button.jsx
A simple Like button with a nice animation using react-native-reanimated v2, support for my post in https://vcapretz.com/2021/instagram-button-react-native
import React from "react";
import Animated, {
useSharedValue,
withSpring,
useAnimatedStyle,
Extrapolate,
interpolate,
} from "react-native-reanimated";
import { Pressable, View, Button, StyleSheet } from "react-native";
import { MaterialCommunityIcons } from "@expo/vector-icons";
@hirbod
hirbod / useKeyboardBottomInset hook
Created July 1, 2022 16:27 — forked from intergalacticspacehighway/useKeyboardBottomInset hook
Hook to get keyboard height in React Native and add bottom/padding inset on a view.
import { Keyboard, Platform, KeyboardEvent } from 'react-native';
const useKeyboardBottomInset = () => {
const [bottom, setBottom] = React.useState(0);
const subscriptions = React.useRef([]);
React.useEffect(() => {
function onKeyboardChange(e) {
if (
e.startCoordinates &&
@hirbod
hirbod / withIosTextInputMask.js
Created March 14, 2022 16:25
Expo config plugin to make react-native-text-input-mask works on iOS.
const { withDangerousMod, createRunOncePlugin } = require('@expo/config-plugins');
const { readFile, writeFile } = require('fs');
const pkg = require('./node_modules/react-native-text-input-mask/package.json');
function withIosTextInputMask(config) {
return withDangerousMod(config, [
'ios',
async (config) => {
const filePath = 'ios/Podfile';
import { createContext, forwardRef, useCallback, useMemo } from "react";
import { FlatList, FlatListProps, ViewToken } from "react-native";
import Animated, { useSharedValue } from "react-native-reanimated";
const MAX_VIEWABLE_ITEMS = 4;
type ViewabilityItemsContextType = string[];
export const ViewabilityItemsContext = createContext<
Animated.SharedValue<ViewabilityItemsContextType>
@hirbod
hirbod / withDisableForcedDarkModeAndroid.js
Last active May 21, 2025 13:32
Expo Config Plugin to disable forced Dark mode.
// disable forced dark mode to prevent weird color changes
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { createRunOncePlugin, withAndroidStyles, AndroidConfig } = require('expo/config-plugins')
function setForceDarkModeToFalse(styles) {
const newStyles = AndroidConfig.Styles.assignStylesValue(styles, {
add: true,
// ############# FOLLOW IF YOU'RE ON SDK 52 #############
// TODO: AndroidConfig.Styles.getAppThemeGroup() will be available in SDK 52 (or expo/config-plugins 9+), for now I just hardcoded AppTheme
// parent: AndroidConfig.Styles.getAppThemeGroup(),
@hirbod
hirbod / expoAnimatedWebPforIOSandAndroid.md
Last active January 10, 2024 09:11
expo-config-plugin: animated webP support for Expo SDK44+ and Custom Dev Client (with FastImage) support

I recommend to not use this anymore. Switch over to expo-image

If anybody needs animated webP support with Expo (Custom Dev Client) for the native <Image /> and <FastImage /> (read comments):

Android

// create a file like plugins/withAnimatedWebPSupport.js -> this is for the native <Image />

const {
@hirbod
hirbod / angular-masonry.js
Created March 21, 2015 05:07
Angular Masonry fixed for OnsenUI
/*!
* angular-masonry 0.10.0
* Pascal Hartig, weluse GmbH, http://weluse.de/
* fixed / optimized for OnseuUI by Hirbod Mirjavadi, nightstomp, http://nightstomp.com
* License: MIT
*/
(function () {
'use strict';
angular.module('wu.masonry', []).controller('MasonryCtrl', [
'$scope',
<!doctype html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<title>Orientation Test</title>
<style>
body { text-align: center; }
@media all and (orientation:portrait) {
body { font-size: 35em; margin-top: .3em; }
}
#install esseintal packages for opencv
apt-get -y install build-essential
apt-get -y install cmake
apt-get -y install pkg-config
apt-get -y install libgtk2.0-dev libgtk2.0
apt-get -y install zlib1g-dev
apt-get -y install libpng-dev
apt-get -y install libjpeg-dev
apt-get -y install libtiff-dev
apt-get -y install libjasper-dev