-
-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add animations + minor peformance improvements
- Loading branch information
Showing
35 changed files
with
1,463 additions
and
1,131 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import React from 'react' | ||
import { ReaderContext } from '@/context' | ||
import { getNestedFocus, getInteractionFocus } from '@/lib/use-focus' | ||
import { toggleFullscreen } from '@/lib/full-screen' | ||
|
||
const KeyboardConsumer = React.memo(({ container }) => { | ||
const context = React.useContext(ReaderContext) | ||
|
||
const { | ||
error, | ||
mangaMode, | ||
navigateBackward, | ||
navigateForward, | ||
allowGlobalShortcuts, | ||
allowFullScreen, | ||
} = context | ||
|
||
// Note: We should provide an api to add, define, overwrite key shortcuts | ||
const handleShortcuts = React.useCallback( | ||
event => { | ||
// Check if it should restrict listening for key shortcuts on player focus | ||
if (error || getInteractionFocus()) { | ||
return | ||
} | ||
|
||
if (!allowGlobalShortcuts && !getNestedFocus(container)) { | ||
return | ||
} | ||
|
||
const navigateRight = mangaMode ? navigateBackward : navigateForward | ||
const navigateLeft = mangaMode ? navigateForward : navigateBackward | ||
|
||
switch (event.key) { | ||
// Toggle fullscreen of viewer. | ||
// Note: PreventDefault is used to remove flp shortcut. | ||
case 'f': | ||
event.preventDefault() | ||
toggleFullscreen(container) | ||
break | ||
|
||
// Navigation to next page (previous when in mangaMode) | ||
case 'ArrowRight': | ||
navigateRight() | ||
break | ||
|
||
// Navigation to previous page (next when in mangaMode) | ||
case 'ArrowLeft': | ||
navigateLeft() | ||
break | ||
} | ||
}, | ||
[ | ||
allowFullScreen, | ||
allowGlobalShortcuts, | ||
mangaMode, | ||
navigateBackward, | ||
navigateForward, | ||
container, | ||
] | ||
) | ||
|
||
React.useEffect(() => { | ||
document.addEventListener('keydown', handleShortcuts) | ||
|
||
return () => { | ||
document.removeEventListener('keydown', handleShortcuts) | ||
} | ||
}, [handleShortcuts]) | ||
|
||
return null | ||
}) | ||
|
||
export default KeyboardConsumer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import React from 'react' | ||
|
||
const Loader = ({ id }) => ( | ||
const Loader = React.memo(({ id }) => ( | ||
<div className="villain-overlay" id={id}> | ||
<div className="villain-loader-indicator" /> | ||
</div> | ||
) | ||
)) | ||
|
||
export default React.memo(Loader) | ||
export default Loader |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.