nuke-dimensions
Version:
屏幕参数
66 lines (63 loc) • 1.4 kB
JSX
/** @jsx createElement */
import { createElement, Component, render } from 'rax';
import View from 'nuke-view';
import Text from 'nuke-text';
import Page from 'nuke-page';
import Dimensions from 'nuke-dimensions';
import Button from 'nuke-button';
const styles = {
result: {
height: '480rem',
margin: '30rem',
padding: '10rem',
backgroundColor: '#ffffff',
justifyContent: 'center',
alignItems: 'center',
},
resultText: {
fontSize: '28rem',
},
btns: {
margin: '30rem',
},
btn: {
marginBottom: '30rem',
},
};
const App = class NukeDemoIndex extends Component {
constructor() {
super();
this.state = {
width: 0,
height: 0,
};
}
press = () => {
const { height, width } = Dimensions.getWindowInfo();
this.setState({
width,
height,
});
};
render() {
return (
<Page title="Dimensions">
<View style={styles.result}>
{this.state.width ? (
<Text style={styles.resultText}>
屏幕宽度:
{this.state.width} rem,高度
{this.state.height} rem
</Text>
) : null}
</View>
<View style={styles.btns}>
<Button style={styles.btn} block onPress={this.press} type="primary">
获取
</Button>
</View>
</Page>
);
}
};
render(<App />);