Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Shreyak Upadhyay shreyakupadhyay

🎯
Focusing
View GitHub Profile
@shreyakupadhyay
shreyakupadhyay / version64.js
Last active Apr 5, 2021
Medium blog 0.64 version
View version64.js
// 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 Feb 22, 2021
Parent component of Image Lazy Load component React-Native
View LazyLoadParent.js
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 Feb 22, 2021
Lazy loading 5 images stacked on a single scrollview in React-Native
View ImageLazyLoad.js
// 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: () => {
View Notifications.js
// 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')
View HeadlessNotifications.js
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();
}
View HandleNotifications.js
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
Mount Notification module in App.js
View 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();
View BaseAxios.js
import axios from 'axios';
import { USER_NAME, PASSWORD, REST_END_POINT } from './ApiConstants';
function baseAxios(options) {
const defaultHeaders = {
'Content-Type': 'application/json',
'Accept-Language': options.language ? options.language : 'en',
'lang': options.lang ? options.lang : 'en',
username: USER_NAME,
password: PASSWORD,
View StyleProperties.js
const widthPercentageToDP = widthPercent => {
const screenWidth = Dimensions.get('window').width;
const elemWidth = parseFloat(widthPercent);
return PixelRatio.roundToNearestPixel(screenWidth * elemWidth / 100);
};
const heightPercentageToDP = heightPercent => {
const screenHeight = Dimensions.get('window').height;
const elemHeight = parseFloat(heightPercent);
return PixelRatio.roundToNearestPixel(screenHeight * elemHeight / 100);
};
View StyledComponent.js
export const CustomText = styled.Text`
font-size: ${props => props.fontSize}px;
color: ${props => props.fontColor};
letter-spacing: ${props => props.letterSpacing};
font-style: ${props => props.fontStyle};
font-weight: ${props => props.fontWeight};
font-family: ${props => props.fontFamily};
line-height: ${props => props.lineHeight};
`;
CustomText.defaultProps = {