react-native-text-size icon indicating copy to clipboard operation
react-native-text-size copied to clipboard

Error in measure: Missing required text

Open kirtishjain9 opened this issue 5 years ago • 1 comments

Hi,

I'm getting following error when try this library to calculate height of text in iOS:

'Error in measure:', { [Error: Missing required text.] framesToPop: 1, code: 'E_MISSING_TEXT', domain: 'RCTErrorDomain', userInfo: null}

My code snippet: for JS - HeightMeasurementFromText.js

import React, { Component } from 'react'; import { Platform } from 'react-native';

import RNTextSize, { TSFontSpecs } from 'react-native-text-size';

const fontSpecs: TSFontSpecs = { fontFamily: (Platform.OS === 'ios' ? 'Proxima Nova' : 'Proxima Nova Bold'), fontWeight: (Platform.OS === 'ios' ? 'bold' : null), fontSize: 18, }

export const nameTextHeight = async (nameText) => { const dimension = { width: 0, height: 0, }; await RNTextSize.measure({ nameText, width: 170, ...fontSpecs, }).then(result => { console.log('result - ' + JSON.stringify(result)); dimension.width = result.width; dimension.height = result.height; }).catch((err) => { console.log('Error in measure:', err); }); return dimension; };

I'm calling this in my some other JS file as:

import { nameTextHeight } from './library/helper/HeightMeasurementFromText';

let nameTextHgt = nameTextHeight(item.name.toUpperCase());

My Environment variables are:

"react": "16.8.3", "react-native": "^0.59.9", "react-native-text-size": "^4.0.0-rc.1",

What's the problem in my code and implementation of your library?

Kindly suggest. Please.

Thanks in advance.

kirtishjain9 avatar Sep 12 '19 10:09 kirtishjain9

The text property is incorrectly named. You changed the text field to nameText. await RNTextSize.measure({ nameText, width: 170, ...fontSpecs, })

Update to await RNTextSize.measure({ text: nameText, width: 170, ...fontSpecs, })

savaughn avatar May 03 '23 17:05 savaughn