handle opening urls in lite mode

This commit is contained in:
Akinwale Ariwodola 2020-03-10 22:06:29 +01:00
parent 40e2080c52
commit 6116bd3809
9 changed files with 81 additions and 32 deletions

@ -1 +1 @@
Subproject commit 1a5c8b7ba7d4f21c9258361aae216d3c6a3cb20d Subproject commit b7b6c05bd3a61c1cec09a08f1b5c413a68597026

View file

@ -15,7 +15,7 @@
"base-64": "^0.1.0", "base-64": "^0.1.0",
"@expo/vector-icons": "^8.1.0", "@expo/vector-icons": "^8.1.0",
"gfycat-style-urls": "^1.0.3", "gfycat-style-urls": "^1.0.3",
"lbry-redux": "lbryio/lbry-redux#f36b91496b3852e3d032b6d360b14d5fafbc07a9", "lbry-redux": "lbryio/lbry-redux#f6e99498d2bc5b3f07e1e2b6f668a1a48de35047",
"lbryinc": "lbryio/lbryinc#1fc104c2d29d1d3975234c3606e848eaa28e1b6e", "lbryinc": "lbryio/lbryinc#1fc104c2d29d1d3975234c3606e848eaa28e1b6e",
"lodash": ">=4.17.11", "lodash": ">=4.17.11",
"merge": ">=1.2.1", "merge": ">=1.2.1",

View file

@ -39,10 +39,14 @@ class ClaimResultItem extends React.PureComponent {
} }
onPressHandler = () => { onPressHandler = () => {
const { autoplay, navigation, result, setPlayerVisible } = this.props; const { autoplay, navigation, result, urlOpenHandler, setPlayerVisible } = this.props;
const { claimId, name } = result; const { claimId, name } = result;
const url = normalizeURI(`${name}#${claimId}`); const url = normalizeURI(`${name}#${claimId}`);
navigateToUri(navigation, url, { autoplay }, false, url, setPlayerVisible); if (urlOpenHandler) {
urlOpenHandler(url);
} else {
navigateToUri(navigation, url, { autoplay }, false, url, setPlayerVisible);
}
}; };
render() { render() {

View file

@ -15,7 +15,13 @@ const RESULT_SIZE = 16;
const select = (state, props) => ({ const select = (state, props) => ({
claim: makeSelectClaimForUri(props.uri)(state), claim: makeSelectClaimForUri(props.uri)(state),
isSearching: selectIsSearching(state), isSearching: selectIsSearching(state),
recommendedContent: makeSelectResolvedRecommendedContentForUri(props.uri, RESULT_SIZE)(state), recommendedContent: makeSelectResolvedRecommendedContentForUri(
props.uri,
RESULT_SIZE,
props.claimId,
props.claimName,
props.title,
)(state),
resolvingUris: selectResolvingUris(state), resolvingUris: selectResolvingUris(state),
showNsfwContent: selectShowNsfw(state), showNsfwContent: selectShowNsfw(state),
}); });
@ -26,7 +32,4 @@ const perform = dispatch => ({
dispatch(doResolvedSearch(query, RESULT_SIZE, undefined, true, { related_to: claimId }, nsfw)), dispatch(doResolvedSearch(query, RESULT_SIZE, undefined, true, { related_to: claimId }, nsfw)),
}); });
export default connect( export default connect(select, perform)(RelatedContent);
select,
perform,
)(RelatedContent);

View file

