This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect, useState } from "react"; | |
import { Keyboard, KeyboardEvent } from "react-native"; | |
export const useKeyboard = () => { | |
// TODO: uncomment to return the height | |
// const [ keyboardHeight, setKeyboardHeight ] = useState(0); | |
const [isKeyboardVisible, setIsKeyboardVisible] = useState(false); | |
// const onKeyboardDidShow = (e) => setKeyboardHeight(e.endCoordinates.height); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// check version | |
node -v || node --version | |
// list locally installed versions of node | |
nvm ls | |
// list remove available versions of node | |
nvm ls-remote | |
// install specific version of node |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function formatDateDifference(isoDateString) { | |
const inputDate = new Date(isoDateString); | |
const currentDate = new Date(); | |
const timeDifference = currentDate - inputDate; | |
// Calculate the number of years | |
const years = Math.floor(timeDifference / (365.25 * 24 * 60 * 60 * 1000)); | |
// Calculate the number of months |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ============================================== | |
// Function validates whether passed string is valid iso format | |
function isIsoDate(str) { | |
if (!/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z/.test(str)) return false; | |
const d = new Date(str); | |
return d instanceof Date && !isNaN(d) && d.toISOString()===str; // valid date | |
} | |
console.log(isIsoDate('2011-10-05T14:48:00.000Z')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ================================================ | |
<< Error >> | |
APNS device token not set before retrieving FCM Token for Sender ID | |
<< Fix >> | |
Add a firebase.json file at the root and add the following | |
{ | |
"react-native": { | |
"analytics_auto_collection_enabled": false, | |
"messaging_ios_auto_register_for_remote_messages": false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"compilerOptions": { | |
"baseUrl": ".", | |
"paths": { | |
"src/*": [ | |
"./src/*" | |
] | |
} | |
}, | |
"include": [ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// useful to debug js code errors | |
adb logcat "*:S" ReactNative:V ReactNativeJS:V | |
// useful to debug native errors (when the app won't even start) | |
adb logcat "*:E" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const generateString = (length = 10) => { | |
const characters = | |
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; | |
let result = ""; | |
// const charactersLength = characters.length; | |
for (let i = 0; i < length; i++) { | |
result += characters.charAt(Math.floor(Math.random() * characters.length)); | |
} | |
return result; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const grouped = array.reduce((obj, item) => { | |
const key = item.age; | |
if (!obj[key]) { | |
obj[key] = []; | |
} | |
obj[key].push(item); | |
return obj; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get screen dimensions | |
const { WIDTH, HEIGHT } = Dimensions.get(); | |
// style={{ aspectRatio: image.width / image.height }} | |
const getImageStyles = (imageWidth, imageHeight) => { | |
// WIDTH - Screen Width. | |
// HEIGHT - Screen Height. | |
return { width: WIDTH, height: imageHeight / imageWidth * WIDTH }; | |
}; |
NewerOlder