Add appbar fade on focus view.

This commit is contained in:
Timothy Farrell 2018-01-04 16:47:34 -06:00
parent 89b3159c12
commit 3d66205755
2 changed files with 80 additions and 28 deletions

View File

@ -9,7 +9,7 @@ import { CLICKABLE } from '../styles.js';
let seq = 0; let seq = 0;
export function AppBarView(vm, params, key, opts) { export function AppBarView(vm, params, key, opts) {
const stateStack = container([], arr => arr.length); const stateStack = container([], arr => arr.length && arr[0]._seq);
const companionScrollTop = prop(0); const companionScrollTop = prop(0);
const currentState = computed(stack => stack[0] || {}, [stateStack]); const currentState = computed(stack => stack[0] || {}, [stateStack]);
@ -51,9 +51,16 @@ export function AppBarView(vm, params, key, opts) {
} }
} }
function replaceState(newState) {
companionScrollTop(0);
stateStack._.shift();
stateStack.unshift(Object.assign({ _seq: seq++ }, newState));
}
opts.appbar = { opts.appbar = {
pushState, pushState,
popState, popState,
replaceState,
companionScrollTop companionScrollTop
}; };
@ -88,7 +95,8 @@ const appBarContainer = styled({
zIndex: 1000, zIndex: 1000,
display: 'flex', display: 'flex',
alignItems: 'center', alignItems: 'center',
width: '100%' width: '100%',
transition: 'opacity .13s cubic-bezier(0.0,0.0,0.2,1)'
}); });
const upButtonContainer = styled( const upButtonContainer = styled(

View File

@ -25,6 +25,8 @@ export function FocusView(vm, params, key, { appbar, appbarView }) {
const { body } = document; const { body } = document;
const nextLink = prop(); const nextLink = prop();
const prevLink = prop(); const prevLink = prop();
const mouseActive = prop(true);
let mouseMoveTimeout = null;
const imageStyle = computed( const imageStyle = computed(
({ width: iw, height: ih }, { width: vw, height: vh }) => { ({ width: iw, height: ih }, { width: vw, height: vh }) => {
@ -49,6 +51,17 @@ export function FocusView(vm, params, key, { appbar, appbarView }) {
}, },
[doc, fullViewportSize] [doc, fullViewportSize]
); );
const appbarState = computed(
mA => ({
title: '',
actions: renderAppBarButtons,
style: { position: 'fixed', opacity: mA ? 1 : 0 },
up: {
navigateTo: 'home'
}
}),
[mouseActive]
);
function navBack() { function navBack() {
appbar.popState('home'); appbar.popState('home');
@ -61,6 +74,25 @@ export function FocusView(vm, params, key, { appbar, appbarView }) {
} }
} }
const mouseLeave = () => {
mouseActive(false);
};
const mouseMove = () => {
if (mouseMoveTimeout !== null) {
clearTimeout(mouseMoveTimeout);
}
mouseMoveTimeout = setTimeout(mouseLeave, 3000);
mouseActive(true);
};
const mouseClick = () => {
if (mouseMoveTimeout !== null) {
clearTimeout(mouseMoveTimeout);
}
mouseActive(!mouseActive());
};
function renderAppBarButtons() { function renderAppBarButtons() {
return [ return [
trashButtonContainer( trashButtonContainer(
@ -78,10 +110,13 @@ export function FocusView(vm, params, key, { appbar, appbarView }) {
} }
// Set the appbar title. // Set the appbar title.
appbar.pushState({ appbar.pushState({
title: '', title: '',
actions: renderAppBarButtons, actions: renderAppBarButtons,
style: { position: 'fixed' }, style: {
position: 'fixed'
},
up: { up: {
navigateTo: 'home' navigateTo: 'home'
} }
@ -94,6 +129,7 @@ export function FocusView(vm, params, key, { appbar, appbarView }) {
doc, doc,
nextLink, nextLink,
prevLink, prevLink,
() => appbarState.subscribe(appbar.replaceState),
// Look for our image and set it. // Look for our image and set it.
() => () =>
id.subscribe(async _id => { id.subscribe(async _id => {
@ -128,31 +164,39 @@ export function FocusView(vm, params, key, { appbar, appbarView }) {
return Overlay('Loading...'); return Overlay('Loading...');
} }
return focusContainer({ class: 'focus' }, [ return focusContainer(
iv(appbarView), {
focusContent([ class: 'focus',
prevLink() onmousemove: mouseMove,
? prevClickZone({ href: prevLink() }, [ onmouseleave: mouseLeave,
Icon({ onclick: mouseClick
name: 'chevron_left', },
size: 0.75 [
}) iv(appbarView),
]) focusContent([
: null, prevLink()
AttachmentImageView({ ? prevClickZone({ href: prevLink() }, [
src: _id ? doc().sizes.full : null, Icon({
style: imageStyle name: 'chevron_left',
}), size: 0.75
nextLink() })
? nextClickZone({ href: nextLink() }, [ ])
Icon({ : null,
name: 'chevron_right', AttachmentImageView({
size: 0.75 src: _id ? doc().sizes.full : null,
}) style: imageStyle
]) }),
: null nextLink()
]) ? nextClickZone({ href: nextLink() }, [
]); Icon({
name: 'chevron_right',
size: 0.75
})
])
: null
])
]
);
}; };
} }