@ -22,7 +22,7 @@ export default class RelatedContent extends React.PureComponent {
} }
render() { render() {
const { isSearching, recommendedContent, navigation, uri, fullUri } = this.props; const { isSearching, recommendedContent, navigation, urlOpenHandler, uri, fullUri } = this.props;
return ( return (
<View style={relatedContentStyle.container}> <View style={relatedContentStyle.container}>
@ -33,6 +33,7 @@ export default class RelatedContent extends React.PureComponent {
<ClaimResultItem <ClaimResultItem
style={fileListStyle.item} style={fileListStyle.item}
uri={result ? normalizeURI(`${result.name}#${result.claimId}`) : null} uri={result ? normalizeURI(`${result.name}#${result.claimId}`) : null}
urlOpenHandler={urlOpenHandler}
key={result.claimId} key={result.claimId}
result={result} result={result}
navigation={navigation} navigation={navigation}

View file

@ -187,8 +187,9 @@ class UriBar extends React.PureComponent {
handleNavigationButtonPress = () => { handleNavigationButtonPress = () => {
const { navigation } = this.props; const { navigation } = this.props;
if (!navigation.openDrawer) { if (!navigation.openDrawer) {
Alert.alert(__('Switch to full mode'), Alert.alert(
'This will reload the app in full mode. Do you wish to continue?', __('Stop watching?'),
'The LBRY service is still loading stuff in the background. Would you like to continue?',
[ [
{ text: __('No') }, { text: __('No') },
{ {
@ -196,16 +197,19 @@ class UriBar extends React.PureComponent {
onPress: () => { onPress: () => {
const resetAction = StackActions.reset({ const resetAction = StackActions.reset({
index: 0, index: 0,
actions: [NavigationActions.navigate({ routeName: 'Splash' })], actions: [
NavigationActions.navigate({ routeName: 'Splash', params: { resetUrl: 'lbry://?subscriptions' } }),
],
}); });
navigation.dispatch(resetAction); navigation.dispatch(resetAction);
}, },
}, },
]); ],
);
} else { } else {
navigation.openDrawer(); navigation.openDrawer();
} }
} };
render() { render() {
const { const {

View file

@ -28,6 +28,7 @@ import { decode, formatLbryUrlForWeb, navigateToUri } from 'utils/helper';
import Icon from 'react-native-vector-icons/FontAwesome5'; import Icon from 'react-native-vector-icons/FontAwesome5';
import Constants from 'constants'; // eslint-disable-line node/no-deprecated-api import Constants from 'constants'; // eslint-disable-line node/no-deprecated-api
import uriBarStyle from 'styles/uriBar'; import uriBarStyle from 'styles/uriBar';
import { NavigationActions, StackActions } from 'react-navigation';
// This page will only be used for playing audio / video content from a remote stream URL // This page will only be used for playing audio / video content from a remote stream URL
class LiteFilePage extends React.PureComponent { class LiteFilePage extends React.PureComponent {
@ -40,10 +41,11 @@ class LiteFilePage extends React.PureComponent {
state = { state = {
channelName: null, channelName: null,
channelUrl: null, channelUrl: null,
contentTitle: null, title: null,
fullscreenMode: false, fullscreenMode: false,
playerHeight: null, playerHeight: null,
isLandscape: false, isLandscape: false,
sdkReady: false, // TODO: progressively enable features (e.g. tip) when sdk is ready
showRecommended: false, showRecommended: false,
viewCount: 0, viewCount: 0,
}; };
@ -104,11 +106,32 @@ class LiteFilePage extends React.PureComponent {
NativeModules.UtilityModule.shareUrl(shareUrl); NativeModules.UtilityModule.shareUrl(shareUrl);
}; };
handleOpenUrl = url => {
const { navigation } = this.props;
Alert.alert(
__('Stop watching?'),
'The LBRY service is still loading stuff in the background. Would you like to continue?',
[
{ text: __('No') },
{
text: __('Yes'),
onPress: () => {
const resetAction = StackActions.reset({
index: 0,
actions: [NavigationActions.navigate({ routeName: 'Splash', params: { resetUrl: url } })],
});
navigation.dispatch(resetAction);
},
},
],
);
};
componentDidUpdate() { componentDidUpdate() {
const { navigation } = this.props; const { navigation } = this.props;
const { uri } = navigation.state.params; const { uri } = navigation.state.params;
if (!this.state.contentTitle) { if (!this.state.title) {
const params = parseQueryParams(uri); const params = parseQueryParams(uri);
const { channelUrl, contentTitle } = params; const { channelUrl, contentTitle } = params;
const channelName = channelUrl ? parseURI(decode(channelUrl)).claimName : null; const channelName = channelUrl ? parseURI(decode(channelUrl)).claimName : null;
@ -124,7 +147,7 @@ class LiteFilePage extends React.PureComponent {
render() { render() {
const { navigation, rewardedContentClaimIds } = this.props; const { navigation, rewardedContentClaimIds } = this.props;
const { channelName, channelUrl, title, viewCount } = this.state; const { channelName, channelUrl, title, sdkReady, viewCount } = this.state;
const { uri } = navigation.state.params; const { uri } = navigation.state.params;
const { claimName, claimId } = parseURI(uri); const { claimName, claimId } = parseURI(uri);
const isRewardContent = rewardedContentClaimIds.includes(claimId); const isRewardContent = rewardedContentClaimIds.includes(claimId);
@ -212,10 +235,15 @@ class LiteFilePage extends React.PureComponent {
<Text style={filePageStyle.largeButtonText}>{__('Share')}</Text> <Text style={filePageStyle.largeButtonText}>{__('Share')}</Text>
</TouchableOpacity> </TouchableOpacity>
<TouchableOpacity style={filePageStyle.largeButton} onPress={() => this.setState({ showTipView: true })}> {sdkReady && (
<Icon name={'gift'} size={16} style={filePageStyle.largeButtonIcon} /> <TouchableOpacity
<Text style={filePageStyle.largeButtonText}>{__('Tip')}</Text> style={filePageStyle.largeButton}
</TouchableOpacity> onPress={() => this.setState({ showTipView: true })}
>
<Icon name={'gift'} size={16} style={filePageStyle.largeButtonIcon} />
<Text style={filePageStyle.largeButtonText}>{__('Tip')}</Text>
</TouchableOpacity>
)}
</View> </View>
<View style={filePageStyle.channelRow}> <View style={filePageStyle.channelRow}>
@ -227,9 +255,7 @@ class LiteFilePage extends React.PureComponent {
text={channelName} text={channelName}
numberOfLines={1} numberOfLines={1}
ellipsizeMode={'tail'} ellipsizeMode={'tail'}
onPress={() => { onPress={() => this.handleOpenUrl(channelUrl)}
navigateToUri(navigation, normalizeURI(channelUrl), null, false, null, false);
}}
/> />
)} )}
{!channelName && ( {!channelName && (
@ -243,7 +269,15 @@ class LiteFilePage extends React.PureComponent {
<View onLayout={this.setRelatedContentPosition} /> <View onLayout={this.setRelatedContentPosition} />
{this.state.showRecommended && ( {this.state.showRecommended && (
<RelatedContent navigation={navigation} claimId={claimId} title={title} uri={uri} fullUri={uri} /> <RelatedContent
navigation={navigation}
claimId={claimId}
claimName={claimName}
title={title}
urlOpenHandler={this.handleOpenUrl}
uri={uri}
fullUri={uri}
/>
)} )}
</ScrollView> </ScrollView>
</View> </View>

View file

@ -338,19 +338,22 @@ class SplashScreen extends React.PureComponent {
componentDidMount() { componentDidMount() {
NativeModules.Firebase.track('app_launch', null); NativeModules.Firebase.track('app_launch', null);
NativeModules.Firebase.setCurrentScreen('Splash'); NativeModules.Firebase.setCurrentScreen('Splash');
const { navigation } = this.props;
const { resetUrl } = navigation.state.params;
const isResetUrlSet = !!resetUrl;
this.props.fetchRewardedContent(); this.props.fetchRewardedContent();
Linking.getInitialURL().then(url => { Linking.getInitialURL().then(url => {
let liteMode; let liteMode;
if (url) { if (url) {
liteMode = url.indexOf('liteMode=1') > -1; liteMode = !isResetUrlSet && url.indexOf('liteMode=1') > -1;
this.setState({ launchUrl: url, liteMode }); this.setState({ launchUrl: resetUrl || url, liteMode });
} }
NativeModules.UtilityModule.getNotificationLaunchTarget().then(target => { NativeModules.UtilityModule.getNotificationLaunchTarget().then(target => {
if (target) { if (target) {
liteMode = target.indexOf('liteMode=1') > -1; liteMode = !isResetUrlSet && target.indexOf('liteMode=1') > -1;
this.setState({ launchUrl: target, liteMode }); this.setState({ launchUrl: resetUrl || target, liteMode });
} }
// Only connect after checking initial launch url / notification launch target // Only connect after checking initial launch url / notification launch target

View file

@ -4591,9 +4591,9 @@ latest-version@^3.0.0:
dependencies: dependencies:
package-json "^4.0.0" package-json "^4.0.0"
lbry-redux@lbryio/lbry-redux#f36b91496b3852e3d032b6d360b14d5fafbc07a9: lbry-redux@lbryio/lbry-redux#f6e99498d2bc5b3f07e1e2b6f668a1a48de35047:
version "0.0.1" version "0.0.1"
resolved "https://codeload.github.com/lbryio/lbry-redux/tar.gz/f36b91496b3852e3d032b6d360b14d5fafbc07a9" resolved "https://codeload.github.com/lbryio/lbry-redux/tar.gz/f6e99498d2bc5b3f07e1e2b6f668a1a48de35047"
dependencies: dependencies:
proxy-polyfill "0.1.6" proxy-polyfill "0.1.6"
reselect "^3.0.0" reselect "^3.0.0"