mirror of
https://github.com/ecency/ecency-mobile.git
synced 2025-01-07 06:32:02 +03:00
working on internet connectivity feature created structure
This commit is contained in:
parent
2398cf7830
commit
b852575410
@ -2,6 +2,7 @@ import Card from './view/card/cardView';
|
|||||||
import Chip from './view/chip/chipView';
|
import Chip from './view/chip/chipView';
|
||||||
import GrayWrapper from './view/grayWrapper/grayWrapperView';
|
import GrayWrapper from './view/grayWrapper/grayWrapperView';
|
||||||
import LineBreak from './view/lineBreak/lineBreakView';
|
import LineBreak from './view/lineBreak/lineBreakView';
|
||||||
|
import NoInternetConnection from './view/noInternetConnection/noInternetConnectionView';
|
||||||
import NoPost from './view/noPost/noPostView';
|
import NoPost from './view/noPost/noPostView';
|
||||||
import PostCardPlaceHolder from './view/placeHolder/postCardPlaceHolderView';
|
import PostCardPlaceHolder from './view/placeHolder/postCardPlaceHolderView';
|
||||||
import PostPlaceHolder from './view/placeHolder/postPlaceHolderView';
|
import PostPlaceHolder from './view/placeHolder/postPlaceHolderView';
|
||||||
@ -19,6 +20,7 @@ export {
|
|||||||
Chip,
|
Chip,
|
||||||
GrayWrapper,
|
GrayWrapper,
|
||||||
LineBreak,
|
LineBreak,
|
||||||
|
NoInternetConnection,
|
||||||
NoPost,
|
NoPost,
|
||||||
PostCardPlaceHolder,
|
PostCardPlaceHolder,
|
||||||
PostPlaceHolder,
|
PostPlaceHolder,
|
||||||
|
@ -0,0 +1,15 @@
|
|||||||
|
import EStyleSheet from 'react-native-extended-stylesheet';
|
||||||
|
|
||||||
|
export default EStyleSheet.create({
|
||||||
|
container: {
|
||||||
|
alignItems: 'center',
|
||||||
|
height: 30,
|
||||||
|
backgroundColor: '$primaryRed',
|
||||||
|
justifyContent: 'center',
|
||||||
|
},
|
||||||
|
text: {
|
||||||
|
color: '$primaryDarkGray',
|
||||||
|
fontSize: 14,
|
||||||
|
fontWeight: 'bold',
|
||||||
|
},
|
||||||
|
});
|
@ -0,0 +1,11 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { View, Text } from 'react-native';
|
||||||
|
import styles from './noInternetConnectionStyle';
|
||||||
|
|
||||||
|
const NoInternetConnection = () => (
|
||||||
|
<View style={styles.container}>
|
||||||
|
<Text style={styles.text}> No internet conenction</Text>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
|
||||||
|
export default NoInternetConnection;
|
@ -1,17 +1,18 @@
|
|||||||
import {
|
import {
|
||||||
ACTIVE_APPLICATION,
|
ACTIVE_APPLICATION,
|
||||||
CLOSE_PIN_CODE_MODAL,
|
CLOSE_PIN_CODE_MODAL,
|
||||||
|
IS_CONNECTED,
|
||||||
IS_DARK_THEME,
|
IS_DARK_THEME,
|
||||||
IS_LOGIN_DONE,
|
IS_LOGIN_DONE,
|
||||||
IS_NOTIFICATION_OPEN,
|
IS_NOTIFICATION_OPEN,
|
||||||
LOGIN,
|
LOGIN,
|
||||||
|
LOGOUT_DONE,
|
||||||
LOGOUT,
|
LOGOUT,
|
||||||
OPEN_PIN_CODE_MODAL,
|
OPEN_PIN_CODE_MODAL,
|
||||||
SET_API,
|
SET_API,
|
||||||
SET_CURRENCY,
|
SET_CURRENCY,
|
||||||
SET_LANGUAGE,
|
SET_LANGUAGE,
|
||||||
SET_UPVOTE_PERCENT,
|
SET_UPVOTE_PERCENT,
|
||||||
LOGOUT_DONE,
|
|
||||||
} from '../constants/constants';
|
} from '../constants/constants';
|
||||||
|
|
||||||
export const login = payload => ({
|
export const login = payload => ({
|
||||||
@ -73,3 +74,8 @@ export const isDarkTheme = payload => ({
|
|||||||
payload,
|
payload,
|
||||||
type: IS_DARK_THEME,
|
type: IS_DARK_THEME,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const setConnectivityStatus = payload => ({
|
||||||
|
payload,
|
||||||
|
type: IS_CONNECTED,
|
||||||
|
});
|
||||||
|
@ -6,6 +6,7 @@ export const SET_USER_DATA = 'SET_USER_DATA';
|
|||||||
// Applicaiton
|
// Applicaiton
|
||||||
export const ACTIVE_APPLICATION = 'ACTIVE_APPLICATION';
|
export const ACTIVE_APPLICATION = 'ACTIVE_APPLICATION';
|
||||||
export const CLOSE_PIN_CODE_MODAL = 'CLOSE_PIN_CODE_MODAL';
|
export const CLOSE_PIN_CODE_MODAL = 'CLOSE_PIN_CODE_MODAL';
|
||||||
|
export const IS_CONNECTED = 'IS_CONNECTED';
|
||||||
export const IS_DARK_THEME = 'IS_DARK_THEME';
|
export const IS_DARK_THEME = 'IS_DARK_THEME';
|
||||||
export const IS_LOGGED_IN = 'IS_LOGGED_IN';
|
export const IS_LOGGED_IN = 'IS_LOGGED_IN';
|
||||||
export const IS_LOGIN_DONE = 'IS_LOGIN_DONE';
|
export const IS_LOGIN_DONE = 'IS_LOGIN_DONE';
|
||||||
|
@ -1,23 +1,25 @@
|
|||||||
import {
|
import {
|
||||||
ACTIVE_APPLICATION,
|
ACTIVE_APPLICATION,
|
||||||
CLOSE_PIN_CODE_MODAL,
|
CLOSE_PIN_CODE_MODAL,
|
||||||
|
IS_CONNECTED,
|
||||||
|
IS_DARK_THEME,
|
||||||
|
IS_LOGIN_DONE,
|
||||||
|
IS_NOTIFICATION_OPEN,
|
||||||
LOGIN,
|
LOGIN,
|
||||||
|
LOGOUT_DONE,
|
||||||
LOGOUT,
|
LOGOUT,
|
||||||
OPEN_PIN_CODE_MODAL,
|
OPEN_PIN_CODE_MODAL,
|
||||||
SET_API,
|
SET_API,
|
||||||
SET_CURRENCY,
|
SET_CURRENCY,
|
||||||
SET_LANGUAGE,
|
SET_LANGUAGE,
|
||||||
IS_NOTIFICATION_OPEN,
|
|
||||||
IS_DARK_THEME,
|
|
||||||
IS_LOGIN_DONE,
|
|
||||||
SET_UPVOTE_PERCENT,
|
SET_UPVOTE_PERCENT,
|
||||||
LOGOUT_DONE,
|
|
||||||
} from '../constants/constants';
|
} from '../constants/constants';
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
api: 'api.steemit.com',
|
api: 'api.steemit.com',
|
||||||
currency: 'usd',
|
currency: 'usd',
|
||||||
isActive: false,
|
isActive: false,
|
||||||
|
isConnected: true, // internet connectivity
|
||||||
isDarkTheme: false,
|
isDarkTheme: false,
|
||||||
isLoggedIn: false, // Has any logged in user.
|
isLoggedIn: false, // Has any logged in user.
|
||||||
isLoginDone: false,
|
isLoginDone: false,
|
||||||
@ -41,6 +43,11 @@ export default function (state = initialState, action) {
|
|||||||
...state,
|
...state,
|
||||||
isLoginDone: true,
|
isLoginDone: true,
|
||||||
};
|
};
|
||||||
|
case IS_CONNECTED:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
isConnected: action.payload,
|
||||||
|
};
|
||||||
case LOGOUT:
|
case LOGOUT:
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import { Platform, BackHandler, Alert } from 'react-native';
|
import {
|
||||||
|
Platform, BackHandler, Alert, NetInfo,
|
||||||
|
} from 'react-native';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { addLocaleData } from 'react-intl';
|
import { addLocaleData } from 'react-intl';
|
||||||
import Config from 'react-native-config';
|
import Config from 'react-native-config';
|
||||||
@ -44,12 +46,13 @@ import {
|
|||||||
isLoginDone,
|
isLoginDone,
|
||||||
isNotificationOpen,
|
isNotificationOpen,
|
||||||
login,
|
login,
|
||||||
|
logoutDone,
|
||||||
openPinCodeModal,
|
openPinCodeModal,
|
||||||
setApi,
|
setApi,
|
||||||
|
setConnectivityStatus,
|
||||||
setCurrency,
|
setCurrency,
|
||||||
setLanguage,
|
setLanguage,
|
||||||
setUpvotePercent,
|
setUpvotePercent,
|
||||||
logoutDone,
|
|
||||||
} from '../../../redux/actions/applicationActions';
|
} from '../../../redux/actions/applicationActions';
|
||||||
|
|
||||||
// Container
|
// Container
|
||||||
@ -68,9 +71,21 @@ class ApplicationContainer extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount = async () => {
|
componentDidMount = async () => {
|
||||||
BackHandler.addEventListener('hardwareBackPress', this._onBackPress);
|
let isConnected;
|
||||||
await this._getUserData();
|
|
||||||
await this._getSettings();
|
await NetInfo.isConnected.fetch().then((_isConnected) => {
|
||||||
|
isConnected = _isConnected;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (isConnected) {
|
||||||
|
BackHandler.addEventListener('hardwareBackPress', this._onBackPress);
|
||||||
|
NetInfo.isConnected.addEventListener('connectionChange', this._handleConntectionChange);
|
||||||
|
|
||||||
|
this._getSettings();
|
||||||
|
await this._getUserData();
|
||||||
|
} else {
|
||||||
|
Alert.alert('No internet connection');
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
componentWillReceiveProps(nextProps) {
|
||||||
@ -87,8 +102,15 @@ class ApplicationContainer extends Component {
|
|||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
BackHandler.removeEventListener('hardwareBackPress', this.onBackPress);
|
BackHandler.removeEventListener('hardwareBackPress', this.onBackPress);
|
||||||
|
NetInfo.isConnected.removeEventListener('connectionChange', this._handleConntectionChange);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_handleConntectionChange = (isConnected) => {
|
||||||
|
const { dispatch } = this.props;
|
||||||
|
|
||||||
|
dispatch(setConnectivityStatus(isConnected));
|
||||||
|
};
|
||||||
|
|
||||||
_onBackPress = () => {
|
_onBackPress = () => {
|
||||||
const { dispatch } = this.props;
|
const { dispatch } = this.props;
|
||||||
|
|
||||||
@ -260,7 +282,7 @@ class ApplicationContainer extends Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { selectedLanguage } = this.props;
|
const { selectedLanguage, isConnected } = this.props;
|
||||||
const { isRenderRequire, isReady } = this.state;
|
const { isRenderRequire, isReady } = this.state;
|
||||||
|
|
||||||
// For testing It comented out.
|
// For testing It comented out.
|
||||||
@ -270,7 +292,7 @@ class ApplicationContainer extends Component {
|
|||||||
// || selectedLanguage;
|
// || selectedLanguage;
|
||||||
|
|
||||||
if (isRenderRequire && isReady) {
|
if (isRenderRequire && isReady) {
|
||||||
return <ApplicationScreen locale={selectedLanguage} {...this.props} />;
|
return <ApplicationScreen isConnected={isConnected} locale={selectedLanguage} {...this.props} />;
|
||||||
}
|
}
|
||||||
return <Launch />;
|
return <Launch />;
|
||||||
}
|
}
|
||||||
@ -283,6 +305,7 @@ const mapStateToProps = state => ({
|
|||||||
notificationSettings: state.application.isNotificationOpen,
|
notificationSettings: state.application.isNotificationOpen,
|
||||||
isLogingOut: state.application.isLogingOut,
|
isLogingOut: state.application.isLogingOut,
|
||||||
isLoggedIn: state.application.isLoggedIn,
|
isLoggedIn: state.application.isLoggedIn,
|
||||||
|
isConnected: state.application.isConnected,
|
||||||
|
|
||||||
// Account
|
// Account
|
||||||
unreadActivityCount: state.account.currentAccount.unread_activity_count,
|
unreadActivityCount: state.account.currentAccount.unread_activity_count,
|
||||||
|
@ -1,11 +1,16 @@
|
|||||||
import React, { Component, Fragment } from 'react';
|
import React, { Component, Fragment } from 'react';
|
||||||
import { IntlProvider } from 'react-intl';
|
import { IntlProvider } from 'react-intl';
|
||||||
import { StatusBar, Platform } from 'react-native';
|
import {
|
||||||
|
View, Text, StatusBar, Platform,
|
||||||
|
} from 'react-native';
|
||||||
import EStyleSheet from 'react-native-extended-stylesheet';
|
import EStyleSheet from 'react-native-extended-stylesheet';
|
||||||
import { ReduxNavigation } from '../../../navigation/reduxNavigation';
|
import { ReduxNavigation } from '../../../navigation/reduxNavigation';
|
||||||
import { flattenMessages } from '../../../utils/flattenMessages';
|
import { flattenMessages } from '../../../utils/flattenMessages';
|
||||||
import messages from '../../../config/locales';
|
import messages from '../../../config/locales';
|
||||||
|
|
||||||
|
// Components
|
||||||
|
import { NoInternetConnection } from '../../../components/basicUIElements';
|
||||||
|
|
||||||
// Themes (Styles)
|
// Themes (Styles)
|
||||||
import darkTheme from '../../../themes/darkTheme';
|
import darkTheme from '../../../themes/darkTheme';
|
||||||
import lightTheme from '../../../themes/lightTheme';
|
import lightTheme from '../../../themes/lightTheme';
|
||||||
@ -22,7 +27,7 @@ class ApplicationScreen extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { locale, isDarkTheme } = this.props;
|
const { isConnected, isDarkTheme, locale } = this.props;
|
||||||
const barStyle = isDarkTheme ? 'light-content' : 'dark-content';
|
const barStyle = isDarkTheme ? 'light-content' : 'dark-content';
|
||||||
const barColor = isDarkTheme ? '#1e2835' : '#fff';
|
const barColor = isDarkTheme ? '#1e2835' : '#fff';
|
||||||
|
|
||||||
@ -34,6 +39,12 @@ class ApplicationScreen extends Component {
|
|||||||
<StatusBar barStyle={barStyle} backgroundColor={barColor} />
|
<StatusBar barStyle={barStyle} backgroundColor={barColor} />
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{!isConnected && (
|
||||||
|
<IntlProvider locale={locale} messages={flattenMessages(messages[locale])}>
|
||||||
|
<NoInternetConnection />
|
||||||
|
</IntlProvider>
|
||||||
|
)}
|
||||||
|
|
||||||
<IntlProvider locale={locale} messages={flattenMessages(messages[locale])}>
|
<IntlProvider locale={locale} messages={flattenMessages(messages[locale])}>
|
||||||
<ReduxNavigation />
|
<ReduxNavigation />
|
||||||
</IntlProvider>
|
</IntlProvider>
|
||||||
|
Loading…
Reference in New Issue
Block a user