add fullscreen mode to app state to better handle suspend / resume #82

Merged
akinwale merged 2 commits from fullscreen-navigation-bar into master 2019-11-18 06:50:56 +01:00
7 changed files with 65 additions and 17 deletions
Showing only changes of commit eb18871015 - Show all commits

View file

@ -33,6 +33,7 @@ import {
DeviceEventEmitter, DeviceEventEmitter,
Linking, Linking,
NativeModules, NativeModules,
StatusBar,
TextInput, TextInput,
ToastAndroid, ToastAndroid,
} from 'react-native'; } from 'react-native';
@ -50,7 +51,7 @@ import {
selectHashChanged, selectHashChanged,
selectUser, selectUser,
} from 'lbryinc'; } from 'lbryinc';
import { makeSelectClientSetting } from 'redux/selectors/settings'; import { makeSelectClientSetting, selectFullscreenMode } from 'redux/selectors/settings';
import { decode as atob } from 'base-64'; import { decode as atob } from 'base-64';
import { dispatchNavigateBack, dispatchNavigateToUri, transformUrl } from 'utils/helper'; import { dispatchNavigateBack, dispatchNavigateToUri, transformUrl } from 'utils/helper';
import AsyncStorage from '@react-native-community/async-storage'; import AsyncStorage from '@react-native-community/async-storage';
@ -435,6 +436,26 @@ class AppWithNavigationState extends React.Component {
if (backgroundPlayEnabled || NativeModules.BackgroundMedia) { if (backgroundPlayEnabled || NativeModules.BackgroundMedia) {
NativeModules.BackgroundMedia.hidePlaybackNotification(); NativeModules.BackgroundMedia.hidePlaybackNotification();
} }
// check fullscreen mode and show / hide navigation bar accordingly
this.checkFullscreenMode();
}
};
checkFullscreenMode = () => {
const { fullscreenMode } = this.props;
StatusBar.setHidden(fullscreenMode);
if (fullscreenMode) {
// fullscreen, so change orientation to landscape mode
NativeModules.ScreenOrientation.lockOrientationLandscape();
// hide the navigation bar (on devices that have the soft navigation bar)
NativeModules.UtilityModule.hideNavigationBar();
} else {
// Switch back to portrait mode when the media is not fullscreen
NativeModules.ScreenOrientation.lockOrientationPortrait();
// hide the navigation bar (on devices that have the soft navigation bar)
NativeModules.UtilityModule.showNavigationBar();
} }
}; };
@ -489,6 +510,7 @@ const mapStateToProps = state => ({
emailVerifyErrorMessage: selectEmailVerifyErrorMessage(state), emailVerifyErrorMessage: selectEmailVerifyErrorMessage(state),
showNsfw: makeSelectClientSetting(SETTINGS.SHOW_NSFW)(state), showNsfw: makeSelectClientSetting(SETTINGS.SHOW_NSFW)(state),
user: selectUser(state), user: selectUser(state),
fullscreenMode: selectFullscreenMode(state),
}); });
export default connect(mapStateToProps)(AppWithNavigationState); export default connect(mapStateToProps)(AppWithNavigationState);

View file

