Skip to content

Commit

Permalink
Render main screen faster. Small fixes. (#1145)
Browse files Browse the repository at this point in the history
  • Loading branch information
borisyankov committed Sep 9, 2017
1 parent 664dc67 commit 400971c
Show file tree
Hide file tree
Showing 14 changed files with 83 additions and 79 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
"date-fns": "^1.28.5",
"entities": "^1.1.1",
"events": "^1.1.1",
"g": "^2.0.1",
"htmlparser2": "^3.9.2",
"immutable": "^3.8.1",
"lodash.isequal": "^4.4.0",
Expand Down
5 changes: 4 additions & 1 deletion src/Providers.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import '../vendor/intl/intl';
import messages from './i18n/messages';
import StylesProvider from './StylesProvider';
import AppContainer from './nav/AppContainer';
import CompatibilityChecker from './nav/CompatibilityChecker';

require('./i18n/locale');

Expand All @@ -23,7 +24,9 @@ class Providers extends PureComponent {
return (
<IntlProvider key={locale} locale={locale} textComponent={Text} messages={messages[locale]}>
<StylesProvider key={theme} theme={theme}>
<AppContainer />
<CompatibilityChecker>
<AppContainer />
</CompatibilityChecker>
</StylesProvider>
</IntlProvider>
);
Expand Down
12 changes: 0 additions & 12 deletions src/StoreHydrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,21 @@ import { Provider } from 'react-redux';

import store, { restore } from './store';
import timing from './utils/timing';
import LoadingScreen from './start/LoadingScreen';
import Providers from './Providers';

export default class StoreHydrator extends PureComponent {
state: {
isHydrated: boolean,
};

state = {
isHydrated: false,
};

componentWillMount() {
timing.start('Store hydration');
restore(() => {
timing.end('Store hydration');
this.setState({ isHydrated: true });
});
}

render() {
const { isHydrated } = this.state;

if (!isHydrated) {
return <LoadingScreen />;
}

return (
<Provider store={store}>
<Providers />
Expand Down
2 changes: 2 additions & 0 deletions src/app/appReducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const initialState: AppState = {
editMessage: null,
isOnline: true,
isActive: true,
isHydrated: false,
lastActivityTime: new Date(),
needsInitialFetch: false,
orientation: 'PORTRAIT',
Expand All @@ -50,6 +51,7 @@ export default (state: AppState = initialState, action: Action) => {
case REHYDRATE:
return {
...state,
isHydrated: true,
needsInitialFetch: !!getAuth(action.payload).apiKey,
};

Expand Down
9 changes: 1 addition & 8 deletions src/main/MainScreenContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import isEqual from 'lodash.isequal';

import type { Actions, Message, Narrow } from '../types';
import boundActions from '../boundActions';
import { getShownMessagesInActiveNarrow } from '../selectors';
import MainScreen from './MainScreenWithDrawers';
// import MainScreen from './MainScreenWithTabs';

Expand All @@ -28,10 +27,4 @@ class MainScreenContainer extends PureComponent {
}
}

export default connect(
state => ({
narrow: state.chat.narrow,
messages: getShownMessagesInActiveNarrow(state),
}),
boundActions,
)(MainScreenContainer);
export default connect(null, boundActions)(MainScreenContainer);
2 changes: 2 additions & 0 deletions src/main/MainScreenWithTabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import React, { PureComponent } from 'react';
import { StyleSheet, View } from 'react-native';

import { ZulipStatusBar } from '../common';
import MainNavBar from '../nav/MainNavBar';
import MainTabs from './MainTabs';

Expand All @@ -16,6 +17,7 @@ export default class MainScreenWithTabs extends PureComponent {
render() {
return (
<View style={styles.wrapper}>
<ZulipStatusBar />
<MainNavBar />
<MainTabs />
</View>
Expand Down
4 changes: 2 additions & 2 deletions src/main/MainTabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { BRAND_COLOR } from '../styles';
import UnreadStreamsContainer from '../unread/UnreadStreamsContainer';
import StreamTabs from '../nav/StreamTabs';
import ConversationsContainer from '../conversations/ConversationsContainer';
import SettingsCard from '../settings/SettingsCard';
import SettingsContainer from '../settings/SettingsContainer';
import { IconHome, IconStream, IconPrivateChat, IconSettings } from '../common/Icons';

export default TabNavigator(
Expand All @@ -33,7 +33,7 @@ export default TabNavigator(
},
},
settings: {
screen: SettingsCard,
screen: SettingsContainer,
navigationOptions: {
tabBarLabel: 'Settings',
tabBarIcon: ({ tintColor }) => <IconSettings size={24} color={tintColor} />,
Expand Down
1 change: 1 addition & 0 deletions src/message/MessageListContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { connectActionSheet } from '@expo/react-native-action-sheet';

import boundActions from '../boundActions';
import MessageList from './MessageList';
// import MessageList from './MessageListFlatList';
import {
getAuth,
getCurrentTypingUsers,
Expand Down
18 changes: 17 additions & 1 deletion src/message/MessageListFlatList.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { SectionList } from 'react-native';

import type { Actions, TypingState } from '../types';
import { nullFunction } from '../nullObjects';
import { LoadingIndicator } from '../common';
import MessageListSection from './MessageListSection';
import MessageListItem from './MessageListItem';

Expand All @@ -17,8 +18,10 @@ export default class MessageList extends PureComponent {
typingUsers?: TypingState,
fetchingOlder: boolean,
fetchingNewer: boolean,
singleFetchProgress: boolean,
renderedMessages: Object[],
listRef: (component: Object) => void,
onScroll: () => void,
};

static defaultProps = {
Expand All @@ -27,7 +30,19 @@ export default class MessageList extends PureComponent {

render() {
const { styles } = this.context;
const { actions, renderedMessages, fetchingOlder, listRef } = this.props;
const {
actions,
renderedMessages,
singleFetchProgress,
fetchingOlder,
fetchingNewer,
listRef,
onScroll,
} = this.props;

if (!singleFetchProgress && fetchingNewer) {
return <LoadingIndicator active />;
}

return (
<SectionList
Expand All @@ -43,6 +58,7 @@ export default class MessageList extends PureComponent {
onStartReached={actions.fetchOlder}
onEndReached={actions.fetchNewer}
onRefresh={actions.fetchOlder}
onScroll={onScroll}
ref={component => {
if (listRef) listRef(component);
}}
Expand Down
20 changes: 0 additions & 20 deletions src/message/MessageListWeb.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,6 @@ export default class MessageListWeb extends PureComponent {
}
};

componentDidMount = () => {};
/*
shouldComponentUpdate = (nextProps) => {
// if (this.props.messages.length < nextProps.messages.length) {
console.log('NEW MSGS');
// this.webview.postMessage(JSON.stringify({
// type: 'message',
// html: '<div>Hello World</div>'
// }));
console.log(nextProps.messages.length - this.props.messages.length);
console.log(nextProps.messages.slice(nextProps.messages.length - this.props.messages.length));
// }
if (this.once) {
return false;
}
this.once = true;
return true;
};
*/
render() {
const { auth } = this.props;
const messagesHtml = renderMessagesAsHtml(this.props);
Expand Down
26 changes: 8 additions & 18 deletions src/nav/AppContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import React, { PureComponent } from 'react';
import { AppState, BackHandler, NetInfo, View } from 'react-native';
import { connect } from 'react-redux';

import { Auth, Actions } from '../types';
import boundActions from '../boundActions';
import AppWithNavigationState from './AppWithNavigationState';
import { getAuth, getNavigationIndex } from '../selectors';
import { registerAppActivity } from '../utils/activity';
import { checkCompatibility } from '../api';
import CompatibilityScreen from '../start/CompatibilityScreen';
import { Auth, Actions } from '../types';
import LoadingScreen from '../start/LoadingScreen';

type Props = {
auth: Auth,
navIndex: number,
isHydrated: boolean,
needsInitialFetch: boolean,
actions: Actions,
};
Expand All @@ -24,10 +24,6 @@ class AppContainer extends PureComponent {
};
props: Props;

state = {
compatibilityCheckFail: false,
};

handleLayout = event => {
const { actions } = this.props;
const { width, height } = event.nativeEvent.layout;
Expand Down Expand Up @@ -56,7 +52,7 @@ class AppContainer extends PureComponent {
return true;
}
return false;
}
};

handleMemoryWarning = () => {
// Release memory here
Expand All @@ -67,13 +63,6 @@ class AppContainer extends PureComponent {
AppState.addEventListener('change', this.handleAppStateChange);
AppState.addEventListener('memoryWarning', this.handleMemoryWarning);
BackHandler.addEventListener('hardwareBackPress', this.handleBackButtonPress);
checkCompatibility().then(res => {
if (res.status === 400) {
this.setState({
compatibilityCheckFail: true,
});
}
});
}

componentWillUnmount() {
Expand All @@ -95,10 +84,10 @@ class AppContainer extends PureComponent {
};

render() {
const { compatibilityCheckFail } = this.state;
const { isHydrated } = this.props;

if (compatibilityCheckFail) {
return <CompatibilityScreen />;
if (!isHydrated) {
return <LoadingScreen />;
}

return (
Expand All @@ -112,6 +101,7 @@ class AppContainer extends PureComponent {
export default connect(
state => ({
auth: getAuth(state),
isHydrated: state.app.isHydrated,
needsInitialFetch: state.app.needsInitialFetch,
navIndex: getNavigationIndex(state),
}),
Expand Down
27 changes: 27 additions & 0 deletions src/nav/CompatibilityChecker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* @flow */
import React, { PureComponent } from 'react';

import { checkCompatibility } from '../api';
import CompatibilityScreen from '../start/CompatibilityScreen';

export default class CompatibilityChecker extends PureComponent {
state = {
compatibilityCheckFail: false,
};

componentDidMount() {
checkCompatibility().then(res => {
if (res.status === 400) {
this.setState({
compatibilityCheckFail: true,
});
}
});
}

render() {
const { compatibilityCheckFail } = this.state;

return compatibilityCheckFail ? <CompatibilityScreen /> : this.props.children;
}
}
16 changes: 16 additions & 0 deletions src/settings/SettingsContainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* TODO flow */
import { connect } from 'react-redux';

import boundActions from '../boundActions';
import { getAuth } from '../selectors';
import SettingsCard from './SettingsCard';

export default connect(
state => ({
offlineNotification: state.settings.offlineNotification,
onlineNotification: state.settings.onlineNotification,
theme: state.settings.theme,
auth: getAuth(state),
}),
boundActions,
)(SettingsCard);
19 changes: 3 additions & 16 deletions src/settings/SettingsScreen.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,15 @@
/* TODO flow */
import React, { PureComponent } from 'react';
import { connect } from 'react-redux';

import boundActions from '../boundActions';
import { getAuth } from '../selectors';
import { Screen } from '../common';
import SettingsCard from './SettingsCard';
import SettingsContainer from './SettingsContainer';

class SettingsScreen extends PureComponent {
export default class SettingsScreen extends PureComponent {
render() {
return (
<Screen title="Settings">
<SettingsCard {...this.props} />
<SettingsContainer />
</Screen>
);
}
}

export default connect(
state => ({
offlineNotification: state.settings.offlineNotification,
onlineNotification: state.settings.onlineNotification,
theme: state.settings.theme,
auth: getAuth(state),
}),
boundActions,
)(SettingsScreen);

0 comments on commit 400971c

Please sign in to comment.