A temporary API for disabling play/pause via the space key (#386)

This commit is contained in:
Aria 2023-02-01 16:11:41 +01:00 committed by GitHub
parent e3a3e0124c
commit 1bac84bbfc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 0 deletions

View file

@ -15,6 +15,10 @@ import getStudio from './getStudio'
import {debounce} from 'lodash-es'
import type Sheet from '@theatre/core/sheets/Sheet'
import type {PaneInstanceId, ProjectId} from '@theatre/shared/utils/ids'
import {
__experimental_disblePlayPauseKeyboardShortcut,
__experimental_enablePlayPauseKeyboardShortcut,
} from './UIRoot/useKeyboardShortcuts'
export interface ITransactionAPI {
/**
@ -390,6 +394,22 @@ export interface IStudio {
* ```
*/
createContentOfSaveFile(projectId: string): Record<string, unknown>
__experimental: {
/**
* Warning: This is an experimental API and will change in the future.
*
* Disables the play/pause keyboard shortcut (spacebar)
* Also see `__experimental_enablePlayPauseKeyboardShortcut()` to re-enable it.
*/
__experimental_disblePlayPauseKeyboardShortcut(): void
/**
* Warning: This is an experimental API and will change in the future.
*
* Disables the play/pause keyboard shortcut (spacebar)
*/
__experimental_enablePlayPauseKeyboardShortcut(): void
}
}
export default class TheatreStudio implements IStudio {
@ -413,6 +433,21 @@ export default class TheatreStudio implements IStudio {
private readonly _cache = new SimpleCache()
__experimental = {
__experimental_disblePlayPauseKeyboardShortcut(): void {
// This is an experimental API to respond to this issue: https://discord.com/channels/870988717190426644/870988717190426647/1067906775602430062
// Ideally we need a coherent way for the user to control keyboard inputs, so we will remove this method in the future.
// Here is the procedure for removing it:
// 1. Replace this code with a `throw new Error("This is experimental method is now deprecated, and here is how to migrate: ...")`
// 2. Then keep it for a few months, and then remove it.
__experimental_disblePlayPauseKeyboardShortcut()
},
__experimental_enablePlayPauseKeyboardShortcut(): void {
// see __experimental_disblePlayPauseKeyboardShortcut()
__experimental_enablePlayPauseKeyboardShortcut()
},
}
/**
* @internal
*/

View file

@ -9,6 +9,15 @@ import type {IPlaybackRange} from '@theatre/core/sequences/Sequence'
import type Sequence from '@theatre/core/sequences/Sequence'
import memoizeFn from '@theatre/shared/utils/memoizeFn'
let playPauseKeyboardShortcutIsEnabled = true
export function __experimental_disblePlayPauseKeyboardShortcut() {
playPauseKeyboardShortcutIsEnabled = false
}
export function __experimental_enablePlayPauseKeyboardShortcut() {
playPauseKeyboardShortcutIsEnabled = true
}
export default function useKeyboardShortcuts() {
const studio = getStudio()
useEffect(() => {
@ -39,6 +48,7 @@ export default function useKeyboardShortcuts() {
!e.altKey &&
!e.ctrlKey
) {
if (!playPauseKeyboardShortcutIsEnabled) return
// Control the playback using the `Space` key
const seq = getSelectedSequence()
if (seq) {