Skip to content

Instantly share code, notes, and snippets.

View naqvitalha's full-sized avatar

Talha Naqvi naqvitalha

View GitHub Profile
@naqvitalha
naqvitalha / MetroConfig.js
Created February 22, 2024 17:41
Inline Requires true
const path = require("path");
const exclusionList = require("metro-config/src/defaults/exclusionList");
const escape = require("escape-string-regexp");
const package = require("../package.json");
const modules = Object.keys({
...package.peerDependencies,
});
@naqvitalha
naqvitalha / BatchedSetState.ts
Last active April 16, 2024 02:46
Batched setState
import React from 'react';
import {unstable_batchedUpdates} from 'react-native';
const originalUseState = React.useState;
export function createBatchedStateHook(
batchingFunction: (fn: () => void) => void,
) {
const useState = originalUseState;
let updateQueue: (() => void)[] = [];
@naqvitalha
naqvitalha / LazyScrollView.tsx
Created February 5, 2024 21:56
LazyScrollView
export const LazyScrollView = forwardRef(function LazyScrollView(
props: LazyScrollViewProps,
ref: ForwardedRef<FlashList<unknown[]>>,
): JSX.Element {
const {children, estimatedScrollViewSize, estimatedItemSize} =
props;
const data = isArray(children) ? children : Children.toArray(children);
// No specific reason for 2000, just a big number. Roughly 2x the screen size
@naqvitalha
naqvitalha / RecyclableImage.tsx
Last active March 16, 2023 05:16
iOS images inside FlashList
const RecyclableImage = (props) => {
const imageUri = useRef(props.source.uri);
const imageRef = useRef(null);
if (props.source.uri && props.source.uri !== imageUri.current) {
imageUri.current = props.source.uri;
imageRef.current?.setNativeProps({ opacity: 0 });
}
return <Image {...props} ref={imageRef} onLoad={()=> { imageRef.current?.setNativeProps({ opacity: 1 }) }} />
}
@naqvitalha
naqvitalha / .js
Last active November 30, 2020 13:59
Native modules on web
import { NativeModules } from 'react-native';
//resolves to the web version when relevant, reduces the need of .web.ts files
NativeModules.Toast.show('hello');