Advertisement
rodrigofbm

Untitled

May 12th, 2018
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component } from 'react';
  2. import {
  3.     Dimensions
  4. } from 'react-native';
  5. import DeviceInfo from 'react-native-device-info';
  6.  
  7.  
  8. import {
  9.     isPortrait,
  10.     isLandscape,
  11. } from './scalign';
  12.  
  13. class ScalingSize extends Component{
  14.     state = {
  15.         orientation: null,
  16.         devicetype: null,
  17.         width: null,
  18.         inputSize: null,
  19.         scale: null,
  20.         textScale: null
  21.     };
  22.  
  23.     //Guideline sizes are based on standard ~5" screen mobile device
  24.     guidelineBaseWidth = 350;
  25.     guidelineBaseHeight = 680;
  26.  
  27.    
  28.  
  29.     componentWillMount(){
  30.         //alert(DeviceInfo.isTablet())
  31.         // Event Listener for orientation changes
  32.        
  33.         Dimensions.addEventListener('change', () => {
  34.             alert('modou')
  35.             this.setState({
  36.                orientation: isPortrait() ? 'portrait' : 'landscape',
  37.                devicetype: DeviceInfo.isTablet() ? 'tablet' : 'phone',
  38.                width: Dimensions.get('window').width,
  39.            });
  40.  
  41.            if(isPortrait()){
  42.                 this.setState({
  43.                     scale:  DeviceInfo.isTablet() ? 315: 279,
  44.                     textScale: DeviceInfo.isTablet() ? 18: 16,
  45.                 })
  46.            }else{
  47.                 this.setState({
  48.                     scale:  DeviceInfo.isTablet() ? 323 : 306,
  49.                     textScale: DeviceInfo.isTablet() ? 18: 16,
  50.                 })
  51.            }
  52.         });
  53.  
  54.        
  55.         if(isPortrait()){
  56.             this.setState({
  57.                 scale:  DeviceInfo.isTablet() ? 315: 279,
  58.                 textScale: DeviceInfo.isTablet() ? 18: 16,
  59.             })
  60.         }else{
  61.             this.setState({
  62.                 scale:  DeviceInfo.isTablet() ? 323 : 306,
  63.                 textScale: DeviceInfo.isTablet() ? 18: 16,
  64.             })
  65.         }
  66.     }
  67.  
  68.     scale(size) {
  69.         return Dimensions.get('window').width / this.guidelineBaseWidth * size;
  70.     }
  71.  
  72.     verticalScale (size) {
  73.         return Dimensions.get('window').height / this.guidelineBaseHeight * size
  74.     }
  75.  
  76.     moderateScale (size, factor = 0.5) {
  77.        return size + ( this.scale(size) - size ) * factor;
  78.     }  
  79.  
  80. }
  81.  
  82. export default ScalingSize
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement