1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-11-28 03:08:30 +00:00

Rewrited navigation rendering

This commit is contained in:
Vladimir Volek 2018-08-16 18:38:57 +02:00
parent 503ba7eaab
commit d88f5b7b98
2 changed files with 92 additions and 85 deletions

View File

@ -71,6 +71,7 @@ RowAccount.propTypes = {
const AccountMenu = (props: Props): ?React$Element<string> => { const AccountMenu = (props: Props): ?React$Element<string> => {
const selected = props.wallet.selectedDevice; const selected = props.wallet.selectedDevice;
console.warn('selected', selected);
if (!selected) return null; if (!selected) return null;
const { location } = props.router; const { location } = props.router;

View File

@ -1,115 +1,121 @@
/* @flow */ /* @flow */
import * as React from 'react'; import React, { Component } from 'react';
import PropTypes from 'prop-types';
import colors from 'config/colors';
import { TransitionGroup, CSSTransition } from 'react-transition-group'; import { TransitionGroup, CSSTransition } from 'react-transition-group';
import styled from 'styled-components'; import styled from 'styled-components';
import type { TrezorDevice } from 'flowtype'; import type { TrezorDevice } from 'flowtype';
import { import {
AccountMenu, AccountMenu, CoinMenu, DeviceSelect, DeviceDropdown,
CoinMenu,
DeviceSelect,
DeviceDropdown,
} from './NavigationMenu'; } from './NavigationMenu';
import StickyContainer from './StickyContainer'; import StickyContainer from './StickyContainer';
import type { Props } from './common';
type TransitionMenuProps = {
animationType: string;
children?: React.Node;
}
const TransitionGroupWrapper = styled(TransitionGroup)` const TransitionGroupWrapper = styled(TransitionGroup)`
width: 640px; width: 640px;
`; `;
const TransitionContentWrapper = styled.div` const TransitionContentWrapper = styled.div`
width: 320px; width: 320px;
display: inline-block; display: inline-block;
vertical-align: top; vertical-align: top;
`; `;
const TransitionMenu = (props: TransitionMenuProps): React$Element<TransitionGroup> => { const StickyBottom = styled.div`
return ( position: fixed;
<TransitionGroupWrapper component="div" className="transition-container"> bottom: 0;
<CSSTransition background: ${colors.MAIN};
key={props.animationType} border-right: 1px solid ${colors.DIVIDER};
onExit={() => { window.dispatchEvent(new Event('resize')); }} `;
onExited={() => window.dispatchEvent(new Event('resize'))}
in
out
classNames={props.animationType}
appear={false}
timeout={300}
>
<TransitionContentWrapper>
{props.children}
</TransitionContentWrapper>
</CSSTransition>
</TransitionGroupWrapper>
);
};
const MenuWrapper = styled.div``;
const LeftNavigation = (props: Props): React$Element<typeof StickyContainer | string> => { const Help = styled.div``;
const selected: ?TrezorDevice = props.wallet.selectedDevice;
const { location } = props.router;
if (location.pathname === '/' || !selected) return (<aside />); class LeftNavigation extends Component {
constructor(props) {
let menu = <section />; super(props);
this.state = {
let shouldRenderDeviceSelection = false; animationType: null,
// let shouldRenderCoins = false; shouldRenderDeviceSelection: false,
// let shouldRenderAccounts = false; };
let animationType = '';
if (props.deviceDropdownOpened) {
shouldRenderDeviceSelection = true;
// menu = <DeviceDropdown {...props} />;
} else if (location.state.network) {
// shouldRenderAccounts = true;
shouldRenderDeviceSelection = false;
animationType = 'slide-left';
// menu = (
// <TransitionMenu animationType="slide-left">
// <AccountMenu {...props} />
// </TransitionMenu>
// );
} else if (selected.features && !selected.features.bootloader_mode && selected.features.initialized) {
// shouldRenderCoins = true;
shouldRenderDeviceSelection = false;
animationType = 'slide-right';
// menu = (
// <TransitionMenu animationType="slide-right">
// <CoinMenu {...props} />
// </TransitionMenu>
// );
} }
return ( componentWillReceiveProps() {
<StickyContainer location={location.pathname} deviceSelection={props.deviceDropdownOpened}> const { selectedDevice } = this.props.wallet;
<DeviceSelect {...props} /> const hasFeatures = selectedDevice && selectedDevice.features;
{/* { menu } */}
{shouldRenderDeviceSelection ? ( if (this.props.deviceDropdownOpened) {
<DeviceDropdown {...props} /> this.setState({ shouldRenderDeviceSelection: true });
) : ( } else if (this.props.location.network) {
<TransitionMenu this.setState({
animationType={animationType} shouldRenderDeviceSelection: false,
animationType: 'slide-left',
});
} else if (selectedDevice && hasFeatures && !selectedDevice.features.bootloader_mode && selectedDevice.features.initialized) {
this.setState({
shouldRenderDeviceSelection: false,
animationType: 'slide-right',
});
}
}
// TODO: refactor to transition component for reuse of transitions
getMenuTransition(children) {
return (
<TransitionGroupWrapper component="div" className="transition-container">
<CSSTransition
key={this.state.animationType}
onExit={() => { window.dispatchEvent(new Event('resize')); }}
onExited={() => window.dispatchEvent(new Event('resize'))}
in
out
classNames={this.state.animationType}
appear={false}
timeout={300}
> >
{animationType === 'slide-left' && <AccountMenu key="accounts" {...props} />} <TransitionContentWrapper>
{animationType === 'slide-right' && <CoinMenu key="coins" {...props} />} {children}
</TransitionMenu> </TransitionContentWrapper>
)} </CSSTransition>
</TransitionGroupWrapper>);
}
shouldRenderAccounts() {
return !this.state.shouldRenderDeviceSelection && this.state.animationType === 'slide-left';
}
<div className="sticky-bottom"> shouldRenderCoins() {
<div className="help"> return !this.state.shouldRenderDeviceSelection && this.state.animationType === 'slide-right';
<a href="https://trezor.io/support/" target="_blank" rel="noreferrer noopener">Need help?</a> }
</div>
</div> render() {
</StickyContainer> return (
); <StickyContainer
location={this.props.location.pathname}
deviceSelection={this.props.deviceDropdownOpened}
>
<DeviceSelect {...this.props} />
<MenuWrapper>
{this.state.shouldRenderDeviceSelection && this.getMenuTransition(<DeviceDropdown {...this.props} />) }
{/* {this.shouldRenderAccounts && <AccountMenu key="accounts" {...this.props} />} */}
{this.shouldRenderCoins && <CoinMenu key="coins" {...this.props} />}
</MenuWrapper>
<StickyBottom>
<Help className="help">
<a href="https://trezor.io/support/" target="_blank" rel="noreferrer noopener">Need help?</a>
</Help>
</StickyBottom>
</StickyContainer>
);
}
}
LeftNavigation.propTypes = {
selectedDevice: PropTypes.object,
wallet: PropTypes.object,
deviceDropdownOpened: PropTypes.bool,
}; };
export default LeftNavigation; export default LeftNavigation;