Skip to content

Instantly share code, notes, and snippets.

View mrousavy's full-sized avatar
🐍
slime season

Marc Rousavy mrousavy

🐍
slime season
View GitHub Profile
@mrousavy
mrousavy / useStyle.ts
Last active August 1, 2023 13:16
`useStyle` - a typed `useMemo` for styles which also includes style flattening and searching
import { DependencyList, useMemo } from "react";
import {
ImageStyle,
RegisteredStyle,
StyleProp,
StyleSheet,
TextStyle,
ViewStyle,
} from "react-native";
@mrousavy
mrousavy / MEMOIZE.md
Last active October 20, 2025 02:24
Memoize!!! 💾 - a react (native) performance guide
In computing, memoization or memoisation
is an optimization technique used primarily
to speed up computer programs by storing
the results of expensive function calls and  
returning the cached result when the same
inputs occur again.                                         
                                                     — wikipedia
@mrousavy
mrousavy / FastList.tsx
Created March 17, 2021 12:37 — forked from derekstavis/FastList.tsx
Discord's FastList, but in TypeScript
import { forEachObjIndexed } from "ramda";
import * as React from "react";
import {
Animated,
ScrollView,
View,
ViewStyle,
LayoutChangeEvent,
NativeScrollEvent,
} from "react-native";
@mrousavy
mrousavy / lottie-react-native+3.5.0.patch
Created February 8, 2021 14:07
A patch for lottie-react-native so it successfully builds with React Native 0.64
diff --git a/node_modules/lottie-react-native/lottie-react-native.podspec b/node_modules/lottie-react-native/lottie-react-native.podspec
index 006d118..63caf4a 100644
--- a/node_modules/lottie-react-native/lottie-react-native.podspec
+++ b/node_modules/lottie-react-native/lottie-react-native.podspec
@@ -14,7 +14,11 @@ Pod::Spec.new do |s|
s.source = { :git => "https://github.com/react-community/lottie-react-native.git", :tag => "v#{s.version}" }
s.source_files = "src/ios/**/*.{h,m,swift}"
- s.swift_version = "5.0"
- s.dependency 'React'
@mrousavy
mrousavy / magic.ts
Last active September 14, 2020 09:35
TypeScript: Omit parameter using generics (e.g. useful for navigation commands with optional parameters)
interface StoryView {
onStoryPressed: <TStory extends UserStory | CategoryStory>(
...args: TStory extends UserStory ? [stories: Story[], selectedStory: UserStory, user: User] : [stories: Story[], selectedStory: CategoryStory]
) => void;
}
@mrousavy
mrousavy / a.gif
Last active July 26, 2020 09:49
a.gif
@mrousavy
mrousavy / react-native+0.63.0.patch
Last active January 29, 2022 04:14
react-native 0.63 patch for iOS 13 Modal's onRequestClose (Swipe down gesture)
diff --git a/node_modules/react-native/React/Views/RCTModalHostView.h b/node_modules/react-native/React/Views/RCTModalHostView.h
index 4e61886..2b8b6c0 100644
--- a/node_modules/react-native/React/Views/RCTModalHostView.h
+++ b/node_modules/react-native/React/Views/RCTModalHostView.h
@@ -17,7 +17,7 @@
@protocol RCTModalHostViewInteractor;
-@interface RCTModalHostView : UIView <RCTInvalidating>
+@interface RCTModalHostView : UIView <RCTInvalidating, UIAdaptivePresentationControllerDelegate>
@mrousavy
mrousavy / useDebouncedEffect.ts
Created June 30, 2020 12:29
A React hook similar to useEffect, but with a custom timeout to debounce an extra function, for example fetch data from a server when the text changes.
import { useEffect, useRef } from 'react';
/**
* Like useEffect but with a custom timeout to debounce an extra function, for example fetch data from a server when the text changes.
* @param shouldExecuteDebounce A function (created with `useCallback`!) which checks whether the `debounceExecute` function should be executed (after it's debounce delay).
* @param debouncedExecute A function (created with `useCallback`!) to run after `{debounceMs}` milliseconds. This function only gets executed, when this hook doesn't re-run within `{debounceMs}` milliseconds after the execution of the `alwaysExecute` function. Note: Because of it's async nature, this function cannot return a cleanup function.
* @param debounceMs The milliseconds to wait until the debounce function gets executed
* @example
* useDebouncedEffect(
* useCallback(() => {
@mrousavy
mrousavy / react-native-screens+2.7.0.patch
Created May 12, 2020 14:53
react-native-screens Native Stack Navigator Android Translucent StatusBar inset patch
diff --git a/node_modules/react-native-screens/android/src/main/java/com/swmansion/rnscreens/ScreenStackHeaderConfig.java b/node_modules/react-native-screens/android/src/main/java/com/swmansion/rnscreens/ScreenStackHeaderConfig.java
index a9779ad..36726d6 100644
--- a/node_modules/react-native-screens/android/src/main/java/com/swmansion/rnscreens/ScreenStackHeaderConfig.java
+++ b/node_modules/react-native-screens/android/src/main/java/com/swmansion/rnscreens/ScreenStackHeaderConfig.java
@@ -3,6 +3,7 @@ package com.swmansion.rnscreens;
import android.content.Context;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
+import android.os.Build;
import android.text.TextUtils;