add fullscreen mode to app state to better handle suspend / resume (#82)
* add fullscreen mode to app state to better handle suspend / resume * rename argument mode -> isFullscreen
This commit is contained in:
parent
357be73947
commit
afbb9e1d79
7 changed files with 68 additions and 20 deletions
|
@ -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);
|
||||||
|
|
|
@ -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',
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,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';
|
||||||
|
|
||||||
|
@ -102,6 +103,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(
|
||||||
|
|
|
@ -228,26 +228,26 @@ class FilePage extends React.PureComponent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleFullscreenToggle = mode => {
|
handleFullscreenToggle = isFullscreen => {
|
||||||
this.setState({ fullscreenMode: mode });
|
const { toggleFullscreenMode } = this.props;
|
||||||
StatusBar.setHidden(mode);
|
this.setState({ fullscreenMode: isFullscreen });
|
||||||
if (NativeModules.ScreenOrientation) {
|
toggleFullscreenMode(isFullscreen);
|
||||||
if (mode) {
|
|
||||||
|
StatusBar.setHidden(isFullscreen);
|
||||||
|
|
||||||
|
if (isFullscreen) {
|
||||||
// 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();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
onEditPressed = () => {
|
onEditPressed = () => {
|
||||||
|
|
|
@ -38,3 +38,14 @@ export function doSetTimeItem(item) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function doToggleFullscreenMode(mode) {
|
||||||
|
return dispatch => {
|
||||||
|
dispatch({
|
||||||
|
type: Constants.ACTION_FULLSCREEN_MODE_TOGGLED,
|
||||||
|
data: {
|
||||||
|
mode,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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
|
||||||
|
);
|
||||||
|
|
Loading…
Reference in a new issue