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

Fixed animation loading

This commit is contained in:
Vladimir Volek 2018-08-22 15:45:00 +02:00
parent 88a94ec06e
commit a4d88fb919
3 changed files with 71 additions and 65 deletions

View File

@ -1,4 +1,4 @@
import React from 'react'; import React, { Component } from 'react';
import styled, { css } from 'styled-components'; import styled, { css } from 'styled-components';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import Icon from 'components/Icon'; import Icon from 'components/Icon';
@ -82,17 +82,29 @@ const Dot = styled.div`
height: 10px; height: 10px;
`; `;
const DeviceHeader = ({ class DeviceHeader extends Component {
disabled = false, constructor(props) {
handleOpen, super(props);
status, this.state = {
label, clicked: false,
deviceCount, };
isOpen = false, }
trezorModel,
}) => ( handleClick() {
this.setState({ clicked: true });
if (!this.props.disabled) {
this.props.handleOpen();
}
}
render() {
console.log('cananitem', this.state.clicked);
const {
status, label, deviceCount, isOpen, trezorModel,
} = this.props;
return (
<Wrapper> <Wrapper>
<ClickWrapper onClick={!disabled ? handleOpen : null}> <ClickWrapper onClick={() => this.handleClick()}>
<ImageWrapper> <ImageWrapper>
<Dot color={getStatusColor(status)} /> <Dot color={getStatusColor(status)} />
<TrezorImage status={status} model={trezorModel} /> <TrezorImage status={status} model={trezorModel} />
@ -104,7 +116,8 @@ const DeviceHeader = ({
<IconWrapper> <IconWrapper>
{deviceCount > 1 && <Counter>{deviceCount}</Counter>} {deviceCount > 1 && <Counter>{deviceCount}</Counter>}
<Icon <Icon
isOpen={isOpen} canAnimate={this.state.clicked === true}
isActive={isOpen}
size={25} size={25}
color={colors.TEXT_SECONDARY} color={colors.TEXT_SECONDARY}
icon={icons.ARROW_DOWN} icon={icons.ARROW_DOWN}
@ -113,7 +126,10 @@ const DeviceHeader = ({
</IconWrapper> </IconWrapper>
</ClickWrapper> </ClickWrapper>
</Wrapper> </Wrapper>
); );
}
}
DeviceHeader.propTypes = { DeviceHeader.propTypes = {
deviceCount: PropTypes.number, deviceCount: PropTypes.number,

View File

@ -1,12 +1,11 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import styled, { css, keyframes } from 'styled-components'; import styled, { keyframes } from 'styled-components';
const rotate180up = keyframes` const rotate180up = keyframes`
from { from {
transform: rotate(0deg); transform: rotate(0deg);
} }
to { to {
transform: rotate(180deg); transform: rotate(180deg);
} }
@ -16,50 +15,41 @@ const rotate180down = keyframes`
from { from {
transform: rotate(180deg); transform: rotate(180deg);
} }
to { to {
transform: rotate(0deg); transform: rotate(0deg);
} }
`; `;
const SvgWrapper = styled.svg` const SvgWrapper = styled.svg`
animation: ${props => (props.isActive ? rotate180up : rotate180down)} 0.2s linear 1 forwards; animation: ${props => (props.canAnimate ? (props.isActive ? rotate180up : rotate180down) : null)} 0.2s linear 1 forwards;
`; `;
const Path = styled.path``; const Path = styled.path``;
const Icon = ({ const Icon = ({
icon, size = 32, color = 'black', isActive = false, icon, size = 32, color = 'black', isActive, canAnimate,
}) => { }) => (
const styles = { <SvgWrapper
svg: { canAnimate={canAnimate}
isActive={isActive}
style={{
display: 'inline-block', display: 'inline-block',
verticalAlign: 'middle', verticalAlign: 'middle',
}, }}
path: {
fill: color,
},
};
return (
<SvgWrapper
isOpen={isOpen}
style={styles.svg}
width={`${size}`} width={`${size}`}
height={`${size}`} height={`${size}`}
viewBox="0 0 1024 1024" viewBox="0 0 1024 1024"
> >
<Path <Path
isActive={isActive} isActive={isActive}
style={styles.path} style={{ fill: color }}
d={icon} d={icon}
/> />
</SvgWrapper> </SvgWrapper>
); );
};
Icon.propTypes = { Icon.propTypes = {
canAnimate: PropTypes.bool,
icon: PropTypes.string.isRequired, icon: PropTypes.string.isRequired,
size: PropTypes.number, size: PropTypes.number,
isActive: PropTypes.bool, isActive: PropTypes.bool,

View File

@ -64,7 +64,7 @@ export const DeviceSelect = (props: Props) => {
handleOpen={handleOpen} handleOpen={handleOpen}
label={selected.instanceLabel} label={selected.instanceLabel}
status={getStatus(selected)} status={getStatus(selected)}
deviceCount={deviceCount} deviceCount={devices.length}
isOpen={props.deviceDropdownOpened} isOpen={props.deviceDropdownOpened}
trezorModel={getVersion(selected)} trezorModel={getVersion(selected)}
/> />