Playable downloads (#111)

* enable download button for video and audio content
* fix media player source and button display
* show notifications for video downloads. fix double playback.
* fix ongoing playback when back button pressed
* fix double-playback when navigating to related content links
* update url for stop download
This commit is contained in:
Akinwale Ariwodola 2020-01-16 22:00:34 +01:00 committed by GitHub
parent 156e310368
commit 5df8b8c4aa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 129 additions and 82 deletions

View file

@ -10,6 +10,7 @@ import {
makeSelectTitleForUri,
makeSelectThumbnailForUri,
} from 'lbry-redux';
import { doSetPlayerVisible } from 'redux/actions/drawer';
import { selectBlackListedOutpoints, selectFilteredOutpoints, selectRewardContentClaimIds } from 'lbryinc';
import { selectShowNsfw } from 'redux/selectors/settings';
import ClaimResultItem from './view';
@ -32,6 +33,7 @@ const select = (state, props) => ({
const perform = dispatch => ({
resolveUri: uri => dispatch(doResolveUri(uri)),
setPlayerVisible: (visible, uri) => dispatch(doSetPlayerVisible(visible, uri)),
});
export default connect(

View file

@ -39,14 +39,14 @@ class ClaimResultItem extends React.PureComponent {
}
onPressHandler = () => {
const { autoplay, navigation, result } = this.props;
const { autoplay, navigation, result, setPlayerVisible } = this.props;
const { claimId, name } = result;
const url = normalizeURI(`${name}#${claimId}`);
navigateToUri(navigation, url, { autoplay }, false, url);
navigateToUri(navigation, url, { autoplay }, false, url, setPlayerVisible);
};
render() {
const { fileInfo, navigation, obscureNsfw, result, rewardedContentClaimIds, style } = this.props;
const { fileInfo, navigation, obscureNsfw, result, rewardedContentClaimIds, setPlayerVisible, style } = this.props;
const {
channel,
channel_claim_id: channelClaimId,
@ -134,6 +134,7 @@ class ClaimResultItem extends React.PureComponent {
null,
false,
isChannel ? url : channelUrl,
setPlayerVisible,
);
}}
/>
@ -141,7 +142,7 @@ class ClaimResultItem extends React.PureComponent {
<View style={fileListStyle.info}>
{fileInfo && !isNaN(fileInfo.written_bytes) && fileInfo.written_bytes > 0 && (
<Text>{getStorageForFileInfo(fileInfo)}</Text>
<Text style={fileListStyle.infoText}>{getStorageForFileInfo(fileInfo)}</Text>
)}
<DateTime
style={fileListStyle.publishInfo}

View file

@ -10,6 +10,7 @@ import {
makeSelectClaimIsNsfw,
makeSelectShortUrlForUri,
} from 'lbry-redux';
import { doSetPlayerVisible } from 'redux/actions/drawer';
import { selectBlackListedOutpoints, selectFilteredOutpoints, selectRewardContentClaimIds } from 'lbryinc';
import { selectShowNsfw } from 'redux/selectors/settings';
import FileItem from './view';
@ -31,9 +32,10 @@ const select = (state, props) => ({
const perform = dispatch => ({
resolveUri: uri => dispatch(doResolveUri(uri)),
setPlayerVisible: (visible, uri) => dispatch(doSetPlayerVisible(visible, uri)),
});
export default connect(
select,
perform
perform,
)(FileItem);

View file

@ -56,6 +56,7 @@ class FileItem extends React.PureComponent {
obscureNsfw,
showDetails,
compactView,
setPlayerVisible,
titleBeforeThumbnail,
} = this.props;
@ -135,6 +136,7 @@ class FileItem extends React.PureComponent {
null,
false,
fullChannelUri,
setPlayerVisible,
);
}}
/>

View file

@ -10,6 +10,7 @@ import {
makeSelectTitleForUri,
makeSelectThumbnailForUri,
} from 'lbry-redux';
import { doSetPlayerVisible } from 'redux/actions/drawer';
import { selectBlackListedOutpoints, selectFilteredOutpoints, selectRewardContentClaimIds } from 'lbryinc';
import { selectShowNsfw } from 'redux/selectors/settings';
import FileListItem from './view';
@ -32,6 +33,7 @@ const select = (state, props) => ({
const perform = dispatch => ({
resolveUri: uri => dispatch(doResolveUri(uri)),
setPlayerVisible: (visible, uri) => dispatch(doSetPlayerVisible(visible, uri)),
});
export default connect(

View file

@ -80,6 +80,7 @@ class FileListItem extends React.PureComponent {
onPress,
navigation,
rewardedContentClaimIds,
setPlayerVisible,
thumbnail,
hideChannel,
onLongPress,
@ -236,6 +237,7 @@ class FileListItem extends React.PureComponent {
null,
false,
isChannel ? claim && claim.permanent_url : fullChannelUri,
setPlayerVisible,
);
}}
/>

View file

@ -32,6 +32,7 @@ export default class RelatedContent extends React.PureComponent {
recommendedContent.map(result => (
<ClaimResultItem
style={fileListStyle.item}
uri={result ? normalizeURI(`${result.name}#${result.claimId}`) : null}
key={result.claimId}
result={result}
navigation={navigation}

View file

@ -6,6 +6,7 @@ import {
selectSearchSuggestions,
SETTINGS,
} from 'lbry-redux';
import { doSetPlayerVisible } from 'redux/actions/drawer';
import { selectCurrentRoute } from 'redux/selectors/drawer';
import { makeSelectClientSetting } from 'redux/selectors/settings';
import UriBar from './view';
@ -24,9 +25,10 @@ const select = state => {
const perform = dispatch => ({
updateSearchQuery: query => dispatch(doUpdateSearchQuery(query)),
setPlayerVisible: (visible, uri) => dispatch(doSetPlayerVisible(visible, uri)),
});
export default connect(
select,
perform
perform,
)(UriBar);

View file

@ -83,7 +83,7 @@ class UriBar extends React.PureComponent {
};
handleItemPress = item => {
const { navigation, onSearchSubmitted, updateSearchQuery } = this.props;
const { navigation, onSearchSubmitted, setPlayerVisible, updateSearchQuery } = this.props;
const { type, value } = item;
Keyboard.dismiss();
@ -112,7 +112,7 @@ class UriBar extends React.PureComponent {
});
} else {
const uri = normalizeURI(value);
navigateToUri(navigation, uri);
navigateToUri(navigation, uri, null, false, null, setPlayerVisible);
}
};
@ -128,7 +128,7 @@ class UriBar extends React.PureComponent {
};
handleSubmitEditing = () => {
const { navigation, onSearchSubmitted, updateSearchQuery } = this.props;
const { navigation, onSearchSubmitted, setPlayerVisible, updateSearchQuery } = this.props;
if (this.state.inputText) {
let inputText = this.state.inputText,
inputTextIsUrl = false;
@ -137,7 +137,7 @@ class UriBar extends React.PureComponent {
// if it's a URI (lbry://...), open the file page
if (transformedUrl && isURIValid(transformedUrl)) {
inputTextIsUrl = true;
navigateToUri(navigation, transformedUrl);
navigateToUri(navigation, transformedUrl, null, false, null, setPlayerVisible);
}
}

View file

@ -11,7 +11,7 @@ import {
selectSubscriptionClaims,
selectUnreadSubscriptions,
} from 'lbryinc';
import { doPushDrawerStack } from 'redux/actions/drawer';
import { doPushDrawerStack, doSetPlayerVisible } from 'redux/actions/drawer';
import { doSetClientSetting, doSetSortByItem, doSetTimeItem } from 'redux/actions/settings';
import { makeSelectClientSetting, selectSortByItem, selectTimeItem } from 'redux/selectors/settings';
import Constants from 'constants'; // eslint-disable-line node/no-deprecated-api
@ -41,11 +41,12 @@ const perform = dispatch => ({
pushDrawerStack: () => dispatch(doPushDrawerStack(Constants.DRAWER_ROUTE_DISCOVER)),
removeUnreadSubscriptions: () => dispatch(doRemoveUnreadSubscriptions()),
setClientSetting: (key, value) => dispatch(doSetClientSetting(key, value)),
setPlayerVisible: () => dispatch(doSetPlayerVisible(false)),
setSortByItem: item => dispatch(doSetSortByItem(item)),
setTimeItem: item => dispatch(doSetTimeItem(item)),
});
export default connect(
select,
perform
perform,
)(DiscoverPage);

View file

@ -86,9 +86,11 @@ class DiscoverPage extends React.PureComponent {
}
onComponentFocused = () => {
const { pushDrawerStack } = this.props;
const { pushDrawerStack, setPlayerVisible } = this.props;
// pushDrawerStack();
NativeModules.Firebase.setCurrentScreen('Your tags');
setPlayerVisible();
};
handleSortByItemSelected = item => {
@ -135,7 +137,7 @@ class DiscoverPage extends React.PureComponent {
Alert.alert(
__('Enjoying LBRY?'),
__(
'Are you enjoying your experience with the LBRY app? You can leave a review for us on the Play Store.'
'Are you enjoying your experience with the LBRY app? You can leave a review for us on the Play Store.',
),
[
{
@ -151,7 +153,7 @@ class DiscoverPage extends React.PureComponent {
},
},
],
{ cancelable: false }
{ cancelable: false },
);
}
}

View file

@ -79,7 +79,7 @@ class DownloadsPage extends React.PureComponent {
const { claims, fileInfos } = this.props;
const claimUris = claims.map(claim => normalizeURI(`${claim.name}#${claim.claim_id}`));
return fileInfos.filter(
fileInfo => !claimUris.includes(normalizeURI(`${fileInfo.claim_name}#${fileInfo.claim_id}`))
fileInfo => !claimUris.includes(normalizeURI(`${fileInfo.claim_name}#${fileInfo.claim_id}`)),
);
};
@ -135,7 +135,7 @@ class DownloadsPage extends React.PureComponent {
],
{
cancelable: true,
}
},
);
};
@ -184,7 +184,7 @@ class DownloadsPage extends React.PureComponent {
this.handleSelectItem(item, claim);
} else {
// TODO: when shortUrl is available for my claims, navigate to that URL instead
navigateToUri(navigation, item, { autoplay: true });
navigateToUri(navigation, item, { autoplay: true }, false, null);
}
}}
onLongPress={claim => this.handleItemLongPress(item, claim)}

View file

@ -41,7 +41,7 @@ import {
import { doDeleteFile, doStopDownloadingFile } from 'redux/actions/file';
import { doPushDrawerStack, doPopDrawerStack, doSetPlayerVisible } from 'redux/actions/drawer';
import { doToggleFullscreenMode } from 'redux/actions/settings';
import { selectDrawerStack, selectIsPlayerVisible } from 'redux/selectors/drawer';
import { selectDrawerStack, makeSelectPlayerVisible } from 'redux/selectors/drawer';
import FilePage from './view';
const select = (state, props) => {
@ -61,7 +61,7 @@ const select = (state, props) => {
fileInfo: makeSelectFileInfoForUri(contentUri)(state),
rewardedContentClaimIds: selectRewardContentClaimIds(state, selectProps),
channelUri: makeSelectChannelForClaimUri(contentUri, true)(state),
isPlayerVisible: selectIsPlayerVisible(state),
isPlayerVisible: makeSelectPlayerVisible(uri)(state), // use navigation uri for this selector
position: makeSelectContentPositionForUri(contentUri)(state),
purchasedUris: selectPurchasedUris(state),
failedPurchaseUris: selectFailedPurchaseUris(state),
@ -96,7 +96,7 @@ const perform = dispatch => ({
resolveUris: uris => dispatch(doResolveUris(uris)),
sendTip: (amount, claimId, isSupport, successCallback, errorCallback) =>
dispatch(doSendTip(amount, claimId, isSupport, successCallback, errorCallback)),
setPlayerVisible: () => dispatch(doSetPlayerVisible(true)),
setPlayerVisible: (visible, uri) => dispatch(doSetPlayerVisible(visible, uri)),
stopDownload: (uri, fileInfo) => dispatch(doStopDownloadingFile(uri, fileInfo)),
toggleFullscreenMode: mode => dispatch(doToggleFullscreenMode(mode)),
});

View file

@ -94,6 +94,7 @@ class FilePage extends React.PureComponent {
showImageViewer: false,
showWebView: false,
showTipView: false,
playbackStarted: false,
playerBgHeight: 0,
playerHeight: 0,
uri: null,
@ -115,6 +116,8 @@ class FilePage extends React.PureComponent {
onComponentFocused = () => {
StatusBar.setHidden(false);
NativeModules.Firebase.setCurrentScreen('File').then(result => {
const { setPlayerVisible } = this.props;
DeviceEventEmitter.addListener('onStoragePermissionGranted', this.handleStoragePermissionGranted);
DeviceEventEmitter.addListener('onStoragePermissionRefused', this.handleStoragePermissionRefused);
@ -122,6 +125,7 @@ class FilePage extends React.PureComponent {
const { uri, uriVars } = navigation.state.params;
this.setState({ uri, uriVars });
setPlayerVisible(true, uri);
if (!isResolvingUri && !claim) resolveUri(uri);
this.fetchFileInfo(uri, this.props);
@ -162,7 +166,6 @@ class FilePage extends React.PureComponent {
notify,
drawerStack: prevDrawerStack,
} = this.props;
const { uri } = navigation.state.params;
const {
currentRoute: prevRoute,
failedPurchaseUris,
@ -173,6 +176,7 @@ class FilePage extends React.PureComponent {
drawerStack,
resolveUris,
} = nextProps;
const uri = this.getPurchaseUrl();
if (Constants.ROUTE_FILE === currentRoute && currentRoute !== prevRoute) {
this.onComponentFocused();
@ -206,7 +210,7 @@ class FilePage extends React.PureComponent {
NativeModules.UtilityModule.checkDownloads();
}
if (!this.state.streamingMode && isPlayable) {
if ((!fileInfo || (fileInfo && !fileInfo.completed)) && !this.state.streamingMode && isPlayable) {
if (streamingUrl) {
this.setState({ streamingMode: true, currentStreamUrl: streamingUrl });
} else if (fileInfo && fileInfo.streaming_url) {
@ -231,6 +235,9 @@ class FilePage extends React.PureComponent {
}
shouldComponentUpdate(nextProps, nextState) {
const { fileInfo: prevFileInfo } = this.props;
const { fileInfo } = nextProps;
return (
Object.keys(this.difference(nextProps, this.props)).length > 0 ||
Object.keys(this.difference(nextState, this.state)).length > 0
@ -368,14 +375,14 @@ class FilePage extends React.PureComponent {
const { deletePurchasedUri, fileInfo, navigation, notify, stopDownload } = this.props;
Alert.alert(
'Stop download',
'Are you sure you want to stop downloading this file?',
__('Stop download'),
__('Are you sure you want to stop downloading this file?'),
[
{ text: 'No' },
{ text: __('No') },
{
text: 'Yes',
text: __('Yes'),
onPress: () => {
const { uri } = navigation.state.params;
const uri = this.getPurchaseUrl();
stopDownload(uri, fileInfo);
deletePurchasedUri(uri);
if (NativeModules.UtilityModule) {
@ -391,7 +398,7 @@ class FilePage extends React.PureComponent {
// there can be a bit of lag between the user pressing Yes and the UI being updated
// after the file_set_status and file_delete operations, so let the user know
notify({
message: 'The download will stop momentarily. You do not need to wait to discover something else.',
message: __('The download will stop momentarily. You do not need to wait to discover something else.'),
});
},
},
@ -416,8 +423,6 @@ class FilePage extends React.PureComponent {
if (window.currentMediaInfo) {
window.currentMediaInfo = null;
}
window.player = null;
DeviceEventEmitter.removeListener('onStoragePermissionGranted', this.handleStoragePermissionGranted);
DeviceEventEmitter.removeListener('onStoragePermissionRefused', this.handleStoragePermissionRefused);
}
@ -434,7 +439,7 @@ class FilePage extends React.PureComponent {
})
.then(() => this.performDownload())
.catch(() => {
notify({ message: 'The file could not be downloaded to the default download directory.', isError: true });
notify({ message: __('The file could not be downloaded to the default download directory.'), isError: true });
});
});
};
@ -452,12 +457,14 @@ class FilePage extends React.PureComponent {
if (!fileInfo) {
return null;
}
return 'file:///' + fileInfo.download_path;
return 'file://' + fileInfo.download_path;
};
playerUriForFileInfo = fileInfo => {
const { streamingUrl } = this.props;
if (fileInfo && fileInfo.download_path) {
if (!this.state.streamingMode && fileInfo && fileInfo.download_path && fileInfo.completed) {
// take streamingMode in the state into account because if the download completes while
// the media is already streaming, it will restart from the beginning
return this.getEncodedDownloadPath(fileInfo);
}
if (streamingUrl) {
@ -564,7 +571,7 @@ class FilePage extends React.PureComponent {
NativeModules.Firebase.track('play', payload);
// only fetch recommended content after playback has started
this.setState({ showRecommended: true });
this.setState({ playbackStarted: true, showRecommended: true });
};
onPlaybackFinished = () => {
@ -668,7 +675,7 @@ class FilePage extends React.PureComponent {
if (isPlayable) {
this.startTime = Date.now();
this.setState({ downloadPressed: true, autoPlayMedia: true, stopDownloadConfirmed: false });
setPlayerVisible();
// setPlayerVisible(purchaseUrl);
}
if (isViewable) {
this.setState({ downloadPressed: true });
@ -682,7 +689,7 @@ class FilePage extends React.PureComponent {
let purchaseUrl;
if (navigation.state.params) {
const { uri, fullUri } = navigation.state.params;
purchaseUrl = fullUri || uri || permanentUrl;
purchaseUrl = fullUri || permanentUrl || uri;
}
if (!purchaseUrl && permanentUrl) {
purchaseUrl = permanentUrl;
@ -708,7 +715,7 @@ class FilePage extends React.PureComponent {
};
performDownload = () => {
const { claim, costInfo, purchaseUri } = this.props;
const { claim, costInfo, fileGet, fileInfo, purchasedUris } = this.props;
this.setState(
{
downloadPressed: true,
@ -716,15 +723,21 @@ class FilePage extends React.PureComponent {
stopDownloadConfirmed: false,
},
() => {
this.confirmPurchaseUri(claim.permanent_url, costInfo, true);
const url = this.getPurchaseUrl();
if (fileInfo || purchasedUris.includes(url)) {
// file already in library or URI already purchased, use fileGet directly
this.setState({ fileGetStarted: true }, () => fileGet(url, true));
} else {
this.confirmPurchaseUri(url, costInfo, true);
}
NativeModules.UtilityModule.checkDownloads();
},
);
};
onBackButtonPressed = () => {
const { navigation, drawerStack, popDrawerStack } = this.props;
navigateBack(navigation, drawerStack, popDrawerStack);
const { navigation, drawerStack, popDrawerStack, setPlayerVisible } = this.props;
navigateBack(navigation, drawerStack, popDrawerStack, setPlayerVisible);
};
onOpenFilePressed = () => {
@ -732,25 +745,16 @@ class FilePage extends React.PureComponent {
const localFileUri = this.localUriForFileInfo(fileInfo);
const mediaType = Lbry.getMediaType(contentType);
const isViewable = mediaType === 'image' || mediaType === 'text';
const isPlayable = mediaType === 'video' || mediaType === 'audio';
if (isViewable) {
this.openFile(localFileUri, mediaType, contentType);
} else if (isPlayable) {
notify({ message: __('Please press the Play button.') });
} else {
notify({ message: __('This file cannot be displayed in the LBRY app.') });
}
};
onSaveFilePressed = () => {
const { costInfo, fileGet, fileInfo, navigation, purchasedUris, purchaseUri } = this.props;
const { uri } = navigation.state.params;
if (fileInfo || purchasedUris.includes(uri)) {
// file already in library or URI already purchased, use fileGet directly
this.setState({ fileGetStarted: true }, () => fileGet(uri, true));
} else {
this.checkStoragePermissionForDownload();
}
};
openFile = (localFileUri, mediaType, contentType) => {
const { pushDrawerStack } = this.props;
const isWebViewable = mediaType === 'text';
@ -880,6 +884,7 @@ class FilePage extends React.PureComponent {
position,
purchaseUri,
pushDrawerStack,
setPlayerVisible,
thumbnail,
title,
viewCount,
@ -1199,7 +1204,7 @@ class FilePage extends React.PureComponent {
<Text style={filePageStyle.largeButtonText}>{__('Tip')}</Text>
</TouchableOpacity>
{!canEdit && !isPlayable && (
{!canEdit && (
<View style={filePageStyle.sharedLargeButton}>
{(!fileInfo || (fileInfo.written_bytes <= 0 && !completed)) && (
<TouchableOpacity style={filePageStyle.innerLargeButton} onPress={this.onDownloadPressed}>
@ -1210,7 +1215,6 @@ class FilePage extends React.PureComponent {
{!completed &&
fileInfo &&
!fileInfo.stopped &&
fileInfo.written_bytes > 0 &&
fileInfo.written_bytes < fileInfo.total_bytes &&
!this.state.stopDownloadConfirmed && (
@ -1270,6 +1274,7 @@ class FilePage extends React.PureComponent {
null,
false,
fullChannelUri,
setPlayerVisible,
);
}}
/>
@ -1288,14 +1293,6 @@ class FilePage extends React.PureComponent {
/>
</View>
<View style={filePageStyle.subscriptionRow}>
{false && ((isPlayable && !fileInfo) || (isPlayable && fileInfo && !fileInfo.download_path)) && (
<Button
style={[filePageStyle.actionButton, filePageStyle.saveFileButton]}
theme={'light'}
icon={'download'}
onPress={this.onSaveFilePressed}
/>
)}
{channelName && (
<SubscribeButton
style={filePageStyle.actionButton}

View file

@ -239,6 +239,7 @@ class SearchPage extends React.PureComponent {
renderItem={({ item }) => (
<ClaimResultItem
key={item.claimId}
uri={item ? normalizeURI(`${item.name}#${item.claimId}`) : null}
result={item}
style={searchStyle.resultItem}
navigation={navigation}

View file

@ -11,8 +11,8 @@ export const doPopDrawerStack = () => dispatch =>
type: Constants.ACTION_POP_DRAWER_STACK,
});
export const doSetPlayerVisible = visible => dispatch =>
export const doSetPlayerVisible = (visible, uri) => dispatch =>
dispatch({
type: Constants.ACTION_SET_PLAYER_VISIBLE,
data: { visible },
data: { visible, uri },
});

View file

@ -4,13 +4,27 @@ const reducers = {};
const defaultState = {
stack: [{ route: Constants.DRAWER_ROUTE_DISCOVER, params: {} }], // Discover is always the first drawer route
playerVisible: false,
playerVisibleByUri: {},
currentRoute: null,
};
reducers[Constants.ACTION_SET_PLAYER_VISIBLE] = (state, action) =>
Object.assign({}, state, {
reducers[Constants.ACTION_SET_PLAYER_VISIBLE] = (state, action) => {
const { visible, uri } = action.data;
const playerVisibleByUri = Object.assign({}, state.playerVisibleByUri);
if (!uri) {
Object.keys(playerVisibleByUri).forEach(playerUri => {
playerVisibleByUri[playerUri] = visible;
});
} else {
playerVisibleByUri[uri] = visible;
}
return Object.assign({}, state, {
playerVisible: action.data.visible,
playerVisibleByUri,
});
};
reducers[Constants.ACTION_PUSH_DRAWER_STACK] = (state, action) => {
const { routeName, params } = action.data;

View file

@ -4,14 +4,25 @@ export const selectState = state => state.drawer || {};
export const selectDrawerStack = createSelector(
selectState,
state => state.stack
state => state.stack,
);
export const selectIsPlayerVisible = createSelector(
selectState,
state => state.playerVisible
state => state.playerVisible,
);
export const selectPlayerVisibleByUri = createSelector(
selectState,
state => state.playerVisibleByUri,
);
export const makeSelectPlayerVisible = uri =>
createSelector(
selectPlayerVisibleByUri,
byUri => (byUri ? byUri[uri] : false),
);
export const selectLastDrawerRoute = createSelector(
selectState,
state => {
@ -20,10 +31,10 @@ export const selectLastDrawerRoute = createSelector(
}
return null;
}
},
);
export const selectCurrentRoute = createSelector(
selectState,
state => state.currentRoute
state => state.currentRoute,
);

View file

@ -403,7 +403,7 @@ const filePageStyle = StyleSheet.create({
},
largeButtonText: {
fontFamily: 'Inter-Regular',
fontSize: 14,
fontSize: 12,
marginTop: 4,
},
largeButtonsRow: {

View file

@ -54,9 +54,10 @@ export function dispatchNavigateToUri(dispatch, nav, uri, isNavigatingBack, full
if (!isNavigatingBack) {
dispatch(doPushDrawerStack(uri));
dispatch(doSetPlayerVisible(true));
}
dispatch(doSetPlayerVisible(false));
if (nav && nav.routes && nav.routes.length > 0 && nav.routes[0].routeName === 'Main') {
const mainRoute = nav.routes[0];
const discoverRoute = mainRoute.routes[0];
@ -64,14 +65,14 @@ export function dispatchNavigateToUri(dispatch, nav, uri, isNavigatingBack, full
const fileRoute = discoverRoute.routes[discoverRoute.index];
// Currently on a file page, so we can ignore (if the URI is the same) or replace (different URIs)
if (uri !== fileRoute.params.uri) {
const stackAction = StackActions.replace({ routeName: 'File', newKey: 'file', params });
const stackAction = StackActions.replace({ routeName: 'File', newKey: uri, params });
dispatch(stackAction);
return;
}
}
}
const navigateAction = NavigationActions.navigate({ routeName: 'File', key: 'file', params });
const navigateAction = NavigationActions.navigate({ routeName: 'File', key: uri, params });
dispatch(navigateAction);
}
@ -113,7 +114,7 @@ function parseUriVars(vars) {
return uriVars;
}
export function navigateToUri(navigation, uri, additionalParams, isNavigatingBack, fullUri) {
export function navigateToUri(navigation, uri, additionalParams, isNavigatingBack, fullUri, setPlayerVisible) {
if (!navigation) {
return;
}
@ -135,26 +136,28 @@ export function navigateToUri(navigation, uri, additionalParams, isNavigatingBac
uriVars = parseUriVars(uriVarsStr);
}
if (setPlayerVisible) {
setPlayerVisible(false);
}
const { store } = window;
const params = Object.assign({ uri, uriVars, fullUri: fullUri }, additionalParams);
if (navigation.state.routeName === 'File') {
const stackAction = StackActions.replace({ routeName: 'File', newKey: 'file', params });
const stackAction = StackActions.replace({ routeName: 'File', newKey: uri, params });
navigation.dispatch(stackAction);
if (store && store.dispatch && !isNavigatingBack) {
store.dispatch(doPushDrawerStack(uri));
store.dispatch(doSetPlayerVisible(true));
}
return;
}
navigation.navigate({ routeName: 'File', key: 'file', params });
navigation.navigate({ routeName: 'File', key: uri, params });
if (store && store.dispatch && !isNavigatingBack) {
store.dispatch(doPushDrawerStack(uri));
store.dispatch(doSetPlayerVisible(true));
}
}
export function navigateBack(navigation, drawerStack, popDrawerStack) {
export function navigateBack(navigation, drawerStack, popDrawerStack, setPlayerVisible) {
if (drawerStack[drawerStack.length - 1].route === Constants.DRAWER_ROUTE_FILE_VIEW) {
// inner file_view (web / image view) is handled differently
if (popDrawerStack) {
@ -166,12 +169,15 @@ export function navigateBack(navigation, drawerStack, popDrawerStack) {
if (popDrawerStack) {
popDrawerStack();
}
if (setPlayerVisible) {
setPlayerVisible(false);
}
const target = drawerStack[drawerStack.length > 1 ? drawerStack.length - 2 : 0];
const { route, params } = target;
navigation.goBack(navigation.state.key);
if (!DrawerRoutes.includes(route) && !InnerDrawerRoutes.includes(route) && isURIValid(route)) {
navigateToUri(navigation, route, null, true);
navigateToUri(navigation, route, null, true, null, setPlayerVisible);
} else {
let targetRoute = route;
let targetParams = params;
@ -201,6 +207,7 @@ export function dispatchNavigateBack(dispatch, nav, drawerStack) {
}
dispatch(doPopDrawerStack());
dispatch(doSetPlayerVisible(false));
const target = drawerStack[drawerStack.length > 1 ? drawerStack.length - 2 : 0];
const { route } = target;