2018-03-11 16:32:13 +01:00
|
|
|
import React from 'react';
|
2018-05-03 20:58:31 +02:00
|
|
|
import AboutPage from '../page/about';
|
2018-03-11 16:32:13 +01:00
|
|
|
import DiscoverPage from '../page/discover';
|
|
|
|
import FilePage from '../page/file';
|
2018-06-08 10:13:45 +02:00
|
|
|
import FirstRunScreen from '../page/firstRun';
|
2018-04-09 20:39:35 +02:00
|
|
|
import SearchPage from '../page/search';
|
2018-06-05 20:52:10 +02:00
|
|
|
import TrendingPage from '../page/trending';
|
2018-03-23 00:03:05 +01:00
|
|
|
import SettingsPage from '../page/settings';
|
2018-03-11 16:32:13 +01:00
|
|
|
import SplashScreen from '../page/splash';
|
2018-05-03 20:58:31 +02:00
|
|
|
import TransactionHistoryPage from '../page/transactionHistory';
|
|
|
|
import WalletPage from '../page/wallet';
|
2018-04-09 20:39:35 +02:00
|
|
|
import SearchInput from '../component/searchInput';
|
|
|
|
import {
|
|
|
|
addNavigationHelpers,
|
|
|
|
DrawerNavigator,
|
|
|
|
StackNavigator,
|
|
|
|
NavigationActions
|
|
|
|
} from 'react-navigation';
|
2018-03-11 16:32:13 +01:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { addListener } from '../utils/redux';
|
2018-04-24 21:32:17 +02:00
|
|
|
import {
|
|
|
|
AppState,
|
|
|
|
AsyncStorage,
|
|
|
|
BackHandler,
|
2018-05-25 09:13:05 +02:00
|
|
|
Linking,
|
2018-04-24 21:32:17 +02:00
|
|
|
NativeModules,
|
2018-05-03 20:58:31 +02:00
|
|
|
TextInput,
|
|
|
|
ToastAndroid
|
2018-04-24 21:32:17 +02:00
|
|
|
} from 'react-native';
|
2018-05-03 20:58:31 +02:00
|
|
|
import { SETTINGS, doHideNotification, selectNotification } from 'lbry-redux';
|
2018-04-09 20:39:35 +02:00
|
|
|
import { makeSelectClientSetting } from '../redux/selectors/settings';
|
2018-08-08 19:11:25 +02:00
|
|
|
import Icon from 'react-native-vector-icons/FontAwesome5';
|
2018-03-11 16:32:13 +01:00
|
|
|
import discoverStyle from '../styles/discover';
|
2018-04-09 20:39:35 +02:00
|
|
|
import searchStyle from '../styles/search';
|
2018-05-18 20:13:27 +02:00
|
|
|
import SearchRightHeaderIcon from "../component/searchRightHeaderIcon";
|
2018-03-11 16:32:13 +01:00
|
|
|
|
|
|
|
const discoverStack = StackNavigator({
|
|
|
|
Discover: {
|
|
|
|
screen: DiscoverPage,
|
|
|
|
navigationOptions: ({ navigation }) => ({
|
|
|
|
title: 'Discover',
|
2018-08-08 19:11:25 +02:00
|
|
|
headerLeft: <Icon name="bars" size={24} style={discoverStyle.drawerHamburger} onPress={() => navigation.navigate('DrawerOpen')} />,
|
2018-03-11 16:32:13 +01:00
|
|
|
})
|
|
|
|
},
|
|
|
|
File: {
|
|
|
|
screen: FilePage,
|
|
|
|
navigationOptions: {
|
2018-03-22 07:26:04 +01:00
|
|
|
header: null,
|
|
|
|
drawerLockMode: 'locked-closed'
|
2018-03-11 16:32:13 +01:00
|
|
|
}
|
2018-04-09 20:39:35 +02:00
|
|
|
},
|
|
|
|
Search: {
|
|
|
|
screen: SearchPage,
|
|
|
|
navigationOptions: ({ navigation }) => ({
|
2018-05-26 01:20:44 +02:00
|
|
|
drawerLockMode: 'locked-closed'
|
2018-04-09 20:39:35 +02:00
|
|
|
})
|
2018-03-11 16:32:13 +01:00
|
|
|
}
|
|
|
|
}, {
|
|
|
|
headerMode: 'screen',
|
|
|
|
});
|
|
|
|
|
2018-06-05 20:52:10 +02:00
|
|
|
const trendingStack = StackNavigator({
|
|
|
|
Trending: {
|
|
|
|
screen: TrendingPage,
|
|
|
|
navigationOptions: ({ navigation }) => ({
|
|
|
|
title: 'Trending',
|
2018-08-08 19:11:25 +02:00
|
|
|
headerLeft: <Icon name="bars" size={24} style={discoverStyle.drawerHamburger} onPress={() => navigation.navigate('DrawerOpen')} />,
|
2018-06-05 20:52:10 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-05-03 20:58:31 +02:00
|
|
|
const walletStack = StackNavigator({
|
|
|
|
Wallet: {
|
|
|
|
screen: WalletPage,
|
|
|
|
navigationOptions: ({ navigation }) => ({
|
|
|
|
title: 'Wallet',
|
2018-08-08 19:11:25 +02:00
|
|
|
headerLeft: <Icon name="bars" size={24} style={discoverStyle.drawerHamburger} onPress={() => navigation.navigate('DrawerOpen')} />,
|
2018-05-03 20:58:31 +02:00
|
|
|
})
|
|
|
|
},
|
|
|
|
TransactionHistory: {
|
|
|
|
screen: TransactionHistoryPage,
|
|
|
|
navigationOptions: {
|
|
|
|
title: 'Transaction History',
|
|
|
|
drawerLockMode: 'locked-closed'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
headerMode: 'screen'
|
|
|
|
});
|
|
|
|
|
2018-03-11 16:32:13 +01:00
|
|
|
const drawer = DrawerNavigator({
|
2018-05-10 22:07:18 +02:00
|
|
|
DiscoverStack: { screen: discoverStack },
|
2018-06-05 20:52:10 +02:00
|
|
|
TrendingStack: { screen: trendingStack },
|
2018-05-10 22:07:18 +02:00
|
|
|
WalletStack: { screen: walletStack },
|
2018-04-23 06:10:18 +02:00
|
|
|
Settings: { screen: SettingsPage, navigationOptions: { drawerLockMode: 'locked-closed' } },
|
|
|
|
About: { screen: AboutPage, navigationOptions: { drawerLockMode: 'locked-closed' } }
|
2018-03-11 16:32:13 +01:00
|
|
|
}, {
|
|
|
|
drawerWidth: 300,
|
|
|
|
headerMode: 'none'
|
|
|
|
});
|
|
|
|
|
|
|
|
export const AppNavigator = new StackNavigator({
|
2018-06-08 10:13:45 +02:00
|
|
|
FirstRun: {
|
|
|
|
screen: FirstRunScreen,
|
|
|
|
navigationOptions: {
|
|
|
|
drawerLockMode: 'locked-closed'
|
|
|
|
}
|
|
|
|
},
|
2018-03-11 16:32:13 +01:00
|
|
|
Splash: {
|
2018-04-09 20:39:35 +02:00
|
|
|
screen: SplashScreen,
|
|
|
|
navigationOptions: {
|
|
|
|
drawerLockMode: 'locked-closed'
|
|
|
|
}
|
2018-03-11 16:32:13 +01:00
|
|
|
},
|
|
|
|
Main: {
|
|
|
|
screen: drawer
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
headerMode: 'none'
|
|
|
|
});
|
|
|
|
|
|
|
|
class AppWithNavigationState extends React.Component {
|
2018-05-03 20:58:31 +02:00
|
|
|
static supportedDisplayTypes = ['toast'];
|
2018-06-08 10:13:45 +02:00
|
|
|
|
2018-03-11 16:32:13 +01:00
|
|
|
componentWillMount() {
|
2018-03-23 00:03:05 +01:00
|
|
|
AppState.addEventListener('change', this._handleAppStateChange);
|
2018-03-11 16:32:13 +01:00
|
|
|
BackHandler.addEventListener('hardwareBackPress', function() {
|
2018-05-25 09:13:05 +02:00
|
|
|
const { dispatch, nav } = this.props;
|
2018-04-23 06:01:33 +02:00
|
|
|
// There should be a better way to check this
|
2018-05-10 22:07:18 +02:00
|
|
|
if (nav.routes.length > 0) {
|
2018-07-24 15:37:31 +02:00
|
|
|
if (nav.routes[0].routes && nav.routes[0].routes.length > 0) {
|
|
|
|
const subRoutes = nav.routes[0].routes[0].routes;
|
|
|
|
const lastRoute = subRoutes[subRoutes.length - 1];
|
|
|
|
if (nav.routes[0].routes[0].index > 0 &&
|
|
|
|
['About', 'Settings'].indexOf(lastRoute.key) > -1) {
|
|
|
|
dispatch(NavigationActions.back());
|
|
|
|
return true;
|
|
|
|
}
|
2018-03-11 16:32:13 +01:00
|
|
|
}
|
2018-05-10 22:07:18 +02:00
|
|
|
if (nav.routes[0].routeName === 'Main') {
|
2018-06-08 10:13:45 +02:00
|
|
|
if (nav.routes[0].routes[0].routes[0].index > 0) {
|
2018-05-10 22:07:18 +02:00
|
|
|
dispatch(NavigationActions.back());
|
2018-04-23 06:01:33 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2018-03-11 16:32:13 +01:00
|
|
|
}
|
2018-08-08 19:11:25 +02:00
|
|
|
return false;fo
|
2018-03-11 16:32:13 +01:00
|
|
|
}.bind(this));
|
|
|
|
}
|
2018-06-08 10:13:45 +02:00
|
|
|
|
2018-05-25 09:13:05 +02:00
|
|
|
componentDidMount() {
|
|
|
|
Linking.addEventListener('url', this._handleUrl);
|
|
|
|
}
|
2018-06-08 10:13:45 +02:00
|
|
|
|
2018-03-11 16:32:13 +01:00
|
|
|
componentWillUnmount() {
|
2018-03-23 00:03:05 +01:00
|
|
|
AppState.removeEventListener('change', this._handleAppStateChange);
|
2018-03-11 16:32:13 +01:00
|
|
|
BackHandler.removeEventListener('hardwareBackPress');
|
2018-05-25 09:13:05 +02:00
|
|
|
Linking.removeEventListener('url', this._handleUrl);
|
2018-03-11 16:32:13 +01:00
|
|
|
}
|
2018-06-08 10:13:45 +02:00
|
|
|
|
2018-05-03 20:58:31 +02:00
|
|
|
componentWillUpdate(nextProps) {
|
|
|
|
const { dispatch } = this.props;
|
|
|
|
const { notification } = nextProps;
|
|
|
|
if (notification) {
|
|
|
|
const { displayType, message } = notification;
|
|
|
|
let currentDisplayType;
|
|
|
|
if (displayType.length) {
|
|
|
|
for (let i = 0; i < displayType.length; i++) {
|
|
|
|
const type = displayType[i];
|
|
|
|
if (AppWithNavigationState.supportedDisplayTypes.indexOf(type) > -1) {
|
|
|
|
currentDisplayType = type;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (AppWithNavigationState.supportedDisplayTypes.indexOf(displayType) > -1) {
|
|
|
|
currentDisplayType = displayType;
|
|
|
|
}
|
2018-06-08 10:13:45 +02:00
|
|
|
|
2018-05-03 20:58:31 +02:00
|
|
|
if ('toast' === currentDisplayType) {
|
|
|
|
ToastAndroid.show(message, ToastAndroid.SHORT);
|
|
|
|
}
|
2018-06-08 10:13:45 +02:00
|
|
|
|
2018-05-03 20:58:31 +02:00
|
|
|
dispatch(doHideNotification());
|
|
|
|
}
|
|
|
|
}
|
2018-06-08 10:13:45 +02:00
|
|
|
|
2018-03-23 00:03:05 +01:00
|
|
|
_handleAppStateChange = (nextAppState) => {
|
2018-04-24 21:32:17 +02:00
|
|
|
// Check if the app was suspended
|
|
|
|
if (AppState.currentState && AppState.currentState.match(/inactive|background/)) {
|
|
|
|
AsyncStorage.getItem('firstLaunchTime').then(start => {
|
|
|
|
if (start !== null && !isNaN(parseInt(start, 10))) {
|
|
|
|
// App suspended during first launch?
|
|
|
|
// If so, this needs to be included as a property when tracking
|
|
|
|
AsyncStorage.setItem('firstLaunchSuspended', 'true');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2018-03-23 00:03:05 +01:00
|
|
|
}
|
2018-06-08 10:13:45 +02:00
|
|
|
|
2018-05-25 09:13:05 +02:00
|
|
|
_handleUrl = (evt) => {
|
|
|
|
const { dispatch } = this.props;
|
|
|
|
if (evt.url) {
|
|
|
|
const navigateAction = NavigationActions.navigate({
|
|
|
|
routeName: 'File',
|
2018-06-06 10:25:51 +02:00
|
|
|
key: evt.url,
|
2018-05-25 09:13:05 +02:00
|
|
|
params: { uri: evt.url }
|
|
|
|
});
|
|
|
|
dispatch(navigateAction);
|
|
|
|
}
|
|
|
|
}
|
2018-06-08 10:13:45 +02:00
|
|
|
|
2018-03-11 16:32:13 +01:00
|
|
|
render() {
|
|
|
|
const { dispatch, nav } = this.props;
|
|
|
|
return (
|
|
|
|
<AppNavigator
|
|
|
|
navigation={addNavigationHelpers({
|
|
|
|
dispatch,
|
|
|
|
state: nav,
|
|
|
|
addListener,
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapStateToProps = state => ({
|
|
|
|
nav: state.nav,
|
2018-05-03 20:58:31 +02:00
|
|
|
notification: selectNotification(state),
|
2018-03-23 00:03:05 +01:00
|
|
|
keepDaemonRunning: makeSelectClientSetting(SETTINGS.KEEP_DAEMON_RUNNING)(state),
|
|
|
|
showNsfw: makeSelectClientSetting(SETTINGS.SHOW_NSFW)(state)
|
2018-03-11 16:32:13 +01:00
|
|
|
});
|
2018-06-08 10:13:45 +02:00
|
|
|
|
2018-05-03 20:58:31 +02:00
|
|
|
export default connect(mapStateToProps)(AppWithNavigationState);
|