aMarCruz / react-native-text-size

Measure text accurately before laying it out and get font information from your App.
BSD 2-Clause "Simplified" License
405 stars 95 forks source link

Cannot read property 'measure' of undefined #9

Closed SaeedZhiany closed 6 years ago

SaeedZhiany commented 6 years ago

here is my code:

import rnTextSize, { TSFontSpecs } from 'react-native-text-size'
.
.
.
function renderedTextSize(text: string, size: number = 14, fontFamily: string = 'moein') {

  const dimension = {
    width: 0,
    height: 0,
  };
  const fontSpecs: TSFontSpecs = {
    fontFamily: fontFamily,
    fontSize: size,
  };

  rnTextSize.measure({
    text,             // text to measure, can include symbols
    ...fontSpecs,     // RN font specification
  }).then(result=> {
    dimension.width = result.width;
    dimension.height = result.height;
  });

  return dimension;
}

when I try to call the function, I get this error message, Cannot read property 'measure' of undefined. why should rnTextSize be undefined when I import it from library?

SaeedZhiany commented 6 years ago

I change rnTextSize to TextSize and manually link project to android and problem has been fixed.