From 48481a4cd5474dfcda65215dc4579dd291f4d4fb Mon Sep 17 00:00:00 2001 From: xmflsct Date: Wed, 8 Feb 2023 19:22:20 +0100 Subject: [PATCH] Improve auto fetch --- src/App.tsx | 5 +---- src/components/Instance/index.tsx | 6 +++--- src/components/Timeline/index.tsx | 24 +++++++++++++++--------- src/screens/Tabs/Me/Push.tsx | 4 ++-- src/screens/Tabs/Me/Settings/App.tsx | 2 +- src/utils/api/general.ts | 2 +- src/utils/api/helpers/connect.ts | 2 +- src/utils/api/helpers/index.ts | 2 +- src/utils/api/instance.ts | 2 +- src/utils/storage/index.ts | 4 ++++ 10 files changed, 30 insertions(+), 23 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 32072655..89748fed 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -11,6 +11,7 @@ import log from '@utils/startup/log' import netInfo from '@utils/startup/netInfo' import push from '@utils/startup/push' import sentry from '@utils/startup/sentry' +import { GLOBAL } from '@utils/storage' import { getGlobalStorage, setAccount, setGlobalStorage } from '@utils/storage/actions' import { migrateFromAsyncStorage, versionStorageGlobal } from '@utils/storage/migrations/toMMKV' import ThemeManager from '@utils/styles/ThemeManager' @@ -24,10 +25,6 @@ import { enableFreeze } from 'react-native-screens' import i18n from './i18n' import Screens from './screens' -export const GLOBAL: { connect?: boolean } = { - connect: undefined -} - Platform.select({ android: LogBox.ignoreLogs(['Setting a timer for a long period of time']) }) diff --git a/src/components/Instance/index.tsx b/src/components/Instance/index.tsx index f4fba00f..d9997133 100644 --- a/src/components/Instance/index.tsx +++ b/src/components/Instance/index.tsx @@ -19,8 +19,8 @@ import { import { StyleConstants } from '@utils/styles/constants' import { useTheme } from '@utils/styles/ThemeManager' import * as AuthSession from 'expo-auth-session' +import * as Crypto from 'expo-crypto' import { Image } from 'expo-image' -import * as Random from 'expo-random' import * as WebBrowser from 'expo-web-browser' import { debounce } from 'lodash' import React, { RefObject, useCallback, useState } from 'react' @@ -162,7 +162,7 @@ const ComponentInstance: React.FC = ({ 'admin.sign_up': false, 'admin.report': false }, - key: fromByteArray(Random.getRandomBytes(16)) + key: fromByteArray(Crypto.getRandomBytes(16)) }, page_local: { showBoosts: true, @@ -233,7 +233,7 @@ const ComponentInstance: React.FC = ({ ) : null} diff --git a/src/components/Timeline/index.tsx b/src/components/Timeline/index.tsx index 9319852c..13ff0573 100644 --- a/src/components/Timeline/index.tsx +++ b/src/components/Timeline/index.tsx @@ -134,15 +134,6 @@ const Timeline: React.FC = ({ { onScroll: ({ contentOffset: { y } }) => { scrollY.value = y - if ( - y < 300 && - !isFetchingPrev.value && - fetchingType.value === 0 && - shouldAutoFetch.value && - Platform.OS === 'ios' - ) { - fetchingType.value = 1 - } }, onEndDrag: ({ contentOffset: { y } }) => { if (!disableRefresh && !isFetching) { @@ -157,6 +148,21 @@ const Timeline: React.FC = ({ }, [isFetching] ) + useAnimatedReaction( + () => scrollY.value < 600, + (curr, prev) => { + if ( + curr === true && + prev === false && + !isFetchingPrev.value && + fetchingType.value === 0 && + shouldAutoFetch.value && + Platform.OS === 'ios' + ) { + fetchingType.value = 1 + } + } + ) const latestMarker = useRef() const updateMarkers = useCallback( diff --git a/src/screens/Tabs/Me/Push.tsx b/src/screens/Tabs/Me/Push.tsx index 14acb6b1..3fdf1fe7 100644 --- a/src/screens/Tabs/Me/Push.tsx +++ b/src/screens/Tabs/Me/Push.tsx @@ -16,8 +16,8 @@ import { setAccountStorage, useAccountStorage, useGlobalStorage } from '@utils/s import { StyleConstants } from '@utils/styles/constants' import layoutAnimation from '@utils/styles/layoutAnimation' import { useTheme } from '@utils/styles/ThemeManager' +import * as Crypto from 'expo-crypto' import * as Notifications from 'expo-notifications' -import * as Random from 'expo-random' import * as WebBrowser from 'expo-web-browser' import React, { useEffect, useState } from 'react' import { useTranslation } from 'react-i18next' @@ -173,7 +173,7 @@ const TabMePush: React.FC = () => { // Fix a bug for some users of v4.8.0 let authKey = push.key if (push.key?.length <= 10) { - authKey = fromByteArray(Random.getRandomBytes(16)) + authKey = fromByteArray(Crypto.getRandomBytes(16)) } // Turning on const randomPath = (Math.random() + 1).toString(36).substring(2) diff --git a/src/screens/Tabs/Me/Settings/App.tsx b/src/screens/Tabs/Me/Settings/App.tsx index 82584399..642dee40 100644 --- a/src/screens/Tabs/Me/Settings/App.tsx +++ b/src/screens/Tabs/Me/Settings/App.tsx @@ -5,13 +5,13 @@ import { LOCALES } from '@i18n/locales' import { useNavigation } from '@react-navigation/native' import { connectVerify } from '@utils/api/helpers/connect' import { androidActionSheetStyles } from '@utils/helpers/androidActionSheetStyles' +import { GLOBAL } from '@utils/storage' import { useGlobalStorage } from '@utils/storage/actions' import { useTheme } from '@utils/styles/ThemeManager' import * as Localization from 'expo-localization' import React, { useEffect, useState } from 'react' import { useTranslation } from 'react-i18next' import { Linking, Platform } from 'react-native' -import { GLOBAL } from '../../../../App' import { mapFontsizeToName } from '../SettingsFontsize' const SettingsApp: React.FC = () => { diff --git a/src/utils/api/general.ts b/src/utils/api/general.ts index 2dd214d5..9da3fc4c 100644 --- a/src/utils/api/general.ts +++ b/src/utils/api/general.ts @@ -1,5 +1,5 @@ +import { GLOBAL } from '@utils/storage' import axios from 'axios' -import { GLOBAL } from '../../App' import { ctx, handleError, PagedResponse, parseHeaderLinks, userAgent } from './helpers' import { CONNECT_DOMAIN } from './helpers/connect' diff --git a/src/utils/api/helpers/connect.ts b/src/utils/api/helpers/connect.ts index ebc7d66c..a84601ef 100644 --- a/src/utils/api/helpers/connect.ts +++ b/src/utils/api/helpers/connect.ts @@ -1,9 +1,9 @@ import { mapEnvironment } from '@utils/helpers/checkEnvironment' +import { GLOBAL } from '@utils/storage' import { setGlobalStorage } from '@utils/storage/actions' import axios from 'axios' import parse from 'url-parse' import { userAgent } from '.' -import { GLOBAL } from '../../../App' const list = [ 'n61owz4leck', diff --git a/src/utils/api/helpers/index.ts b/src/utils/api/helpers/index.ts index ff796526..c65ec17c 100644 --- a/src/utils/api/helpers/index.ts +++ b/src/utils/api/helpers/index.ts @@ -1,10 +1,10 @@ import * as Sentry from '@sentry/react-native' +import { GLOBAL } from '@utils/storage' import { setGlobalStorage } from '@utils/storage/actions' import chalk from 'chalk' import Constants from 'expo-constants' import { Platform } from 'react-native' import parse from 'url-parse' -import { GLOBAL } from '../../../App' const userAgent = { 'User-Agent': `tooot/${Constants.expoConfig?.version} ${Platform.OS}/${Platform.Version}` diff --git a/src/utils/api/instance.ts b/src/utils/api/instance.ts index ea91d425..7b6c115a 100644 --- a/src/utils/api/instance.ts +++ b/src/utils/api/instance.ts @@ -1,7 +1,7 @@ +import { GLOBAL } from '@utils/storage' import { getAccountDetails } from '@utils/storage/actions' import { StorageGlobal } from '@utils/storage/global' import axios, { AxiosRequestConfig } from 'axios' -import { GLOBAL } from '../../App' import { ctx, handleError, PagedResponse, parseHeaderLinks, userAgent } from './helpers' import { CONNECT_DOMAIN } from './helpers/connect' diff --git a/src/utils/storage/index.ts b/src/utils/storage/index.ts index d27cc26f..3b8bca51 100644 --- a/src/utils/storage/index.ts +++ b/src/utils/storage/index.ts @@ -4,3 +4,7 @@ import { MMKV } from 'react-native-mmkv' export const storage: { global: MMKV; account?: MMKV } = { global: new MMKV(), account: undefined } export const secureStorage = createSecureStore() + +export const GLOBAL: { connect?: boolean } = { + connect: undefined +}