Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nt/img cache optimise #2641

Merged
merged 3 commits into from Mar 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions ios/Podfile.lock
Expand Up @@ -575,7 +575,7 @@ PODS:
- React-Core
- RNDeviceInfo (10.2.1):
- React-Core
- RNFastImage (8.6.1):
- RNFastImage (8.6.3):
- React-Core
- SDWebImage (~> 5.11.1)
- SDWebImageWebPCoder (~> 0.8.4)
Expand Down Expand Up @@ -1079,7 +1079,7 @@ SPEC CHECKSUMS:
RNCClipboard: 2834e1c4af68697089cdd455ee4a4cdd198fa7dd
RNCPushNotificationIOS: 87b8d16d3ede4532745e05b03c42cff33a36cc45
RNDeviceInfo: c31137f22ee779fe3931d1a8d60cc1af80ef4077
RNFastImage: 3207b9eb17c2425d574ca40db35185db6e324f4e
RNFastImage: 5c9c9fed9c076e521b3f509fe79e790418a544e8
RNFBAnalytics: ea1421b49a0bf5e5bb7274df4a330713d0e85d2e
RNFBApp: e4439717c23252458da2b41b81b4b475c86f90c4
RNFBDynamicLinks: 538840f6e3f58511f857d15df1bc25ed655dc283
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -111,7 +111,7 @@
"react-native-dynamic": "^1.0.0",
"react-native-email-link": "^1.14.3",
"react-native-extended-stylesheet": "^0.10.0",
"react-native-fast-image": "^8.3.2",
"react-native-fast-image": "^8.6.3",
"react-native-fingerprint-scanner": "hieuvp/react-native-fingerprint-scanner",
"react-native-flipper": "^0.164.0",
"react-native-gesture-handler": "^2.9.0",
Expand Down
12 changes: 12 additions & 0 deletions src/screens/application/hook/useInitApplication.tsx
Expand Up @@ -26,6 +26,7 @@ import { markNotifications } from '../../../providers/ecency/ecency';
import { updateUnreadActivityCount } from '../../../redux/actions/accountAction';
import RootNavigation from '../../../navigation/rootNavigation';
import ROUTES from '../../../constants/routeNames';
import FastImage from 'react-native-fast-image';

export const useInitApplication = () => {
const dispatch = useAppDispatch();
Expand All @@ -35,6 +36,7 @@ export const useInitApplication = () => {

const appState = useRef(AppState.currentState);
const appStateSubRef = useRef<NativeEventSubscription | null>(null);
const lowMemSubRef = useRef<NativeEventSubscription | null>(null);

const notifeeEventRef = useRef<any>(null);
const messagingEventRef = useRef<any>(null);
Expand All @@ -57,6 +59,7 @@ export const useInitApplication = () => {
BackgroundTimer.start(); // ref: https://github.com/ocetnik/react-native-background-timer#ios

appStateSubRef.current = AppState.addEventListener('change', _handleAppStateChange);
lowMemSubRef.current = AppState.addEventListener('memoryWarning', _handleLowMemoryWarning)

// check for device landscape status and lcok orientation accordingly. Fix for orientation bug on android tablet devices
isLandscape().then((isLandscape) => {
Expand Down Expand Up @@ -93,6 +96,10 @@ export const useInitApplication = () => {
appStateSubRef.current.remove();
}

if (lowMemSubRef.current){
lowMemSubRef.current.remove();
}

if (notifeeEventRef.current) {
notifeeEventRef.current();
}
Expand Down Expand Up @@ -142,6 +149,11 @@ export const useInitApplication = () => {
appState.current = nextAppState;
};


const _handleLowMemoryWarning = () => {
FastImage.clearMemoryCache();
}

const _pushNavigate = (notification) => {
let params = null;
let key = null;
Expand Down
8 changes: 8 additions & 0 deletions src/screens/post/screen/postScreen.tsx
Expand Up @@ -7,6 +7,7 @@ import styles from '../styles/postScreen.styles';

// Component
import { postQueries } from '../../../providers/queries';
import FastImage from 'react-native-fast-image';

const PostScreen = ({ route }) => {
const params = route.params || {};
Expand All @@ -21,6 +22,13 @@ const PostScreen = ({ route }) => {
const getPostQuery = postQueries.useGetPostQuery(author, permlink, params.content);
const getParentPostQuery = postQueries.useGetPostQuery();

useEffect(()=>{
return () => {
//clears FastImage RAM, not disk usage;
FastImage.clearMemoryCache();
}
},[])

useEffect(() => {
const post = getPostQuery.data;
if (post) {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Expand Up @@ -9191,10 +9191,10 @@ react-native-extended-stylesheet@^0.10.0:
css-mediaquery "^0.1.2"
object-resolve-path "^1.1.0"

react-native-fast-image@^8.3.2:
version "8.6.1"
resolved "https://registry.yarnpkg.com/react-native-fast-image/-/react-native-fast-image-8.6.1.tgz#6a3a11b8ebc7629919265d33a420a04d13c897e0"
integrity sha512-ILuP7EuakqHNzTr8ZbumhuxG4tE/wGQ66z4nEEuzc0FlqY6rYaPsnq/UD2ahoyFj6QP1WvA2RIK3odib+VcqWg==
react-native-fast-image@^8.6.3:
version "8.6.3"
resolved "https://registry.yarnpkg.com/react-native-fast-image/-/react-native-fast-image-8.6.3.tgz#6edc3f9190092a909d636d93eecbcc54a8822255"
integrity sha512-Sdw4ESidXCXOmQ9EcYguNY2swyoWmx53kym2zRsvi+VeFCHEdkO+WG1DK+6W81juot40bbfLNhkc63QnWtesNg==

react-native-fingerprint-scanner@hieuvp/react-native-fingerprint-scanner:
version "6.0.0"
Expand Down