get size of a view in react native

Solutions on MaxInterview for get size of a view in react native by the best coders in the world

showing results for - "get size of a view in react native"
Carla
01 Oct 2016
1import React, { Component } from 'react';
2import {
3  AppRegistry,
4  StyleSheet,
5  Text,
6  View,
7  Image
8} from 'react-native';
9
10export default class Comp extends Component {
11
12  find_dimesions(layout){
13    const {x, y, width, height} = layout;
14    console.warn(x);
15    console.warn(y);
16    console.warn(width);
17    console.warn(height);
18  }
19  render() {
20    return (
21      <View onLayout={(event) => { this.find_dimesions(event.nativeEvent.layout) }} style={styles.container}>
22        <Text style={styles.welcome}>
23          Welcome to React Native!
24        </Text>
25        <Text style={styles.instructions}>
26          To get started, edit index.android.js
27        </Text>
28        <Text style={styles.instructions}>
29          Double tap R on your keyboard to reload,{'\n'}
30          Shake or press menu button for dev menu
31        </Text>
32      </View>
33    );
34  }
35}
36
37const styles = StyleSheet.create({
38  container: {
39    flex: 1,
40    justifyContent: 'center',
41    alignItems: 'center',
42    backgroundColor: '#F5FCFF',
43  },
44  welcome: {
45    fontSize: 20,
46    textAlign: 'center',
47    margin: 10,
48  },
49  instructions: {
50    textAlign: 'center',
51    color: '#333333',
52    marginBottom: 5,
53  },
54});
55
56AppRegistry.registerComponent('Comp', () => Comp);
57