1
0
mirror of https://github.com/trezor/trezor-wallet synced 2025-01-28 00:41:08 +00:00

set minHeight to fix rendering of devicemenu for unitialized device

This commit is contained in:
slowbackspace 2019-01-22 12:57:10 +01:00
parent 9f190dc993
commit cc41a963cd
2 changed files with 35 additions and 14 deletions

View File

@ -54,6 +54,7 @@ class DeviceMenu extends PureComponent<Props> {
super(props); super(props);
this.mouseDownHandler = this.mouseDownHandler.bind(this); this.mouseDownHandler = this.mouseDownHandler.bind(this);
this.blurHandler = this.blurHandler.bind(this); this.blurHandler = this.blurHandler.bind(this);
this.myRef = React.createRef();
} }
componentDidMount(): void { componentDidMount(): void {
@ -85,6 +86,10 @@ class DeviceMenu extends PureComponent<Props> {
} }
} }
getMenuHeight(): number {
return this.myRef.current ? this.myRef.current.getBoundingClientRect().height : 0;
}
blurHandler(): void { blurHandler(): void {
this.props.toggleDeviceDropdown(false); this.props.toggleDeviceDropdown(false);
} }
@ -118,13 +123,15 @@ class DeviceMenu extends PureComponent<Props> {
return deviceUtils.isDeviceAccessible(this.props.wallet.selectedDevice); return deviceUtils.isDeviceAccessible(this.props.wallet.selectedDevice);
} }
myRef: { current: ?HTMLDivElement }
render() { render() {
const { devices, onSelectDevice, forgetDevice } = this.props; const { devices, onSelectDevice, forgetDevice } = this.props;
const { transport } = this.props.connect; const { transport } = this.props.connect;
const { selectedDevice } = this.props.wallet; const { selectedDevice } = this.props.wallet;
return ( return (
<Wrapper> <Wrapper ref={this.myRef}>
{this.showMenuItems() && <MenuItems device={selectedDevice} {...this.props} />} {this.showMenuItems() && <MenuItems device={selectedDevice} {...this.props} />}
{this.showDivider() && <StyledDivider hasBorder textLeft="Other devices" />} {this.showDivider() && <StyledDivider hasBorder textLeft="Other devices" />}
<DeviceList <DeviceList

View File

@ -56,6 +56,7 @@ const Footer = styled.div.attrs(props => ({
const Body = styled.div` const Body = styled.div`
width: 320px; width: 320px;
min-height: ${props => (props.minHeight ? `${props.minHeight}px` : '0px')};
`; `;
const Help = styled.div` const Help = styled.div`
@ -109,45 +110,48 @@ const TransitionMenu = (props: TransitionMenuProps): React$Element<TransitionGro
type State = { type State = {
animationType: ?string; animationType: ?string;
shouldRenderDeviceSelection: boolean;
clicked: boolean; clicked: boolean;
bodyMinHeight: number;
} }
class LeftNavigation extends React.PureComponent<Props, State> { class LeftNavigation extends React.PureComponent<Props, State> {
constructor(props: Props) { constructor(props: Props) {
super(props); super(props);
this.deviceMenuRef = React.createRef();
const { location } = this.props.router; const { location } = this.props.router;
const hasNetwork = location && location.state && location.state.network; const hasNetwork = location && location.state && location.state.network;
this.state = { this.state = {
animationType: hasNetwork ? 'slide-left' : null, animationType: hasNetwork ? 'slide-left' : null,
shouldRenderDeviceSelection: false,
clicked: false, clicked: false,
bodyMinHeight: 0,
}; };
} }
componentDidMount() {
this.recalculateBodyMinHeight();
}
componentWillReceiveProps(nextProps: Props) { componentWillReceiveProps(nextProps: Props) {
const { dropdownOpened, selectedDevice } = nextProps.wallet; const { selectedDevice } = nextProps.wallet;
const { location } = nextProps.router; const { location } = nextProps.router;
const hasNetwork = location && location.state.network; const hasNetwork = location && location.state.network;
const deviceReady = selectedDevice && selectedDevice.features && selectedDevice.mode === 'normal'; const deviceReady = selectedDevice && selectedDevice.features && selectedDevice.mode === 'normal';
if (dropdownOpened) {
this.setState({ shouldRenderDeviceSelection: true });
} else {
this.setState({ shouldRenderDeviceSelection: false });
}
if (hasNetwork) { if (hasNetwork) {
this.setState({ this.setState({
// shouldRenderDeviceSelection: false,
animationType: 'slide-left', animationType: 'slide-left',
}); });
} else { } else {
this.setState({ this.setState({
// shouldRenderDeviceSelection: false,
animationType: deviceReady ? 'slide-right' : null, animationType: deviceReady ? 'slide-right' : null,
}); });
} }
} }
componentDidUpdate() {
this.recalculateBodyMinHeight();
}
shouldRenderAccounts() { shouldRenderAccounts() {
const { selectedDevice } = this.props.wallet; const { selectedDevice } = this.props.wallet;
const { location } = this.props.router; const { location } = this.props.router;
@ -167,6 +171,16 @@ class LeftNavigation extends React.PureComponent<Props, State> {
return this.state.animationType !== 'slide-left'; return this.state.animationType !== 'slide-left';
} }
recalculateBodyMinHeight() {
if (this.deviceMenuRef.current) {
this.setState({
bodyMinHeight: this.deviceMenuRef.current.getMenuHeight(),
});
}
}
deviceMenuRef: { current: any };
render() { render() {
const { props } = this; const { props } = this;
let menu; let menu;
@ -184,7 +198,7 @@ class LeftNavigation extends React.PureComponent<Props, State> {
); );
} }
const { selectedDevice } = props.wallet; const { selectedDevice, dropdownOpened } = props.wallet;
const isDeviceAccessible = deviceUtils.isDeviceAccessible(selectedDevice); const isDeviceAccessible = deviceUtils.isDeviceAccessible(selectedDevice);
return ( return (
<StickyContainer <StickyContainer
@ -219,8 +233,8 @@ class LeftNavigation extends React.PureComponent<Props, State> {
)} )}
{...this.props} {...this.props}
/> />
<Body> <Body minHeight={this.state.bodyMinHeight}>
{this.state.shouldRenderDeviceSelection && <DeviceMenu {...this.props} />} {dropdownOpened && <DeviceMenu ref={this.deviceMenuRef} {...this.props} />}
{isDeviceAccessible && menu} {isDeviceAccessible && menu}
</Body> </Body>
<Footer key="sticky-footer"> <Footer key="sticky-footer">