Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.

Commit 7191f1c

Browse files
Dynamically adjust top padding of balance unit label.
This is to ensure it stays level with the balance itself.
1 parent 210e168 commit 7191f1c

File tree

1 file changed

+57
-20
lines changed

1 file changed

+57
-20
lines changed

src/view/home.js

Lines changed: 57 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import React from 'react';
1+
import React, { Component } from 'react';
22
import { StyleSheet, View } from 'react-native';
33
import { observer } from 'mobx-react';
44
import PropTypes from 'prop-types';
55
import Background from '../component/background';
66
import MainContent from '../component/main-content';
77
import { Header, Title } from '../component/header';
8-
import { color } from '../component/style';
8+
import { createStyles, maxWidth } from '../component/media-query';
9+
import { color, breakWidth, smallBreakWidth } from '../component/style';
910
import { H4Text } from '../component/text';
1011
import Icon from '../component/icon';
1112
import ChannelIcon from '../asset/icon/channel';
@@ -17,6 +18,7 @@ import {
1718
SmallBalanceLabel,
1819
} from '../component/label';
1920
import { Button, QrButton, GlasButton, DownButton } from '../component/button';
21+
import { calculateTopPadding } from '../helper';
2022

2123
//
2224
// Home View
@@ -83,7 +85,7 @@ HomeView.propTypes = {
8385
// Balance Display
8486
//
8587

86-
const balanceStyles = StyleSheet.create({
88+
const baseBalanceStyles = {
8789
wrapper: {
8890
flex: 1,
8991
justifyContent: 'center',
@@ -92,26 +94,61 @@ const balanceStyles = StyleSheet.create({
9294
marginTop: 30,
9395
marginBottom: 5,
9496
},
95-
});
97+
};
9698

97-
const BalanceDisplay = ({
98-
depositLabel,
99-
channelBalanceLabel,
100-
unitLabel,
101-
toggleDisplayFiat,
102-
}) => (
103-
<View style={balanceStyles.wrapper}>
104-
<Button onPress={toggleDisplayFiat}>
105-
<BalanceLabel>
106-
<BalanceLabelNumeral>{channelBalanceLabel}</BalanceLabelNumeral>
107-
<BalanceLabelUnit>{unitLabel}</BalanceLabelUnit>
108-
</BalanceLabel>
109-
<H4Text style={balanceStyles.smallLabel}>Chain Deposit</H4Text>
110-
<SmallBalanceLabel unit={unitLabel}>{depositLabel}</SmallBalanceLabel>
111-
</Button>
112-
</View>
99+
const balanceStyles = createStyles(
100+
baseBalanceStyles,
101+
102+
maxWidth(breakWidth, {
103+
wrapper: {
104+
width: 350,
105+
},
106+
}),
107+
108+
maxWidth(smallBreakWidth, {
109+
wrapper: {
110+
width: 250,
111+
},
112+
})
113113
);
114114

115+
class BalanceDisplay extends Component {
116+
constructor(props) {
117+
super(props);
118+
this.state = {
119+
height: 80,
120+
};
121+
}
122+
123+
render() {
124+
const {
125+
depositLabel,
126+
channelBalanceLabel,
127+
unitLabel,
128+
toggleDisplayFiat,
129+
} = this.props;
130+
return (
131+
<View style={balanceStyles.wrapper}>
132+
<Button onPress={toggleDisplayFiat}>
133+
<BalanceLabel>
134+
<BalanceLabelNumeral>{channelBalanceLabel}</BalanceLabelNumeral>
135+
<BalanceLabelUnit
136+
onLayout={event => {
137+
this.setState({ height: event.nativeEvent.layout.height });
138+
}}
139+
style={{ paddingTop: calculateTopPadding(this.state.height) }}
140+
>
141+
{unitLabel}
142+
</BalanceLabelUnit>
143+
</BalanceLabel>
144+
<H4Text style={balanceStyles.smallLabel}>Chain Deposit</H4Text>
145+
<SmallBalanceLabel unit={unitLabel}>{depositLabel}</SmallBalanceLabel>
146+
</Button>
147+
</View>
148+
);
149+
}
150+
}
151+
115152
BalanceDisplay.propTypes = {
116153
depositLabel: PropTypes.string.isRequired,
117154
channelBalanceLabel: PropTypes.string.isRequired,

0 commit comments

Comments
 (0)