MesureText 文本高度测量工具

API兼容性:
QRN:v3.7.0
iOS:80011161
Android:60001224

MesureText 根据输入信息来测量文本对应的实际高度

引入

import { MeasureText } from 'qunar-react-native';

API

MeasureText.heights (opt)
  opti: {
    texts: ['xxx','xxx','xxx'],   // 要测量的文本
    widths: [width, width, width], // 文本渲染时实际的行宽
    fontSizes: [18, 15, 12], // 三个文本对应的字体大小
    fontFamilies: ['Helvetica','Helvetica','Helvetica'], // 三个文本对应的字体类型
    texdtPaddings: [{paddingTop:5, paddingLeft:20, paddingBottom:5, paddingRight:20},   
                     {....}, // 文本的 padding,注意关键字不能变(paddingXXX)
                     {....}]
  }

注意 opti 中各项参数均为必须参数,且每个参数的数组长度要一一对应(如下例三个文本,即每项属性均为三个),该 Api 需要通过 Promise 语法进行调用。

使用说明

import { MesureText } from 'qunar-react-native';

const heights =  MeasureText.heights({
      texts: ['那黑的终点可有光,那夜的尽头可会亮,那成名在望,会有希望,或者是,无知的狂妄',
      '那黑的终点可有光,那夜的尽头可会亮,那成名在望,会有希望,或者是,无知的狂妄',
      '那黑的终点可有光'],
      widths: [width,width,width], // 宽度需要用户自行输入,为文本输入的实际行宽
      fontSizes: [18,15,12],
      fontFamilies:['Helvetica','Helvetica','Helvetica'],
      textPaddings:[{paddingTop:5, paddingLeft:20, paddingBottom:5, paddingRight:20},
      {paddingTop:5, paddingLeft:20, paddingBottom:5, paddingRight:20},
      {paddingTop:5, paddingLeft:20, paddingBottom:5, paddingRight:20}],
  })
.then(heights => {alert(heights)})
.catch(function(error) {
  alert('There has been a problem with your fetch operation: ' + error.message);
  throw error;
});