@theoplayer/react-native-ui
Version:
A React Native UI for @theoplayer/react-native
29 lines (28 loc) • 1.31 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.usePresentationMode = void 0;
var _react = require("react");
var _reactNativeUi = require("@theoplayer/react-native-ui");
var _reactNativeTheoplayer = require("react-native-theoplayer");
/**
* Returns {@link react-native-theoplayer!THEOplayer.presentationMode | the player's presentationMode}, automatically updating whenever it changes.
*
* This hook must only be used in a component mounted inside a {@link THEOplayerDefaultUi} or {@link UiContainer},
* or alternatively any other component that provides a {@link PlayerContext}.
*
* @group Hooks
*/
const usePresentationMode = () => {
const {
player
} = (0, _react.useContext)(_reactNativeUi.PlayerContext);
const subscribe = (0, _react.useCallback)(callback => {
player?.addEventListener(_reactNativeTheoplayer.PlayerEventType.PRESENTATIONMODE_CHANGE, callback);
return () => player?.removeEventListener(_reactNativeTheoplayer.PlayerEventType.PRESENTATIONMODE_CHANGE, callback);
}, [player]);
return (0, _react.useSyncExternalStore)(subscribe, () => player ? player.presentationMode : _reactNativeTheoplayer.PresentationMode.inline);
};
exports.usePresentationMode = usePresentationMode;
//# sourceMappingURL=usePresentationMode.js.map