@ -64,6 +64,8 @@ const Constants = {
ACTION_CLEAR_PUBLISH_FORM_STATE: 'CLEAR_PUBLISH_FORM_STATE', ACTION_CLEAR_PUBLISH_FORM_STATE: 'CLEAR_PUBLISH_FORM_STATE',
ACTION_CLEAR_CHANNEL_FORM_STATE: 'CLEAR_CHANNEL_FORM_STATE', ACTION_CLEAR_CHANNEL_FORM_STATE: 'CLEAR_CHANNEL_FORM_STATE',
ACTION_FULLSCREEN_MODE_TOGGLED: 'FULLSCREEN_MODE_TOGGLED',
ORIENTATION_HORIZONTAL: 'horizontal', ORIENTATION_HORIZONTAL: 'horizontal',
ORIENTATION_VERTICAL: 'vertical', ORIENTATION_VERTICAL: 'vertical',

View file

@ -42,6 +42,7 @@ import {
doStopDownloadingFile, doStopDownloadingFile,
} from 'redux/actions/file'; } from 'redux/actions/file';
import { doPopDrawerStack, doSetPlayerVisible } from 'redux/actions/drawer'; import { doPopDrawerStack, doSetPlayerVisible } from 'redux/actions/drawer';
import { doToggleFullscreenMode } from 'redux/actions/settings';
import { selectDrawerStack } from 'redux/selectors/drawer'; import { selectDrawerStack } from 'redux/selectors/drawer';
import FilePage from './view'; import FilePage from './view';
@ -96,6 +97,7 @@ const perform = dispatch => ({
startDownload: (uri, outpoint, fileInfo) => dispatch(doStartDownload(uri, outpoint, fileInfo)), startDownload: (uri, outpoint, fileInfo) => dispatch(doStartDownload(uri, outpoint, fileInfo)),
updateDownload: (uri, outpoint, fileInfo, progress) => dispatch(doUpdateDownload(uri, outpoint, fileInfo, progress)), updateDownload: (uri, outpoint, fileInfo, progress) => dispatch(doUpdateDownload(uri, outpoint, fileInfo, progress)),
completeDownload: (uri, outpoint, fileInfo) => dispatch(doCompleteDownload(uri, outpoint, fileInfo)), completeDownload: (uri, outpoint, fileInfo) => dispatch(doCompleteDownload(uri, outpoint, fileInfo)),
toggleFullscreenMode: mode => dispatch(doToggleFullscreenMode(mode)),
}); });
export default connect( export default connect(

View file

@ -215,25 +215,25 @@ class FilePage extends React.PureComponent {
} }
handleFullscreenToggle = mode => { handleFullscreenToggle = mode => {
const { toggleFullscreenMode } = this.props;
this.setState({ fullscreenMode: mode }); this.setState({ fullscreenMode: mode });
toggleFullscreenMode(mode);
StatusBar.setHidden(mode); StatusBar.setHidden(mode);
if (NativeModules.ScreenOrientation) {
if (mode) { if (mode) {
// fullscreen, so change orientation to landscape mode // fullscreen, so change orientation to landscape mode
NativeModules.ScreenOrientation.lockOrientationLandscape(); NativeModules.ScreenOrientation.lockOrientationLandscape();
if (NativeModules.UtilityModule) {
// hide the navigation bar (on devices that use have soft navigation bar) // hide the navigation bar (on devices that have the soft navigation bar)
NativeModules.UtilityModule.hideNavigationBar(); NativeModules.UtilityModule.hideNavigationBar();
}
} else { } else {
// Switch back to portrait mode when the media is not fullscreen // Switch back to portrait mode when the media is not fullscreen
NativeModules.ScreenOrientation.lockOrientationPortrait(); NativeModules.ScreenOrientation.lockOrientationPortrait();
if (NativeModules.UtilityModule) {
// hide the navigation bar (on devices that use have soft navigation bar) // hide the navigation bar (on devices that have the soft navigation bar)
NativeModules.UtilityModule.showNavigationBar(); NativeModules.UtilityModule.showNavigationBar();
} }
}
}
}; };
kauffj commented 2019-11-15 15:41:02 +01:00 (Migrated from github.com)
Review

is mode just a boolean value? maybe call this isFullScreen ?

is `mode` just a boolean value? maybe call this `isFullScreen` ?
onEditPressed = () => { onEditPressed = () => {

View file

@ -38,3 +38,14 @@ export function doSetTimeItem(item) {
}); });
}; };
} }
export function doToggleFullscreenMode(mode) {
return dispatch => {
dispatch({
type: Constants.ACTION_FULLSCREEN_MODE_TOGGLED,
data: {
mode,
},
});
};
}

View file

@ -6,6 +6,7 @@ const defaultState = {
clientSettings: {}, clientSettings: {},
sortByItemName: Constants.SORT_BY_HOT, sortByItemName: Constants.SORT_BY_HOT,
timeItemName: Constants.TIME_WEEK, timeItemName: Constants.TIME_WEEK,
fullscreenMode: false,
}; };
reducers[ACTIONS.CLIENT_SETTING_CHANGED] = (state, action) => { reducers[ACTIONS.CLIENT_SETTING_CHANGED] = (state, action) => {
@ -29,6 +30,11 @@ reducers[Constants.ACTION_TIME_ITEM_CHANGED] = (state, action) =>
timeItemName: action.data.name, timeItemName: action.data.name,
}); });
reducers[Constants.ACTION_FULLSCREEN_MODE_TOGGLED] = (state, action) =>
Object.assign({}, state, {
fullscreenMode: action.data.mode,
});
export default function reducer(state = defaultState, action) { export default function reducer(state = defaultState, action) {
const handler = reducers[action.type]; const handler = reducers[action.type];
if (handler) return handler(state, action); if (handler) return handler(state, action);

View file

@ -34,3 +34,8 @@ export const makeSelectClientSetting = setting =>
export const selectShowNsfw = makeSelectClientSetting(SETTINGS.SHOW_NSFW); export const selectShowNsfw = makeSelectClientSetting(SETTINGS.SHOW_NSFW);
export const selectKeepDaemonRunning = makeSelectClientSetting(SETTINGS.KEEP_DAEMON_RUNNING); export const selectKeepDaemonRunning = makeSelectClientSetting(SETTINGS.KEEP_DAEMON_RUNNING);
export const selectFullscreenMode = createSelector(
selectState,
state => state.fullscreenMode
);