Skip to content

Commit

Permalink
add animations + minor peformance improvements
Browse files Browse the repository at this point in the history
fix #213

fix #220

fix #221

fix #188

some progress for #135
  • Loading branch information
btzr-io committed Nov 22, 2019
1 parent b2e1575 commit 7fdcd95
Show file tree
Hide file tree
Showing 35 changed files with 1,463 additions and 1,131 deletions.
2 changes: 1 addition & 1 deletion dist/villain.js

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions examples/demo.css
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,6 @@ body,
display: inline-block;
}

.villain-demo .field select::-ms-expand {
display: none;
}

.villain-demo .instance {
align-self: center;
margin: 0 auto;
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@
"dependencies": {
"clsx": "^1.0.4",
"libarchive.js": "^1.3.0",
"memoize-one": "^5.1.1",
"openseadragon": "^2.4.1",
"prop-types": "^15.7.2",
"react-compound-slider": "^2.3.0",
"react-localization": "^1.0.15"
"react-localization": "^1.0.15",
"react-spring": "^8.0.27"
},
"devDependencies": {
"@babel/core": "^7.4.4",
Expand Down
73 changes: 73 additions & 0 deletions src/components/keyboard.js
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
6 changes: 3 additions & 3 deletions src/components/loader.js
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
61 changes: 32 additions & 29 deletions src/components/menu/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,43 @@ import {
mdiRadioboxMarked,
} from '@mdi/js'

export const CustomSeparator = props => (
<MenuSeparator {...props} className={'villain-menu__separator'} />
)
export const CustomSeparator = React.forwardRef((props, ref) => (
<MenuSeparator {...props} ref={ref} className={'villain-menu__separator'} />
))

export const CustomItem = ({ children, ...props }) => (
<MenuItem as={Button} className={'villain-menu__item'} {...props}>
export const CustomItem = React.forwardRef(({ children, ...props }, ref) => (
<MenuItem as={Button} className={'villain-menu__item'} {...props} ref={ref}>
<div className={'villain-menu__item__content'}>
<div className={'villain-menu__item__label'}>{children}</div>
</div>
</MenuItem>
)
))

export const CustomCheckbox = ({ children, ...props }) => (
<MenuItemCheckbox as={Button} {...props}>
export const CustomCheckbox = React.forwardRef(({ children, ...props }, ref) => (
<MenuItemCheckbox as={Button} {...props} ref={ref}>
<div className={'villain-menu__item__content'}>
<div className={'villain-menu__item__label'}>{children}</div>
<div className={'villain-menu__item__toggler'} />
</div>
</MenuItemCheckbox>
)
))

export const CustomRadio = ({ children, ...props }) => (
export const CustomRadio = React.forwardRef(({ children, ...props }, ref) => (
<MenuItemRadio
as={Button}
icon={props.checked ? mdiRadioboxMarked : mdiRadioboxBlank}
iconSize={'20px'}
{...props}
ref={ref}
>
<div className={'villain-menu__item__content'}>
<div className={'villain-menu__item__label'}>{children}</div>
</div>
</MenuItemRadio>
)
))

export const CustomSubmenu = ({ children, ...props }) => (
<MenuItem {...props} as={Button}>
export const CustomSubmenu = React.forwardRef(({ children, ...props }, ref) => (
<MenuItem {...props} ref={ref} as={Button}>
<div className={'villain-menu__item__content'}>
<div className={'villain-menu__item__label'}>{children}</div>
<Icon
Expand All @@ -62,23 +63,25 @@ export const CustomSubmenu = ({ children, ...props }) => (
/>
</div>
</MenuItem>
)
))

export const MenuHeader = ({ title, closeSubmenu, menuProps, ...props }) => {
return (
<div {...props} className={'villain-menu__header'}>
<CustomItem {...menuProps} icon={mdiChevronLeft} onClick={closeSubmenu}>
{title}
</CustomItem>
<CustomSeparator {...menuProps} style={{ margin: 0 }} />
</div>
)
}
export const MenuHeader = React.forwardRef(
({ title, closeSubmenu, menuProps, ...props }, ref) => {
return (
<div {...props} className={'villain-menu__header'}>
<CustomItem {...menuProps} icon={mdiChevronLeft} onClick={closeSubmenu} ref={ref}>
{title}
</CustomItem>
<CustomSeparator {...menuProps} style={{ margin: 0 }} />
</div>
)
}
)

export const CustomItems = {
item: CustomItem,
radio: CustomRadio,
submenu: CustomSubmenu,
checkbox: CustomCheckbox,
separator: CustomSeparator,
item: React.memo(CustomItem),
radio: React.memo(CustomRadio),
submenu: React.memo(CustomSubmenu),
checkbox: React.memo(CustomCheckbox),
separator: React.memo(CustomSeparator),
}
Loading

0 comments on commit 7fdcd95

Please sign in to comment.