Skip to content

Instantly share code, notes, and snippets.

View shreyakupadhyay's full-sized avatar
🎯
Focusing

Shreyak Upadhyay shreyakupadhyay

🎯
Focusing
View GitHub Profile
@shreyakupadhyay
shreyakupadhyay / advanced-typescript-api-response.ts
Created December 29, 2022 05:52
Advanced level typescript implementation of API response handling
<!-- common payload: stats associated with data -->
type StatsRange = {
max: number, min: number
}
type StatsKeys = 'count' | 'aum' | 'priceusd' | 'value'
type PartialStats<
T extends Partial<{
[key in StatsKeys]: any;
@shreyakupadhyay
shreyakupadhyay / intermediate-typescript-api-response.ts
Created December 28, 2022 21:14
Intermediate level typescript implementation of API response handling
<!-- common payload: stats associated with data -->
type StatsRange = {
max: number, min: number
}
type StatsKeys = 'count' | 'aum' | 'priceusd' | 'value'
interface PartialStats<Type extends string|number|symbol, RangeType> {
stats?: Partial<Record<Type, RangeType>>
}
@shreyakupadhyay
shreyakupadhyay / beginner-typescript-api-response.ts
Last active December 28, 2022 09:13
Beginner level typescript implementation of API response handling
<!-- common payload: stats associated with data -->
type StatsRange = {
max: number, min: number
}
type StatsKeys = 'count' | 'aum' | 'priceusd' | 'value'
type PartialStats = {
stats?: {
[key in StatsKeys]?: StatsRange
@shreyakupadhyay
shreyakupadhyay / version64.js
Last active April 5, 2021 13:27
Medium blog 0.64 version
// before inline default
import { BeforeFunction } from 'before-module';
const BeforeComponent = (props) => {
const view = BeforeFunction();
return <View>{view}</View>;
};
// after inline default
@shreyakupadhyay
shreyakupadhyay / LazyLoadParent.js
Last active February 22, 2021 09:19
Parent component of Image Lazy Load component React-Native
class LazyLoadParent extends Component {
const container = React.createRef(null);
return (
<>
<ScrollView
showsVerticalScrollIndicator={false}
scrollEventThrottle={10}
onScroll={(event) => {
container.current.onScroll();
}}
@shreyakupadhyay
shreyakupadhyay / ImageLazyLoad.js
Last active February 22, 2021 09:32
Lazy loading 5 images stacked on a single scrollview in React-Native
// lazy loading for three images
const ImageLazyLoad = React.forwardRef((props, ref) => {
const marker1 = React.useRef(null);
const marker2 = React.useRef(null);
const marker3 = React.useRef(null);
const [markerVisible, setmarkerVisible] = useState(0);
// marker Visible set with value -> 1,2,3
React.useImperativeHandle(ref, () => ({
onScroll: () => {
// Push Notifications constants
let baseNotification = new firebase.notifications.Notification({
sound: 'default',
show_in_foreground: true,
})
.setSound("default")
.android.setChannelId('channelId') // id you have set in HandleNotifications.js
.android.setColor('#ffffff') // you can set a color here
.android.setPriority(firebase.notifications.Android.Priority.High)
.android.setSmallIcon('ic_launcher')
import firebase from 'react-native-firebase';
import type { NotificationOpen } from 'react-native-firebase';
export default async (notificationOpen: NotificationOpen) => {
if (notificationOpen.action === 'snooze') {
// handle notification.
}
return Promise.resolve();
}
import React, { Component } from "react";
import firebase from 'react-native-firebase';
class HandleNotifications extends Component {
constructor(props) {
super(props);
this.getToken = this.getToken.bind(this);
this.requestPermission = this.requestPermission.bind(this);
this.checkNotificationPermission = this.checkNotificationPermission.bind(this);
}
@shreyakupadhyay
shreyakupadhyay / App.js
Created May 9, 2020 14:57
Mount Notification module in App.js
import { AppRegistry, View, StyleSheet, AppState } from 'react-native';
import App from './App';
import React from 'react';
import { Provider } from 'react-redux';
import configureStore from './configureStore';
import HandleNotifications from "./src/components/HandleNotifications/HandleNotifications";
const store = configureStore();