Skip to content

Instantly share code, notes, and snippets.

View vincicat's full-sized avatar

Vinci vincicat

View GitHub Profile
@vincicat
vincicat / React-native_caveats.md
Last active March 15, 2024 15:39
React native caveats

Modal / BottomSheet / React-Navigation Modal presentation

iOS-only.

Open an Modal On/Off in short duration will "freeze" the App - and no way to resolve it as the app stop to respond if this occur (RN hide the error):

Warning: Attempt to present <UIViewController: [hash1]> on <UIViewController: [hash2]> which is already presenting (null)

Analysis

@vincicat
vincicat / elden-ring-equip-acquire.csv
Last active November 27, 2023 11:18
elden ring gear with effects (zh-TW)
名稱 取得方法
布質套裝 寧姆格福-濛流洞窟,BOSS房打開帕奇的寶箱
旅行套裝 米凱拉的聖樹-聖樹底層-附近探索撿取整套
居民套裝 居民頭巾(輕裝)、居民上衣和居民鞋子:刷史東薇爾城的平民敵人掉落; 居民便衣:在史東薇爾城-門旁小屋-出陽台撿; 居民頭巾:格密爾火山-艾格蕾教堂上山後遇到的鞭子蛇人右側欄桿向外延伸的蛇頭雕像上撿
權貴套裝 權貴頭帶&權貴上衣&權貴靴子,徘徊權貴法師掉落,魔法學院-校舍內的教室外面刷; 權貴上衣(輕裝)由普通權貴掉落,權貴帽子和權貴大衣由羽毛帽類型的權貴掉落; *寧姆格福-驛站街遺跡,外面的巨人寶車護送隊伍,可以刷全部權貴套裝&年邁系列
年邁權貴套裝 年邁權貴是那種拿旗子吹號角的徘徊權貴;推結緣教堂門口
@vincicat
vincicat / axios-error.md
Last active August 24, 2023 09:34
axios default error messages (v1.x)

Axios Message and error code

Message code
"Request aborted" ECONNABORTED
"Network Error" ERR_NETWORK
config.timeoutErrorMessage transitional.clarifyTimeoutError ? ETIMEDOUT : ECONNABORTED
"timeout exceeded" transitional.clarifyTimeoutError ? ETIMEDOUT : ECONNABORTED
"timeout of " + config.timeout + "ms exceeded" transitional.clarifyTimeoutError ? ETIMEDOUT : ECONNABORTED
"Unsupported protocol " + protocol + ":" ERR_BAD_REQUEST

Intro

The idea of this is to list the App.js I used for library testing so

a. I don't need a mega repo for everything I tested in React Native (from the installation limitation on physical device to disk space and so on you don't want to have a standalone App for every library you tested)

b. easy demo in snack.io, which is also famous for 'bad to native modules' - so the dependency should be minimal

The current testing enviroment is RN 0.70.7+

@vincicat
vincicat / App.js
Last active March 10, 2023 21:35
Single-File JavaScript Example: react-query in React Native (0.70)
/* eslint-disable react-native/no-inline-styles */
import * as React from 'react';
import movies from './data/movies.json';
import {
AppStateStatus,
Platform,
AppState,
TouchableHighlight,
ActivityIndicator,
View,
@vincicat
vincicat / App.js
Last active March 10, 2023 21:50
Single-File JavaScript Example: useSWR in React Native
/* eslint-disable react-native/no-inline-styles */
import React, {useEffect, useRef} from 'react';
import {View, Text, AppState, StyleSheet, SafeAreaView} from 'react-native';
import NetInfo from '@react-native-community/netinfo';
import useSWR, {SWRConfig} from 'swr';
import {FlatList} from 'react-native-gesture-handler';
const randomInt = range => Math.floor(Math.random() * range);
// https://github.com/vercel/swr/discussions/532
const initFocusOld = revalidate => {
@vincicat
vincicat / scrollview.md
Created March 2, 2023 16:04
ScrollView & FlatList ceveats...

ScrollView

onMomentumScrollEnd

Some mention onMomentumScrollEnd will fire multiple times. To solve it we need a solution that will not trigger re-rendering like Ref or SharedValue (Reanimated 2)

  import { useSharedValue } from 'react-native-reanimated';
  const canMomentum = useSharedValue(false); // or use `useRef` API
@vincicat
vincicat / Promise.md
Created February 9, 2023 16:16
smalltalk on JS promises.

Small detail everywhere.

Issues

  1. yes you can resolve with an object with property function then() (also known as thenable), but some engine will not allow you chain the then() call if you resolve your promise in that way.

solution:

a. use Promise.all() to queue your callbacks;

@vincicat
vincicat / MapExample.js
Created August 11, 2022 15:13
Bottom Sheet Example with Map (Standalone)
// @gorhom/bottom-sheet@^4
import React, {
useCallback,
useLayoutEffect,
useMemo,
useRef,
// useState,
} from 'react';
import { View, StyleSheet, Dimensions, Text } from 'react-native';
import MapView from 'react-native-maps';
@vincicat
vincicat / useScreenReaderEnabled.js
Created June 20, 2022 14:35
Hook for properly use `screenReaderEnabled` (RN 0.68+)
import React, { useEffect, useState } from 'react';
import { AccessibilityInfo } from 'react-native';
const useScreenReaderEnabled = () => {
const [screenReaderEnabled, setScreenReaderEnabled] = useState(false);
useEffect(() => {
const screenReaderChangedSubscription = AccessibilityInfo.addEventListener(
"screenReaderChanged",
(screenReaderEnabled) => {
setScreenReaderEnabled(screenReaderEnabled);