From fefc13bc7a97d4f93a5c4cfab0d9726a73951291 Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Wed, 15 Jan 2020 06:44:31 +0100 Subject: [PATCH] fix double-playback when navigating to related content links --- src/component/claimResultItem/index.js | 2 ++ src/component/claimResultItem/view.js | 7 ++++--- src/component/fileItem/index.js | 4 +++- src/component/fileItem/view.js | 2 ++ src/component/fileListItem/index.js | 2 ++ src/component/fileListItem/view.js | 2 ++ src/component/uriBar/index.js | 4 +++- src/component/uriBar/view.js | 8 ++++---- src/page/downloads/view.js | 6 +++--- src/page/file/view.js | 3 ++- src/utils/helper.js | 10 ++++++++-- 11 files changed, 35 insertions(+), 15 deletions(-) diff --git a/src/component/claimResultItem/index.js b/src/component/claimResultItem/index.js index 4a44701..6a0c712 100644 --- a/src/component/claimResultItem/index.js +++ b/src/component/claimResultItem/index.js @@ -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( diff --git a/src/component/claimResultItem/view.js b/src/component/claimResultItem/view.js index f1ebc9e..576f323 100644 --- a/src/component/claimResultItem/view.js +++ b/src/component/claimResultItem/view.js @@ -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, ); }} /> diff --git a/src/component/fileItem/index.js b/src/component/fileItem/index.js index 33f2b3d..618388e 100644 --- a/src/component/fileItem/index.js +++ b/src/component/fileItem/index.js @@ -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); diff --git a/src/component/fileItem/view.js b/src/component/fileItem/view.js index e10cde6..5de069b 100644 --- a/src/component/fileItem/view.js +++ b/src/component/fileItem/view.js @@ -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, ); }} /> diff --git a/src/component/fileListItem/index.js b/src/component/fileListItem/index.js index 4f4e0e5..e4b6756 100644 --- a/src/component/fileListItem/index.js +++ b/src/component/fileListItem/index.js @@ -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( diff --git a/src/component/fileListItem/view.js b/src/component/fileListItem/view.js index 3aae58e..7a6f75b 100644 --- a/src/component/fileListItem/view.js +++ b/src/component/fileListItem/view.js @@ -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, ); }} /> diff --git a/src/component/uriBar/index.js b/src/component/uriBar/index.js index 9320187..5f0ad96 100644 --- a/src/component/uriBar/index.js +++ b/src/component/uriBar/index.js @@ -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); diff --git a/src/component/uriBar/view.js b/src/component/uriBar/view.js index 3666e8a..46554cc 100644 --- a/src/component/uriBar/view.js +++ b/src/component/uriBar/view.js @@ -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); } } diff --git a/src/page/downloads/view.js b/src/page/downloads/view.js index d9b068b..5640d48 100644 --- a/src/page/downloads/view.js +++ b/src/page/downloads/view.js @@ -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)} diff --git a/src/page/file/view.js b/src/page/file/view.js index 81397b2..18d2d31 100644 --- a/src/page/file/view.js +++ b/src/page/file/view.js @@ -117,7 +117,6 @@ class FilePage extends React.PureComponent { StatusBar.setHidden(false); NativeModules.Firebase.setCurrentScreen('File').then(result => { const { setPlayerVisible } = this.props; - setPlayerVisible(false); // reset visible state for all other file pages that may be active DeviceEventEmitter.addListener('onStoragePermissionGranted', this.handleStoragePermissionGranted); DeviceEventEmitter.addListener('onStoragePermissionRefused', this.handleStoragePermissionRefused); @@ -885,6 +884,7 @@ class FilePage extends React.PureComponent { position, purchaseUri, pushDrawerStack, + setPlayerVisible, thumbnail, title, viewCount, @@ -1274,6 +1274,7 @@ class FilePage extends React.PureComponent { null, false, fullChannelUri, + setPlayerVisible, ); }} /> diff --git a/src/utils/helper.js b/src/utils/helper.js index 9715173..380a7d7 100644 --- a/src/utils/helper.js +++ b/src/utils/helper.js @@ -56,6 +56,8 @@ export function dispatchNavigateToUri(dispatch, nav, uri, isNavigatingBack, full dispatch(doPushDrawerStack(uri)); } + 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]; @@ -112,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; } @@ -134,6 +136,10 @@ 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') { @@ -171,7 +177,7 @@ export function navigateBack(navigation, drawerStack, popDrawerStack, setPlayerV 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;