mirror of
https://github.com/ecency/ecency-mobile.git
synced 2025-01-04 03:56:54 +03:00
introduced app intiailiser hook for better code management
This commit is contained in:
parent
3e6ce86a5f
commit
5269c6bea2
@ -7,17 +7,14 @@ import changeNavigationBarColor from 'react-native-navigation-bar-color';
|
||||
import { connect } from 'react-redux';
|
||||
import { injectIntl } from 'react-intl';
|
||||
import { bindActionCreators } from 'redux';
|
||||
import EStyleSheet from 'react-native-extended-stylesheet';
|
||||
import { isEmpty, some } from 'lodash';
|
||||
import messaging from '@react-native-firebase/messaging';
|
||||
import PushNotification from 'react-native-push-notification';
|
||||
import VersionNumber from 'react-native-version-number';
|
||||
import ReceiveSharingIntent from 'react-native-receive-sharing-intent';
|
||||
import SplashScreen from 'react-native-splash-screen';
|
||||
import DeviceInfo from 'react-native-device-info';
|
||||
|
||||
// Constants
|
||||
import Orientation from 'react-native-orientation-locker';
|
||||
import AUTH_TYPE from '../../../constants/authType';
|
||||
import ROUTES from '../../../constants/routeNames';
|
||||
|
||||
@ -71,7 +68,6 @@ import {
|
||||
} from '../../../redux/actions/applicationActions';
|
||||
import {
|
||||
setAvatarCacheStamp,
|
||||
setLockedOrientation,
|
||||
showActionModal,
|
||||
toastNotification,
|
||||
updateActiveBottomTab,
|
||||
@ -81,8 +77,6 @@ import { fetchCoinQuotes } from '../../../redux/actions/walletActions';
|
||||
|
||||
import { decryptKey, encryptKey } from '../../../utils/crypto';
|
||||
|
||||
import darkTheme from '../../../themes/darkTheme';
|
||||
import lightTheme from '../../../themes/lightTheme';
|
||||
import persistAccountGenerator from '../../../utils/persistAccountGenerator';
|
||||
import parseVersionNumber from '../../../utils/parseVersionNumber';
|
||||
import { setMomentLocale } from '../../../utils/time';
|
||||
@ -91,8 +85,6 @@ import { fetchSubscribedCommunities } from '../../../redux/actions/communitiesAc
|
||||
import MigrationHelpers from '../../../utils/migrationHelpers';
|
||||
import { deepLinkParser } from '../../../utils/deepLinkParser';
|
||||
import bugsnapInstance from '../../../config/bugsnag';
|
||||
import isAndroidTablet from '../../../utils/isAndroidTablet';
|
||||
import { orientations } from '../../../redux/constants/orientationsConstants';
|
||||
|
||||
let firebaseOnNotificationOpenedAppListener = null;
|
||||
let firebaseOnMessageListener = null;
|
||||
@ -879,21 +871,6 @@ class ApplicationContainer extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
UNSAFE_componentWillMount() {
|
||||
const { isDarkTheme: _isDarkTheme, dispatch } = this.props as any;
|
||||
// check for device landscape status and lcok orientation accordingly. Fix for orientation bug on android tablet devices
|
||||
DeviceInfo.isLandscape().then((isLandscape) => {
|
||||
if (isLandscape && isAndroidTablet()) {
|
||||
Orientation.lockToLandscape();
|
||||
dispatch(setLockedOrientation(orientations.LANDSCAPE));
|
||||
} else {
|
||||
Orientation.lockToPortrait();
|
||||
dispatch(setLockedOrientation(orientations.PORTRAIT));
|
||||
}
|
||||
});
|
||||
EStyleSheet.build(_isDarkTheme ? darkTheme : lightTheme);
|
||||
}
|
||||
|
||||
render() {
|
||||
const {
|
||||
selectedLanguage,
|
||||
|
35
src/screens/application/hook/useInitApplication.tsx
Normal file
35
src/screens/application/hook/useInitApplication.tsx
Normal file
@ -0,0 +1,35 @@
|
||||
import { useEffect } from 'react';
|
||||
import Orientation, { useDeviceOrientationChange } from 'react-native-orientation-locker';
|
||||
import { isLandscape } from 'react-native-device-info';
|
||||
import EStyleSheet from 'react-native-extended-stylesheet';
|
||||
import { useAppDispatch, useAppSelector } from '../../../hooks';
|
||||
import { setDeviceOrientation, setLockedOrientation } from '../../../redux/actions/uiAction';
|
||||
import { orientations } from '../../../redux/constants/orientationsConstants';
|
||||
import isAndroidTablet from '../../../utils/isAndroidTablet';
|
||||
import darkTheme from '../../../themes/darkTheme';
|
||||
import lightTheme from '../../../themes/lightTheme';
|
||||
|
||||
export const useInitApplication = () => {
|
||||
const dispatch = useAppDispatch();
|
||||
const isDarkTheme = useAppSelector((state) => state.application.isDarkTheme);
|
||||
|
||||
useDeviceOrientationChange((o) => {
|
||||
// Handle device orientation change
|
||||
console.log('device orientation changed : ', o);
|
||||
dispatch(setDeviceOrientation(o));
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
// check for device landscape status and lcok orientation accordingly. Fix for orientation bug on android tablet devices
|
||||
isLandscape().then((isLandscape) => {
|
||||
if (isLandscape && isAndroidTablet()) {
|
||||
Orientation.lockToLandscape();
|
||||
dispatch(setLockedOrientation(orientations.LANDSCAPE));
|
||||
} else {
|
||||
Orientation.lockToPortrait();
|
||||
dispatch(setLockedOrientation(orientations.PORTRAIT));
|
||||
}
|
||||
});
|
||||
EStyleSheet.build(isDarkTheme ? darkTheme : lightTheme);
|
||||
}, []);
|
||||
};
|
@ -1,25 +1,14 @@
|
||||
import React from 'react';
|
||||
|
||||
import { useDeviceOrientationChange, useOrientationChange } from 'react-native-orientation-locker';
|
||||
import { useDispatch } from 'react-redux';
|
||||
import ApplicationContainer from './container/applicationContainer';
|
||||
import ApplicationScreen from './children/applicationScreen';
|
||||
import ErrorBoundary from './children/errorBoundary';
|
||||
import { setDeviceOrientation } from '../../redux/actions/uiAction';
|
||||
import { useInitApplication } from './hook/useInitApplication';
|
||||
|
||||
const Application = () => {
|
||||
const dispatch = useDispatch();
|
||||
|
||||
useOrientationChange((o) => {
|
||||
// Handle orientation change
|
||||
console.log('UI orientation changed : ', o);
|
||||
});
|
||||
|
||||
useDeviceOrientationChange((o) => {
|
||||
// Handle device orientation change
|
||||
console.log('device orientation changed : ', o);
|
||||
dispatch(setDeviceOrientation(o));
|
||||
});
|
||||
//New hook to handle all custom app initializations
|
||||
//it will help clean index.tsx stay clean and completely discard ApplicationContainer moving forward
|
||||
useInitApplication();
|
||||
|
||||
return (
|
||||
<ApplicationContainer>
|
||||
|
@ -24,7 +24,8 @@ const getWindowDimensions = () => {
|
||||
const height = isDeviceRotated ? nativeDimensions.width : nativeDimensions.height;
|
||||
|
||||
if (isAndroidTablet()) {
|
||||
// return default dimension if device is android tablet. There is an issue on certain android tablets in locking orientation which is handled separatly and used default dimensions
|
||||
// return default dimension if device is android tablet.
|
||||
//There is an issue on certain android tablets in locking orientation which is handled separatly and used default dimensions
|
||||
return {
|
||||
width: nativeDimensions.width,
|
||||
height: nativeDimensions.height,
|
||||
|
Loading…
Reference in New Issue
Block a user